use of org.apache.chemistry.opencmis.client.api.ObjectType in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method deleteType.
/**
* Deletes a type.
*/
protected void deleteType(Session session, String typeId) {
ObjectType type = session.getTypeDefinition(typeId);
if (type == null) {
addResult(createResult(FAILURE, "Type does not exist and therefore cannot be deleted! ID: " + typeId));
return;
}
// check if type can be deleted
if (type.getTypeMutability() == null) {
addResult(createResult(FAILURE, "Type does not provide type mutability data! ID: " + typeId));
} else {
if (!Boolean.TRUE.equals(type.getTypeMutability().canDelete())) {
addResult(createResult(WARNING, "Type indicates that it cannot be deleted. Trying it anyway. ID: " + typeId));
}
}
// delete it
try {
session.deleteType(typeId);
} catch (CmisBaseException e) {
addResult(createResult(FAILURE, "Deleting type '" + typeId + "' failed: " + e.getMessage(), e, false));
return;
}
// check if the type still exists
try {
session.getTypeDefinition(typeId);
addResult(createResult(FAILURE, "Type should not exist anymore but it is still there! ID: " + typeId, true));
} catch (CmisObjectNotFoundException e) {
// expected result
}
}
use of org.apache.chemistry.opencmis.client.api.ObjectType 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.client.api.ObjectType 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.client.api.ObjectType in project copper-cms by PogeyanOSS.
the class SecondaryTypesTest method run.
@Override
public void run(Session session) {
if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_0) {
addResult(createResult(SKIPPED, "Secondary types are not supported by CMIS 1.0. Test skipped!"));
return;
}
if (!hasSecondaries(session)) {
addResult(createResult(SKIPPED, "Repository doesn't support secondary types. Test skipped!"));
return;
}
// check cmis:secondaryObjectTypeIds property definition
ObjectType docType = session.getTypeDefinition(getDocumentTestTypeId());
PropertyDefinition<?> secTypesPropDef = docType.getPropertyDefinitions().get(PropertyIds.SECONDARY_OBJECT_TYPE_IDS);
if (secTypesPropDef == null) {
addResult(createResult(FAILURE, "Test document type has no " + PropertyIds.SECONDARY_OBJECT_TYPE_IDS + " property!"));
return;
} else if (secTypesPropDef.getUpdatability() != Updatability.READWRITE) {
addResult(createResult(SKIPPED, "Test document type does not allow attaching secondary types. Test skipped!"));
return;
}
// create a test folder
Folder testFolder = createTestFolder(session);
try {
String secondaryTestTypeId = getSecondaryTestTypeId();
ObjectType secondaryTestType = session.getTypeDefinition(secondaryTestTypeId);
createDocumentAndAttachSecondaryType(session, testFolder, secondaryTestType);
createDocumentWithSecondaryType(session, testFolder, secondaryTestType);
} finally {
// delete the test folder
deleteTestFolder();
}
}
use of org.apache.chemistry.opencmis.client.api.ObjectType 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));
}
}
}
}
Aggregations