use of org.motechproject.mds.web.domain.EntityRecord in project motech by motech.
the class InstanceServiceTest method shouldReturnNewInstances.
@Test
public void shouldReturnNewInstances() {
mockSampleFields();
mockEntity();
EntityRecord record = instanceService.newInstance(ENTITY_ID);
assertNotNull(record);
assertEquals(Long.valueOf(ENTITY_ID), record.getEntitySchemaId());
assertNull(record.getId());
List<FieldRecord> fieldRecords = record.getFields();
assertCommonFieldRecordFields(fieldRecords);
assertEquals(asList("Default", 7, null, null, null), extract(fieldRecords, on(FieldRecord.class).getValue()));
}
use of org.motechproject.mds.web.domain.EntityRecord in project motech by motech.
the class InstanceServiceTest method shouldReturnEntityInstance.
@Test
public void shouldReturnEntityInstance() {
mockDataService();
mockSampleFields();
mockEntity();
when(motechDataService.retrieve("id", INSTANCE_ID)).thenReturn(new TestSample("Hello world", 99));
EntityRecord record = instanceService.getEntityInstance(ENTITY_ID, INSTANCE_ID);
assertNotNull(record);
assertEquals(Long.valueOf(ENTITY_ID), record.getEntitySchemaId());
assertEquals(Long.valueOf(INSTANCE_ID), record.getId());
List<FieldRecord> fieldRecords = record.getFields();
assertCommonFieldRecordFields(fieldRecords);
assertEquals(asList("Hello world", 99, null, null, null), extract(fieldRecords, on(FieldRecord.class).getValue()));
}
use of org.motechproject.mds.web.domain.EntityRecord in project motech by motech.
the class InstanceServiceTest method shouldAcceptUserWithRegularAccessPermissionWhileReadingInstance.
@Test
public void shouldAcceptUserWithRegularAccessPermissionWhileReadingInstance() {
EntityDto entityDto = new EntityDto();
entityDto.setReadOnlySecurityMode(SecurityMode.NO_ACCESS);
entityDto.setSecurityMode(SecurityMode.EVERYONE);
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);
}
use of org.motechproject.mds.web.domain.EntityRecord in project motech by motech.
the class InstanceServiceTest method buildRelationshipUpdate.
private RelationshipsUpdate buildRelationshipUpdate() {
EntityRecord relatedRecord = new EntityRecord(null, 1L, new ArrayList<>());
RelationshipsUpdate relationshipsUpdate = new RelationshipsUpdate();
relationshipsUpdate.getAddedIds().add(4L);
relationshipsUpdate.getAddedIds().add(5L);
relationshipsUpdate.getAddedNewRecords().add(relatedRecord);
return relationshipsUpdate;
}
use of org.motechproject.mds.web.domain.EntityRecord in project motech by motech.
the class InstanceServiceTest method shouldNotAutoPopulateOwnerAndCreatorForNonEditableFields.
@Test
public void shouldNotAutoPopulateOwnerAndCreatorForNonEditableFields() {
FieldDto ownerField = FieldTestHelper.fieldDto(1L, "owner", String.class.getName(), "String field", null);
ownerField.setNonEditable(true);
FieldDto creatorField = FieldTestHelper.fieldDto(1L, "creator", String.class.getName(), "String field", null);
creatorField.setNonEditable(true);
when(entityService.getEntityFieldsForUI(ENTITY_ID)).thenReturn(asList(ownerField, creatorField));
mockEntity();
setUpSecurityContext();
EntityRecord record = instanceService.newInstance(ENTITY_ID);
List<FieldRecord> fieldRecords = record.getFields();
assertEquals(asList(null, null), extract(fieldRecords, on(FieldRecord.class).getValue()));
}
Aggregations