Search in sources :

Example 21 with LookupDto

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

the class LookupProcessorTest method shouldNotCreateIndexForLookup.

@Test
public void shouldNotCreateIndexForLookup() throws Exception {
    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(5))).thenReturn(argNames);
    Method method = getTestMethod(5);
    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 5", true, false, asList(lookupFieldDto("arg1"), lookupFieldDto("secondArgument", "LIKE")), true, "testMethod5", new ArrayList<>(), false);
    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)

Example 22 with LookupDto

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

the class LookupProcessorTest method shouldProcessMethodWithSetParam.

@Test
public void shouldProcessMethodWithSetParam() throws NoSuchMethodException {
    FieldDto arg0Field = new FieldDto("arg0Field", "Arg 0 Field", TypeDto.STRING);
    FieldDto setField = new FieldDto("setField", "Range Field", TypeDto.STRING);
    FieldDto regularField = new FieldDto("regularField", "Regular Field", TypeDto.STRING);
    FieldDto setFieldDouble = new FieldDto("setFieldDouble", "Set Field", TypeDto.DOUBLE);
    EntityProcessorOutput eop = mockEntityProcessorOutput(new EntityDto(TestClass.class.getName()), Arrays.asList(arg0Field, setField, regularField, setFieldDouble));
    lookupProcessor.setEntityProcessingResult(Arrays.asList(eop));
    LookupFieldDto[][] expectedFields = { { lookupFieldDto("arg0"), lookupFieldDto("set", SET) }, { lookupFieldDto("regularField"), lookupFieldDto("setField", SET) } };
    String[][] expectedFieldsOrder = { { "arg0", "range" }, { "regularField", "rangeField" } };
    // test two methods, one with @LookupField annotations, second without
    for (int i = 0; i < 2; i++) {
        Method method = getTestMethodWithSetParam(i);
        when(paranamer.lookupParameterNames(method)).thenReturn(new String[] { "arg0", "set" });
        LookupDto expectedLookup = new LookupDto("Test Method With Set Param " + i, true, false, asList(expectedFields[i]), true, "testMethodWithSetParam" + i, asList(expectedFieldsOrder[i]), 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(expectedLookup, list.get(0));
        assertEquals(asList(VALUE, SET), extract(list.get(0).getLookupFields(), on(LookupFieldDto.class).getType()));
        lookupProcessor.clear();
    }
}
Also used : LookupDto(org.motechproject.mds.dto.LookupDto) Method(java.lang.reflect.Method) EntityDto(org.motechproject.mds.dto.EntityDto) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) FieldTestHelper.lookupFieldDto(org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) Test(org.junit.Test)

Example 23 with LookupDto

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

the class FieldHelperTest method advancedSettingsDto.

private AdvancedSettingsDto advancedSettingsDto() {
    AdvancedSettingsDto advancedSettings = new AdvancedSettingsDto();
    advancedSettings.setEntityId(100L);
    LookupDto lookup = new LookupDto(1L, "look1Name", true, true, null, false, "look1", new ArrayList<String>());
    LookupDto lookup2 = new LookupDto(2L, "look2Name", false, false, null, false, "look2", new ArrayList<String>());
    advancedSettings.setIndexes(new ArrayList<>((asList(lookup, lookup2))));
    return advancedSettings;
}
Also used : LookupDto(org.motechproject.mds.dto.LookupDto) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto)

Example 24 with LookupDto

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

the class MdsLookupServiceImpl method buildLookupExecutor.

private LookupExecutor buildLookupExecutor(String entityClassName, String lookupName) {
    String fullyQualifiedEntityClassName;
    if (entityClassName.contains(".")) {
        fullyQualifiedEntityClassName = entityClassName;
    } else {
        fullyQualifiedEntityClassName = Constants.PackagesGenerated.ENTITY + "." + entityClassName;
    }
    MotechDataService dataService = OSGiServiceUtils.findService(bundleContext, MotechClassPool.getInterfaceName(fullyQualifiedEntityClassName));
    EntityDto entity = entityService.getEntityByClassName(fullyQualifiedEntityClassName);
    LookupDto lookup = entityService.getLookupByName(entity.getId(), lookupName);
    return new LookupExecutor(dataService, lookup, entityService.getLookupFieldsMapping(entity.getId(), lookupName));
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) LookupDto(org.motechproject.mds.dto.LookupDto) LookupExecutor(org.motechproject.mds.lookup.LookupExecutor) MotechDataService(org.motechproject.mds.service.MotechDataService)

Example 25 with LookupDto

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

the class EntityMetadataBuilderTest method shouldSetIndexOnMetadataLookupField.

@Test
public void shouldSetIndexOnMetadataLookupField() throws Exception {
    FieldDto lookupField = fieldDto("lookupField", String.class);
    LookupDto lookup = new LookupDto();
    lookup.setLookupName("A lookup");
    lookup.setLookupFields(singletonList(new LookupFieldDto("lookupField", LookupFieldType.VALUE)));
    lookup.setIndexRequired(true);
    lookupField.setLookups(singletonList(lookup));
    FieldMetadata fmd = mock(FieldMetadata.class);
    when(entity.getName()).thenReturn(ENTITY_NAME);
    when(entity.getId()).thenReturn(14L);
    when(schemaHolder.getFields(entity)).thenReturn(singletonList(lookupField));
    when(entity.getTableName()).thenReturn(TABLE_NAME);
    when(jdoMetadata.newPackageMetadata(PACKAGE)).thenReturn(packageMetadata);
    when(packageMetadata.newClassMetadata(ENTITY_NAME)).thenReturn(classMetadata);
    when(classMetadata.newFieldMetadata("lookupField")).thenReturn(fmd);
    when(fmd.newIndexMetadata()).thenReturn(indexMetadata);
    PowerMockito.mockStatic(FieldUtils.class);
    when(FieldUtils.getDeclaredField(eq(Sample.class), anyString(), eq(true))).thenReturn(Sample.class.getDeclaredField("notInDefFg"));
    entityMetadataBuilder.addEntityMetadata(jdoMetadata, entity, Sample.class, schemaHolder);
    verifyCommonClassMetadata();
    verify(fmd).newIndexMetadata();
    verify(indexMetadata).setName("lkp_idx_" + ENTITY_NAME + "_lookupField_14");
}
Also used : FieldMetadata(javax.jdo.metadata.FieldMetadata) AnotherSample(org.motechproject.mds.annotations.internal.samples.AnotherSample) Sample(org.motechproject.mds.builder.Sample) LookupDto(org.motechproject.mds.dto.LookupDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) 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