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.SKIPPED;
23
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 import org.apache.chemistry.opencmis.client.api.CmisObject;
30 import org.apache.chemistry.opencmis.client.api.Folder;
31 import org.apache.chemistry.opencmis.client.api.Item;
32 import org.apache.chemistry.opencmis.client.api.ItemIterable;
33 import org.apache.chemistry.opencmis.client.api.Session;
34 import org.apache.chemistry.opencmis.commons.enums.CmisVersion;
35 import org.apache.chemistry.opencmis.tck.CmisTestResult;
36 import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
37
38
39
40
41 public class CreateAndDeleteItemTest extends AbstractSessionTest {
42
43 @Override
44 public void init(Map<String, String> parameters) {
45 super.init(parameters);
46 setName("Create and Delete Item Test");
47 setDescription("Creates a few items, checks the newly created items and their parent and finally deletes the created items.");
48 }
49
50 @Override
51 public void run(Session session) {
52 if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_0) {
53 addResult(createResult(SKIPPED, "Items are not supported by CMIS 1.0. Test skipped!"));
54 return;
55 }
56
57 if (hasItems(session)) {
58 CmisTestResult f;
59
60 int numOfItems = 20;
61
62
63 Folder testFolder = createTestFolder(session);
64
65 try {
66 Map<String, Item> items = new HashMap<String, Item>();
67
68
69 for (int i = 0; i < numOfItems; i++) {
70 Item newItem = createItem(session, testFolder, "item" + i);
71 items.put(newItem.getId(), newItem);
72 }
73
74
75 ItemIterable<CmisObject> children = testFolder.getChildren(SELECT_ALL_NO_CACHE_OC);
76 List<String> childrenIds = new ArrayList<String>();
77 for (CmisObject child : children) {
78 if (child != null) {
79 childrenIds.add(child.getId());
80 Item item = items.get(child.getId());
81
82 f = createResult(FAILURE, "Item and test folder child don't match! Id: " + child.getId());
83 addResult(assertShallowEquals(item, child, null, f));
84 }
85 }
86
87 f = createResult(FAILURE, "Number of created items does not match the number of existing items!");
88 addResult(assertEquals(numOfItems, childrenIds.size(), null, f));
89
90 for (Item item : items.values()) {
91 if (!childrenIds.contains(item.getId())) {
92 addResult(createResult(FAILURE,
93 "Created item not found in test folder children! Id: " + item.getId()));
94 }
95 }
96
97
98 for (Item item : items.values()) {
99 item.delete(true);
100
101 f = createResult(FAILURE,
102 "Item should not exist anymore but it is still there! Id: " + item.getId());
103 addResult(assertIsFalse(exists(item), null, f));
104 }
105 } finally {
106
107 deleteTestFolder();
108 }
109
110 addResult(createInfoResult("Tested the creation and deletion of " + numOfItems + " items."));
111 } else {
112 addResult(createResult(SKIPPED, "Items not supported. Test skipped!"));
113 }
114 }
115 }