This project has retired. For details please refer to its
Attic page.
CreateAndDeleteDocumentTest 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.io.IOException;
24import java.util.ArrayList;
25import java.util.HashMap;
26import java.util.List;
27import java.util.Map;
2829import org.apache.chemistry.opencmis.client.api.CmisObject;
30import org.apache.chemistry.opencmis.client.api.Document;
31import org.apache.chemistry.opencmis.client.api.Folder;
32import org.apache.chemistry.opencmis.client.api.ItemIterable;
33import org.apache.chemistry.opencmis.client.api.Session;
34import org.apache.chemistry.opencmis.commons.data.ContentStream;
35import org.apache.chemistry.opencmis.tck.CmisTestResult;
36import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
3738/**39 * Simple document test.40 */41publicclassCreateAndDeleteDocumentTestextendsAbstractSessionTest {
4243privatestaticfinal String CONTENT = "TCK test content.";
4445 @Override
46publicvoid init(Map<String, String> parameters) {
47super.init(parameters);
48 setName("Create and Delete Document Test");
49 setDescription("Creates a few documents, checks the newly created documents and their parent and finally deletes the created documents.");
50 }
5152 @Override
53publicvoid run(Session session) {
54CmisTestResult f;
5556int numOfDocuments = 20;
5758// create a test folder59 Folder testFolder = createTestFolder(session);
6061try {
62 Map<String, Document> documents = new HashMap<String, Document>();
6364// create documents65for (int i = 0; i < numOfDocuments; i++) {
66 Document newDocument = createDocument(session, testFolder, "doc" + i, CONTENT);
67 documents.put(newDocument.getId(), newDocument);
68 }
6970// simple children test71 addResult(checkChildren(session, testFolder, "Test folder children check"));
7273// check if all documents are there74 ItemIterable<CmisObject> children = testFolder.getChildren(SELECT_ALL_NO_CACHE_OC);
75 List<String> childrenIds = new ArrayList<String>();
76for (CmisObject child : children) {
77if (child != null) {
78 childrenIds.add(child.getId());
79 Document document = documents.get(child.getId());
8081 f = createResult(FAILURE, "Document and test folder child don't match! Id: " + child.getId());
82 addResult(assertShallowEquals(document, child, null, f));
83 }
84 }
8586 f = createResult(FAILURE, "Number of created folders does not match the number of existing folders!");
87 addResult(assertEquals(numOfDocuments, childrenIds.size(), null, f));
8889for (Document document : documents.values()) {
90if (!childrenIds.contains(document.getId())) {
91 addResult(createResult(FAILURE, "Created document not found in test folder children! Id: "92 + document.getId()));
93 }
94 }
9596// check paging97int pageSize = 5;
98 CmisObject lastObject = null;
99100int count = 0;
101 ItemIterable<CmisObject> page1 = testFolder.getChildren(SELECT_ALL_NO_CACHE_OC_ORDER_BY_NAME).getPage(
102 pageSize);
103for (CmisObject child : page1) {
104 count++;
105 lastObject = child;
106 }
107108 f = createResult(FAILURE, "Returned number of children doesn't match the page size!");
109 addResult(assertEquals(pageSize, count, null, f));
110111 count = 0;
112 ItemIterable<CmisObject> page2 = testFolder.getChildren(SELECT_ALL_NO_CACHE_OC_ORDER_BY_NAME)
113 .skipTo(pageSize - 1).getPage(pageSize);
114for (CmisObject child : page2) {
115 count++;
116117if (count == 1) {
118 f = createResult(FAILURE,
119"Last object of the first page doesn't match the first object of the second page.");
120 addResult(assertEquals(lastObject.getId(), child.getId(), null, f));
121 }
122 }
123124 f = createResult(FAILURE, "Returned number of children doesn't match the page size!");
125 addResult(assertEquals(pageSize, count, null, f));
126127// check content128for (Document document : documents.values()) {
129 ContentStream contentStream = document.getContentStream();
130if (contentStream == null || contentStream.getStream() == null) {
131 addResult(createResult(FAILURE, "Document has no content! Id: " + document.getId()));
132continue;
133 } else {
134try {
135 contentStream.getStream().close();
136 } catch (IOException e) {
137 }
138 }
139140// TODO: content checks141 }
142143// delete all documents144for (Document document : documents.values()) {
145 document.delete(true);
146147 f = createResult(FAILURE,
148"Document should not exist anymore but it is still there! Id: " + document.getId());
149 addResult(assertIsFalse(exists(document), null, f));
150 }
151 } finally {
152// delete the test folder153 deleteTestFolder();
154 }
155156 addResult(createInfoResult("Tested the creation and deletion of " + numOfDocuments + " documents."));
157 }
158 }