Search in sources :

Example 16 with LookupDto

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"));
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) FieldBasicDto(org.motechproject.mds.dto.FieldBasicDto) LookupDto(org.motechproject.mds.dto.LookupDto) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) LinkedList(java.util.LinkedList) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) Test(org.junit.Test)

Example 17 with LookupDto

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

Example 18 with LookupDto

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());
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) LookupDto(org.motechproject.mds.dto.LookupDto) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) RestOptionsDto(org.motechproject.mds.dto.RestOptionsDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) Test(org.junit.Test)

Example 19 with LookupDto

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

Example 20 with LookupDto

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));
}
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) FieldTestHelper.lookupFieldDto(org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) Test(org.junit.Test)

Aggregations

LookupDto (org.motechproject.mds.dto.LookupDto)54 LookupFieldDto (org.motechproject.mds.dto.LookupFieldDto)32 FieldDto (org.motechproject.mds.dto.FieldDto)29 ArrayList (java.util.ArrayList)26 EntityDto (org.motechproject.mds.dto.EntityDto)24 Test (org.junit.Test)23 List (java.util.List)10 Method (java.lang.reflect.Method)9 Arrays.asList (java.util.Arrays.asList)8 FieldTestHelper.lookupFieldDto (org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto)7 HashMap (java.util.HashMap)6 Field (org.motechproject.mds.domain.Field)5 Lookup (org.motechproject.mds.domain.Lookup)5 AdvancedSettingsDto (org.motechproject.mds.dto.AdvancedSettingsDto)5 FieldBasicDto (org.motechproject.mds.dto.FieldBasicDto)5 Before (org.junit.Before)4 Matchers.anyString (org.mockito.Matchers.anyString)4 RestOptionsDto (org.motechproject.mds.dto.RestOptionsDto)4 LookupExecutor (org.motechproject.mds.lookup.LookupExecutor)4 MetadataDto (org.motechproject.mds.dto.MetadataDto)3