This project has retired. For details please refer to its Attic page.
ContentChangesSmokeTest 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.query;
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.ChangeEvent;
27  import org.apache.chemistry.opencmis.client.api.ChangeEvents;
28  import org.apache.chemistry.opencmis.client.api.CmisObject;
29  import org.apache.chemistry.opencmis.client.api.Session;
30  import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
31  import org.apache.chemistry.opencmis.commons.enums.BindingType;
32  import org.apache.chemistry.opencmis.commons.enums.CapabilityChanges;
33  import org.apache.chemistry.opencmis.commons.enums.ChangeType;
34  import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
35  import org.apache.chemistry.opencmis.tck.CmisTestResult;
36  import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
37  
38  /**
39   * Content Changes smoke test.
40   */
41  public class ContentChangesSmokeTest extends AbstractSessionTest {
42  
43      @Override
44      public void init(Map<String, String> parameters) {
45          super.init(parameters);
46          setName("Content Changes Smoke Test");
47          setDescription("Calls getContentChanges(). It does not check if the results are correct!");
48      }
49  
50      @Override
51      public void run(Session session) {
52          CmisTestResult f;
53  
54          if (supportsContentChanges(session)) {
55              ChangeEvents events = session.getContentChanges(null, true, 1000, SELECT_ALL_NO_CACHE_OC);
56  
57              f = createResult(FAILURE, "Change events are null!");
58              addResult(assertNotNull(events, null, f));
59  
60              if (events != null && events.getChangeEvents() != null) {
61  
62                  if (getBinding() != BindingType.ATOMPUB) {
63                      // the AtompPub binding does not return a change log token
64                      f = createResult(FAILURE, "Change log token is null!");
65                      addResult(assertNotNull(events.getLatestChangeLogToken(), null, f));
66                  }
67  
68                  for (ChangeEvent event : events.getChangeEvents()) {
69                      f = createResult(FAILURE, "Object Id is not set!");
70                      addResult(assertStringNotEmpty(event.getObjectId(), null, f));
71  
72                      f = createResult(FAILURE, "Change Type is not set! Id: " + event.getObjectId());
73                      addResult(assertNotNull(event.getChangeType(), null, f));
74  
75                      f = createResult(FAILURE, "Change Time is not set! Id: " + event.getObjectId());
76                      addResult(assertNotNull(event.getChangeTime(), null, f));
77  
78                      if (event.getObjectId() != null) {
79                          if (event.getChangeType() == ChangeType.DELETED) {
80                              try {
81                                  session.getObject(event.getObjectId(), SELECT_ALL_NO_CACHE_OC);
82                                  addResult(createResult(FAILURE,
83                                          "Change event indicates that an object has been deleted but it still exists. Id: "
84                                                  + event.getObjectId()));
85                              } catch (CmisObjectNotFoundException e) {
86                              }
87                          } else {
88                              try {
89                                  CmisObject object = session.getObject(event.getObjectId(), SELECT_ALL_NO_CACHE_OC);
90                                  addResult(checkObject(session, object, getAllProperties(object), "Object check. Id: "
91                                          + event.getObjectId()));
92                              } catch (CmisObjectNotFoundException e) {
93                                  // object might have been deleted later
94                              }
95                          }
96                      }
97                  }
98              }
99          } else {
100             addResult(createResult(SKIPPED, "Content Changes not supported. Test Skipped!"));
101         }
102     }
103 
104     protected boolean supportsContentChanges(Session session) {
105         RepositoryInfo repository = session.getRepositoryInfo();
106 
107         if (repository.getCapabilities().getChangesCapability() == null) {
108             return false;
109         }
110 
111         return repository.getCapabilities().getChangesCapability() != CapabilityChanges.NONE;
112     }
113 }