Search in sources :

Example 1 with CreatablePropertyTypes

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());
}
Also used : CreatablePropertyTypes(org.apache.chemistry.opencmis.commons.data.CreatablePropertyTypes) ArrayList(java.util.ArrayList) PropertyType(org.apache.chemistry.opencmis.commons.enums.PropertyType) DocumentTypeDefinitionImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.DocumentTypeDefinitionImpl) PropertyDefinition(org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition) AbstractPropertyDefinition(org.apache.chemistry.opencmis.commons.impl.dataobjects.AbstractPropertyDefinition) ObjectType(org.apache.chemistry.opencmis.client.api.ObjectType) CmisObjectNotFoundException(org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException) CmisTestResult(org.apache.chemistry.opencmis.tck.CmisTestResult) Map(java.util.Map)

Aggregations

ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 ObjectType (org.apache.chemistry.opencmis.client.api.ObjectType)1 CreatablePropertyTypes (org.apache.chemistry.opencmis.commons.data.CreatablePropertyTypes)1 PropertyDefinition (org.apache.chemistry.opencmis.commons.definitions.PropertyDefinition)1 PropertyType (org.apache.chemistry.opencmis.commons.enums.PropertyType)1 CmisObjectNotFoundException (org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException)1 AbstractPropertyDefinition (org.apache.chemistry.opencmis.commons.impl.dataobjects.AbstractPropertyDefinition)1 DocumentTypeDefinitionImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.DocumentTypeDefinitionImpl)1 CmisTestResult (org.apache.chemistry.opencmis.tck.CmisTestResult)1