1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.chemistry.opencmis.tck.tests.crud;
20
21 import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.FAILURE;
22 import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.INFO;
23 import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.SKIPPED;
24
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29
30 import org.apache.chemistry.opencmis.client.api.CmisObject;
31 import org.apache.chemistry.opencmis.client.api.Document;
32 import org.apache.chemistry.opencmis.client.api.Folder;
33 import org.apache.chemistry.opencmis.client.api.Session;
34 import org.apache.chemistry.opencmis.commons.PropertyIds;
35 import org.apache.chemistry.opencmis.commons.data.BulkUpdateObjectIdAndChangeToken;
36 import org.apache.chemistry.opencmis.commons.enums.BindingType;
37 import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
38 import org.apache.chemistry.opencmis.tck.CmisTestResult;
39 import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
40
41 public class BulkUpdatePropertiesTest extends AbstractSessionTest {
42
43 private static final String CONTENT = "Bluk update test content.";
44 private static final String NEW_NAME = "bunewname.txt";
45
46 @Override
47 public void init(Map<String, String> parameters) {
48 super.init(parameters);
49 setName("Bulk Update Properties Test");
50 setDescription("Creates a few folders and documents, renames all documents at once, and deletes all created objects.");
51 }
52
53 @Override
54 public void run(Session session) {
55 if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_0) {
56 addResult(createResult(SKIPPED, "Bulk Update Properties is not supported by CMIS 1.0. Test skipped!"));
57 return;
58 }
59
60 CmisTestResult failure = null;
61 int numOfObjects = 20;
62
63
64 Folder testFolder = createTestFolder(session);
65
66 try {
67 Map<String, Folder> folders = new HashMap<String, Folder>();
68 Map<String, Document> documents = new HashMap<String, Document>();
69
70
71 for (int i = 0; i < numOfObjects; i++) {
72 Folder newFolder = createFolder(session, testFolder, "bufolder" + i);
73 folders.put(newFolder.getId(), newFolder);
74 Document newDocument = createDocument(session, newFolder, "budoc" + i + ".txt", CONTENT);
75 documents.put(newDocument.getId(), newDocument);
76 }
77
78
79 List<CmisObject> objects = new ArrayList<CmisObject>(documents.values());
80 Map<String, Object> properties = new HashMap<String, Object>();
81 properties.put(PropertyIds.NAME, NEW_NAME);
82
83 List<BulkUpdateObjectIdAndChangeToken> updatedIds = session.bulkUpdateProperties(objects, properties, null,
84 null);
85
86
87 if (getBinding() == BindingType.WEBSERVICES) {
88
89 addResult(createResult(INFO, "The Web Services binding does not return the updated ids."
90 + " This issue has to be clarified by the CMIS TC and the test to adopted later."));
91 } else {
92 if (updatedIds == null || updatedIds.isEmpty()) {
93 addResult(createResult(FAILURE, "Bulk Update Properties did not update any documents!"));
94 } else {
95 failure = createResult(FAILURE, "Bulk Update Properties did not update all test documents!");
96 addResult(assertEquals(documents.size(), updatedIds.size(), null, failure));
97 }
98 }
99
100
101 for (Folder folder : folders.values()) {
102 List<CmisObject> children = new ArrayList<CmisObject>();
103 for (CmisObject child : folder.getChildren(SELECT_ALL_NO_CACHE_OC)) {
104 children.add(child);
105 }
106
107 if (children.size() != 1) {
108 addResult(createResult(FAILURE,
109 "Test folder should have exactly one child, but it has " + children.size() + "!"));
110 } else {
111 failure = createResult(FAILURE, "Document does not have the new name! Id: "
112 + children.get(0).getId());
113 addResult(assertEquals(NEW_NAME, children.get(0).getName(), null, failure));
114 }
115 }
116
117
118 for (Folder folder : folders.values()) {
119 folder.deleteTree(true, null, true);
120 }
121 } finally {
122
123 deleteTestFolder();
124 }
125
126 }
127 }