View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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   * Document without content test.
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          // create a test folder
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              // create and fetch the document
86              ObjectId id = session.createDocument(properties, testFolder, null, versioningState);
87              Document doc = (Document) session.getObject(id, SELECT_ALL_NO_CACHE_OC);
88  
89              // check the new document
90              addResult(checkObject(session, doc, getAllProperties(doc), "New document object spec compliance"));
91  
92              // check the MIME type
93              f = createResult(FAILURE, "The document has no content but a MIME type!", true);
94              assertNull(doc.getContentStreamMimeType(), null, f);
95  
96              // check the content size
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             // delete it
106             doc.delete(true);
107         } finally {
108             // delete the test folder
109             deleteTestFolder();
110         }
111     }
112 }