Search in sources :

Example 51 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class CsvImportExportServiceImpl method importCsv.

@Override
public CsvImportResults importCsv(String entityClassName, Reader reader, String fileName, boolean continueOnError) {
    LOGGER.debug("Importing instances of entity: {}", entityClassName);
    CsvImportResults importResults;
    try {
        importResults = csvImporterExporter.importCsv(entityClassName, reader, continueOnError);
    } catch (RuntimeException e) {
        EntityDto entity = entityService.getEntityByClassName(entityClassName);
        sendImportFailureEvent(entity, fileName, e);
        throw e;
    }
    sendImportSuccessEvent(importResults, fileName);
    return importResults;
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) CsvImportResults(org.motechproject.mds.dto.CsvImportResults)

Example 52 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class AllEntitiesContextIT method shouldCreateEntity.

@Test
public void shouldCreateEntity() throws Exception {
    assertFalse(String.format("Found %s in database", BAR_CLASS), containsEntity(BAR_CLASS));
    EntityDto entity = new EntityDto();
    entity.setClassName(BAR_CLASS);
    allEntities.create(entity);
    assertTrue(String.format("Not found %s in database", BAR_CLASS), containsEntity(BAR_CLASS));
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) Test(org.junit.Test)

Example 53 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class AllEntitiesContextIT method shouldDeleteEntity.

@Test
public void shouldDeleteEntity() throws Exception {
    EntityDto entity = new EntityDto();
    entity.setClassName(BAR_CLASS);
    allEntities.create(entity);
    assertTrue(String.format("Not found %s in database", BAR_CLASS), allEntities.contains(BAR_CLASS));
    Query query = getPersistenceManager().newQuery(Entity.class);
    query.setFilter("className == name");
    query.declareParameters("java.lang.String name");
    query.setUnique(true);
    Entity found = (Entity) query.execute(BAR_CLASS);
    allEntities.delete(found.getId());
    assertFalse(String.format("Found %s in database", BAR_CLASS), allEntities.contains(BAR_CLASS));
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) Entity(org.motechproject.mds.domain.Entity) Query(javax.jdo.Query) Test(org.junit.Test)

Example 54 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class LookupProcessorTest method shouldBreakProcessingWhenEntityNotFound.

@Test
public void shouldBreakProcessingWhenEntityNotFound() throws NoSuchMethodException {
    when(paranamer.lookupParameterNames(getTestMethod(4))).thenReturn(argNames);
    EntityProcessorOutput eop = mockEntityProcessorOutput(new EntityDto(TestClass.class.getName()), Arrays.asList(new FieldDto("aaa", "bbb", TypeDto.STRING)));
    lookupProcessor.setEntityProcessingResult(Arrays.asList(eop));
    Method method = getTestMethod(4);
    lookupProcessor.process(method);
    assertTrue(lookupProcessor.getProcessingResult().isEmpty());
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) Method(java.lang.reflect.Method) FieldTestHelper.lookupFieldDto(org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) Test(org.junit.Test)

Example 55 with EntityDto

use of org.motechproject.mds.dto.EntityDto in project motech by motech.

the class LookupProcessorTest method shouldProcessMethodWithCustomLookupName.

@Test
public void shouldProcessMethodWithCustomLookupName() throws NoSuchMethodException {
    lookupProcessor.setEntityProcessingResult(Arrays.asList(mockEntityProcessorOutput(new EntityDto(TestClass.class.getName()), Collections.EMPTY_LIST)));
    when(paranamer.lookupParameterNames(getTestMethod(3))).thenReturn(argNames);
    Method method = getTestMethod(3);
    LookupDto dto = new LookupDto("My new custom lookup", false, false, lookupFieldDtos(argNames), true, "testMethod3", asList(argNames), true);
    lookupProcessor.process(method);
    Map<String, List<LookupDto>> elements = lookupProcessor.getProcessingResult();
    assertTrue(elements.containsKey(TEST_CLASS_NAME));
    List<LookupDto> list = elements.get(TEST_CLASS_NAME);
    assertEquals(1, list.size());
    assertEquals(dto, list.get(0));
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) LookupDto(org.motechproject.mds.dto.LookupDto) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Method(java.lang.reflect.Method) 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