This project has retired. For details please refer to its
Attic page.
UnfilingTest xref
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19package org.apache.chemistry.opencmis.tck.tests.filing;
2021importstatic org.apache.chemistry.opencmis.tck.CmisTestResultStatus.FAILURE;
22importstatic org.apache.chemistry.opencmis.tck.CmisTestResultStatus.SKIPPED;
2324import java.util.Map;
2526import org.apache.chemistry.opencmis.client.api.Document;
27import org.apache.chemistry.opencmis.client.api.Folder;
28import org.apache.chemistry.opencmis.client.api.Session;
29import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
30import org.apache.chemistry.opencmis.tck.CmisTestResult;
31import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
3233/**34 * Unfiling test.35 */36publicclassUnfilingTestextendsAbstractSessionTest {
3738 @Override
39publicvoid init(Map<String, String> parameters) {
40super.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 }
4445 @Override
46publicvoid run(Session session) {
47if (supportsUnfiling(session)) {
48CmisTestResult f;
4950int count;
51int parents;
5253try {
54// create folders55 Folder testFolder = createTestFolder(session);
56 Folder folder1 = createFolder(session, testFolder, "folder1");
5758// create document59 Document doc1 = createDocument(session, folder1, "testdoc.txt", "unfiling test");
6061 addResult(checkChildren(session, folder1, "Folder after createDocument()"));
6263 count = countFolderChildren(folder1);
64 f = createResult(FAILURE, "Folder should have exactly one child but has " + count + " children!");
65 addResult(assertEquals(1, count, null, f));
6667 parents = doc1.getParents().size();
68 f = createResult(FAILURE, "Document should have one parent but has " + parents + " parents!");
69 addResult(assertEquals(1, parents, null, f));
7071// remove from folder72 doc1.removeFromFolder(folder1);
7374 addResult(checkChildren(session, folder1, "Folder after removeFromFolder()"));
7576 count = countFolderChildren(folder1);
77 f = createResult(FAILURE, "Folder should have no children but has " + count + " children!");
78 addResult(assertEquals(0, count, null, f));
7980 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));
8384// add to folder again85 doc1.addToFolder(folder1, true);
8687 addResult(checkChildren(session, folder1, "Folder after addToFolder()"));
8889 count = countFolderChildren(folder1);
90 f = createResult(FAILURE, "Folder should have exactly one child but has " + count + " children!");
91 addResult(assertEquals(1, count, null, f));
9293 parents = doc1.getParents().size();
94 f = createResult(FAILURE, "Document should have one parent but has " + parents + " parents!");
95 addResult(assertEquals(1, parents, null, f));
9697// delete everything98 deleteObject(doc1);
99 deleteObject(folder1);
100 } finally {
101// clean up102 deleteTestFolder();
103 }
104 } else {
105 addResult(createResult(SKIPPED, "Unfiling not supported. Test Skipped!"));
106 }
107 }
108109protectedboolean supportsUnfiling(Session session) {
110 RepositoryInfo repository = session.getRepositoryInfo();
111112if (repository.getCapabilities().isUnfilingSupported() == null) {
113return false;
114 }
115116return repository.getCapabilities().isUnfilingSupported().booleanValue();
117 }
118 }