use of org.apache.chemistry.opencmis.client.api.ObjectType in project copper-cms by PogeyanOSS.
the class CreateAndDeleteTypeTest method createTypeWithProperties.
private void createTypeWithProperties(Session session, ObjectType parentType) {
CmisTestResult failure = null;
CreatablePropertyTypes cpt = session.getRepositoryInfo().getCapabilities().getCreatablePropertyTypes();
if (cpt == null || cpt.canCreate() == null || cpt.canCreate().isEmpty()) {
addResult(createResult(FAILURE, "Repository Info does not indicate, which property types can be created!"));
return;
}
// define the type
DocumentTypeDefinitionImpl newTypeDef = createDocumentTypeDefinition(session, "tck:testid_with_properties", parentType);
// add a property for each creatable property type
for (PropertyType propType : PropertyType.values()) {
if (!cpt.canCreate().contains(propType)) {
continue;
}
newTypeDef.addPropertyDefinition(createPropertyDefinition(propType));
}
// 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));
}
// check properties
List<PropertyDefinition<?>> newPropDefs = new ArrayList<PropertyDefinition<?>>();
for (Map.Entry<String, PropertyDefinition<?>> propDef : newType.getPropertyDefinitions().entrySet()) {
if (Boolean.FALSE.equals(propDef.getValue().isInherited())) {
newPropDefs.add(propDef.getValue());
}
}
failure = createResult(FAILURE, "The number of defined properties and the number of non-inherited properties don't match!");
addResult(assertEquals(newTypeDef.getPropertyDefinitions().size(), newPropDefs.size(), null, failure));
// check the order of the properties, which must match the order of the
// original type definition
// (OpenCMIS keeps the order of the property definitions.)
int i = 0;
for (Map.Entry<String, PropertyDefinition<?>> propDef : newTypeDef.getPropertyDefinitions().entrySet()) {
PropertyDefinition<?> newPropDef = newPropDefs.get(i);
failure = createResult(FAILURE, "Property " + (i + 1) + " must be of type " + propDef.getValue().getPropertyType() + " but is of type " + newPropDef.getPropertyType() + "!");
addResult(assertEquals(propDef.getValue().getPropertyType(), newPropDef.getPropertyType(), null, failure));
addResult(createInfoResult("Repository assigned the property '" + propDef.getValue().getId() + "' the following property id: " + newPropDef.getId()));
i++;
}
// delete the type
deleteType(session, newType.getId());
}
use of org.apache.chemistry.opencmis.client.api.ObjectType in project copper-cms by PogeyanOSS.
the class CreateAndDeleteTypeTest method run.
@Override
public void run(Session session) {
if (session.getRepositoryInfo().getCmisVersion() == CmisVersion.CMIS_1_0) {
addResult(createResult(SKIPPED, "Type mutability is not supported by CMIS 1.0. Test skipped!"));
return;
}
ObjectType parentType = session.getTypeDefinition(getDocumentTestTypeId());
if (parentType.getTypeMutability() == null || !Boolean.TRUE.equals(parentType.getTypeMutability().canCreate())) {
addResult(createResult(SKIPPED, "Test document type doesn't allow creating a sub-type. Test skipped!"));
return;
}
createTypeWithoutProperties(session, parentType);
createTypeWithProperties(session, parentType);
}
use of org.apache.chemistry.opencmis.client.api.ObjectType 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;
}
use of org.apache.chemistry.opencmis.client.api.ObjectType in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method createType.
// --- type helpers ---
/**
* Creates a new type.
*/
protected ObjectType createType(Session session, TypeDefinition typeDef) {
NewTypeSettableAttributes settableAttributes = session.getRepositoryInfo().getCapabilities().getNewTypeSettableAttributes();
if (settableAttributes == null) {
addResult(createResult(WARNING, "Repository Info does not indicate, which type attributes can be set!"));
} else {
}
ObjectType newType = null;
try {
newType = session.createType(typeDef);
addResult(createInfoResult("Created type '" + typeDef.getId() + "'. Repository assigned the following type ID: " + newType.getId()));
} catch (CmisBaseException e) {
addResult(createResult(FAILURE, "Creating type '" + typeDef.getId() + "' failed: " + e.getMessage(), e, false));
return null;
}
addResult(checkTypeDefinition(session, newType, "Newly created type spec compliance."));
if (newType.getTypeMutability() == null) {
addResult(createResult(FAILURE, "Newly created type does not provide type mutability data! ID: " + newType.getId()));
}
return newType;
}
use of org.apache.chemistry.opencmis.client.api.ObjectType in project copper-cms by PogeyanOSS.
the class AbstractSessionTest method createPolicy.
/**
* Creates a policy.
*/
protected Policy createPolicy(Session session, Folder parent, String name, String policyText, 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, "Policy type '" + objectTypeId + "' is not available: " + e.getMessage(), e, true));
return null;
}
if (Boolean.FALSE.equals(type.isCreatable())) {
addResult(createResult(SKIPPED, "Policy type '" + objectTypeId + "' is not creatable!", true));
return null;
}
boolean isFilable = Boolean.TRUE.equals(type.isFileable());
addResult(createResult(INFO, "Policy type '" + objectTypeId + "' is " + (isFilable ? "" : "not ") + "filable."));
// create
Map<String, Object> properties = new HashMap<String, Object>();
properties.put(PropertyIds.NAME, name);
properties.put(PropertyIds.OBJECT_TYPE_ID, objectTypeId);
if (policyText != null) {
properties.put(PropertyIds.POLICY_TEXT, policyText);
}
Policy result = null;
try {
// create the item
if (isFilable) {
result = parent.createPolicy(properties, null, null, null, SELECT_ALL_NO_CACHE_OC);
} else {
ObjectId policyId = session.createPolicy(properties, null, null, null, null);
result = (Policy) session.getObject(policyId, SELECT_ALL_NO_CACHE_OC);
}
} catch (CmisBaseException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Policy could not be created! Exception: " + e.getMessage(), e, true));
return null;
}
CmisTestResult f;
try {
// check item name
f = createResult(FAILURE, "Policy name does not match!", false);
addResult(assertEquals(name, result.getName(), null, f));
addResult(checkObject(session, result, getAllProperties(result), "New policy object spec compliance"));
} catch (CmisBaseException e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Newly created policy is invalid! Exception: " + e.getMessage(), e, true));
}
// check parents
List<Folder> parents = result.getParents(SELECT_ALL_NO_CACHE_OC);
if (isFilable) {
boolean found = false;
for (Folder folder : parents) {
if (parent.getId().equals(folder.getId())) {
found = true;
break;
}
}
if (!found) {
addResult(createResult(FAILURE, "The folder the item has been created in is not in the list of the item parents!"));
}
} else {
f = createResult(FAILURE, "Policy is not filable but has a parent!", false);
addResult(assertIsTrue(parents.isEmpty(), null, f));
}
return result;
}
Aggregations