Search in sources :

Example 16 with FieldRecord

use of org.motechproject.mds.web.domain.FieldRecord 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 FieldRecord

use of org.motechproject.mds.web.domain.FieldRecord 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 FieldRecord

use of org.motechproject.mds.web.domain.FieldRecord 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 FieldRecord

use of org.motechproject.mds.web.domain.FieldRecord 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 FieldRecord

use of org.motechproject.mds.web.domain.FieldRecord 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

FieldRecord (org.motechproject.mds.web.domain.FieldRecord)24 BasicFieldRecord (org.motechproject.mds.web.domain.BasicFieldRecord)19 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)16 EntityRecord (org.motechproject.mds.web.domain.EntityRecord)15 Test (org.junit.Test)14 EntityDto (org.motechproject.mds.dto.EntityDto)7 FieldDto (org.motechproject.mds.dto.FieldDto)6 List (java.util.List)3 Matchers.anyString (org.mockito.Matchers.anyString)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 Arrays.asList (java.util.Arrays.asList)2 SettingDto (org.motechproject.mds.dto.SettingDto)2 ObjectNotFoundException (org.motechproject.mds.exception.object.ObjectNotFoundException)2 ObjectReadException (org.motechproject.mds.exception.object.ObjectReadException)2 MotechDataService (org.motechproject.mds.service.MotechDataService)2 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1