use of org.motechproject.mds.dto.LookupDto in project motech by motech.
the class MdsDataProviderBuilderImplTest method shouldGenerateJson.
@Test
public void shouldGenerateJson() {
String json = "{\n" + " \"name\": \"data-services\",\n" + " \"objects\": [ {\n" + " \"displayName\": \"TestEntity\",\n" + " \"type\": \"org.motechproject.TestEntity\",\n" + " \"lookupFields\": [ {\n" + " \"displayName\": \"TestLookupName\",\n" + " \"fields\": [\n" + " \"TestFieldName\" ]\n" + " }, {\n" + " \"displayName\": \"mds.dataprovider.byinstanceid\",\n" + " \"fields\": [\n" + " \"mds.dataprovider.instanceid\"\n" + " ]\n" + " }\n" + " ],\n" + " \"fields\": [\n" + " {\n" + " \"displayName\": \"TestFieldDisplayName\",\n" + " \"fieldKey\": \"TestFieldName\"\n" + " } ]\n" + " } ]\n" + "}\n";
EntityDto entity = new EntityDto();
entity.setId(Long.valueOf("1"));
entity.setName("TestEntity");
entity.setClassName("org.motechproject.TestEntity");
FieldDto field = new FieldDto();
FieldBasicDto fieldBasicDto = new FieldBasicDto();
fieldBasicDto.setName("TestFieldName");
fieldBasicDto.setDisplayName("TestFieldDisplayName");
field.setBasic(fieldBasicDto);
fieldList.add(field);
LookupDto lookup = new LookupDto();
lookup.setLookupName("TestLookupName");
List<LookupFieldDto> lookupFields = new LinkedList<>();
lookupFields.add(FieldTestHelper.lookupFieldDto("TestFieldName"));
lookup.setLookupFields(lookupFields);
lookupList.add(lookup);
AdvancedSettingsDto advancedSettings = new AdvancedSettingsDto();
advancedSettings.setIndexes(lookupList);
SchemaHolder schema = new SchemaHolder();
schema.addEntity(entity, advancedSettings, fieldList);
String generatedJson = mdsDataProviderBuilder.generateDataProvider(schema);
assertEquals(json, generatedJson.replace("\r\n", "\n"));
}
use of org.motechproject.mds.dto.LookupDto in project motech by motech.
the class EntityServiceContextIT method shouldAddLookups.
@Test
public void shouldAddLookups() throws IOException {
EntityDto entityDto = new EntityDto();
entityDto.setName("LookupTestEnt");
entityDto = entityService.createEntity(entityDto);
FieldDto boolField = FieldTestHelper.fieldDto("boolField", Boolean.class);
FieldDto dtField = FieldTestHelper.fieldDto("dtField", DateTime.class);
FieldDto strField = FieldTestHelper.fieldDto("strField", String.class);
entityService.addFields(entityDto, asList(boolField, dtField, strField));
List<LookupFieldDto> lookupFieldDtos = lookupFieldsFromNames("boolField", "dtField", "strField");
lookupFieldDtos.get(1).setType(RANGE);
lookupFieldDtos.get(2).setType(SET);
LookupDto lookup = new LookupDto("lookup", false, false, lookupFieldDtos, true);
entityService.addLookups(entityDto.getId(), asList(lookup));
LookupDto lookupFromDb = entityService.getLookupByName(entityDto.getId(), "lookup");
assertNotNull(lookupFromDb);
assertEquals("lookup", lookupFromDb.getLookupName());
assertEquals("lookup", lookupFromDb.getMethodName());
assertEquals(asList("boolField", "dtField", "strField"), extract(lookupFromDb.getLookupFields(), on(LookupFieldDto.class).getName()));
assertEquals(asList(VALUE, RANGE, SET), extract(lookupFromDb.getLookupFields(), on(LookupFieldDto.class).getType()));
assertEquals(asList("boolField", "dtField", "strField"), lookupFromDb.getFieldsOrder());
}
use of org.motechproject.mds.dto.LookupDto in project motech by motech.
the class EntityServiceContextIT method shouldUpdateRestOptions.
@Test
public void shouldUpdateRestOptions() throws IOException {
// given
EntityDto entityDto = new EntityDto();
entityDto.setName("RestTestEnt");
entityDto = entityService.createEntity(entityDto);
FieldDto boolField = FieldTestHelper.fieldDto("boolField", Boolean.class);
FieldDto dtField = FieldTestHelper.fieldDto("dtField", DateTime.class);
FieldDto strField = FieldTestHelper.fieldDto("strField", String.class);
entityService.addFields(entityDto, asList(boolField, dtField, strField));
List<LookupFieldDto> lookupFieldDtos = lookupFieldsFromNames("boolField", "dtField", "strField");
LookupDto lookup = new LookupDto("lookup", false, false, lookupFieldDtos, true);
List<LookupFieldDto> strLookupFieldDtos = lookupFieldsFromNames("strField");
LookupDto strLookup = new LookupDto("strLookup", false, false, strLookupFieldDtos, true);
entityService.addLookups(entityDto.getId(), asList(lookup, strLookup));
RestOptionsDto restOptionsDto = new RestOptionsDto(true, false, true, false, false);
restOptionsDto.addField("boolField");
restOptionsDto.addField("strField");
restOptionsDto.addLookup("strLookup");
// when
entityService.updateRestOptions(entityDto.getId(), restOptionsDto);
// then
AdvancedSettingsDto advancedSettingsDto = entityService.getAdvancedSettings(entityDto.getId(), true);
RestOptionsDto fromDb = advancedSettingsDto.getRestOptions();
assertTrue(fromDb.isCreate());
assertFalse(fromDb.isRead());
assertTrue(fromDb.isUpdate());
assertFalse(fromDb.isDelete());
assertEquals(asList("strLookup"), fromDb.getLookupNames());
assertEquals(asList("boolField", "strField"), fromDb.getFieldNames());
}
use of org.motechproject.mds.dto.LookupDto 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));
}
use of org.motechproject.mds.dto.LookupDto in project motech by motech.
the class LookupProcessorTest method shouldProcessMethodWithLookupFields.
@Test
public void shouldProcessMethodWithLookupFields() throws NoSuchMethodException {
FieldDto arg1Field = new FieldDto("arg1", "Arg1", TypeDto.INTEGER);
FieldDto secondArgumentField = new FieldDto("secondArgument", "Second Argument", TypeDto.STRING);
lookupProcessor.setEntityProcessingResult(Arrays.asList(mockEntityProcessorOutput(new EntityDto(TestClass.class.getName()), Arrays.asList(arg1Field, secondArgumentField))));
when(paranamer.lookupParameterNames(getTestMethod(1))).thenReturn(argNames);
Method method = getTestMethod(1);
lookupProcessor.process(method);
Map<String, List<LookupDto>> elements = lookupProcessor.getProcessingResult();
assertTrue(elements.containsKey(TEST_CLASS_NAME));
List<LookupDto> list = elements.get(TEST_CLASS_NAME);
LookupDto expected = new LookupDto("Test Method 1", true, false, asList(lookupFieldDto("arg1"), lookupFieldDto("secondArgument", "LIKE")), true, "testMethod1", asList("arg1", "secondArgument"), true);
assertEquals(1, list.size());
assertEquals(expected, list.get(0));
}
Aggregations