This project has retired. For details please refer to its Attic page.
UnfilingTest 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.filing;
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.data.RepositoryInfo;
30  import org.apache.chemistry.opencmis.tck.CmisTestResult;
31  import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
32  
33  /**
34   * Unfiling test.
35   */
36  public class UnfilingTest extends AbstractSessionTest {
37  
38      @Override
39      public void init(Map<String, String> parameters) {
40          super.init(parameters);
41          setName("Unfiling Test");
42          setDescription("Creates a folder and a document, removes the document from the folder and then adds it again.");
43      }
44  
45      @Override
46      public void run(Session session) {
47          if (supportsUnfiling(session)) {
48              CmisTestResult f;
49  
50              int count;
51              int parents;
52  
53              try {
54                  // create folders
55                  Folder testFolder = createTestFolder(session);
56                  Folder folder1 = createFolder(session, testFolder, "folder1");
57  
58                  // create document
59                  Document doc1 = createDocument(session, folder1, "testdoc.txt", "unfiling test");
60  
61                  addResult(checkChildren(session, folder1, "Folder after createDocument()"));
62  
63                  count = countFolderChildren(folder1);
64                  f = createResult(FAILURE, "Folder should have exactly one child but has " + count + " children!");
65                  addResult(assertEquals(1, count, null, f));
66  
67                  parents = doc1.getParents().size();
68                  f = createResult(FAILURE, "Document should have one parent but has " + parents + " parents!");
69                  addResult(assertEquals(1, parents, null, f));
70  
71                  // remove from folder
72                  doc1.removeFromFolder(folder1);
73  
74                  addResult(checkChildren(session, folder1, "Folder after removeFromFolder()"));
75  
76                  count = countFolderChildren(folder1);
77                  f = createResult(FAILURE, "Folder should have no children but has " + count + " children!");
78                  addResult(assertEquals(0, count, null, f));
79  
80                  parents = doc1.getParents().size();
81                  f = createResult(FAILURE, "Document should not have no parents but has " + parents + " parents!");
82                  addResult(assertEquals(0, parents, null, f));
83  
84                  // add to folder again
85                  doc1.addToFolder(folder1, true);
86  
87                  addResult(checkChildren(session, folder1, "Folder after addToFolder()"));
88  
89                  count = countFolderChildren(folder1);
90                  f = createResult(FAILURE, "Folder should have exactly one child but has " + count + " children!");
91                  addResult(assertEquals(1, count, null, f));
92  
93                  parents = doc1.getParents().size();
94                  f = createResult(FAILURE, "Document should have one parent but has " + parents + " parents!");
95                  addResult(assertEquals(1, parents, null, f));
96  
97                  // delete everything
98                  deleteObject(doc1);
99                  deleteObject(folder1);
100             } finally {
101                 // clean up
102                 deleteTestFolder();
103             }
104         } else {
105             addResult(createResult(SKIPPED, "Unfiling not supported. Test Skipped!"));
106         }
107     }
108 
109     protected boolean supportsUnfiling(Session session) {
110         RepositoryInfo repository = session.getRepositoryInfo();
111 
112         if (repository.getCapabilities().isUnfilingSupported() == null) {
113             return false;
114         }
115 
116         return repository.getCapabilities().isUnfilingSupported().booleanValue();
117     }
118 }