use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class TestCustomModel method testListBasicModels.
@Test
public void testListBasicModels() throws Exception {
setRequestContext(customModelAdmin);
String modelName_1 = "testModel1" + System.currentTimeMillis();
// Create the model as a Model Administrator
CustomModel customModel_1 = createCustomModel(modelName_1, getTestNamespaceUriPrefixPair(), ModelStatus.DRAFT);
String modelName_2 = "testModel2" + System.currentTimeMillis();
CustomModel customModel_2 = createCustomModel(modelName_2, getTestNamespaceUriPrefixPair(), ModelStatus.DRAFT);
String modelName_3 = "testModel3" + System.currentTimeMillis();
CustomModel customModel_3 = createCustomModel(modelName_3, getTestNamespaceUriPrefixPair(), ModelStatus.DRAFT);
Paging paging = getPaging(0, Integer.MAX_VALUE);
HttpResponse response = getAll("cmm", paging, 200);
List<CustomModel> models = RestApiUtil.parseRestApiEntries(response.getJsonResponse(), CustomModel.class);
assertTrue(models.size() >= 3);
assertTrue(models.contains(customModel_1));
assertTrue(models.contains(customModel_2));
assertTrue(models.contains(customModel_3));
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class TestCustomModel method testUpdateModel_WithAspectsAndTypes.
@Test
public // SHA-726
void testUpdateModel_WithAspectsAndTypes() throws Exception {
setRequestContext(customModelAdmin);
String modelName = "testModel" + System.currentTimeMillis();
Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
// Create the model as a Model Administrator
createCustomModel(modelName, namespacePair, ModelStatus.DRAFT);
// Add type
String typeBaseName = "testTypeBase" + System.currentTimeMillis();
final String typeBaseNameWithPrefix = namespacePair.getSecond() + QName.NAMESPACE_PREFIX + typeBaseName;
createTypeAspect(CustomType.class, modelName, typeBaseName, "test typeBase title", null, "cm:content");
// Add aspect
final String aspectName = "testAspect" + System.currentTimeMillis();
final String aspectNameWithPrefix = namespacePair.getSecond() + QName.NAMESPACE_PREFIX + aspectName;
createTypeAspect(CustomAspect.class, modelName, aspectName, null, null, null);
// Activate the model
CustomModel modelOneStatusPayload = new CustomModel();
modelOneStatusPayload.setStatus(ModelStatus.ACTIVE);
put("cmm", modelName, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 200);
// Add another type with 'typeBaseName' as its parent
String childTypeName = "testTypeChild" + System.currentTimeMillis();
createTypeAspect(CustomType.class, modelName, childTypeName, "test typeChild title", "test typeChild Desc", typeBaseNameWithPrefix);
// Add another aspect with 'aspectName' as its parent
final String childAspectName = "testChildAspect" + System.currentTimeMillis();
createTypeAspect(CustomAspect.class, modelName, childAspectName, "test child aspect title", null, aspectNameWithPrefix);
// Deactivate the model
modelOneStatusPayload = new CustomModel();
modelOneStatusPayload.setStatus(ModelStatus.DRAFT);
put("cmm", modelName, RestApiUtil.toJsonAsString(modelOneStatusPayload), SELECT_STATUS_QS, 200);
// Test update the namespace prefix
CustomModel updatePayload = new CustomModel();
String modifiedPrefix = namespacePair.getSecond() + "Modified";
updatePayload.setNamespacePrefix(modifiedPrefix);
updatePayload.setNamespaceUri(namespacePair.getFirst());
HttpResponse response = put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), null, 200);
CustomModel returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class);
assertEquals(modifiedPrefix, returnedModel.getNamespacePrefix());
assertEquals("The namespace URI shouldn't have changed.", namespacePair.getFirst(), returnedModel.getNamespaceUri());
// Test update the namespace URI
updatePayload = new CustomModel();
updatePayload.setNamespacePrefix(modifiedPrefix);
String modifiedURI = namespacePair.getFirst() + "Modified";
updatePayload.setNamespaceUri(modifiedURI);
response = put("cmm", modelName, RestApiUtil.toJsonAsString(updatePayload), null, 200);
returnedModel = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomModel.class);
assertEquals(modifiedURI, returnedModel.getNamespaceUri());
assertEquals("The namespace prefix shouldn't have changed.", modifiedPrefix, returnedModel.getNamespacePrefix());
// Retrieve the child type
response = getSingle("cmm/" + modelName + "/types", childTypeName, 200);
CustomType returnedChildType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
final String newTypeParentName = modifiedPrefix + QName.NAMESPACE_PREFIX + typeBaseName;
assertEquals("The parent name prefix should have been updated.", newTypeParentName, returnedChildType.getParentName());
// Retrieve the child aspect
response = getSingle("cmm/" + modelName + "/aspects", childAspectName, 200);
CustomAspect returnedChildAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class);
final String newAspectParentName = modifiedPrefix + QName.NAMESPACE_PREFIX + aspectName;
assertEquals("The parent name prefix should have been updated.", newAspectParentName, returnedChildAspect.getParentName());
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class TestCustomProperty method testCreateProperties.
@Test
public void testCreateProperties() throws Exception {
setRequestContext(customModelAdmin);
String modelName = "testModel" + System.currentTimeMillis();
Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
// Create the model as a Model Administrator
createCustomModel(modelName, namespacePair, ModelStatus.DRAFT);
{
// Create aspect
String aspectName = "testAspect1" + System.currentTimeMillis();
CustomAspect aspect = createTypeAspect(CustomAspect.class, modelName, aspectName, null, null, null);
// Update the Aspect by adding property
CustomAspect payload = new CustomAspect();
String aspectPropName = "testAspect1Prop1" + System.currentTimeMillis();
CustomModelProperty aspectProp = new CustomModelProperty();
aspectProp.setName(aspectPropName);
aspectProp.setTitle("property title");
aspectProp.setMultiValued(true);
aspectProp.setIndexed(true);
aspectProp.setFacetable(Facetable.TRUE);
aspectProp.setIndexTokenisationMode(IndexTokenisationMode.BOTH);
List<CustomModelProperty> props = new ArrayList<>(1);
props.add(aspectProp);
payload.setProperties(props);
setRequestContext(nonAdminUserName);
// Try to update the aspect as a non Admin user
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 403);
setRequestContext(customModelAdmin);
// Try to update the aspect as a Model Administrator
// Type name is mandatory
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 400);
// Add the mandatory aspect name to the payload
payload.setName(aspectName);
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200);
// Retrieve the updated aspect
HttpResponse response = getSingle("cmm/" + modelName + "/aspects", aspect.getName(), 200);
CustomAspect returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class);
// Check the aspect's added property
assertEquals(1, returnedAspect.getProperties().size());
CustomModelProperty customModelProperty = returnedAspect.getProperties().get(0);
assertEquals(aspectPropName, customModelProperty.getName());
assertEquals("property title", customModelProperty.getTitle());
assertEquals(namespacePair.getSecond() + QName.NAMESPACE_PREFIX + aspectPropName, customModelProperty.getPrefixedName());
assertEquals("Default data type is 'd:text'.", "d:text", customModelProperty.getDataType());
assertNull(customModelProperty.getDescription());
assertTrue(customModelProperty.isMultiValued());
assertFalse(customModelProperty.isMandatory());
assertFalse(customModelProperty.isMandatoryEnforced());
assertNull(customModelProperty.getDefaultValue());
assertTrue(customModelProperty.isIndexed());
assertEquals(Facetable.TRUE, customModelProperty.getFacetable());
assertEquals(IndexTokenisationMode.BOTH, customModelProperty.getIndexTokenisationMode());
// Test duplicate property name
aspectProp = new CustomModelProperty();
// Existing name
aspectProp.setName(aspectPropName);
aspectProp.setTitle("new property title");
props = new ArrayList<>(1);
props.add(aspectProp);
payload.setProperties(props);
// Try to update the aspect as a Model Administrator
// property name already exists
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 409);
}
{
// Create type
String typeName = "testType1" + System.currentTimeMillis();
CustomType type = createTypeAspect(CustomType.class, modelName, typeName, "test type1 title", "test type1 Desc", "cm:content");
// Update the Type by adding property
CustomType payload = new CustomType();
String typePropName = "testType1Prop1" + System.currentTimeMillis();
CustomModelProperty typeProp = new CustomModelProperty();
typeProp.setName(typePropName);
typeProp.setTitle("property title");
typeProp.setDataType("d:int");
typeProp.setIndexed(false);
typeProp.setFacetable(Facetable.FALSE);
typeProp.setIndexTokenisationMode(IndexTokenisationMode.FALSE);
List<CustomModelProperty> props = new ArrayList<>(1);
props.add(typeProp);
payload.setProperties(props);
setRequestContext(nonAdminUserName);
// Try to update the type as a non Admin user
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 403);
setRequestContext(customModelAdmin);
// Try to update the type as a Model Administrator
// Type name is mandatory
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 400);
// Add the mandatory type name to the payload
payload.setName(typeName);
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200);
// Retrieve the updated type
HttpResponse response = getSingle("cmm/" + modelName + "/types", type.getName(), 200);
CustomType returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
// Check the type's added property
assertEquals(1, returnedType.getProperties().size());
CustomModelProperty customModelProperty = returnedType.getProperties().get(0);
assertEquals(typePropName, customModelProperty.getName());
assertEquals("property title", customModelProperty.getTitle());
assertEquals(namespacePair.getSecond() + QName.NAMESPACE_PREFIX + typePropName, customModelProperty.getPrefixedName());
assertEquals("d:int", customModelProperty.getDataType());
assertNull(customModelProperty.getDescription());
assertFalse(customModelProperty.isMultiValued());
assertFalse(customModelProperty.isMandatory());
assertFalse(customModelProperty.isMandatoryEnforced());
assertNull(customModelProperty.getDefaultValue());
assertFalse(customModelProperty.isIndexed());
assertEquals(Facetable.FALSE, customModelProperty.getFacetable());
assertEquals(IndexTokenisationMode.FALSE, customModelProperty.getIndexTokenisationMode());
// Retrieve the updated type with all the properties (include inherited)
response = getSingle("cmm/" + modelName + "/types", type.getName() + SELECT_ALL_PROPS, 200);
returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
assertEquals(3, returnedType.getProperties().size());
// Check for the inherited properties
// cm:content
assertNotNull(getProperty(returnedType.getProperties(), "content"));
// cm:name
assertNotNull(getProperty(returnedType.getProperties(), "name"));
// Create another property and set all of its attributes
payload = new CustomType();
payload.setName(typeName);
String typePropName2 = "testType1Prop2" + System.currentTimeMillis();
typeProp = new CustomModelProperty();
typeProp.setName(typePropName2);
typeProp.setTitle("property2 title");
typeProp.setDescription("property2 desciption");
typeProp.setDataType("d:int");
typeProp.setDefaultValue("0");
typeProp.setMultiValued(false);
typeProp.setMandatory(true);
typeProp.setMandatoryEnforced(true);
props = new ArrayList<>(1);
props.add(typeProp);
payload.setProperties(props);
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 200);
// Retrieve the updated type
response = getSingle("cmm/" + modelName + "/types", type.getName(), 200);
returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
// Check the type's added property
assertEquals(2, returnedType.getProperties().size());
customModelProperty = getProperty(returnedType.getProperties(), typePropName2);
assertNotNull(customModelProperty);
assertEquals(typePropName2, customModelProperty.getName());
assertEquals("property2 title", customModelProperty.getTitle());
assertEquals(namespacePair.getSecond() + QName.NAMESPACE_PREFIX + typePropName2, customModelProperty.getPrefixedName());
assertEquals("d:int", customModelProperty.getDataType());
assertEquals("property2 desciption", customModelProperty.getDescription());
assertFalse(customModelProperty.isMultiValued());
assertTrue(customModelProperty.isMandatory());
assertTrue(customModelProperty.isMandatoryEnforced());
assertEquals("0", customModelProperty.getDefaultValue());
// Test duplicate property name
typeProp = new CustomModelProperty();
// Existing name
typeProp.setName(typePropName2);
typeProp.setTitle("new property title");
typeProp.setDataType("d:text");
props = new ArrayList<>(1);
props.add(typeProp);
payload.setProperties(props);
// property name already exists
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(payload), SELECT_PROPS_QS, 409);
}
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class TestCustomProperty method testDeleteProperty.
@Test
public void testDeleteProperty() throws Exception {
setRequestContext(customModelAdmin);
String modelName = "testModelDeleteProp" + System.currentTimeMillis();
Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
// Create the model as a Model Administrator
createCustomModel(modelName, namespacePair, ModelStatus.DRAFT);
/*
* Create aspect and update it by adding two properties
*/
String aspectName = "testAspect1" + System.currentTimeMillis();
createTypeAspect(CustomAspect.class, modelName, aspectName, null, null, null);
// Update the Aspect by adding property - property one
CustomAspect aspectPayload = new CustomAspect();
aspectPayload.setName(aspectName);
String aspectPropNameOne = "testAspect1Prop1" + System.currentTimeMillis();
CustomModelProperty aspectPropOne = new CustomModelProperty();
aspectPropOne.setName(aspectPropNameOne);
aspectPropOne.setTitle("aspect property one title");
aspectPropOne.setMultiValued(true);
List<CustomModelProperty> props = new ArrayList<>(1);
props.add(aspectPropOne);
aspectPayload.setProperties(props);
// create property one
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 200);
// Update the Aspect by adding another property - property two
aspectPayload = new CustomAspect();
aspectPayload.setName(aspectName);
String aspectPropNameTwo = "testAspect1Prop2" + System.currentTimeMillis();
CustomModelProperty aspectPropTwo = new CustomModelProperty();
aspectPropTwo.setName(aspectPropNameTwo);
aspectPropTwo.setTitle("aspect property two title");
aspectPropTwo.setMandatory(true);
aspectPropTwo.setDataType("d:int");
aspectPropTwo.setDefaultValue("1");
props = new ArrayList<>(1);
props.add(aspectPropTwo);
aspectPayload.setProperties(props);
// create property two
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 200);
// Retrieve the updated aspect
HttpResponse response = getSingle("cmm/" + modelName + "/aspects", aspectName, 200);
CustomAspect returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class);
// Check the aspect's added properties
assertEquals(2, returnedAspect.getProperties().size());
/*
* Create type and update it by adding two properties
*/
String typeName = "testType1" + System.currentTimeMillis();
createTypeAspect(CustomType.class, modelName, typeName, "test type1 title", null, "cm:content");
// Update the Type by adding property - property one
CustomType typePayload = new CustomType();
typePayload.setName(typeName);
String typePropNameOne = "testType1Prop1" + System.currentTimeMillis();
CustomModelProperty typePropOne = new CustomModelProperty();
typePropOne.setName(typePropNameOne);
typePropOne.setTitle("type property one title");
props = new ArrayList<>(1);
props.add(typePropOne);
typePayload.setProperties(props);
// create property one
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 200);
// Update the Type by adding another property - property two
typePayload = new CustomType();
typePayload.setName(typeName);
// Create inline MINMAX constraint
CustomModelConstraint inlineMinMaxConstraint = new CustomModelConstraint();
inlineMinMaxConstraint.setType("MINMAX");
inlineMinMaxConstraint.setTitle("test MINMAX title");
// Create the MinMax constraint's parameters
List<CustomModelNamedValue> parameters = new ArrayList<>(2);
parameters.add(buildNamedValue("maxValue", "100.0"));
parameters.add(buildNamedValue("minValue", "0.0"));
// Add the parameters into the constraint
inlineMinMaxConstraint.setParameters(parameters);
String typePropNameTwo = "testType1Prop2" + System.currentTimeMillis();
CustomModelProperty typePropTwo = new CustomModelProperty();
typePropTwo.setName(typePropNameTwo);
typePropTwo.setTitle("type property two title");
typePropTwo.setDataType("d:int");
// add the inline constraint
typePropTwo.setConstraints(Arrays.asList(inlineMinMaxConstraint));
props = new ArrayList<>(1);
props.add(typePropTwo);
typePayload.setProperties(props);
// create property one
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), SELECT_PROPS_QS, 200);
// Retrieve the updated type
response = getSingle("cmm/" + modelName + "/types", typeName, 200);
CustomType returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
// Check the type's added properties
assertEquals(2, returnedType.getProperties().size());
// Delete aspect's property one - model is inactive
{
final String deletePropOneAspectQS = getPropDeleteUpdateQS(aspectPropNameOne, true);
// Try to delete propertyOne from aspect
// missing payload
put("cmm/" + modelName + "/aspects", aspectName, null, deletePropOneAspectQS, 400);
CustomAspect deletePropAspectPayload = new CustomAspect();
// missing aspect name
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropOneAspectQS, 400);
setRequestContext(nonAdminUserName);
deletePropAspectPayload.setName(aspectName);
// unauthorised
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropOneAspectQS, 403);
setRequestContext(customModelAdmin);
// Delete as a Model Administrator
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropOneAspectQS, 200);
// Check the property has been deleted
response = getSingle("cmm/" + modelName + "/aspects", aspectName, 200);
returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class);
assertEquals(1, returnedAspect.getProperties().size());
assertFalse("Property one should have been deleted.", aspectPropNameOne.equals(returnedAspect.getProperties().get(0).getName()));
// Not found
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropOneAspectQS, 404);
}
// Delete type's property two - model is inactive
{
final String deletePropTwoTypeQS = getPropDeleteUpdateQS(typePropNameTwo, true);
// Try to delete propertyOne from type
// missing payload
put("cmm/" + modelName + "/types", typeName, null, deletePropTwoTypeQS, 400);
CustomType deletePropTypePayload = new CustomType();
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropTwoTypeQS, // missing type name
400);
setRequestContext(nonAdminUserName);
deletePropTypePayload.setName(typeName);
// unauthorised
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropTwoTypeQS, 403);
setRequestContext(customModelAdmin);
// Delete as a Model Administrator
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropTwoTypeQS, 200);
// Check the property has been deleted
response = getSingle("cmm/" + modelName + "/types", typeName, 200);
returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
assertEquals(1, returnedType.getProperties().size());
assertFalse("Property two should have been deleted.", typePropNameTwo.equals(returnedType.getProperties().get(0).getName()));
// Not found
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropTwoTypeQS, 404);
}
/*
* APPSREPO-59: delete the last property of a Type / Aspect for an active model
*/
// Activate the model
CustomModel statusPayload = new CustomModel();
statusPayload.setStatus(ModelStatus.ACTIVE);
put("cmm", modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200);
// Delete aspect's property two - model is active
{
setRequestContext(customModelAdmin);
final String deletePropTwoAspectQS = getPropDeleteUpdateQS(aspectPropNameTwo, true);
CustomAspect deletePropAspectPayload = new CustomAspect();
deletePropAspectPayload.setName(aspectName);
// Delete as a Model Administrator
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropTwoAspectQS, 200);
// Check the property has been deleted
response = getSingle("cmm/" + modelName + "/aspects", aspectName, 200);
returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class);
assertEquals("Property two should have been deleted.", 0, returnedAspect.getProperties().size());
// Not found
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(deletePropAspectPayload), deletePropTwoAspectQS, 404);
}
// Delete type's property one - model is active
{
final String deletePropOneTypeQS = getPropDeleteUpdateQS(typePropNameOne, true);
CustomType deletePropTypePayload = new CustomType();
deletePropTypePayload.setName(typeName);
// Delete as a Model Administrator
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropOneTypeQS, 200);
// Check the property has been deleted
response = getSingle("cmm/" + modelName + "/types", typeName, 200);
returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
assertEquals("Property one should have been deleted.", 0, returnedType.getProperties().size());
// Not found
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(deletePropTypePayload), deletePropOneTypeQS, 404);
}
}
use of org.alfresco.rest.api.tests.client.HttpResponse in project alfresco-remote-api by Alfresco.
the class TestCustomTypeAspect method testUpdateAspectsTypes.
@Test
public void testUpdateAspectsTypes() throws Exception {
setRequestContext(customModelAdmin);
String modelName = "testModeEditAspectType" + System.currentTimeMillis();
final Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
// Create the model as a Model Administrator
createCustomModel(modelName, namespacePair, ModelStatus.DRAFT);
// Test update aspect
{
// Create aspect
String aspectName = "testAspect" + System.currentTimeMillis();
createTypeAspect(CustomAspect.class, modelName, aspectName, "title", "desc", null);
// Update the aspect
CustomAspect aspectPayload = new CustomAspect();
aspectPayload.setDescription(null);
aspectPayload.setTitle("title modified");
aspectPayload.setParentName("cm:titled");
setRequestContext(nonAdminUserName);
// Try to update the aspect as a non Admin user
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 403);
setRequestContext(customModelAdmin);
// Modify the name
aspectPayload.setName(aspectName + "Modified");
// Try to update the aspect as a Model Administrator
// Note: aspect/type name cannot be modified
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 404);
aspectPayload.setName(aspectName);
// Update the aspect as a Model Administrator
HttpResponse response = put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 200);
CustomAspect returnedAspect = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomAspect.class);
compareCustomTypesAspects(aspectPayload, returnedAspect, "prefixedName");
// Update the aspect with an invalid parent
aspectPayload.setParentName("cm:titled" + System.currentTimeMillis());
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 409);
// Activate the model
CustomModel statusPayload = new CustomModel();
statusPayload.setStatus(ModelStatus.ACTIVE);
put("cmm", modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200);
// Remove the aspect's parent
// Note: cannot update the parent of an ACTIVE type/aspect.
aspectPayload.setParentName(null);
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 409);
statusPayload = new CustomModel();
statusPayload.setStatus(ModelStatus.DRAFT);
put("cmm", modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200);
// now update the aspect's parent - model is inactive
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), null, 200);
}
// Test update type
{
// Create type
String typeName = "testType" + System.currentTimeMillis();
createTypeAspect(CustomType.class, modelName, typeName, "title", "desc", "cm:content");
// Add property
CustomType addPropertyPayload = new CustomType();
addPropertyPayload.setName(typeName);
String typePropName = "testTypeProp1" + System.currentTimeMillis();
CustomModelProperty typeProp = new CustomModelProperty();
typeProp.setName(typePropName);
typeProp.setTitle("property title");
typeProp.setDataType("d:text");
List<CustomModelProperty> props = new ArrayList<>(1);
props.add(typeProp);
addPropertyPayload.setProperties(props);
// Create the property
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(addPropertyPayload), SELECT_PROPS_QS, 200);
// Update the type
CustomType typePayload = new CustomType();
typePayload.setDescription("desc modified");
typePayload.setTitle("title modified");
setRequestContext(nonAdminUserName);
// Try to update the type as a non Admin user
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), null, 403);
setRequestContext(customModelAdmin);
// Modify the name
typePayload.setName(typeName + "Modified");
// Try to update the type as a Model Administrator
// Note: type/type name cannot be modified
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), null, 404);
typePayload.setName(typeName);
// Update the type as a Model Administrator
HttpResponse response = put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), null, 200);
CustomType returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
assertEquals(typePayload.getDescription(), returnedType.getDescription());
assertEquals(typePayload.getTitle(), returnedType.getTitle());
// Check that properties are unmodified
assertNotNull(returnedType.getProperties());
assertEquals(1, returnedType.getProperties().size());
assertEquals(typePropName, returnedType.getProperties().iterator().next().getName());
// Update the type with an invalid parent
typePayload.setParentName("cm:folder" + System.currentTimeMillis());
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), null, 409);
// Activate the model
CustomModel statusPayload = new CustomModel();
statusPayload.setStatus(ModelStatus.ACTIVE);
put("cmm", modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200);
// Remove the type's parent
// Note: cannot update the parent of an ACTIVE type/type.
typePayload.setParentName("cm:folder");
put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), null, 409);
statusPayload = new CustomModel();
statusPayload.setStatus(ModelStatus.DRAFT);
put("cmm", modelName, RestApiUtil.toJsonAsString(statusPayload), SELECT_STATUS_QS, 200);
// now update the type's parent - model is inactive
response = put("cmm/" + modelName + "/types", typeName, RestApiUtil.toJsonAsString(typePayload), null, 200);
returnedType = RestApiUtil.parseRestApiEntry(response.getJsonResponse(), CustomType.class);
assertEquals(typePayload.getParentName(), returnedType.getParentName());
}
}
Aggregations