Search in sources :

Example 21 with FieldRecord

use of org.motechproject.mds.web.domain.FieldRecord in project motech by motech.

the class InstanceServiceTest method shouldThrowExceptionWhileSavingInstanceInNonEditableEntity.

@Test(expected = EntityInstancesNonEditableException.class)
public void shouldThrowExceptionWhileSavingInstanceInNonEditableEntity() {
    EntityDto nonEditableEntity = new EntityDto();
    nonEditableEntity.setNonEditable(true);
    nonEditableEntity.setId(ANOTHER_ENTITY_ID);
    EntityRecord entityRecord = new EntityRecord(null, ANOTHER_ENTITY_ID, new ArrayList<FieldRecord>());
    when(entityService.getEntity(ANOTHER_ENTITY_ID)).thenReturn(nonEditableEntity);
    instanceService.saveInstance(entityRecord);
}
Also used : BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) EntityRecord(org.motechproject.mds.web.domain.EntityRecord) EntityDto(org.motechproject.mds.dto.EntityDto) FieldRecord(org.motechproject.mds.web.domain.FieldRecord) BasicFieldRecord(org.motechproject.mds.web.domain.BasicFieldRecord) Test(org.junit.Test)

Example 22 with FieldRecord

use of org.motechproject.mds.web.domain.FieldRecord in project motech by motech.

the class InstanceServiceTest method shouldThrowExceptionWhileSavingInstanceWithReadOnlyPermission.

@Test(expected = SecurityException.class)
public void shouldThrowExceptionWhileSavingInstanceWithReadOnlyPermission() {
    EntityDto entityDto = new EntityDto();
    entityDto.setReadOnlySecurityMode(SecurityMode.EVERYONE);
    entityDto.setSecurityMode(SecurityMode.NO_ACCESS);
    EntityRecord entityRecord = new EntityRecord(null, ANOTHER_ENTITY_ID, new ArrayList<FieldRecord>());
    when(entityService.getEntity(ANOTHER_ENTITY_ID)).thenReturn(entityDto);
    instanceService.saveInstance(entityRecord);
}
Also used : BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) EntityRecord(org.motechproject.mds.web.domain.EntityRecord) EntityDto(org.motechproject.mds.dto.EntityDto) FieldRecord(org.motechproject.mds.web.domain.FieldRecord) BasicFieldRecord(org.motechproject.mds.web.domain.BasicFieldRecord) Test(org.junit.Test)

Example 23 with FieldRecord

use of org.motechproject.mds.web.domain.FieldRecord in project motech by motech.

the class InstanceServiceTest method testUpdateCreate.

private void testUpdateCreate(boolean edit) throws ClassNotFoundException {
    final DateTime dtValue = DateUtil.now();
    mockSampleFields();
    mockDataService();
    mockEntity();
    when(motechDataService.retrieve("id", INSTANCE_ID)).thenReturn(new TestSample());
    List<FieldRecord> fieldRecords = asList(FieldTestHelper.fieldRecord("strField", String.class.getName(), "", "this is a test"), FieldTestHelper.fieldRecord("intField", Integer.class.getName(), "", 16), FieldTestHelper.fieldRecord("timeField", Time.class.getName(), "", "10:17"), FieldTestHelper.fieldRecord("dtField", DateTime.class.getName(), "", dtValue));
    Long id = (edit) ? INSTANCE_ID : null;
    EntityRecord record = new EntityRecord(id, ENTITY_ID, fieldRecords);
    MDSClassLoader.getInstance().loadClass(TestSample.class.getName());
    instanceService.saveInstance(record);
    ArgumentCaptor<TestSample> captor = ArgumentCaptor.forClass(TestSample.class);
    if (edit) {
        verify(motechDataService).update(captor.capture());
    } else {
        verify(motechDataService).create(captor.capture());
    }
    TestSample sample = captor.getValue();
    assertEquals("this is a test", sample.getStrField());
    assertEquals(Integer.valueOf(16), sample.getIntField());
    assertEquals(new Time(10, 17), sample.getTimeField());
    assertEquals(dtValue, sample.getDtField());
}
Also used : BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) EntityRecord(org.motechproject.mds.web.domain.EntityRecord) Matchers.anyLong(org.mockito.Matchers.anyLong) FieldRecord(org.motechproject.mds.web.domain.FieldRecord) BasicFieldRecord(org.motechproject.mds.web.domain.BasicFieldRecord) Time(org.motechproject.commons.date.model.Time) DateTime(org.joda.time.DateTime) DateTime(org.joda.time.DateTime)

