-
Notifications
You must be signed in to change notification settings - Fork 96
Expand file tree
/
Copy pathCreateFolderRemoteOperationIT.java
More file actions
155 lines (127 loc) · 5.9 KB
/
CreateFolderRemoteOperationIT.java
File metadata and controls
155 lines (127 loc) · 5.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
* Nextcloud Android Library
*
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2019-2023 Tobias Kaminsky <tobias@kaminsky.me>
* SPDX-License-Identifier: MIT
*/
package com.owncloud.android;
import static com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode.FOLDER_ALREADY_EXISTS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import com.nextcloud.test.RandomStringGenerator;
import com.owncloud.android.lib.common.operations.RemoteOperationResult;
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation;
import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation;
import com.owncloud.android.lib.resources.files.RemoveFileRemoteOperation;
import com.owncloud.android.lib.resources.files.model.RemoteFile;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
/**
* Class to test Create Folder Operation
*/
public class CreateFolderRemoteOperationIT extends AbstractIT {
private static final String FOLDER_PATH_BASE = "/testCreateFolder";
private static final int TAG_LENGTH = 10;
private final List<String> mCreatedFolderPaths;
private String mFullPath2FolderBase;
public CreateFolderRemoteOperationIT() {
super();
mCreatedFolderPaths = new ArrayList<>();
}
@Before
public void setUp() {
mCreatedFolderPaths.clear();
mFullPath2FolderBase = baseFolderPath + FOLDER_PATH_BASE;
mCreatedFolderPaths.add(mFullPath2FolderBase);
}
/**
* Test Create Folder
*/
@Test
public void testCreateFolder() {
String remotePath = mFullPath2FolderBase;
mCreatedFolderPaths.add(remotePath);
RemoteOperationResult<String> result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
assertTrue(result.isSuccess());
// Create Subfolder
remotePath = mFullPath2FolderBase + FOLDER_PATH_BASE;
mCreatedFolderPaths.add(remotePath);
result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
assertTrue(result.isSuccess());
}
/**
* Test duplicate Folder
*/
@Test
public void testCreateDuplicateFolder() {
String remotePath = mFullPath2FolderBase + "duplicateFolder";
mCreatedFolderPaths.add(remotePath);
RemoteOperationResult<String> result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
assertTrue(result.isSuccess());
// Create folder again
mCreatedFolderPaths.add(remotePath);
result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
assertFalse(result.isSuccess());
assertEquals(FOLDER_ALREADY_EXISTS, result.getCode());
}
@Test
public void testFileID() {
String remotePath = mFullPath2FolderBase + "/" + RandomStringGenerator.make(TAG_LENGTH);
mCreatedFolderPaths.add(remotePath);
RemoteOperationResult<String> result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
assertTrue(result.isSuccess());
RemoteOperationResult readResult = new ReadFileRemoteOperation(remotePath).execute(client);
assertTrue(readResult.isSuccess());
String remoteId = ((RemoteFile) readResult.getData().get(0)).getRemoteId();
assertEquals(result.getResultData(), remoteId);
}
/**
* Test to create folder with special characters: / \ < > : " | ?
* > oc8.1 no characters are forbidden
*/
@Test
public void testCreateFolderSpecialCharactersOnNewVersion() {
String remotePath = mFullPath2FolderBase + "_<";
RemoteOperationResult<String> result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
assertTrue("Remote path: " + remotePath, result.isSuccess());
remotePath = mFullPath2FolderBase + "_>";
result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
assertTrue("Remote path: " + remotePath, result.isSuccess());
remotePath = mFullPath2FolderBase + "_:";
result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
assertTrue("Remote path: " + remotePath, result.isSuccess());
remotePath = mFullPath2FolderBase + "_\"";
result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
assertTrue("Remote path: " + remotePath, result.isSuccess());
remotePath = mFullPath2FolderBase + "_|";
result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
assertTrue("Remote path: " + remotePath, result.isSuccess());
remotePath = mFullPath2FolderBase + "_?";
result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
assertTrue("Remote path: " + remotePath, result.isSuccess());
remotePath = mFullPath2FolderBase + "_*";
result = new CreateFolderRemoteOperation(remotePath, true).execute(client);
assertTrue("Remote path: " + remotePath, result.isSuccess());
}
@After
public void tearDown() {
Iterator<String> it = mCreatedFolderPaths.iterator();
RemoteOperationResult removeResult;
while (it.hasNext()) {
String path = it.next();
ExistenceCheckRemoteOperation existenceCheckOperation = new ExistenceCheckRemoteOperation(path, false);
RemoteOperationResult result = existenceCheckOperation.execute(client);
if (result.isSuccess()) {
removeResult = new RemoveFileRemoteOperation(path).execute(client);
assertTrue("Error removing folder " + path + ":" + removeResult, removeResult.isSuccess());
}
}
}
}