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.versioning;
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.Map;
25  
26  import org.apache.chemistry.opencmis.client.api.CmisObject;
27  import org.apache.chemistry.opencmis.client.api.Document;
28  import org.apache.chemistry.opencmis.client.api.Folder;
29  import org.apache.chemistry.opencmis.client.api.Session;
30  import org.apache.chemistry.opencmis.commons.PropertyIds;
31  import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
32  import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
33  import org.apache.chemistry.opencmis.tck.CmisTestResult;
34  import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
35  
36  public class LatestAccessibleStateIdTest extends AbstractSessionTest {
37  
38      @Override
39      public void init(Map<String, String> parameters) {
40          super.init(parameters);
41          setName("Latest Accessible State ID Test");
42          setDescription("Creates a document and tries to get it with its Latest Accessible State ID.");
43      }
44  
45      @Override
46      public void run(Session session) {
47          CmisTestResult f;
48  
49          try {
50              // create folder and document
51              Folder testFolder = createTestFolder(session);
52              Document doc = createDocument(session, testFolder, "lateststate.txt", "latest state");
53              DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
54  
55              if (!docType.getPropertyDefinitions().containsKey(PropertyIds.LATEST_ACCESSIBLE_STATE_ID)) {
56                  addResult(createResult(SKIPPED,
57                          "Repository does not support the Latest State Identifier feature extension. Test skipped!"));
58                  doc.delete(true);
59                  return;
60              }
61  
62              // check latest accessible state ID
63              f = createResult(FAILURE, "Latest Accessible State ID is not set!");
64              addResult(assertStringNotEmpty(doc.getLatestAccessibleStateId(), null, f));
65  
66              // get document with latest accessible state ID
67              try {
68                  CmisObject latestStateObject = session.getObject(doc.getLatestAccessibleStateId(),
69                          SELECT_ALL_NO_CACHE_OC);
70  
71                  if (latestStateObject instanceof Document) {
72                      f = createResult(FAILURE,
73                              "Latest Accessible State IDs of the orignal and the retrieved document don't match!");
74                      addResult(assertEquals(doc.getLatestAccessibleStateId(),
75                              ((Document) latestStateObject).getLatestAccessibleStateId(), null, f));
76                  } else {
77                      addResult(createResult(FAILURE,
78                              "Object retrieved with the Latest Accessible State ID is not a document!"));
79                  }
80              } catch (CmisObjectNotFoundException onf) {
81                  addResult(createResult(FAILURE, "Document could not be retrieved with the Latest Accessible State ID!"));
82              }
83  
84              doc.delete(true);
85          } finally {
86              // delete the test folder
87              deleteTestFolder();
88          }
89      }
90  }