This project has retired. For details please refer to its
Attic page.
CreateAndDeleteRelationshipTest 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;
22importstatic org.apache.chemistry.opencmis.tck.CmisTestResultStatus.SKIPPED;
2324import 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.Relationship;
30import org.apache.chemistry.opencmis.client.api.Session;
31import org.apache.chemistry.opencmis.commons.enums.RelationshipDirection;
32import org.apache.chemistry.opencmis.tck.CmisTestResult;
33import org.apache.chemistry.opencmis.tck.impl.AbstractSessionTest;
3435/**36 * Simple folder test.37 */38publicclassCreateAndDeleteRelationshipTestextendsAbstractSessionTest {
3940 @Override
41publicvoid init(Map<String, String> parameters) {
42super.init(parameters);
43 setName("Create and Delete Relationship Test");
44 setDescription("Creates a relationship between two documents, checks the newly created relationship and finally deletes the created relationship.");
45 }
4647 @Override
48publicvoid run(Session session) {
49 CmisTestResult f;
50boolean found;
5152if (hasRelationships(session)) {
53// create a test folder54 Folder testFolder = createTestFolder(session);
5556try {
57// create documents58 Document doc1 = createDocument(session, testFolder, "doc1.txt",
59"doc1");
60 Document doc2 = createDocument(session, testFolder, "doc2.txt",
61"doc2");
6263// create relationship64 Relationship rel = createRelationship(session, "rel1", doc1,
65 doc2);
6667 f = createResult(FAILURE,
68"Source document id does not match relationship source id!");
69 addResult(assertEquals(doc1.getId(), rel.getSourceId().getId(),
70null, f));
7172 f = createResult(FAILURE,
73"Target document id does not match relationship target id!");
74 addResult(assertEquals(doc2.getId(), rel.getTarget().getId(),
75null, f));
7677// check the source document78 doc1.refresh();
79 List<Relationship> doc1rels = doc1.getRelationships();
8081 f = createResult(FAILURE,
82"Source document has no relationships but must have at least one!");
83 addResult(assertListNotEmpty(doc1rels, null, f));
8485if (doc1rels != null) {
86 found = false;
87for (Relationship r : doc1rels) {
88if (rel.getId().equals(r.getId())) {
89 found = true;
90break;
91 }
92 }
9394 f = createResult(
95 FAILURE,
96"Newly created relationship not found in the relationships of the source document!");
97 addResult(assertIsTrue(found, null, f));
98 }
99100 found = false;
101for (Relationship r : session.getRelationships(doc1, true,
102 RelationshipDirection.SOURCE, null,
103 SELECT_ALL_NO_CACHE_OC)) {
104if (rel.getId().equals(r.getId())) {
105 found = true;
106break;
107 }
108 }
109110 f = createResult(
111 FAILURE,
112"Newly created relationship not found in the relationships returned by getObjectRelationships() for the source document!");
113 addResult(assertIsTrue(found, null, f));
114115// check the target document116 doc2.refresh();
117 List<Relationship> doc2rels = doc2.getRelationships();
118119 f = createResult(FAILURE,
120"Target document has no relationships but must have at least one!");
121 addResult(assertListNotEmpty(doc2rels, null, f));
122123if (doc2rels != null) {
124 found = false;
125for (Relationship r : doc2rels) {
126if (rel.getId().equals(r.getId())) {
127 found = true;
128break;
129 }
130 }
131132 f = createResult(
133 FAILURE,
134"Newly created relationship not found in the relationships of the target document!");
135 addResult(assertIsTrue(found, null, f));
136 }
137138 found = false;
139for (Relationship r : session.getRelationships(doc2, true,
140 RelationshipDirection.TARGET, null,
141 SELECT_ALL_NO_CACHE_OC)) {
142if (rel.getId().equals(r.getId())) {
143 found = true;
144break;
145 }
146 }
147148 f = createResult(
149 FAILURE,
150"Newly created relationship not found in the relationships returned by getObjectRelationships() for the target document!");
151 addResult(assertIsTrue(found, null, f));
152153// remove154 deleteObject(rel);
155 deleteObject(doc2);
156 deleteObject(doc1);
157 } finally {
158// delete the test folder159 deleteTestFolder();
160 }
161 } else {
162 addResult(createResult(SKIPPED,
163"Relationships not supported. Test Skipped!"));
164 }
165 }
166 }