use of org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException 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");
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException 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);
}
}
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException in project copper-cms by PogeyanOSS.
the class VersioningSmokeTest method run.
@Override
public void run(Session session) {
CmisTestResult f;
try {
// create folder and document
Folder testFolder = createTestFolder(session);
Document doc = createDocument(session, testFolder, "versioningtest.txt", "versioning");
DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
if (!docType.isVersionable()) {
addResult(createResult(SKIPPED, "Test type is not versionable. Test skipped!"));
doc.delete(true);
return;
}
// gather properties for later
String[] propertiesToCheck = new String[doc.getType().getPropertyDefinitions().size()];
int i = 0;
for (String propId : doc.getType().getPropertyDefinitions().keySet()) {
propertiesToCheck[i++] = propId;
}
Map<String, Object> writableProperties = new HashMap<String, Object>();
for (Property<?> property : doc.getProperties()) {
if (property.getDefinition().getUpdatability() == Updatability.READWRITE) {
writableProperties.put(property.getId(), property.getValue());
}
}
// check out
ObjectId pwcId = doc.checkOut();
Document pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC spec compliance - test 1"));
checkCheckedOut(pwc);
// check version series
addResult(checkVersionSeries(session, pwc.getAllVersions(SELECT_ALL_NO_CACHE_OC), propertiesToCheck, "Test version series after check out"));
// cancel checkout
pwc.cancelCheckOut();
doc.refresh();
checkCheckedIn(doc);
// check out again
pwcId = doc.checkOut();
pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC spec compliance - test 2"));
checkCheckedOut(pwc);
// check in
ObjectId newVersionId = pwc.checkIn(true, null, null, "Test Version 2");
Document newVersion = (Document) session.getObject(newVersionId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, newVersion, getAllProperties(newVersion), "New version compliance"));
checkCheckedIn(newVersion);
// check version history
List<Document> versions = newVersion.getAllVersions(SELECT_ALL_NO_CACHE_OC);
f = createResult(FAILURE, "Version series should have 2 versions but has " + versions.size() + "!");
addResult(assertEquals(2, versions.size(), null, f));
if (!versions.isEmpty()) {
f = createResult(FAILURE, "Version history order is incorrect! The first version should be the new version.");
addResult(assertEquals(newVersion.getId(), versions.get(0).getId(), null, f));
f = createResult(FAILURE, "The new version should be the latest version, but cmis:isLatestVersion is not TRUE.");
addResult(assertEquals(true, versions.get(0).isLatestVersion(), null, f));
f = createResult(FAILURE, "The new version should be the latest major version, but cmis:isLatestMajorVersion is not TRUE.");
addResult(assertEquals(true, versions.get(0).isLatestMajorVersion(), null, f));
}
if (versions.size() > 1) {
f = createResult(FAILURE, "Version history order is incorrect! The second version should be the origin document.");
addResult(assertEquals(doc.getId(), versions.get(1).getId(), null, f));
}
// check version series
addResult(checkVersionSeries(session, versions, propertiesToCheck, "Test version series after check in"));
// check out again
pwcId = newVersion.checkOut();
pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC spec compliance - test 3"));
checkCheckedOut(pwc);
// check in giving back all updateable properties
ObjectId thirdVersionId = pwc.checkIn(true, writableProperties, null, "Test Version 3");
Document thirdVersion = (Document) session.getObject(thirdVersionId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, thirdVersion, getAllProperties(thirdVersion), "New version compliance"));
// check out again
pwcId = thirdVersion.checkOut();
pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC spec compliance - test 4"));
checkCheckedOut(pwc);
// check in giving a new content stream
String fourthContent = "new content";
byte[] fourthContentBytes = IOUtils.toUTF8Bytes(fourthContent);
ContentStream fourthContentStream = new ContentStreamImpl("version4", BigInteger.valueOf(fourthContentBytes.length), "text/plain", new ByteArrayInputStream(fourthContentBytes));
ObjectId fourthVersionId = pwc.checkIn(true, null, fourthContentStream, "Test Version 5");
Document fourthVersion = (Document) session.getObject(fourthVersionId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, fourthVersion, getAllProperties(fourthVersion), "New version compliance"));
checkCheckedIn(fourthVersion);
// check out again
pwcId = fourthVersion.checkOut();
pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, pwc, getAllProperties(pwc), "PWC spec compliance - test 5"));
checkCheckedOut(pwc);
// check in giving properties and a new content stream
String fifthContent = "brand-new content";
byte[] fifthContentBytes = IOUtils.toUTF8Bytes(fifthContent);
ContentStream fifthContentStream = new ContentStreamImpl("version5", BigInteger.valueOf(fifthContentBytes.length), "text/plain", new ByteArrayInputStream(fifthContentBytes));
ObjectId fifthVersionId = pwc.checkIn(true, writableProperties, fifthContentStream, "Test Version 5");
Document fifthVersion = (Document) session.getObject(fifthVersionId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, fifthVersion, getAllProperties(fifthVersion), "New version compliance"));
checkCheckedIn(fifthVersion);
// test the latest version
Document latest = session.getLatestDocumentVersion(doc, SELECT_ALL_NO_CACHE_OC);
f = createResult(FAILURE, "getObjectOfLatestVersion() did not return the expected version!");
addResult(assertEquals(fifthVersion.getId(), latest.getId(), null, f));
// repository
try {
pwcId = doc.checkOut();
pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
pwc.cancelCheckOut();
addResult(createInfoResult("Repository allows check out on a version that is not the latest version."));
} catch (CmisBaseException e) {
addResult(createInfoResult("Repository only support check out on the latest version."));
}
// remove the document
deleteObject(doc);
// test if all versions have been deleted
f = createResult(FAILURE, "Version 2 has not been deleted!");
addResult(assertIsFalse(session.exists(newVersion), null, f));
f = createResult(FAILURE, "Version 3 has not been deleted!");
addResult(assertIsFalse(session.exists(thirdVersion), null, f));
f = createResult(FAILURE, "Version 4 has not been deleted!");
addResult(assertIsFalse(session.exists(fourthVersion), null, f));
f = createResult(FAILURE, "Version 5 has not been deleted!");
addResult(assertIsFalse(session.exists(fifthVersion), null, f));
} finally {
deleteTestFolder();
}
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException in project copper-cms by PogeyanOSS.
the class BaseTypesTest method run.
@Override
public void run(Session session) {
CmisTestResult failure;
// check base types
Set<String> cmisTypes = new HashSet<String>();
cmisTypes.add(BaseTypeId.CMIS_DOCUMENT.value());
cmisTypes.add(BaseTypeId.CMIS_FOLDER.value());
cmisTypes.add(BaseTypeId.CMIS_RELATIONSHIP.value());
cmisTypes.add(BaseTypeId.CMIS_POLICY.value());
if (session.getRepositoryInfo().getCmisVersion() != CmisVersion.CMIS_1_0) {
cmisTypes.add(BaseTypeId.CMIS_ITEM.value());
cmisTypes.add(BaseTypeId.CMIS_SECONDARY.value());
}
for (TypeDefinition typeDef : session.getTypeChildren(null, false)) {
String typeId = typeDef.getId();
if (typeId == null || !cmisTypes.contains(typeId)) {
addResult(createResult(FAILURE, "Base type has an invalid ID: " + typeId));
}
if (typeDef.getPropertyDefinitions() != null && !typeDef.getPropertyDefinitions().isEmpty()) {
addResult(createResult(WARNING, "Property type definitions were not requested but delivered. Type ID: " + typeId));
}
}
// document
try {
TypeDefinition documentType = session.getTypeDefinition(BaseTypeId.CMIS_DOCUMENT.value());
addResult(checkTypeDefinition(session, documentType, "Document type spec compliance: " + documentType.getId()));
failure = createResult(FAILURE, "Document type has the wrong base type: " + documentType.getBaseTypeId());
addResult(assertEquals(BaseTypeId.CMIS_DOCUMENT, documentType.getBaseTypeId(), null, failure));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(FAILURE, "Document type not available!", e, false));
}
// folder
try {
TypeDefinition folderType = session.getTypeDefinition(BaseTypeId.CMIS_FOLDER.value());
addResult(checkTypeDefinition(session, folderType, "Folder type spec compliance: " + folderType.getId()));
failure = createResult(FAILURE, "Folder type has the wrong base type: " + folderType.getBaseTypeId());
addResult(assertEquals(BaseTypeId.CMIS_FOLDER, folderType.getBaseTypeId(), null, failure));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(FAILURE, "Folder type not available!", e, false));
}
// relationship
try {
TypeDefinition relationshipType = session.getTypeDefinition(BaseTypeId.CMIS_RELATIONSHIP.value());
addResult(checkTypeDefinition(session, relationshipType, "Relationship type spec compliance: " + relationshipType.getId()));
failure = createResult(FAILURE, "Relationship type has the wrong base type: " + relationshipType.getBaseTypeId());
addResult(assertEquals(BaseTypeId.CMIS_RELATIONSHIP, relationshipType.getBaseTypeId(), null, failure));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(WARNING, "Relationship type not available!", e, false));
}
// policy
try {
TypeDefinition policyType = session.getTypeDefinition(BaseTypeId.CMIS_POLICY.value());
addResult(checkTypeDefinition(session, policyType, "Policy type spec compliance: " + policyType.getId()));
failure = createResult(FAILURE, "Policy type has the wrong base type: " + policyType.getBaseTypeId());
addResult(assertEquals(BaseTypeId.CMIS_POLICY, policyType.getBaseTypeId(), null, failure));
} catch (CmisInvalidArgumentException e) {
addResult(createResult(WARNING, "Policy type not available!", e, false));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(WARNING, "Policy type not available!", e, false));
}
// CMIS 1.1 types
if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_1) {
// item
try {
TypeDefinition itemType = session.getTypeDefinition(BaseTypeId.CMIS_ITEM.value());
addResult(checkTypeDefinition(session, itemType, "Item type spec compliance: " + itemType.getId()));
failure = createResult(FAILURE, "Item type has the wrong base type: " + itemType.getBaseTypeId());
addResult(assertEquals(BaseTypeId.CMIS_ITEM, itemType.getBaseTypeId(), null, failure));
} catch (CmisInvalidArgumentException e) {
addResult(createResult(WARNING, "Item type not available!", e, false));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(WARNING, "Item type not available!", e, false));
}
// secondary type
try {
TypeDefinition secondaryType = session.getTypeDefinition(BaseTypeId.CMIS_SECONDARY.value());
addResult(checkTypeDefinition(session, secondaryType, "Secondary type spec compliance: " + secondaryType.getId()));
failure = createResult(FAILURE, "Secondary type has the wrong base type: " + secondaryType.getBaseTypeId());
addResult(assertEquals(BaseTypeId.CMIS_SECONDARY, secondaryType.getBaseTypeId(), null, failure));
} catch (CmisInvalidArgumentException e) {
addResult(createResult(WARNING, "Secondary type not available!", e, false));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(WARNING, "Secondary type not available!", e, false));
}
} else {
try {
session.getTypeDefinition(BaseTypeId.CMIS_ITEM.value());
addResult(createResult(FAILURE, "CMIS 1.0 repository returns cmis:item type definition!"));
} catch (CmisBaseException e) {
// expected
}
try {
session.getTypeDefinition(BaseTypeId.CMIS_SECONDARY.value());
addResult(createResult(FAILURE, "CMIS 1.0 repository returns cmis:secondary type definition!"));
} catch (CmisBaseException e) {
// expected
}
}
// simple getTypeChildren paging test - skipping over all base types mut
// return an empty list
TypeDefinitionList typeDefinitionList = session.getBinding().getRepositoryService().getTypeChildren(session.getRepositoryInfo().getId(), null, false, BigInteger.valueOf(100), BigInteger.valueOf(6), null);
if (typeDefinitionList == null) {
addResult(createResult(FAILURE, "getTypeChildren() returned nothing!"));
} else {
if (typeDefinitionList.getList() != null && !typeDefinitionList.getList().isEmpty()) {
addResult(createResult(FAILURE, "A getTypeChildren() call on the base types must retrun an empty list if skipCount is >= 6! The repository returned a list of " + typeDefinitionList.getList().size() + " elements."));
}
if (Boolean.TRUE.equals(typeDefinitionList.hasMoreItems())) {
addResult(createResult(FAILURE, "A getTypeChildren() call on the base types must retrun an empty list if skipCount is >= 6! The repository returned hasMoreItems == true."));
}
}
// test getTypeDescendants()
int numOfTypes = runTypeChecks(session, session.getTypeDescendants(null, -1, true));
addResult(createInfoResult("Checked " + numOfTypes + " type definitions."));
}
use of org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method createFolder.
/**
* Creates a folder.
*/
protected Folder createFolder(Session session, Folder parent, String name, String objectTypeId) {
if (parent == null) {
throw new IllegalArgumentException("Parent is not set!");
}
if (name == null) {
throw new IllegalArgumentException("Name is not set!");
}
if (objectTypeId == null) {
throw new IllegalArgumentException("Object Type ID is not set!");
}
// check type
ObjectType type;
try {
type = session.getTypeDefinition(objectTypeId);
} catch (CmisObjectNotFoundException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Folder type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
return null;
}
if (Boolean.FALSE.equals(type.isCreatable())) {
addResult(createResult(SKIPPED, "Folder type '" + objectTypeId + "' is not creatable!", true));
return null;
}
// create
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
Folder result = null;
try {
// create the folder
result = parent.createFolder(properties, null, null, null, SELECT_ALL_NO_CACHE_OC);
} catch (CmisBaseException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Folder could not be created! Exception: " + e.getMessage(), e, true));
return null;
}
try {
CmisTestResult f;
// check folder name
f = createResult(FAILURE, "Folder name does not match!", false);
addResult(assertEquals(name, result.getName(), null, f));
// check the new folder
String[] propertiesToCheck = new String[result.getType().getPropertyDefinitions().size()];
int i = 0;
for (String propId : result.getType().getPropertyDefinitions().keySet()) {
propertiesToCheck[i++] = propId;
}
addResult(checkObject(session, result, propertiesToCheck, "New folder object spec compliance"));
// check object parents
List<Folder> objectParents = result.getParents();
f = createResult(FAILURE, "Newly created folder has no or more than one parent! ID: " + result.getId(), true);
addResult(assertEquals(1, objectParents.size(), null, f));
f = createResult(FAILURE, "First object parent of the newly created folder does not match parent! ID: " + result.getId(), true);
assertShallowEquals(parent, objectParents.get(0), null, f);
// check folder parent
Folder folderParent = result.getFolderParent();
f = createResult(FAILURE, "Newly created folder has no folder parent! ID: " + result.getId(), true);
addResult(assertNotNull(folderParent, null, f));
f = createResult(FAILURE, "Folder parent of the newly created folder does not match parent! ID: " + result.getId(), true);
assertShallowEquals(parent, folderParent, null, f);
// check children of parent
boolean found = false;
for (CmisObject child : parent.getChildren(SELECT_ALL_NO_CACHE_OC)) {
if (child == null) {
addResult(createResult(FAILURE, "Parent folder contains a null child!", true));
} else {
if (result.getId().equals(child.getId())) {
found = true;
f = createResult(FAILURE, "Folder and parent child don't match! ID: " + result.getId(), true);
assertShallowEquals(result, child, null, f);
break;
}
}
}
if (!found) {
addResult(createResult(FAILURE, "Folder is not a child of the parent folder! ID: " + result.getId(), true));
}
} catch (CmisBaseException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created folder is invalid! Exception: " + e.getMessage(), e, true));
}
return result;
}
Aggregations