Search in sources :

Example 1 with EntityRecord

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()));
}
Also used : BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) EntityRecord(org.motechproject.mds.web.domain.EntityRecord) FieldRecord(org.motechproject.mds.web.domain.FieldRecord) BasicFieldRecord(org.motechproject.mds.web.domain.BasicFieldRecord) Test(org.junit.Test)

Example 2 with EntityRecord

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()));
}
Also used : BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) EntityRecord(org.motechproject.mds.web.domain.EntityRecord) FieldRecord(org.motechproject.mds.web.domain.FieldRecord) BasicFieldRecord(org.motechproject.mds.web.domain.BasicFieldRecord) Test(org.junit.Test)

Example 3 with EntityRecord

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);
}
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 4 with EntityRecord

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;
}
Also used : BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) EntityRecord(org.motechproject.mds.web.domain.EntityRecord) RelationshipsUpdate(org.motechproject.mds.web.domain.RelationshipsUpdate)

Example 5 with EntityRecord

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()));
}
Also used : BasicEntityRecord(org.motechproject.mds.web.domain.BasicEntityRecord) EntityRecord(org.motechproject.mds.web.domain.EntityRecord) FieldRecord(org.motechproject.mds.web.domain.FieldRecord) BasicFieldRecord(org.motechproject.mds.web.domain.BasicFieldRecord) Matchers.anyString(org.mockito.Matchers.anyString) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Aggregations

BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)27 EntityRecord (org.motechproject.mds.web.domain.EntityRecord)27 Test (org.junit.Test)16 BasicFieldRecord (org.motechproject.mds.web.domain.BasicFieldRecord)15 FieldRecord (org.motechproject.mds.web.domain.FieldRecord)15 EntityDto (org.motechproject.mds.dto.EntityDto)11 ArrayList (java.util.ArrayList)5 FieldDto (org.motechproject.mds.dto.FieldDto)5 Matchers.anyString (org.mockito.Matchers.anyString)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 List (java.util.List)3 MotechDataService (org.motechproject.mds.service.MotechDataService)3 RelationshipsUpdate (org.motechproject.mds.web.domain.RelationshipsUpdate)3 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Collection (java.util.Collection)2 Predicate (java.util.function.Predicate)2 CannotCompileException (javassist.CannotCompileException)2 FieldNotFoundException (org.motechproject.mds.exception.field.FieldNotFoundException)2 ObjectNotFoundException (org.motechproject.mds.exception.object.ObjectNotFoundException)2