Search in sources :

Example 1 with Field

use of org.motechproject.mds.domain.Field in project motech by motech.

the class UserPreferencesServiceTest method getField2.

private Field getField2() {
    Field field = new Field(null, "sampleField2", "Display Name 2", true, false, false, false, false, false, "default 2", "tooltip 2", "placeholder 2", new HashSet<Lookup>());
    field.setUIDisplayable(true);
    return field;
}
Also used : Field(org.motechproject.mds.domain.Field) Lookup(org.motechproject.mds.domain.Lookup)

Example 2 with Field

use of org.motechproject.mds.domain.Field in project motech by motech.

the class UserPreferencesServiceTest method shouldMergeFieldsInformation.

@Test
public void shouldMergeFieldsInformation() {
    Set<Field> selectedFields = new HashSet<>();
    selectedFields.add(getField3());
    Set<Field> unselectedFields = new HashSet<>();
    unselectedFields.add(getField2());
    UserPreferences preferences = new UserPreferences(USERNAME, CLASS_NAME, 20, selectedFields, unselectedFields);
    when(allUserPreferences.retrieveByClassNameAndUsername(CLASS_NAME, USERNAME)).thenReturn(preferences);
    UserPreferencesDto userPreferencesDto = userPreferencesService.getUserPreferences(15l, USERNAME);
    assertNotNull(userPreferencesDto);
    assertEquals(1, userPreferencesDto.getSelectedFields().size());
    assertEquals(1, userPreferencesDto.getUnselectedFields().size());
    assertEquals(2, userPreferencesDto.getVisibleFields().size());
    assertTrue(userPreferencesDto.getSelectedFields().contains("sampleField3"));
    assertTrue(userPreferencesDto.getUnselectedFields().contains("sampleField2"));
    assertTrue(userPreferencesDto.getVisibleFields().contains("sampleField1"));
    assertTrue(userPreferencesDto.getVisibleFields().contains("sampleField3"));
}
Also used : AllUserPreferences(org.motechproject.mds.repository.internal.AllUserPreferences) UserPreferences(org.motechproject.mds.domain.UserPreferences) Field(org.motechproject.mds.domain.Field) UserPreferencesDto(org.motechproject.mds.dto.UserPreferencesDto) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with Field

use of org.motechproject.mds.domain.Field in project motech by motech.

the class TrashServiceTest method shouldMoveObjectToTrash.

@Test
public void shouldMoveObjectToTrash() throws Exception {
    doReturn(Record__Trash.class).when(classLoader).loadClass(Record__Trash.class.getName());
    Entity entity = mock(Entity.class);
    Field field = mock(Field.class);
    Type type = mock(Type.class);
    doReturn(17L).when(entity).getEntityVersion();
    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).retrieveByClassName(anyString());
    Record instance = new Record();
    trashService.moveToTrash(instance, 1L);
    verify(manager).makePersistent(trashCaptor.capture());
    Record__Trash trash = trashCaptor.getValue();
    assertEquals(instance.getValue(), trash.getValue());
}
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) Record(org.motechproject.mds.testutil.records.Record) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 4 with Field

use of org.motechproject.mds.domain.Field in project motech by motech.

the class FieldTestHelper method fieldWithComboboxSettings.

public static Field fieldWithComboboxSettings(Entity entity, String name, String displayName, Class<?> typeClass, boolean allowsMultipleSelections, boolean allowsUserSupplied, List<String> items) {
    Type type = new Type();
    type.setTypeClass(typeClass);
    type.setDisplayName(Constants.DisplayNames.COMBOBOX);
    Field field = new Field();
    field.setName(name);
    field.setDisplayName(displayName);
    field.setType(type);
    field.setEntity(entity);
    setAllowUserSupplied(field, allowsUserSupplied);
    setAllowMultipleSelections(field, allowsMultipleSelections);
    setComboboxValues(field, items);
    return field;
}
Also used : Field(org.motechproject.mds.domain.Field) LookupFieldType(org.motechproject.mds.dto.LookupFieldType) Type(org.motechproject.mds.domain.Type)

Example 5 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, Class<?> typeClass, boolean required, boolean exposedViaRest, boolean autoGenerated) {
    Field field = field(name, name + " Display", typeClass);
    field.setRequired(required);
    field.setExposedViaRest(exposedViaRest);
    field.addMetadata(new FieldMetadata(field, Constants.Util.AUTO_GENERATED, String.valueOf(autoGenerated)));
    return field;
}
Also used : Field(org.motechproject.mds.domain.Field) FieldMetadata(org.motechproject.mds.domain.FieldMetadata)

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