This project has retired. For details please refer to its Attic page.
UpdateSmokeTest xref

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.WARNING;
23  
24  import java.util.HashMap;
25  import java.util.Map;
26  
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.ObjectId;
30  import org.apache.chemistry.opencmis.client.api.Session;
31  import org.apache.chemistry.opencmis.commons.PropertyIds;
32  import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
33  import org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition;
34  import org.apache.chemistry.opencmis.commons.enums.Updatability;
35  import org.apache.chemistry.opencmis.tck.CmisTestResult;
36  import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
37  
38  /**
39   * Copy test.
40   */
41  public class UpdateSmokeTest extends AbstractSessionTest {
42  
43      private static final String NAME1 = "updatetest1.txt";
44      private static final String NAME2 = "updatetest2.txt";
45  
46      @Override
47      public void init(Map<String, String> parameters) {
48          super.init(parameters);
49          setName("Update Smoke Test");
50          setDescription("Creates a document, updates its name and finally deletes it.");
51      }
52  
53      @Override
54      public void run(Session session) {
55          CmisTestResult f;
56  
57          try {
58              // create folders
59              Folder testFolder = createTestFolder(session);
60  
61              // create document
62              Document doc1 = createDocument(session, testFolder, NAME1, "rename me!");
63              Document workDoc = doc1;
64  
65              f = createResult(FAILURE, "Document name doesn't match with given name!");
66              addResult(assertEquals(NAME1, doc1.getName(), null, f));
67  
68              // test if check out is required
69              boolean checkedout = false;
70              DocumentTypeDefinition type = (DocumentTypeDefinition) doc1.getType();
71              PropertyDefinition<?> namePropDef = type.getPropertyDefinitions().get(PropertyIds.NAME);
72              if (namePropDef.getUpdatability() == Updatability.WHENCHECKEDOUT) {
73                  workDoc = (Document) session.getObject(doc1.checkOut(), SELECT_ALL_NO_CACHE_OC);
74                  checkedout = true;
75              }
76  
77              // update
78              Map<String, Object> properties = new HashMap<String, Object>();
79              properties.put(PropertyIds.NAME, NAME2);
80  
81              ObjectId newId = workDoc.updateProperties(properties, false);
82              Document doc2 = (Document) session.getObject(newId, SELECT_ALL_NO_CACHE_OC);
83  
84              addResult(checkObject(session, doc2, getAllProperties(doc2), "Updated document compliance"));
85  
86              f = createResult(FAILURE, "Document name doesn't match updated value!");
87              addResult(assertEquals(NAME2, doc2.getName(), null, f));
88  
89              // update nothing
90              try {
91                  properties = new HashMap<String, Object>();
92                  doc2.updateProperties(properties, false);
93              } catch (Exception e) {
94                  addResult(createResult(WARNING,
95                          "updateProperties without property changes returned an error: " + e.getMessage(), e, false));
96              }
97  
98              // cancel a possible check out
99              if (checkedout) {
100                 workDoc.cancelCheckOut();
101             }
102 
103             // delete
104             deleteObject(doc2);
105             if (!doc1.getId().equals(doc2.getId())) {
106                 if (exists(doc1)) {
107                     deleteObject(doc1);
108                 }
109             }
110         } finally {
111             // clean up
112             deleteTestFolder();
113         }
114     }
115 }