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