This project has retired. For details please refer to its Attic page.
MultifilingTest 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   * Multifiling test.
35   */
36  public class MultifilingTest extends AbstractSessionTest {
37  
38      @Override
39      public void init(Map<String, String> parameters) {
40          super.init(parameters);
41          setName("Multifiling Test");
42          setDescription("Creates two folders and a document in one of the folders, "
43                  + "adds the document to the second folder and then removes it again for the second folder.");
44      }
45  
46      @Override
47      public void run(Session session) {
48          if (supportsMultifiling(session)) {
49              CmisTestResult f;
50  
51              int count1;
52              int count2;
53              int parents;
54  
55              try {
56                  // create folders
57                  Folder testFolder = createTestFolder(session);
58                  Folder folder1 = createFolder(session, testFolder, "folder1");
59                  Folder folder2 = createFolder(session, testFolder, "folder2");
60  
61                  // create document
62                  Document doc1 = createDocument(session, folder1, "testdoc.txt", "multifiling test");
63  
64                  addResult(checkChildren(session, folder1, "Folder 1 after createDocument()"));
65                  addResult(checkChildren(session, folder2, "Folder 2 after createDocument()"));
66  
67                  count1 = countFolderChildren(folder1);
68                  f = createResult(FAILURE, "Folder 1 should have exactly one child but has " + count1 + " children!");
69                  addResult(assertEquals(1, count1, null, f));
70  
71                  count2 = countFolderChildren(folder2);
72                  f = createResult(FAILURE, "Folder 2 should not have children but has " + count2 + " children!");
73                  addResult(assertEquals(0, count2, null, f));
74  
75                  parents = doc1.getParents().size();
76                  f = createResult(FAILURE, "Document should have one parent but has " + parents + " parents!");
77                  addResult(assertEquals(1, parents, null, f));
78  
79                  // add to other folder
80                  doc1.addToFolder(folder2, true);
81  
82                  addResult(checkChildren(session, folder1, "Folder 1 after addToFolder()"));
83                  addResult(checkChildren(session, folder2, "Folder 2 after addToFolder()"));
84  
85                  count1 = countFolderChildren(folder1);
86                  f = createResult(FAILURE, "Folder 1 should have exactly one child but has " + count1 + " children!");
87                  addResult(assertEquals(1, count1, null, f));
88  
89                  count2 = countFolderChildren(folder2);
90                  f = createResult(FAILURE, "Folder 2 should have exactly one child but has " + count2 + " children!");
91                  addResult(assertEquals(1, count2, null, f));
92  
93                  parents = doc1.getParents().size();
94                  f = createResult(FAILURE, "Document should have two parents but has " + parents + " parents!");
95                  addResult(assertEquals(2, parents, null, f));
96  
97                  // remove from first folder
98                  doc1.removeFromFolder(folder2);
99  
100                 addResult(checkChildren(session, folder1, "Folder 1 after removeFromFolder()"));
101                 addResult(checkChildren(session, folder2, "Folder 2 after removeFromFolder()"));
102 
103                 count1 = countFolderChildren(folder1);
104                 f = createResult(FAILURE, "Folder 1 should have exactly one child but has " + count1 + " children!");
105                 addResult(assertEquals(1, count1, null, f));
106 
107                 count2 = countFolderChildren(folder2);
108                 f = createResult(FAILURE, "Folder 2 should not have children but has " + count2 + " children!");
109                 addResult(assertEquals(0, count2, null, f));
110 
111                 parents = doc1.getParents().size();
112                 f = createResult(FAILURE, "Document should have one parent but has " + parents + " parents!");
113                 addResult(assertEquals(1, parents, null, f));
114 
115                 // delete everything
116                 deleteObject(doc1);
117                 deleteObject(folder2);
118                 deleteObject(folder1);
119             } finally {
120                 // clean up
121                 deleteTestFolder();
122             }
123         } else {
124             addResult(createResult(SKIPPED, "Multifling not supported. Test Skipped!"));
125         }
126     }
127 
128     protected boolean supportsMultifiling(Session session) {
129         RepositoryInfo repository = session.getRepositoryInfo();
130 
131         if (repository.getCapabilities().isMultifilingSupported() == null) {
132             return false;
133         }
134 
135         return repository.getCapabilities().isMultifilingSupported().booleanValue();
136     }
137 }