use of org.motechproject.mds.web.domain.EntityRecord in project motech by motech.
the class InstanceServiceTest method shouldAutoPopulateOwnerAndCreator.
@Test
public void shouldAutoPopulateOwnerAndCreator() {
when(entityService.getEntityFieldsForUI(ENTITY_ID)).thenReturn(asList(FieldTestHelper.fieldDto(1L, "owner", String.class.getName(), "String field", null), FieldTestHelper.fieldDto(1L, "creator", String.class.getName(), "String field", null)));
mockEntity();
setUpSecurityContext();
EntityRecord record = instanceService.newInstance(ENTITY_ID);
List<FieldRecord> fieldRecords = record.getFields();
assertEquals(asList("motech", "motech"), extract(fieldRecords, on(FieldRecord.class).getValue()));
}
use of org.motechproject.mds.web.domain.EntityRecord in project motech by motech.
the class InstanceServiceTest method shouldNotUpdateGridSizeWhenUsernameIsBlank.
@Test
public void shouldNotUpdateGridSizeWhenUsernameIsBlank() {
EntityDto entityDto = new EntityDto();
entityDto.setReadOnlySecurityMode(null);
entityDto.setSecurityMode(null);
entityDto.setClassName(TestSample.class.getName());
EntityRecord entityRecord = new EntityRecord(ENTITY_ID + 1, null, new ArrayList<FieldRecord>());
when(entityService.getEntity(ENTITY_ID + 1)).thenReturn(entityDto);
mockDataService();
instanceService.getEntityRecords(entityRecord.getId(), new QueryParams(1, 100));
verify(entityService).getEntityFieldsForUI(ENTITY_ID + 1);
verify(userPreferencesService, never()).updateGridSize(anyLong(), anyString(), anyInt());
}
use of org.motechproject.mds.web.domain.EntityRecord in project motech by motech.
the class InstanceServiceTest method shouldThrowExceptionWhileReadingInstanceWithoutAnyPermission.
@Test(expected = SecurityException.class)
public void shouldThrowExceptionWhileReadingInstanceWithoutAnyPermission() {
EntityDto entityDto = new EntityDto();
entityDto.setReadOnlySecurityMode(SecurityMode.NO_ACCESS);
entityDto.setSecurityMode(SecurityMode.NO_ACCESS);
EntityRecord entityRecord = new EntityRecord(ANOTHER_ENTITY_ID, null, new ArrayList<FieldRecord>());
when(entityService.getEntity(ANOTHER_ENTITY_ID)).thenReturn(entityDto);
instanceService.getEntityRecords(entityRecord.getId());
}
use of org.motechproject.mds.web.domain.EntityRecord in project motech by motech.
the class InstanceServiceTest method shouldThrowExceptionWhileUpdatingReadonlyField.
@Test(expected = ObjectUpdateException.class)
public void shouldThrowExceptionWhileUpdatingReadonlyField() throws ClassNotFoundException {
mockDataService();
mockEntity();
when(motechDataService.retrieve("id", INSTANCE_ID)).thenReturn(new TestSample());
List<FieldRecord> fieldRecords = asList(FieldTestHelper.fieldRecord("strField", String.class.getName(), "", "CannotEditThis"));
fieldRecords.get(0).setNonEditable(true);
EntityRecord record = new EntityRecord(INSTANCE_ID, ENTITY_ID, fieldRecords);
instanceService.saveInstance(record);
}
use of org.motechproject.mds.web.domain.EntityRecord in project motech by motech.
the class InstanceServiceTest method shouldAcceptUserWithReadAccessPermissionWhileReadingInstance.
@Test
public void shouldAcceptUserWithReadAccessPermissionWhileReadingInstance() {
EntityDto entityDto = new EntityDto();
entityDto.setReadOnlySecurityMode(SecurityMode.EVERYONE);
entityDto.setSecurityMode(SecurityMode.NO_ACCESS);
entityDto.setClassName(TestSample.class.getName());
EntityRecord entityRecord = new EntityRecord(ANOTHER_ENTITY_ID, null, new ArrayList<FieldRecord>());
when(entityService.getEntity(ANOTHER_ENTITY_ID)).thenReturn(entityDto);
mockDataService();
instanceService.getEntityRecords(entityRecord.getId());
verify(entityService).getEntityFieldsForUI(ANOTHER_ENTITY_ID);
}
Aggregations