Search in sources :

Example 1 with EntityDto

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);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) LookupDto(org.motechproject.mds.dto.LookupDto) ArrayList(java.util.ArrayList) TypeDto(org.motechproject.mds.dto.TypeDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto)

Example 2 with EntityDto

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);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto)

Example 3 with EntityDto

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());
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with EntityDto

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)));
}
Also used : SelectData(org.motechproject.mds.web.SelectData) EntityDto(org.motechproject.mds.dto.EntityDto) SelectResult(org.motechproject.mds.web.SelectResult) ArrayList(java.util.ArrayList) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Example 5 with EntityDto

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));
}
Also used : EntityAlreadyExistException(org.motechproject.mds.exception.entity.EntityAlreadyExistException) EntityDto(org.motechproject.mds.dto.EntityDto) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) Test(org.junit.Test)

Aggregations

EntityDto (org.motechproject.mds.dto.EntityDto)136 Test (org.junit.Test)61 FieldDto (org.motechproject.mds.dto.FieldDto)53 ArrayList (java.util.ArrayList)34 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)32 MotechDataService (org.motechproject.mds.service.MotechDataService)26 LookupDto (org.motechproject.mds.dto.LookupDto)24 List (java.util.List)19 BasicEntityRecord (org.motechproject.mds.web.domain.BasicEntityRecord)12 Method (java.lang.reflect.Method)11 FieldTestHelper.lookupFieldDto (org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto)11 Arrays.asList (java.util.Arrays.asList)9 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)9 EntityRecord (org.motechproject.mds.web.domain.EntityRecord)9 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)7 TypeDto (org.motechproject.mds.dto.TypeDto)7 HashMap (java.util.HashMap)6 SchemaHolder (org.motechproject.mds.dto.SchemaHolder)6 BasicFieldRecord (org.motechproject.mds.web.domain.BasicFieldRecord)6 FieldRecord (org.motechproject.mds.web.domain.FieldRecord)6