Search in sources :

Example 6 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class EntityControllerTest method shouldCreateNewEntity.

@Test
public void shouldCreateNewEntity() throws Exception {
    EntityDto given = new EntityDto(11L, "Test", SecurityMode.EVERYONE, null);
    EntityDto expected = new EntityDto(9L, "Test", SecurityMode.EVERYONE, null);
    doReturn(expected).when(entityService).createEntity(given);
    doReturn(expected).when(entityService).getEntityForEdit(9L);
    controller.perform(post("/entities").body(new ObjectMapper().writeValueAsBytes(given)).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().string(new ObjectMapper().writeValueAsString(expected)));
    verify(entityService).createEntity(given);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 7 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class EntityControllerTest method shouldSaveTemporaryChange.

@Test
public void shouldSaveTemporaryChange() throws Exception {
    DraftData data = new DraftData();
    data.setEdit(true);
    data.setValues(new HashMap<>());
    data.getValues().put(DraftData.PATH, "basic.displayName");
    data.getValues().put(DraftData.FIELD_ID, "2");
    data.getValues().put(DraftData.VALUE, singletonList("test"));
    ResultActions actions = controller.perform(get("/entities/9007")).andExpect(status().isOk());
    EntityDto entity = new ObjectMapper().readValue(actions.andReturn().getResponse().getContentAsByteArray(), EntityDto.class);
    actions = controller.perform(get("/entities/9007/fields")).andExpect(status().isOk());
    List<FieldDto> fields = new ObjectMapper().readValue(actions.andReturn().getResponse().getContentAsByteArray(), new TypeReference<List<FieldDto>>() {
    });
    FieldDto fieldDto = findFieldById(fields, 12L);
    // before change
    assertFalse(entity.isModified());
    assertNotNull(fieldDto);
    assertEquals("ID", fieldDto.getBasic().getDisplayName());
    // change
    controller.perform(post("/entities/9007/draft").body(new ObjectMapper().writeValueAsBytes(data)).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk());
    verify(entityService).saveDraftEntityChanges(eq(9007L), draftDataCaptor.capture());
    DraftData captured = draftDataCaptor.getValue();
    assertTrue(captured.isEdit());
    assertEquals("basic.displayName", captured.getPath());
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) DraftData(org.motechproject.mds.dto.DraftData) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) ResultActions(org.springframework.test.web.server.ResultActions) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 8 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class EntityControllerTest method shouldGetEntitiesByBundle.

@Test
public void shouldGetEntitiesByBundle() throws Exception {
    EntityDto lessons = new EntityDto(null, "org.motechproject.mtraining.domain.Lesson", "Lesson", "mtraining", null, SecurityMode.EVERYONE, null);
    EntityDto chapters = new EntityDto(null, "org.motechproject.mtraining.domain.Chapter", "Chapter", "mtraining", null, SecurityMode.EVERYONE, null);
    List<EntityDto> expected = asList(lessons, chapters);
    when(entityService.listEntitiesByBundle("org.motechproject.mtraining")).thenReturn(expected);
    controller.perform(get("/entities/getEntitiesByBundle").param("symbolicName", "org.motechproject.mtraining")).andExpect(status().isOk()).andExpect(content().string(new ObjectMapper().writeValueAsString(expected)));
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 9 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class InstanceServiceTest method shouldLoadBlobField.

@Test
public void shouldLoadBlobField() throws InstanceNotFoundException {
    EntityDto entityDto = new EntityDto();
    entityDto.setReadOnlySecurityMode(null);
    entityDto.setSecurityMode(null);
    entityDto.setClassName(TestSample.class.getName());
    when(entityService.getEntity(ENTITY_ID + 1)).thenReturn(entityDto);
    mockDataService();
    TestSample instance = Mockito.mock(TestSample.class);
    when(motechDataService.findById(ENTITY_ID + 1)).thenReturn(instance);
    instanceService.getInstanceField(12l, ENTITY_ID + 1, "blobField");
    verify(motechDataService).getDetachedField(instance, "blobField");
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) Test(org.junit.Test)

Example 10 with EntityDto

use of org.motechproject.mds.dto.EntityDto 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)

Aggregations

EntityDto (org.motechproject.mds.dto.EntityDto)136 Test (org.junit.Test)61 FieldDto (org.motechproject.mds.dto.FieldDto)53 ArrayList (java.util.ArrayList)34 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)32 MotechDataService (org.motechproject.mds.service.MotechDataService)26 LookupDto (org.motechproject.mds.dto.LookupDto)24 List (java.util.List)19 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)12 Method (java.lang.reflect.Method)11 FieldTestHelper.lookupFieldDto (org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto)11 Arrays.asList (java.util.Arrays.asList)9 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)9 EntityRecord (org.motechproject.mds.web.domain.EntityRecord)9 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)7 TypeDto (org.motechproject.mds.dto.TypeDto)7 HashMap (java.util.HashMap)6 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)6 BasicFieldRecord (org.motechproject.mds.web.domain.BasicFieldRecord)6 FieldRecord (org.motechproject.mds.web.domain.FieldRecord)6