use of com.agiletec.apsadmin.system.entity.type.EntityAttributeConfigAction in project entando-core by entando.
the class TestEntityManagersAction method testSaveNewAttribute.
public void testSaveNewAttribute() throws Throwable {
// Search an entity manager
String[] defNames = this.getApplicationContext().getBeanNamesForType(ApsEntityManager.class);
if (null == defNames || defNames.length == 0)
return;
String entityManagerName = defNames[0];
IEntityManager entityManager = (IEntityManager) this.getApplicationContext().getBean(entityManagerName);
// get the entites managed by the ApsEntityManager
Map<String, IApsEntity> entities = entityManager.getEntityPrototypes();
if (null == entities || entities.size() == 0)
return;
List<String> enitiesTypeCodes = new ArrayList<String>();
enitiesTypeCodes.addAll(entities.keySet());
// get the first entity type code available
String entityTypeCode = enitiesTypeCodes.get(0);
try {
// wrong name
String attributeName = "wrong name";
String attributeTypeCode = "Monotext";
int strutsAction = ApsAdminSystemConstants.ADD;
String result = this.executeSaveAttribute("admin", attributeName, attributeTypeCode, entityTypeCode, strutsAction, null, null, entityManagerName);
assertEquals(Action.INPUT, result);
EntityAttributeConfigAction action = (EntityAttributeConfigAction) this.getAction();
Map<String, List<String>> fieldErrors = action.getFieldErrors();
assertEquals(1, fieldErrors.size());
assertTrue(fieldErrors.containsKey("attributeName"));
// wrong length
attributeName = "right_name";
result = this.executeSaveAttribute("admin", attributeName, attributeTypeCode, entityTypeCode, strutsAction, 3, 5, entityManagerName);
assertEquals(Action.INPUT, result);
fieldErrors = action.getFieldErrors();
assertEquals(1, fieldErrors.size());
assertTrue(fieldErrors.containsKey("minLength"));
// insert ok
attributeName = "right_name";
result = this.executeSaveAttribute("admin", attributeName, attributeTypeCode, entityTypeCode, strutsAction, 5, 3, entityManagerName);
assertEquals(Action.SUCCESS, result);
IApsEntity entity = entityManager.getEntityPrototype(entityTypeCode);
assertTrue(entity.getAttributeMap().containsKey("right_name"));
// duplicate attribute name
attributeName = "right_name";
result = this.executeSaveAttribute("admin", attributeName, attributeTypeCode, entityTypeCode, strutsAction, null, null, entityManagerName);
assertEquals(Action.INPUT, result);
fieldErrors = action.getFieldErrors();
assertEquals(1, fieldErrors.size());
assertTrue(fieldErrors.containsKey("attributeName"));
} catch (Throwable t) {
// nothing to do
} finally {
IApsEntity entity = entityManager.getEntityPrototype(entityTypeCode);
entity.getAttributeMap().remove("right_name");
((IEntityTypesConfigurer) entityManager).updateEntityPrototype(entity);
}
}
use of com.agiletec.apsadmin.system.entity.type.EntityAttributeConfigAction in project entando-core by entando.
the class TestEntityManagersAction method testEditAttribute.
public void testEditAttribute() throws Throwable {
// Search an entity manager
String[] defNames = this.getApplicationContext().getBeanNamesForType(ApsEntityManager.class);
if (null == defNames || defNames.length == 0)
return;
String entityManagerName = defNames[0];
IEntityManager entityManager = (IEntityManager) this.getApplicationContext().getBean(entityManagerName);
// get the entites managed by the ApsEntityManager
Map<String, IApsEntity> entities = entityManager.getEntityPrototypes();
if (null == entities || entities.size() == 0)
return;
List<String> enitiesTypeCodes = new ArrayList<String>();
enitiesTypeCodes.addAll(entities.keySet());
// get the first entity type code available
String entityTypeCode = enitiesTypeCodes.get(0);
List<AttributeInterface> attributes = entities.get(entityTypeCode).getAttributeList();
// get the first attribute
for (int i = 0; i < attributes.size(); i++) {
AttributeInterface currentAttribute = attributes.get(i);
String attributeName = currentAttribute.getName();
String result = this.executeEditAttribute("admin", attributeName, entityTypeCode, entityManagerName);
assertEquals(Action.SUCCESS, result);
EntityAttributeConfigAction action = (EntityAttributeConfigAction) this.getAction();
assertEquals(currentAttribute.getType(), action.getAttributeTypeCode());
assertEquals(currentAttribute.isRequired(), action.getRequired().booleanValue());
assertEquals(currentAttribute.isSearchable(), action.getSearchable().booleanValue());
assertEquals(currentAttribute.getIndexingType().equalsIgnoreCase(IndexableAttributeInterface.INDEXING_TYPE_TEXT), action.getIndexable().booleanValue());
if (currentAttribute.isTextAttribute()) {
ITextAttribute attr = (ITextAttribute) currentAttribute;
if (attr.getMaxLength() == -1) {
assertNull(action.getMaxLength());
} else {
assertEquals(attr.getMaxLength(), action.getMaxLength().intValue());
}
if (attr.getMinLength() == -1) {
assertNull(action.getMinLength());
} else {
assertEquals(attr.getMinLength(), action.getMinLength().intValue());
}
assertEquals(attr.getRegexp(), action.getRegexp());
}
assertEquals(ApsAdminSystemConstants.EDIT, action.getStrutsAction());
}
}
Aggregations