Search in sources :

Example 46 with Field

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;
}
Also used : Field(org.motechproject.mds.domain.Field) Lookup(org.motechproject.mds.domain.Lookup)

Example 47 with 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);
}
Also used : Record__Trash(org.motechproject.mds.testutil.records.history.Record__Trash) Entity(org.motechproject.mds.domain.Entity) Field(org.motechproject.mds.domain.Field) Type(org.motechproject.mds.domain.Type) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 48 with Field

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;
}
Also used : Field(org.motechproject.mds.domain.Field) LookupFieldType(org.motechproject.mds.dto.LookupFieldType) Type(org.motechproject.mds.domain.Type)

Example 49 with 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);
}
Also used : Entity(org.motechproject.mds.domain.Entity) Field(org.motechproject.mds.domain.Field) Lookup(org.motechproject.mds.domain.Lookup) Test(org.junit.Test)

Example 50 with Field

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());
}
Also used : Entity(org.motechproject.mds.domain.Entity) Field(org.motechproject.mds.domain.Field) Test(org.junit.Test)

Aggregations

Field (org.motechproject.mds.domain.Field)73 Entity (org.motechproject.mds.domain.Entity)33 Test (org.junit.Test)24 Lookup (org.motechproject.mds.domain.Lookup)16 MdsEntity (org.motechproject.mds.domain.MdsEntity)15 MdsVersionedEntity (org.motechproject.mds.domain.MdsVersionedEntity)15 Type (org.motechproject.mds.domain.Type)14 ArrayList (java.util.ArrayList)13 Transactional (org.springframework.transaction.annotation.Transactional)13 FieldDto (org.motechproject.mds.dto.FieldDto)12 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)12 HashSet (java.util.HashSet)8 Matchers.anyString (org.mockito.Matchers.anyString)6 FieldSetting (org.motechproject.mds.domain.FieldSetting)6 TypeSetting (org.motechproject.mds.domain.TypeSetting)6 UserPreferences (org.motechproject.mds.domain.UserPreferences)5 EntityDto (org.motechproject.mds.dto.EntityDto)5 AllUserPreferences (org.motechproject.mds.repository.internal.AllUserPreferences)5 FieldMetadata (org.motechproject.mds.domain.FieldMetadata)4 LookupDto (org.motechproject.mds.dto.LookupDto)4