Search in sources :

Example 16 with CmisTestResult

use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.

the class CreateAndDeleteItemTest method run.

@Override
public void run(Session session) {
    if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_0) {
        addResult(createResult(SKIPPED, "Items are not supported by CMIS 1.0. Test skipped!"));
        return;
    }
    if (hasItems(session)) {
        CmisTestResult f;
        int numOfItems = 20;
        // create a test folder
        Folder testFolder = createTestFolder(session);
        try {
            Map<String, Item> items = new HashMap<String, Item>();
            // create items
            for (int i = 0; i < numOfItems; i++) {
                Item newItem = createItem(session, testFolder, "item" + i);
                items.put(newItem.getId(), newItem);
            }
            // check if all items are there
            ItemIterable<CmisObject> children = testFolder.getChildren(SELECT_ALL_NO_CACHE_OC);
            List<String> childrenIds = new ArrayList<String>();
            for (CmisObject child : children) {
                if (child != null) {
                    childrenIds.add(child.getId());
                    Item item = items.get(child.getId());
                    f = createResult(FAILURE, "Item and test folder child don't match! Id: " + child.getId());
                    addResult(assertShallowEquals(item, child, null, f));
                }
            }
            f = createResult(FAILURE, "Number of created items does not match the number of existing items!");
            addResult(assertEquals(numOfItems, childrenIds.size(), null, f));
            for (Item item : items.values()) {
                if (!childrenIds.contains(item.getId())) {
                    addResult(createResult(FAILURE, "Created item not found in test folder children! Id: " + item.getId()));
                }
            }
            // delete all item
            for (Item item : items.values()) {
                item.delete(true);
                f = createResult(FAILURE, "Item should not exist anymore but it is still there! Id: " + item.getId());
                addResult(assertIsFalse(exists(item), null, f));
            }
        } finally {
            // delete the test folder
            deleteTestFolder();
        }
        addResult(createInfoResult("Tested the creation and deletion of " + numOfItems + " items."));
    } else {
        addResult(createResult(SKIPPED, "Items not supported. Test skipped!"));
    }
}
Also used : Item(org.apache.chemistry.opencmis.client.api.Item) HashMap(java.util.HashMap) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) ArrayList(java.util.ArrayList) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Folder(org.apache.chemistry.opencmis.client.api.Folder)

Example 17 with CmisTestResult

use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.

the class CreateDocumentWithoutContent method run.

@Override
public void run(Session session) {
    CmisTestResult f;
    String objectTypeId = getDocumentTestTypeId();
    TypeDefinition type = session.getTypeDefinition(objectTypeId);
    if (!(type instanceof DocumentTypeDefinition)) {
        addResult(createResult(FAILURE, "Type is not a document type! Type: " + objectTypeId, true));
        return;
    }
    DocumentTypeDefinition docType = (DocumentTypeDefinition) type;
    if (docType.getContentStreamAllowed() == ContentStreamAllowed.REQUIRED) {
        addResult(createResult(SKIPPED, "The test document type does not support documents without content. Test skipped!"));
        return;
    }
    // create a test folder
    Folder testFolder = createTestFolder(session);
    try {
        String name = "nocontent";
        Map<String, Object> properties = new HashMap<String, Object>();
        properties.put(PropertyIds.NAME, name);
        properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
        VersioningState versioningState = (Boolean.TRUE.equals(docType.isVersionable()) ? VersioningState.MAJOR : VersioningState.NONE);
        // create and fetch the document
        ObjectId id = session.createDocument(properties, testFolder, null, versioningState);
        Document doc = (Document) session.getObject(id, SELECT_ALL_NO_CACHE_OC);
        // check the new document
        addResult(checkObject(session, doc, getAllProperties(doc), "New document object spec compliance"));
        // check the MIME type
        f = createResult(FAILURE, "The document has no content but a MIME type!", true);
        assertNull(doc.getContentStreamMimeType(), null, f);
        // check the content size
        if (doc.getContentStreamLength() == 0) {
            addResult(createResult(WARNING, "The document has no content but the content length is set to 0! " + "The content length shouldn't be set."));
        } else if (doc.getContentStreamLength() > 0) {
            addResult(createResult(FAILURE, "The document has no content but the content length is set and >0! " + "(content length: " + doc.getContentStreamLength() + ")"));
        }
        // delete it
        doc.delete(true);
    } finally {
        // delete the test folder
        deleteTestFolder();
    }
}
Also used : DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition) HashMap(java.util.HashMap) ObjectId(org.apache.chemistry.opencmis.client.api.ObjectId) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) VersioningState(org.apache.chemistry.opencmis.commons.enums.VersioningState) Folder(org.apache.chemistry.opencmis.client.api.Folder) Document(org.apache.chemistry.opencmis.client.api.Document) TypeDefinition(org.apache.chemistry.opencmis.commons.definitions.TypeDefinition) DocumentTypeDefinition(org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)

Example 18 with CmisTestResult

use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.

the class CoreHtmlReport method printResult.

