use of org.motechproject.mds.dto.DraftData in project motech by motech.
the class EntityControllerTest method shouldNotSaveTemporaryChangeIfEntityNotExists.
@Test
public void shouldNotSaveTemporaryChangeIfEntityNotExists() throws Exception {
doThrow(new EntityNotFoundException(100L)).when(entityService).saveDraftEntityChanges(eq(100L), any(DraftData.class));
controller.perform(post("/entities/100/draft").body(new ObjectMapper().writeValueAsString(new DraftData()).getBytes()).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isConflict()).andExpect(content().string(ENTITY_NOT_FOUND));
}
use of org.motechproject.mds.dto.DraftData in project motech by motech.
the class EntityControllerTest method shouldAbandonChanges.
@Test
public void shouldAbandonChanges() throws Exception {
DraftData data = new DraftData();
data.setEdit(true);
data.setValues(new HashMap<String, Object>());
data.getValues().put(DraftData.PATH, "basic.displayName");
data.getValues().put(DraftData.FIELD_ID, "2");
data.getValues().put(DraftData.VALUE, singletonList("test"));
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 capuredData = draftDataCaptor.getValue();
assertNotNull(capuredData);
assertTrue(capuredData.isEdit());
assertEquals("basic.displayName", capuredData.getPath());
controller.perform(post("/entities/9007/abandon").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk());
verify(entityService).abandonChanges(9007L);
}
use of org.motechproject.mds.dto.DraftData 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.motechproject.mds.dto.DraftData in project motech by motech.
the class DraftBuilder method forFieldRemoval.
public static DraftData forFieldRemoval(Long fieldId) {
Map<String, Object> values = new HashMap<>();
values.put(DraftData.FIELD_ID, fieldId);
DraftData draftData = new DraftData();
draftData.setValues(values);
draftData.setRemove(true);
return draftData;
}
use of org.motechproject.mds.dto.DraftData in project motech by motech.
the class MdsBundleIT method verifyComboboxDataMigration.
private void verifyComboboxDataMigration() throws NoSuchFieldException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException {
Long entityId = entityService.getEntityByClassName(FOO_CLASS).getId();
Long fieldId = getFieldIdByName(entityService.getFields(entityId), "someEnum");
DraftData draft = DraftBuilder.forFieldEdit(fieldId, "settings.2.value", true);
entityService.saveDraftEntityChanges(entityId, draft);
entityService.commitChanges(entityId);
SchemaHolder schemaHolder = entityService.getSchema();
generator.regenerateMdsDataBundle(schemaHolder, true);
service = (MotechDataService) ServiceRetriever.getService(bundleContext, ClassName.getInterfaceName(FOO_CLASS), true);
assertValuesEqual(getExpectedComboboxValues(), getValues(service.detachedCopyAll(service.retrieveAll())));
}
Aggregations