Search in sources :

Example 1 with ResultActions

use of org.springframework.test.web.server.ResultActions 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 2 with ResultActions

use of org.springframework.test.web.server.ResultActions in project motech by motech.

the class EntityControllerTest method shouldGetEntityFields.

@Test
public void shouldGetEntityFields() throws Exception {
    List<MetadataDto> exampleMetadata = new LinkedList<>();
    exampleMetadata.add(new MetadataDto("key1", "value1"));
    exampleMetadata.add(new MetadataDto("key2", "value2"));
    List<FieldDto> expected = new LinkedList<>();
    expected.add(new FieldDto(14L, 9005L, STRING, new FieldBasicDto("Other", "Other", false, false, "test", null, null), false, exampleMetadata, FieldValidationDto.STRING, null, null));
    ResultActions actions = controller.perform(get("/entities/9005/fields")).andExpect(status().isOk());
    List<FieldDto> fields = new ObjectMapper().readValue(actions.andReturn().getResponse().getContentAsByteArray(), new TypeReference<List<FieldDto>>() {
    });
    assertEquals(expected, fields);
}
Also used : FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) 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) MetadataDto(org.motechproject.mds.dto.MetadataDto) LinkedList(java.util.LinkedList) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Example 3 with ResultActions

use of org.springframework.test.web.server.ResultActions in project motech by motech.

the class EntityControllerTest method shouldFindFieldByName.

@Test
public void shouldFindFieldByName() throws Exception {
    List<MetadataDto> exampleMetadata = new LinkedList<>();
    exampleMetadata.add(new MetadataDto("key1", "value1"));
    exampleMetadata.add(new MetadataDto("key2", "value2"));
    FieldDto expected = new FieldDto(14L, 9005L, STRING, new FieldBasicDto("Other", "Other", false, false, "test", null, null), false, exampleMetadata, FieldValidationDto.STRING, null, null);
    ResultActions actions = controller.perform(get("/entities/9005/fields/Other")).andExpect(status().isOk());
    FieldDto field = new ObjectMapper().readValue(actions.andReturn().getResponse().getContentAsByteArray(), FieldDto.class);
    assertEquals(expected, field);
}
Also used : FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) ResultActions(org.springframework.test.web.server.ResultActions) MetadataDto(org.motechproject.mds.dto.MetadataDto) LinkedList(java.util.LinkedList) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) FieldDto(org.motechproject.mds.dto.FieldDto) Test(org.junit.Test)

Aggregations

LinkedList (java.util.LinkedList)3 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)3 Test (org.junit.Test)3 FieldDto (org.motechproject.mds.dto.FieldDto)3 ResultActions (org.springframework.test.web.server.ResultActions)3 ArrayList (java.util.ArrayList)2 Arrays.asList (java.util.Arrays.asList)2 Collections.singletonList (java.util.Collections.singletonList)2 List (java.util.List)2 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)2 MetadataDto (org.motechproject.mds.dto.MetadataDto)2 DraftData (org.motechproject.mds.dto.DraftData)1 EntityDto (org.motechproject.mds.dto.EntityDto)1