This project has retired. For details please refer to its
Attic page.
DeleteTreeTest 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.crud;
2021importstatic org.apache.chemistry.opencmis.tck.CmisTestResultStatus.FAILURE;
2223import java.util.HashMap;
24import java.util.List;
25import java.util.Map;
2627import org.apache.chemistry.opencmis.client.api.Document;
28import org.apache.chemistry.opencmis.client.api.Folder;
29import org.apache.chemistry.opencmis.client.api.Session;
30import org.apache.chemistry.opencmis.commons.enums.UnfileObject;
31import org.apache.chemistry.opencmis.tck.CmisTestResult;
32import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
3334/**35 * Simple document test.36 */37publicclassDeleteTreeTestextendsAbstractSessionTest {
3839privatestaticfinal String CONTENT = "TCK test content.";
4041 @Override
42publicvoid init(Map<String, String> parameters) {
43super.init(parameters);
44 setName("Delete Tree Test");
45 setDescription("Creates a few documents in a folder, deletes the folder and checks if all documents are gone.");
46 }
4748 @Override
49publicvoid run(Session session) {
50CmisTestResult f;
5152int numOfDocuments = 20;
5354// create a test folder55 Folder testFolder = createTestFolder(session);
5657 Map<String, Document> documents = new HashMap<String, Document>();
5859// create documents60for (int i = 0; i < numOfDocuments; i++) {
61 Document newDocument = createDocument(session, testFolder, "doc" + i, CONTENT);
62 documents.put(newDocument.getId(), newDocument);
63 }
6465// delete tree66 List<String> failedIds = testFolder.deleteTree(true, UnfileObject.DELETE, true);
6768// check failed ids69if (failedIds != null && failedIds.size() > 0) {
70 f = createResult(FAILURE, "deleteTree() could not delete " + failedIds.size() + " out of " + numOfDocuments
71 + " objects in the folder!");
72 addResult(assertEquals(0, failedIds.size(), null, f));
73 }
7475// check documents76for (Document doc : documents.values()) {
77 f = createResult(FAILURE, "Document still exists but should have been deleted. Id: " + doc.getId());
78 addResult(assertIsFalse(exists(doc), null, f));
79 }
8081// check folder82 f = createResult(FAILURE, "Folder still exists but should have been deleted. Id: " + testFolder.getId());
83 addResult(assertIsFalse(exists(testFolder), null, f));
8485if (exists(testFolder)) {
86// try to clean up87try {
88 deleteObject(testFolder);
89 } catch (Exception e) {
90 }
91 }
92 }
93 }