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