use of org.apache.chemistry.opencmis.commons.data.CreatablePropertyTypes 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());
}
Aggregations