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.WARNING;
23
24 import java.util.HashSet;
25 import java.util.Map;
26 import java.util.Set;
27
28 import org.apache.chemistry.opencmis.client.api.CmisObject;
29 import org.apache.chemistry.opencmis.client.api.Document;
30 import org.apache.chemistry.opencmis.client.api.Folder;
31 import org.apache.chemistry.opencmis.client.api.OperationContext;
32 import org.apache.chemistry.opencmis.client.api.Session;
33 import org.apache.chemistry.opencmis.client.util.OperationContextUtils;
34 import org.apache.chemistry.opencmis.commons.PropertyIds;
35 import org.apache.chemistry.opencmis.tck.CmisTestResult;
36 import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
37
38 public class PropertyFilterTest extends AbstractSessionTest {
39
40 private static final String CONTENT = "TCK test content.";
41 private static final String INVALID_PROPERTY = "cmis:tck:thisPropertyDoesNotExist";
42
43 @Override
44 public void init(Map<String, String> parameters) {
45 super.init(parameters);
46 setName("Property Filter Test");
47 setDescription("Tests different property filter combinations for documents and folders.");
48 }
49
50 @Override
51 public void run(Session session) {
52 CmisTestResult f;
53
54
55 OperationContext testContext1 = OperationContextUtils.createMinimumOperationContext();
56 Set<String> testfilter1 = new HashSet<String>(testContext1.getFilter());
57 testfilter1.add(PropertyIds.CONTENT_STREAM_MIME_TYPE);
58 testContext1.setFilter(testfilter1);
59
60
61 OperationContext testContext2 = OperationContextUtils.createMinimumOperationContext();
62 Set<String> testfilter2 = new HashSet<String>(testContext2.getFilter());
63 testfilter2.add(PropertyIds.PATH);
64 testContext2.setFilter(testfilter2);
65
66
67 OperationContext testContext3 = OperationContextUtils.createMinimumOperationContext();
68 Set<String> testfilter3 = new HashSet<String>(testContext3.getFilter());
69 testfilter3.add(INVALID_PROPERTY);
70 testContext3.setFilter(testfilter3);
71
72
73 Folder testFolder = createTestFolder(session);
74
75 try {
76 Document doc = createDocument(session, testFolder, "doc", CONTENT);
77
78 Document doc1 = (Document) session.getObject(doc, testContext1);
79
80
81 f = createResult(FAILURE, "Document should have the property " + PropertyIds.CONTENT_STREAM_MIME_TYPE + "!");
82 addResult(assertNotNull(doc1.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE), null, f));
83 f = createResult(FAILURE, "Document should not have the property " + PropertyIds.PATH + "!");
84 addResult(assertNull(doc1.getProperty(PropertyIds.PATH), null, f));
85 f = createResult(FAILURE, "Document should not have the property " + INVALID_PROPERTY + "!");
86 addResult(assertNull(doc1.getProperty(INVALID_PROPERTY), null, f));
87
88 Document doc2 = (Document) session.getObject(doc, testContext2);
89
90 f = createResult(WARNING, "Document should not have the property " + PropertyIds.CONTENT_STREAM_MIME_TYPE
91 + "!");
92 addResult(assertNull(doc2.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE), null, f));
93 f = createResult(FAILURE, "Document should not have the property " + PropertyIds.PATH + "!");
94 addResult(assertNull(doc2.getProperty(PropertyIds.PATH), null, f));
95 f = createResult(FAILURE, "Document should not have the property " + INVALID_PROPERTY + "!");
96 addResult(assertNull(doc2.getProperty(INVALID_PROPERTY), null, f));
97
98 Document doc3 = (Document) session.getObject(doc, testContext3);
99
100 f = createResult(WARNING, "Document should not have the property" + PropertyIds.CONTENT_STREAM_MIME_TYPE
101 + "!");
102 addResult(assertNull(doc3.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE), null, f));
103 f = createResult(FAILURE, "Document should not have the property" + PropertyIds.PATH + "!");
104 addResult(assertNull(doc3.getProperty(PropertyIds.PATH), null, f));
105 f = createResult(FAILURE, "Document should not have the property" + INVALID_PROPERTY + "!");
106 addResult(assertNull(doc3.getProperty(INVALID_PROPERTY), null, f));
107
108
109 Folder folder1 = (Folder) session.getObject(testFolder, testContext1);
110
111 f = createResult(FAILURE, "Folder should not have the property " + PropertyIds.CONTENT_STREAM_MIME_TYPE
112 + "!");
113 addResult(assertNull(folder1.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE), null, f));
114 f = createResult(WARNING, "Folder should not have the property " + PropertyIds.PATH + "!");
115 addResult(assertNull(folder1.getProperty(PropertyIds.PATH), null, f));
116 f = createResult(FAILURE, "Folder should not have the property " + INVALID_PROPERTY + "!");
117 addResult(assertNull(folder1.getProperty(INVALID_PROPERTY), null, f));
118
119 Folder folder2 = (Folder) session.getObject(testFolder, testContext2);
120
121 f = createResult(FAILURE, "Folder should not have the property " + PropertyIds.CONTENT_STREAM_MIME_TYPE
122 + "!");
123 addResult(assertNull(folder2.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE), null, f));
124 f = createResult(FAILURE, "Folder should have the property " + PropertyIds.PATH + "!");
125 addResult(assertNotNull(folder2.getProperty(PropertyIds.PATH), null, f));
126 f = createResult(FAILURE, "Folder should not have the property " + INVALID_PROPERTY + "!");
127 addResult(assertNull(folder2.getProperty(INVALID_PROPERTY), null, f));
128
129 Folder folder3 = (Folder) session.getObject(testFolder, testContext3);
130
131 f = createResult(FAILURE, "Folder should not have the property " + PropertyIds.CONTENT_STREAM_MIME_TYPE
132 + "!");
133 addResult(assertNull(folder3.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE), null, f));
134 f = createResult(WARNING, "Folder should not have the property " + PropertyIds.PATH + "!");
135 addResult(assertNull(folder3.getProperty(PropertyIds.PATH), null, f));
136 f = createResult(FAILURE, "Folder should not have the property " + INVALID_PROPERTY + "!");
137 addResult(assertNull(folder3.getProperty(INVALID_PROPERTY), null, f));
138
139
140 CmisObject obj1 = testFolder.getChildren(testContext1).iterator().next();
141
142 f = createResult(WARNING, "Child should have the property " + PropertyIds.CONTENT_STREAM_MIME_TYPE + "!");
143 addResult(assertNotNull(obj1.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE), null, f));
144 f = createResult(WARNING, "Child should not have the property " + PropertyIds.PATH + "!");
145 addResult(assertNull(obj1.getProperty(PropertyIds.PATH), null, f));
146 f = createResult(FAILURE, "Child should not have the property " + INVALID_PROPERTY + "!");
147 addResult(assertNull(obj1.getProperty(INVALID_PROPERTY), null, f));
148
149 CmisObject obj2 = testFolder.getChildren(testContext2).iterator().next();
150
151 f = createResult(WARNING, "Child should not have the property " + PropertyIds.CONTENT_STREAM_MIME_TYPE
152 + "!");
153 addResult(assertNull(obj2.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE), null, f));
154 f = createResult(WARNING, "Child should not have the property " + PropertyIds.PATH + "!");
155 addResult(assertNull(obj2.getProperty(PropertyIds.PATH), null, f));
156 f = createResult(FAILURE, "Child should not have the property " + INVALID_PROPERTY + "!");
157 addResult(assertNull(obj2.getProperty(INVALID_PROPERTY), null, f));
158
159 CmisObject obj3 = testFolder.getChildren(testContext3).iterator().next();
160
161 f = createResult(WARNING, "Child should not have the property" + PropertyIds.CONTENT_STREAM_MIME_TYPE + "!");
162 addResult(assertNull(obj3.getProperty(PropertyIds.CONTENT_STREAM_MIME_TYPE), null, f));
163 f = createResult(WARNING, "Child should not have the property" + PropertyIds.PATH + "!");
164 addResult(assertNull(obj3.getProperty(PropertyIds.PATH), null, f));
165 f = createResult(FAILURE, "Child should not have the property" + INVALID_PROPERTY + "!");
166 addResult(assertNull(obj3.getProperty(INVALID_PROPERTY), null, f));
167 } finally {
168
169 deleteTestFolder();
170 }
171 }
172 }