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