Search in sources :

Example 6 with Relationship

use of org.apache.chemistry.opencmis.client.api.Relationship in project copper-cms by PogeyanOSS.

the class CreateAndDeleteRelationshipTest method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    boolean found;
    if (hasRelationships(session)) {
        // create a test folder
        Folder testFolder = createTestFolder(session);
        try {
            // create documents
            Document doc1 = createDocument(session, testFolder, "doc1.txt", "doc1");
            Document doc2 = createDocument(session, testFolder, "doc2.txt", "doc2");
            // create relationship
            Relationship rel = createRelationship(session, "rel1", doc1, doc2);
            f = createResult(FAILURE, "Source document id does not match relationship source id!");
            addResult(assertEquals(doc1.getId(), rel.getSourceId().getId(), null, f));
            f = createResult(FAILURE, "Target document id does not match relationship target id!");
            addResult(assertEquals(doc2.getId(), rel.getTarget().getId(), null, f));
            // check the source document
            doc1.refresh();
            List<Relationship> doc1rels = doc1.getRelationships();
            f = createResult(FAILURE, "Source document has no relationships but must have at least one!");
            addResult(assertListNotEmpty(doc1rels, null, f));
            if (doc1rels != null) {
                found = false;
                for (Relationship r : doc1rels) {
                    if (rel.getId().equals(r.getId())) {
                        found = true;
                        break;
                    }
                }
                f = createResult(FAILURE, "Newly created relationship not found in the relationships of the source document!");
                addResult(assertIsTrue(found, null, f));
            }
            found = false;
            for (Relationship r : session.getRelationships(doc1, true, RelationshipDirection.SOURCE, null, SELECT_ALL_NO_CACHE_OC)) {
                if (rel.getId().equals(r.getId())) {
                    found = true;
                    break;
                }
            }
            f = createResult(FAILURE, "Newly created relationship not found in the relationships returned by getObjectRelationships() for the source document!");
            addResult(assertIsTrue(found, null, f));
            // check the target document
            doc2.refresh();
            List<Relationship> doc2rels = doc2.getRelationships();
            f = createResult(FAILURE, "Target document has no relationships but must have at least one!");
            addResult(assertListNotEmpty(doc2rels, null, f));
            if (doc2rels != null) {
                found = false;
                for (Relationship r : doc2rels) {
                    if (rel.getId().equals(r.getId())) {
                        found = true;
                        break;
                    }
                }
                f = createResult(FAILURE, "Newly created relationship not found in the relationships of the target document!");
                addResult(assertIsTrue(found, null, f));
            }
            found = false;
            for (Relationship r : session.getRelationships(doc2, true, RelationshipDirection.TARGET, null, SELECT_ALL_NO_CACHE_OC)) {
                if (rel.getId().equals(r.getId())) {
                    found = true;
                    break;
                }
            }
            f = createResult(FAILURE, "Newly created relationship not found in the relationships returned by getObjectRelationships() for the target document!");
            addResult(assertIsTrue(found, null, f));
            // remove
            deleteObject(rel);
            deleteObject(doc2);
            deleteObject(doc1);
        } finally {
            // delete the test folder
            deleteTestFolder();
        }
    } else {
        addResult(createResult(SKIPPED, "Relationships not supported. Test skipped!"));
    }
}
Also used : CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) Relationship(org.apache.chemistry.opencmis.client.api.Relationship) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document)

Aggregations

Relationship (org.apache.chemistry.opencmis.client.api.Relationship)6 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)5 FileableCmisObject (org.apache.chemistry.opencmis.client.api.FileableCmisObject)4 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)3 ArrayList (java.util.ArrayList)2 Document (org.apache.chemistry.opencmis.client.api.Document)2 Folder (org.apache.chemistry.opencmis.client.api.Folder)2 ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)2 OperationContext (org.apache.chemistry.opencmis.client.api.OperationContext)2 Action (org.apache.chemistry.opencmis.commons.enums.Action)2 CmisBaseException (org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException)2 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)2 CmisNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException)2 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)2 IOException (java.io.IOException)1 AbstractList (java.util.AbstractList)1 GregorianCalendar (java.util.GregorianCalendar)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1