Example 24 with FieldRecord

use of org.motechproject.mds.web.domain.FieldRecord in project motech by motech.

the class FieldRecordTest method shouldExtendOptionsAndHandleDefListValuesForMultiSelect.

@Test
public void shouldExtendOptionsAndHandleDefListValuesForMultiSelect() {
    FieldDto fieldDto = FieldTestHelper.fieldDto(1L, "name", List.class.getName(), "disp", "[one, two]");
    fieldDto.setSettings(asList(new SettingDto(COMBOBOX_VALUES, asList("one", "two", "three"), null, null), new SettingDto(ALLOW_MULTIPLE_SELECTIONS, true, null, null)));
    FieldRecord fieldRecord = new FieldRecord(fieldDto);
    assertEquals(asList("one", "two"), fieldRecord.getValue());
    fieldRecord.setValue(asList("defVal", "secondVal", "two"));
    assertEquals(asList("one", "two", "three", "defVal", "secondVal"), fieldRecord.getSettingByName(COMBOBOX_VALUES).getValue());
    fieldRecord = new FieldRecord(fieldDto);
    fieldRecord.setValue("testSingleObject");
    assertEquals(asList("one", "two", "three", "testSingleObject"), fieldRecord.getSettingByName(COMBOBOX_VALUES).getValue());
    fieldRecord.setValue("[one, two]");
    assertEquals(asList("one", "two"), fieldRecord.getValue());
    assertEquals(asList("one", "two", "three", "testSingleObject"), fieldRecord.getSettingByName(COMBOBOX_VALUES).getValue());
    fieldRecord.setValue("[one, two]");
    assertEquals(asList("one", "two"), fieldRecord.getValue());
    // should return a string for single selections
    fieldRecord.setValue("defVal");
    assertEquals(asList("defVal"), fieldRecord.getValue());
    fieldRecord.setValue("[defVal]");
    assertEquals(asList("defVal"), fieldRecord.getValue());
    // test with enum
    fieldRecord.setValue(TestEnum.ONE);
    assertEquals(asList("ONE"), fieldRecord.getValue());
    fieldRecord.setValue(asList(TestEnum.ONE, TestEnum.THREE));
    assertEquals(asList("ONE", "THREE"), fieldRecord.getValue());
    fieldRecord.setValue(null);
    assertNull(fieldRecord.getValue());
}
Also used : List(java.util.List) Arrays.asList(java.util.Arrays.asList) SettingDto(org.motechproject.mds.dto.SettingDto) FieldRecord(org.motechproject.mds.web.domain.FieldRecord) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Aggregations

FieldRecord (org.motechproject.mds.web.domain.FieldRecord)24 BasicFieldRecord (org.motechproject.mds.web.domain.BasicFieldRecord)19 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)16 EntityRecord (org.motechproject.mds.web.domain.EntityRecord)15 Test (org.junit.Test)14 EntityDto (org.motechproject.mds.dto.EntityDto)7 FieldDto (org.motechproject.mds.dto.FieldDto)6 List (java.util.List)3 Matchers.anyString (org.mockito.Matchers.anyString)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 Arrays.asList (java.util.Arrays.asList)2 SettingDto (org.motechproject.mds.dto.SettingDto)2 ObjectNotFoundException (org.motechproject.mds.exception.object.ObjectNotFoundException)2 ObjectReadException (org.motechproject.mds.exception.object.ObjectReadException)2 MotechDataService (org.motechproject.mds.service.MotechDataService)2 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1