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);
}
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);
}
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());
}
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());
}
Aggregations