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  
23  import java.util.Map;
24  
25  import org.apache.chemistry.opencmis.client.api.Document;
26  import org.apache.chemistry.opencmis.client.api.Folder;
27  import org.apache.chemistry.opencmis.client.api.Session;
28  import org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition;
29  import org.apache.chemistry.opencmis.commons.enums.VersioningState;
30  import org.apache.chemistry.opencmis.tck.CmisTestResult;
31  import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
32  
33  /**
34   * Copy test.
35   */
36  public class CopyTest extends AbstractSessionTest {
37  
38      @Override
39      public void init(Map<String, String> parameters) {
40          super.init(parameters);
41          setName("Copy Test");
42          setDescription("Creates two folders and a document and copies the document from one folder to the other.");
43      }
44  
45      @Override
46      public void run(Session session) {
47          // if (getBinding() == BindingType.ATOMPUB) {
48          // addResult(createResult(SKIPPED,
49          // "AtomPub binding does not support createDocumentFromSource(). Test Skipped!"));
50          // return;
51          // }
52  
53          CmisTestResult f;
54  
55          try {
56              // create folders
57              Folder testFolder = createTestFolder(session);
58              Folder folder1 = createFolder(session, testFolder, "copyfolder1");
59              Folder folder2 = createFolder(session, testFolder, "copyfolder2");
60  
61              // create document
62              Document doc1 = createDocument(session, folder1, "copytestdoc.txt", "copy test");
63  
64              VersioningState versioningState = VersioningState.MAJOR;
65              if (!((DocumentTypeDefinition) doc1.getType()).isVersionable()) {
66                  versioningState = VersioningState.NONE;
67              }
68  
69              // copy
70              Document doc2 = doc1.copy(folder2, null, versioningState, null, null, null, SELECT_ALL_NO_CACHE_OC);
71  
72              if (doc2 == null) {
73                  addResult(createResult(FAILURE, "Copied document is null!"));
74              } else {
75                  addResult(checkObject(session, doc2, getAllProperties(doc2),
76                          "Copied document check. Id: + " + doc2.getName()));
77  
78                  f = createResult(FAILURE, "Content streams don't match!");
79                  addResult(assertEquals(doc1.getContentStream(), doc2.getContentStream(), null, f));
80              }
81  
82              int count1 = countFolderChildren(folder1);
83              f = createResult(FAILURE, "Source folder should have exactly one child but has " + count1 + " children!");
84              addResult(assertEquals(1, count1, null, f));
85  
86              int count2 = countFolderChildren(folder2);
87              f = createResult(FAILURE, "Target folder should have exactly one child but has " + count2 + " children!");
88              addResult(assertEquals(1, count2, null, f));
89  
90              deleteObject(doc2);
91              deleteObject(doc1);
92          } finally {
93              // clean up
94              deleteTestFolder();
95          }
96      }
97  }