use of org.motechproject.mds.domain.Field in project motech by motech.
the class UserPreferencesServiceTest method getField1.
private Field getField1() {
Field field = new Field(null, "sampleField1", "Display Name 1", true, false, false, false, false, false, "default 1", "tooltip 1", "placeholder 1", new HashSet<Lookup>());
field.setUIDisplayable(true);
return field;
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class TrashServiceTest method shouldFindTrashEntityById.
@Test
public void shouldFindTrashEntityById() throws Exception {
doReturn(Record__Trash.class).when(classLoader).loadClass("org.test.history.TestEntity__Trash");
doReturn(query).when(manager).newQuery(Record__Trash.class);
Entity entity = mock(Entity.class);
Field field = mock(Field.class);
Type type = mock(Type.class);
doReturn(17L).when(entity).getEntityVersion();
doReturn("org.test.TestEntity").when(entity).getClassName();
doReturn(field).when(entity).getField("id");
doReturn(field).when(entity).getField("value");
doReturn(type).when(field).getType();
doReturn(false).when(type).isRelationship();
doReturn(entity).when(allEntities).retrieveById(1L);
doReturn(new Record__Trash()).when(query).execute(anyLong());
Object trash = trashService.findTrashById(1L, "org.test.TestEntity");
assertNotNull(trash);
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class FieldTestHelper method field.
public static Field field(String name, String displayName, Class<?> typeClass, Object defaultVal, Long id, boolean readOnly) {
Type type = new Type();
// we only need the type
type.setTypeClass(typeClass);
Field field = new Field();
// we only need the name, type and default value
field.setName(name);
field.setType(type);
field.setDefaultValue(TypeHelper.format(defaultVal));
field.setId(id);
field.setDisplayName(displayName);
field.setReadOnly(readOnly);
return field;
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class FieldHelperTest method shouldAddMetadataForFields.
@Test
public void shouldAddMetadataForFields() {
Entity entity = new Entity("SampleEntity");
Field field = new Field(entity, "sampleField", "Display Name", true, false, false, false, false, "default", "tooltip", "placeholder", new HashSet<Lookup>());
FieldHelper.addMetadataForRelationship(TypeDto.MANY_TO_MANY_RELATIONSHIP.getTypeClass(), field);
assertEquals(field.getMetadata().size(), 4);
field.getMetadata().clear();
FieldHelper.addMetadataForRelationship(TypeDto.ONE_TO_MANY_RELATIONSHIP.getTypeClass(), field);
assertEquals(field.getMetadata().size(), 2);
field.getMetadata().clear();
FieldHelper.addMetadataForRelationship(TypeDto.ONE_TO_ONE_RELATIONSHIP.getTypeClass(), field);
assertEquals(field.getMetadata().size(), 1);
}
use of org.motechproject.mds.domain.Field in project motech by motech.
the class FieldHelperTest method shouldAddAndUpdateComboboxMetadata.
@Test
public void shouldAddAndUpdateComboboxMetadata() {
Entity entity = new Entity("SampleEntity");
entity.setClassName("org.motechproject.samplemodule.domain.SampleEntity");
Field field = FieldTestHelper.fieldWithComboboxSettings(entity, "sampleField", "Display Name", String.class, false, false, asList("Item_1", "Item_2"));
FieldHelper.addOrUpdateMetadataForCombobox(field);
assertEquals("org.motechproject.samplemodule.domain.mdsenum.SampleEntitySampleField", field.getMetadata(Constants.MetadataKeys.ENUM_CLASS_NAME).getValue());
Entity otherEntity = new Entity("OtherEntity");
otherEntity.setClassName("org.motechproject.samplemodule.domain.OtherEntity");
field.setEntity(otherEntity);
FieldHelper.addOrUpdateMetadataForCombobox(field);
assertEquals("org.motechproject.samplemodule.domain.mdsenum.OtherEntitySampleField", field.getMetadata(Constants.MetadataKeys.ENUM_CLASS_NAME).getValue());
}
Aggregations