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 import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.WARNING;
24
25 import java.util.HashMap;
26 import java.util.Map;
27
28 import org.apache.chemistry.opencmis.client.api.Document;
29 import org.apache.chemistry.opencmis.client.api.Folder;
30 import org.apache.chemistry.opencmis.client.api.ObjectId;
31 import org.apache.chemistry.opencmis.client.api.Session;
32 import org.apache.chemistry.opencmis.commons.PropertyIds;
33 import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
34 import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
35 import org.apache.chemistry.opencmis.commons.enums.ContentStreamAllowed;
36 import org.apache.chemistry.opencmis.commons.enums.VersioningState;
37 import org.apache.chemistry.opencmis.tck.CmisTestResult;
38 import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
39
40
41
42
43 public class CreateDocumentWithoutContent extends AbstractSessionTest {
44
45 @Override
46 public void init(Map<String, String> parameters) {
47 super.init(parameters);
48 setName("Create Document without Content Test");
49 setDescription("Creates a document without content and deletes it.");
50 }
51
52 @Override
53 public void run(Session session) {
54 CmisTestResult f;
55
56 String objectTypeId = getDocumentTestTypeId();
57
58 TypeDefinition type = session.getTypeDefinition(objectTypeId);
59 if (!(type instanceof DocumentTypeDefinition)) {
60 addResult(createResult(FAILURE, "Type is not a document type! Type: " + objectTypeId, true));
61 return;
62 }
63
64 DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
65
66 if (docType.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
67 addResult(createResult(SKIPPED,
68 "The test document type does not support documents without content. Test skipped!"));
69 return;
70 }
71
72
73 Folder testFolder = createTestFolder(session);
74
75 try {
76 String name = "nocontent";
77
78 Map<String, Object> properties = new HashMap<String, Object>();
79 properties.put(PropertyIds.NAME, name);
80 properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
81
82 VersioningState versioningState = (Boolean.TRUE.equals(docType.isVersionable()) ? VersioningState.MAJOR
83 : VersioningState.NONE);
84
85
86 ObjectId id = session.createDocument(properties, testFolder, null, versioningState);
87 Document doc = (Document) session.getObject(id, SELECT_ALL_NO_CACHE_OC);
88
89
90 addResult(checkObject(session, doc, getAllProperties(doc), "New document object spec compliance"));
91
92
93 f = createResult(FAILURE, "The document has no content but a MIME type!", true);
94 assertNull(doc.getContentStreamMimeType(), null, f);
95
96
97 if (doc.getContentStreamLength() == 0) {
98 addResult(createResult(WARNING, "The document has no content but the content length is set to 0! "
99 + "The content length shouldn't be set."));
100 } else if (doc.getContentStreamLength() > 0) {
101 addResult(createResult(FAILURE, "The document has no content but the content length is set and >0! "
102 + "(content length: " + doc.getContentStreamLength() + ")"));
103 }
104
105
106 doc.delete(true);
107 } finally {
108
109 deleteTestFolder();
110 }
111 }
112 }