use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.
the class BaseTypesTest method runTypeChecks.
private int runTypeChecks(Session session, List<Tree<ObjectType>> types) {
if (types == null) {
return 0;
}
int numOfTypes = 0;
CmisTestResult failure;
for (Tree<ObjectType> tree : types) {
failure = createResult(FAILURE, "Types tree contains null leaf!");
addResult(assertNotNull(tree, null, failure));
if (tree != null) {
numOfTypes++;
addResult(checkTypeDefinition(session, tree.getItem(), "Type spec compliance: " + tree.getItem().getId()));
// clear the cache to ensure that the type definition is
// reloaded from the repository
session.clear();
try {
TypeDefinition reloadedType = session.getTypeDefinition(tree.getItem().getId());
addResult(checkTypeDefinition(session, reloadedType, "Type spec compliance: " + (reloadedType == null ? "?" : reloadedType.getId())));
failure = createResult(FAILURE, "Type fetched via getTypeDescendants() is does not macth type fetched via getTypeDefinition(): " + tree.getItem().getId());
addResult(assertEquals(tree.getItem(), reloadedType, null, failure));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(FAILURE, "Type fetched via getTypeDescendants() is not available via getTypeDefinition(): " + tree.getItem().getId(), e, false));
}
// clear the cache again to ensure that the type definition
// children are reloaded from the repository
session.clear();
try {
ItemIterable<ObjectType> reloadedTypeChildren = session.getTypeChildren(tree.getItem().getId(), true);
// check type children
Map<String, ObjectType> typeChilden = new HashMap<String, ObjectType>();
for (ObjectType childType : reloadedTypeChildren) {
if (childType == null) {
addResult(createResult(FAILURE, "The list of types contains a null entry!"));
continue;
}
addResult(checkTypeDefinition(session, childType, "Type spec compliance: " + childType.getId()));
typeChilden.put(childType.getId(), childType);
}
// compare type children and type descendants
if (tree.getChildren() == null) {
failure = createResult(FAILURE, "Type children fetched via getTypeDescendants() don't match type children fetched via getTypeChildren(): " + tree.getItem().getId());
addResult(assertEquals(0, typeChilden.size(), null, failure));
} else {
// collect the children
Map<String, ObjectType> typeDescendants = new HashMap<String, ObjectType>();
for (Tree<ObjectType> childType : tree.getChildren()) {
if ((childType != null) && (childType.getItem() != null)) {
typeDescendants.put(childType.getItem().getId(), childType.getItem());
}
}
failure = createResult(FAILURE, "Type children fetched via getTypeDescendants() don't match type children fetched via getTypeChildren(): " + tree.getItem().getId());
addResult(assertEquals(typeDescendants.size(), typeChilden.size(), null, failure));
for (ObjectType compareType : typeDescendants.values()) {
failure = createResult(FAILURE, "Type fetched via getTypeDescendants() doesn't match type fetched via getTypeChildren(): " + tree.getItem().getId());
addResult(assertEquals(compareType, typeChilden.get(compareType.getId()), null, failure));
}
}
} catch (CmisObjectNotFoundException e) {
addResult(createResult(FAILURE, "Type children fetched via getTypeDescendants() are not available via getTypeChildren(): " + tree.getItem().getId(), e, false));
}
numOfTypes += runTypeChecks(session, tree.getChildren());
}
}
return numOfTypes;
}
use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.
the class CreateAndDeleteTypeTest method createTypeWithoutProperties.
private void createTypeWithoutProperties(Session session, ObjectType parentType) {
CmisTestResult failure = null;
// define the type
DocumentTypeDefinitionImpl newTypeDef = createDocumentTypeDefinition(session, "tck:testid_without_properties", parentType);
// create the type
ObjectType newType = createType(session, newTypeDef);
if (newType == null) {
return;
}
// get the type
ObjectType newType2 = null;
try {
newType2 = session.getTypeDefinition(newType.getId());
// assert type definitions
failure = createResult(FAILURE, "The type definition returned by createType() doesn't match the type definition returned by getTypeDefinition()!");
addResult(assertEquals(newType, newType2, null, failure));
} catch (CmisObjectNotFoundException e) {
addResult(createResult(FAILURE, "Newly created type can not be fetched. Id: " + newType.getId(), e, false));
}
// delete the type
deleteType(session, newType.getId());
}
use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.
the class SecondaryTypesTest method detachSecondaryType.
private void detachSecondaryType(Session session, Document doc, ObjectType secondaryTestType) {
CmisTestResult f;
List<String> secondaryTypesId = new ArrayList<String>();
for (SecondaryType secType : doc.getSecondaryTypes()) {
if (!secondaryTestType.getId().equals(secType.getId())) {
secondaryTypesId.add(secType.getId());
}
}
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.SECONDARY_OBJECT_TYPE_IDS, secondaryTypesId);
// detach secondary type
ObjectId newId = doc.updateProperties(properties);
Document newDoc = (Document) session.getObject(newId, SELECT_ALL_NO_CACHE_OC);
boolean found = false;
if (newDoc.getSecondaryTypes() != null) {
for (SecondaryType secType : newDoc.getSecondaryTypes()) {
if (secondaryTestType.getId().equals(secType.getId())) {
found = true;
break;
}
}
}
f = createResult(FAILURE, "Document still has the detached secondary type!");
addResult(assertIsFalse(found, null, f));
// check properties
ObjectType primaryType = newDoc.getType();
List<SecondaryType> secondaryTypes = newDoc.getSecondaryTypes();
for (Property<?> prop : doc.getProperties()) {
if (!primaryType.getPropertyDefinitions().containsKey(prop.getId())) {
f = createResult(FAILURE, "Property '" + prop.getId() + "' is neither defined by the primary type nor by a secondary type!");
if (secondaryTypes == null) {
addResult(f);
} else {
boolean foundProperty = false;
for (SecondaryType secondaryType : secondaryTypes) {
if (secondaryType.getPropertyDefinitions() != null && secondaryType.getPropertyDefinitions().containsKey(prop.getId())) {
foundProperty = true;
break;
}
}
addResult(assertIsTrue(foundProperty, null, f));
}
}
}
}
use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.
the class CheckedOutTest method run.
@Override
public void run(Session session) {
CmisTestResult f;
boolean supportsOrderByName = isOrderByNameSupported(session);
OperationContext orderContext = (supportsOrderByName ? SELECT_ALL_NO_CACHE_OC_ORDER_BY_NAME : SELECT_ALL_NO_CACHE_OC);
Document pwc = null;
try {
// create folder and a checked-out document
Folder testFolder = createTestFolder(session);
Document doc = createDocument(session, testFolder, "checkedouttest.txt", "checked out");
DocumentTypeDefinition docType = (DocumentTypeDefinition) doc.getType();
if (!docType.isVersionable()) {
addResult(createResult(WARNING, "Test type is not versionable. Check out skipped!"));
} else {
ObjectId pwcId = doc.checkOut();
pwc = (Document) session.getObject(pwcId, SELECT_ALL_NO_CACHE_OC);
}
// test all checked-out documents
int sessionCheckedOut = checkPWCs(session, session.getCheckedOutDocs(orderContext), supportsOrderByName);
addResult(createInfoResult(sessionCheckedOut + " checked out document(s) overall."));
if (pwc != null) {
f = createResult(FAILURE, "There should be at least one checked out document in the repository!");
addResult(assertIsTrue(sessionCheckedOut >= 1, null, f));
}
// test checked-out documents in the test folder
int testFolderCheckedOut = checkPWCs(session, testFolder.getCheckedOutDocs(orderContext), supportsOrderByName);
addResult(createInfoResult(testFolderCheckedOut + " checked out document(s) in the test folder."));
if (pwc != null) {
f = createResult(FAILURE, "There should be at least one checked out document in the test folder!");
addResult(assertIsTrue(testFolderCheckedOut >= 1, null, f));
}
// remove the PWC and document
if (pwc != null) {
pwc.cancelCheckOut();
pwc = null;
}
deleteObject(doc);
} finally {
if (pwc != null) {
pwc.cancelCheckOut();
}
deleteTestFolder();
}
}
use of org.apache.chemistry.opencmis.tck.CmisTestResult in project copper-cms by PogeyanOSS.
the class VersionDeleteTest method deleteVersion.
private void deleteVersion(Document versionDoc, Document previousDoc, int version) {
CmisTestResult f;
// check Allowable Action
if (!versionDoc.hasAllowableAction(Action.CAN_DELETE_OBJECT)) {
addResult(createResult(WARNING, "Version " + version + " does not have the Allowable Action 'canDeleteObject'."));
return;
}
// get version history before delete
List<Document> versionsBefore = versionDoc.getAllVersions();
// delete and check
try {
versionDoc.delete(false);
} catch (CmisInvalidArgumentException iae) {
addResult(createResult(WARNING, "Deletion of version " + version + " failed with an invalidArgument exception. " + "Removing just one version doesn't seem to be supported."));
return;
} catch (CmisConstraintException ce) {
addResult(createResult(WARNING, "Deletion of version " + version + " failed with an constraint exception. " + "Removing just one version doesn't seem to be supported."));
return;
}
f = createResult(FAILURE, "Deleted version " + version + " still exists!");
addResult(assertIsFalse(exists(versionDoc), null, f));
// check version history after delete
if (previousDoc != null) {
List<Document> versionsAfter = previousDoc.getAllVersions();
f = createResult(FAILURE, "After version " + version + " has been deleted, the version history should consist of " + (versionsBefore.size() - 1) + " documents but is has " + versionsAfter.size() + " !");
addResult(assertEquals(versionsBefore.size() - 1, versionsAfter.size(), null, f));
}
}
Aggregations