This project has retired. For details please refer to its Attic page.
DeleteTreeTest 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  
23  import java.util.HashMap;
24  import java.util.List;
25  import java.util.Map;
26  
27  import org.apache.chemistry.opencmis.client.api.Document;
28  import org.apache.chemistry.opencmis.client.api.Folder;
29  import org.apache.chemistry.opencmis.client.api.Session;
30  import org.apache.chemistry.opencmis.commons.enums.UnfileObject;
31  import org.apache.chemistry.opencmis.tck.CmisTestResult;
32  import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
33  
34  /**
35   * Simple document test.
36   */
37  public class DeleteTreeTest extends AbstractSessionTest {
38  
39      private static final String CONTENT = "TCK test content.";
40  
41      @Override
42      public void init(Map<String, String> parameters) {
43          super.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      }
47  
48      @Override
49      public void run(Session session) {
50          CmisTestResult f;
51  
52          int numOfDocuments = 20;
53  
54          // create a test folder
55          Folder testFolder = createTestFolder(session);
56  
57          Map<String, Document> documents = new HashMap<String, Document>();
58  
59          // create documents
60          for (int i = 0; i < numOfDocuments; i++) {
61              Document newDocument = createDocument(session, testFolder, "doc" + i, CONTENT);
62              documents.put(newDocument.getId(), newDocument);
63          }
64  
65          // delete tree
66          List<String> failedIds = testFolder.deleteTree(true, UnfileObject.DELETE, true);
67  
68          // check failed ids
69          if (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          }
74  
75          // check documents
76          for (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          }
80  
81          // check folder
82          f = createResult(FAILURE, "Folder still exists but should have been deleted. Id: " + testFolder.getId());
83          addResult(assertIsFalse(exists(testFolder), null, f));
84  
85          if (exists(testFolder)) {
86              // try to clean up
87              try {
88                  deleteObject(testFolder);
89              } catch (Exception e) {
90              }
91          }
92      }
93  }