use of org.alfresco.rest.api.model.CustomModelNamedValue in project alfresco-remote-api by Alfresco.
the class TestCustomConstraint method testCreateListConstraintInvalid.
@Test
public void testCreateListConstraintInvalid() throws Exception {
setRequestContext(customModelAdmin);
String modelName = "testModelConstraintInvalid" + System.currentTimeMillis();
final Pair<String, String> namespacePair = getTestNamespaceUriPrefixPair();
// Create the model as a Model Administrator
createCustomModel(modelName, namespacePair, ModelStatus.DRAFT);
// Create aspect
String aspectName = "testAspect" + System.currentTimeMillis();
createTypeAspect(CustomAspect.class, modelName, aspectName, "title", "desc", null);
// Update the Aspect by adding property
CustomAspect aspectPayload = new CustomAspect();
aspectPayload.setName(aspectName);
final String aspectPropName = "testAspect1Prop" + System.currentTimeMillis();
CustomModelProperty aspectProp = new CustomModelProperty();
aspectProp.setName(aspectPropName);
aspectProp.setTitle("property title");
aspectProp.setDataType("d:int");
// Create LIST constraint
String inlineListConstraintName = "testListConstraint" + System.currentTimeMillis();
CustomModelConstraint inlineListConstraint = new CustomModelConstraint();
inlineListConstraint.setName(inlineListConstraintName);
inlineListConstraint.setType("LIST");
inlineListConstraint.setTitle("test List title");
inlineListConstraint.setDescription("test List desc");
// Create the List constraint's parameters
List<CustomModelNamedValue> parameters = new ArrayList<>(3);
// text list value, but the the property data type is d:int
parameters.add(buildNamedValue("allowedValues", null, "a", "b", "c"));
parameters.add(buildNamedValue("sorted", "false"));
// Add the parameters into the constraint
inlineListConstraint.setParameters(parameters);
// Add inline constraint
aspectProp.setConstraints(Arrays.asList(inlineListConstraint));
List<CustomModelProperty> props = new ArrayList<>(1);
props.add(aspectProp);
aspectPayload.setProperties(props);
// Try to create the property - Invalid LIST values
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400);
// Test d:double LIST values with d:int property data type
parameters = new ArrayList<>(3);
// double list value, but the the property data type is d:int
parameters.add(buildNamedValue("allowedValues", null, "1.0", "2.0", "3.0"));
parameters.add(buildNamedValue("sorted", "false"));
// Add the parameters into the constraint
inlineListConstraint.setParameters(parameters);
// Add inline constraint
aspectProp.setConstraints(Arrays.asList(inlineListConstraint));
props = new ArrayList<>(1);
props.add(aspectProp);
aspectPayload.setProperties(props);
// Try to create the property - Invalid LIST values
put("cmm/" + modelName + "/aspects", aspectName, RestApiUtil.toJsonAsString(aspectPayload), SELECT_PROPS_QS, 400);
}
use of org.alfresco.rest.api.model.CustomModelNamedValue in project alfresco-remote-api by Alfresco.
the class BaseCustomModelApiTest method buildNamedValue.
protected CustomModelNamedValue buildNamedValue(String name, String simpleValue, String... listValue) {
CustomModelNamedValue namedValue = new CustomModelNamedValue();
namedValue.setName(name);
namedValue.setSimpleValue(simpleValue);
if (listValue.length > 0) {
namedValue.setListValue(Arrays.asList(listValue));
}
return namedValue;
}
Aggregations