Search in sources :

Example 16 with EntityRecord

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()));
}
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) Test(org.junit.Test)

Example 17 with EntityRecord

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());
}
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) QueryParams(org.motechproject.mds.query.QueryParams) Test(org.junit.Test)

Example 18 with EntityRecord

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

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

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

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