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