use of org.motechproject.mds.dto.EntityDto in project motech by motech.
the class MdsDummyDataGeneratorImpl method prepareDummyEntity.
private void prepareDummyEntity(int number, int fieldsPerEntity, int lookupsPerEntity) throws IOException {
EntityDto entityDto = new EntityDto(Long.valueOf(number), entityPrefix.concat(String.valueOf(number)));
entityDto = entityService.createEntity(entityDto);
List<FieldDto> fields = new ArrayList<>();
for (int i = 0; i < fieldsPerEntity; i++) {
TypeDto type = pickRandomFieldType();
fields.add(new FieldDto(null, entityDto.getId(), type, new FieldBasicDto(fieldPrefix.concat(String.valueOf(i)), fieldPrefix.concat(String.valueOf(i))), false, null, null, settingsFor(type), null));
}
entityService.addFields(entityDto, fields);
List<LookupDto> lookups = new ArrayList<>();
for (int i = 0; i < lookupsPerEntity; i++) {
List<LookupFieldDto> lookupFields = new ArrayList<>();
List<FieldDto> entityFields = entityService.getFields(entityDto.getId());
int amountOfFields = RAND.nextInt(entityFields.size());
for (int j = 0; j < amountOfFields; j++) {
lookupFields.add(new LookupFieldDto(null, entityFields.get(j).getBasic().getName(), LookupFieldType.VALUE));
}
lookups.add(new LookupDto(lookupPrefix.concat(String.valueOf(i)), RAND.nextBoolean(), RAND.nextBoolean(), lookupFields, false));
}
entityService.addLookups(entityDto.getId(), lookups);
}
use of org.motechproject.mds.dto.EntityDto in project motech by motech.
the class MdsDummyDataGeneratorIT method verifyEudeGetsCreated.
private void verifyEudeGetsCreated() throws IOException {
generator.generateDummyEntities(ENTITIES, FIELDS, LOOKUPS, true);
EntityDto entityDto = entityService.getEntityByClassName(Constants.Packages.ENTITY.concat(".").concat(generator.getEntityPrefix()).concat("0"));
EntityDto entityDto2 = entityService.getEntityByClassName(Constants.Packages.ENTITY.concat(".").concat(generator.getEntityPrefix()).concat(String.valueOf(ENTITIES - 1)));
// Verify the entities were created
Assert.assertNotNull(entityDto);
Assert.assertNotNull(entityDto2);
// Verify the correct amount of fields was added
Assert.assertEquals(entityService.getFields(entityDto.getId()).size(), FIELDS + AUTO_GENERATED_FIELDS);
Assert.assertEquals(entityService.getFields(entityDto2.getId()).size(), FIELDS + AUTO_GENERATED_FIELDS);
// Verify the correct amount of lookups was added
Assert.assertEquals(entityService.getEntityLookups(entityDto.getId()).size(), LOOKUPS);
Assert.assertEquals(entityService.getEntityLookups(entityDto2.getId()).size(), LOOKUPS);
}
use of org.motechproject.mds.dto.EntityDto in project motech by motech.
the class SelectResultTest method shouldReturnCorrectNumberOfRecords.
@Test
public void shouldReturnCorrectNumberOfRecords() throws Exception {
List<EntityDto> expected = new ArrayList<>();
expected.add(new EntityDto(9001L, "org.motechproject.openmrs.ws.resource.model.Patient", "MOTECH OpenMRS Web Services", "navio", SecurityMode.EVERYONE, null));
expected.add(new EntityDto(9002L, "org.motechproject.openmrs.ws.resource.model.Person", "MOTECH OpenMRS Web Services", "navio", SecurityMode.EVERYONE, null));
expected.add(new EntityDto(9003L, "org.motechproject.openmrs.ws.resource.model.Patient", "MOTECH OpenMRS Web Services", "accra", SecurityMode.EVERYONE, null));
expected.add(new EntityDto(9004L, "org.motechproject.openmrs.ws.resource.model.Person", "MOTECH OpenMRS Web Services", "accra", SecurityMode.EVERYONE, null));
SelectResult<EntityDto> result = new SelectResult<>(new SelectData(null, 1, 4), ENTITIES);
assertEquals(expected, result.getResults());
assertTrue(result.isMore());
expected.clear();
expected.add(new EntityDto(9005L, "org.motechproject.appointments.api.model.Appointment", "MOTECH Appointments API", SecurityMode.EVERYONE, null));
expected.add(new EntityDto(9006L, "org.motechproject.ivr.domain.CallDetailRecord", "MOTECH IVR API", SecurityMode.EVERYONE, null));
result = new SelectResult<>(new SelectData(null, 3, 2), ENTITIES);
assertEquals(expected, result.getResults());
assertTrue(result.isMore());
expected.clear();
expected.add(new EntityDto(9007L, "org.motechproject.mds.entity.Voucher", SecurityMode.EVERYONE, null));
expected.add(new EntityDto(9008L, "org.motechproject.messagecampaign.domain.campaign.Campaign", "MOTECH Message Campaign", SecurityMode.EVERYONE, null));
result = new SelectResult<>(new SelectData(null, 4, 3), ENTITIES);
assertEquals(expected, result.getResults());
assertFalse(result.isMore());
}
use of org.motechproject.mds.dto.EntityDto in project motech by motech.
the class EntityControllerTest method shouldReturnRecordsSortedByName.
@Test
public void shouldReturnRecordsSortedByName() throws Exception {
List<EntityDto> expected = new ArrayList<>();
expected.add(new EntityDto(9005L, "org.motechproject.appointments.api.model.Appointment", "MOTECH Appointments API", SecurityMode.EVERYONE, null));
expected.add(new EntityDto(9006L, "org.motechproject.ivr.domain.CallDetailRecord", "MOTECH IVR API", SecurityMode.EVERYONE, null));
expected.add(new EntityDto(9008L, "org.motechproject.messagecampaign.domain.campaign.Campaign", "MOTECH Message Campaign", SecurityMode.EVERYONE, null));
expected.add(new EntityDto(9001L, "org.motechproject.openmrs.ws.resource.model.Patient", "MOTECH OpenMRS Web Services", "navio", SecurityMode.EVERYONE, null));
expected.add(new EntityDto(9003L, "org.motechproject.openmrs.ws.resource.model.Patient", "MOTECH OpenMRS Web Services", "accra", SecurityMode.EVERYONE, null));
expected.add(new EntityDto(9002L, "org.motechproject.openmrs.ws.resource.model.Person", "MOTECH OpenMRS Web Services", "navio", SecurityMode.EVERYONE, null));
expected.add(new EntityDto(9004L, "org.motechproject.openmrs.ws.resource.model.Person", "MOTECH OpenMRS Web Services", "accra", SecurityMode.EVERYONE, null));
expected.add(new EntityDto(9007L, "org.motechproject.mds.entity.Voucher", SecurityMode.EVERYONE, null));
SelectResult expectedResult = new SelectResult(new SelectData(null, 1, 10), expected);
controller.perform(get("/selectEntities").param("term", "").param("page", String.valueOf(1)).param("pageLimit", String.valueOf(10))).andExpect(status().isOk()).andExpect(content().string(new ObjectMapper().writeValueAsString(expectedResult)));
}
use of org.motechproject.mds.dto.EntityDto in project motech by motech.
the class EntityControllerTest method shouldThrowExceptionIfEntityWithGivenNameExists.
@Test
public void shouldThrowExceptionIfEntityWithGivenNameExists() throws Exception {
doThrow(new EntityAlreadyExistException("Voucher")).when(entityService).createEntity(any(EntityDto.class));
controller.perform(post("/entities").body(new ObjectMapper().writeValueAsBytes(new EntityDto(7L, "Voucher", SecurityMode.EVERYONE, null))).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isConflict()).andExpect(content().string(ENTITY_ALREADY_EXSIST));
}
Aggregations