This project has retired. For details please refer to its
Attic page.
CreateAndDeleteFolderTest 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.ArrayList;
24import java.util.HashMap;
25import java.util.List;
26import java.util.Map;
2728import org.apache.chemistry.opencmis.client.api.CmisObject;
29import org.apache.chemistry.opencmis.client.api.Folder;
30import org.apache.chemistry.opencmis.client.api.ItemIterable;
31import org.apache.chemistry.opencmis.client.api.Session;
32import org.apache.chemistry.opencmis.tck.CmisTestResult;
33import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
3435/**36 * Simple folder test.37 */38publicclassCreateAndDeleteFolderTestextendsAbstractSessionTest {
3940 @Override
41publicvoid init(Map<String, String> parameters) {
42super.init(parameters);
43 setName("Create and Delete Folder Test");
44 setDescription("Creates a few folders, checks the newly created folders and their parent and finally deletes the created folders.");
45 }
4647 @Override
48publicvoid run(Session session) {
49CmisTestResult f;
5051int numOfFolders = 20;
5253// create a test folder54 Folder testFolder = createTestFolder(session);
5556try {
57 Map<String, Folder> folders = new HashMap<String, Folder>();
5859// create folders60for (int i = 0; i < numOfFolders; i++) {
61 Folder newFolder = createFolder(session, testFolder, "folder" + i);
62 folders.put(newFolder.getId(), newFolder);
63 }
6465// simple children test66 addResult(checkChildren(session, testFolder, "Test folder children check"));
6768// check if all folders are there69 ItemIterable<CmisObject> children = testFolder.getChildren(SELECT_ALL_NO_CACHE_OC);
70 List<String> childrenIds = new ArrayList<String>();
71for (CmisObject child : children) {
72if (child != null) {
73 childrenIds.add(child.getId());
74 Folder folder = folders.get(child.getId());
7576 f = createResult(FAILURE, "Folder and test folder child don't match! Id: " + child.getId());
77 addResult(assertShallowEquals(folder, child, null, f));
78 }
79 }
8081 f = createResult(FAILURE, "Number of created folders does not match the number of existing folders!");
82 addResult(assertEquals(numOfFolders, childrenIds.size(), null, f));
8384for (Folder folder : folders.values()) {
85if (!childrenIds.contains(folder.getId())) {
86 addResult(createResult(FAILURE,
87"Created folder not found in test folder children! Id: " + folder.getId()));
88 }
89 }
9091// delete all folders92for (Folder folder : folders.values()) {
93// empty folders should be deleteable like this94 folder.delete(true);
9596 f = createResult(FAILURE,
97"Folder should not exist anymore but it is still there! Id: " + folder.getId());
98 addResult(assertIsFalse(exists(folder), null, f));
99 }
100 } finally {
101// delete the test folder102 deleteTestFolder();
103 }
104105 addResult(createInfoResult("Tested the creation and deletion of " + numOfFolders + " folders."));
106 }
107 }