private void printResult(CmisTestResult result, Writer writer) throws IOException {
    stackTraceCounter++;
    String stackTraceId = "tckTrace" + stackTraceCounter;
    String exceptionId = "tckException" + stackTraceCounter;
    boolean hasStackTrace = result.getStackTrace() != null && result.getStackTrace().length > 0;
    boolean hasException = result.getStatus() == CmisTestResultStatus.UNEXPECTED_EXCEPTION && result.getException() != null;
    writer.write("<div class=\"tckResult" + result.getStatus().name() + "\">\n");
    writer.write("<b>" + result.getStatus() + "</b>: " + escape(result.getMessage()));
    if (hasStackTrace) {
        writer.write(" (" + getSourceCodeLink(result.getStackTrace()[0], revision) + ")");
        writer.write(" [<span class=\"tckTraceLink\" onClick=\"tckToggleDisplay('" + stackTraceId + "');\">stacktrace</span>]");
    }
    if (hasException) {
        writer.write(" [<span class=\"tckTraceLink\" onClick=\"tckToggleDisplay('" + exceptionId + "');\">exception details</span>]");
    }
    writer.write("<br/>\n");
    if (hasStackTrace) {
        writer.write("<div class=\"tckTrace\" id=\"" + stackTraceId + "\" style=\"display:none\">\n");
        for (StackTraceElement ste : result.getStackTrace()) {
            if (AbstractRunner.class.getName().equals(ste.getClassName())) {
                break;
            }
            writer.write(ste.getClassName() + "." + ste.getMethodName() + "(" + getSourceCodeLink(ste, revision) + ")<br/>\n");
        }
        writer.write("</div>\n");
    }
    if (hasException) {
        writer.write("<div class=\"tckTrace\" id=\"" + exceptionId + "\" style=\"display:none\">\n");
        writer.write("<b>Exception stack trace:</b><br/><br/>\n");
        for (StackTraceElement ste : result.getException().getStackTrace()) {
            if (AbstractRunner.class.getName().equals(ste.getClassName())) {
                break;
            }
            writer.write(ste.getClassName() + "." + ste.getMethodName() + "(" + getSourceCodeLink(ste, revision) + ")<br/>\n");
        }
        if (result.getException() instanceof CmisBaseException) {
            CmisBaseException cbe = (CmisBaseException) result.getException();
            if (cbe.getErrorContent() != null) {
                writer.write("<br/>\n<b>Error content:</b><br/><br/><pre>\n");
                writer.write(escape(cbe.getErrorContent()) + "</pre>\n");
            }
        }
        writer.write("</div>\n");
    }
    for (CmisTestResult child : result.getChildren()) {
        printResult(child, writer);
    }
    writer.write("</div>\n");
}
Also used : AbstractRunner(org.apache.chemistry.opencmis.tck.runner.AbstractRunner) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult)

Example 19 with CmisTestResult

use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.

the class JsonReport method printTestResults.

private void printTestResults(CmisTest test, JSONArray jsonTests) throws IOException {
    if (!test.isEnabled()) {
        return;
    }
    JSONObject jsonTest = new JSONObject();
    jsonTests.add(jsonTest);
    jsonTest.put("name", test.getName());
    jsonTest.put("time", test.getTime());
    if (test.getResults() != null && !test.getResults().isEmpty()) {
        JSONArray jsonResults = new JSONArray();
        jsonTest.put("results", jsonResults);
        for (CmisTestResult result : test.getResults()) {
            printResult(result, jsonResults);
        }
    }
}
Also used : JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray)

Example 20 with CmisTestResult

use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.

the class JsonReport method printResult.

private void printResult(CmisTestResult result, JSONArray results) throws IOException {
    JSONObject jsonResult = new JSONObject();
    results.add(jsonResult);
    jsonResult.put("status", result.getStatus().toString());
    jsonResult.put("message", result.getMessage());
    if (result.getStackTrace() != null && result.getStackTrace().length > 0) {
        jsonResult.put("file", result.getStackTrace()[0].getFileName() + ":" + result.getStackTrace()[0].getLineNumber());
    }
    if (result.getStatus() == CmisTestResultStatus.UNEXPECTED_EXCEPTION && result.getException() != null) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        result.getException().printStackTrace(pw);
        jsonResult.put("stacktrace", sw.toString());
        if (result.getException() instanceof CmisBaseException) {
            CmisBaseException cbe = (CmisBaseException) result.getException();
            if (cbe.getErrorContent() != null) {
                jsonResult.put("errorcontent", cbe.getErrorContent());
            }
        }
    }
    if (result.getException() != null) {
        jsonResult.put("exception", result.getException().getMessage());
    }
    if (result.getRequest() != null) {
        jsonResult.put("request", result.getRequest());
    }
    if (result.getRequest() != null) {
        jsonResult.put("response", result.getResponse());
    }
    if (!result.getChildren().isEmpty()) {
        JSONArray nextLevel = new JSONArray();
        jsonResult.put("results", nextLevel);
        for (CmisTestResult child : result.getChildren()) {
            printResult(child, nextLevel);
        }
    }
}
Also used : JSONObject(org.apache.chemistry.opencmis.commons.impl.json.JSONObject) StringWriter(java.io.StringWriter) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) JSONArray(org.apache.chemistry.opencmis.commons.impl.json.JSONArray) PrintWriter(java.io.PrintWriter)

Aggregations

CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)82 ArrayList (java.util.ArrayList)33 Folder (org.apache.chemistry.opencmis.client.api.Folder)33 Document (org.apache.chemistry.opencmis.client.api.Document)32 HashMap (java.util.HashMap)19 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)18 DocumentTypeDefinition (org.apache.chemistry.opencmis.commons.definitions.DocumentTypeDefinition)14 CmisBaseException (org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException)14 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)14 ObjectId (org.apache.chemistry.opencmis.client.api.ObjectId)12 ContentStream (org.apache.chemistry.opencmis.commons.data.ContentStream)11 FileableCmisObject (org.apache.chemistry.opencmis.client.api.FileableCmisObject)8 ObjectType (org.apache.chemistry.opencmis.client.api.ObjectType)8 CmisInvalidArgumentException (org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 IOException (java.io.IOException)6 HashSet (java.util.HashSet)6 CmisNotSupportedException (org.apache.chemistry.opencmis.commons.exceptions.CmisNotSupportedException)6 OperationContext (org.apache.chemistry.opencmis.client.api.OperationContext)5 TypeDefinition (org.apache.chemistry.opencmis.commons.definitions.TypeDefinition)4