Search in sources :

Example 56 with EntityDto

use of org.motechproject.mds.dto.EntityDto 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)

Example 57 with EntityDto

use of org.motechproject.mds.dto.EntityDto 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 58 with EntityDto

use of org.motechproject.mds.dto.EntityDto 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 59 with EntityDto

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

the class EntitySorterTest method setUpEntities.

@Before
public void setUpEntities() {
    book = new EntityDto("Book");
    author = new EntityDto("Author");
    authorFieldInBook = fieldDto("author", ManyToManyRelationship.class);
    authorFieldInBook.addMetadata(new MetadataDto(RELATED_CLASS, "Author"));
    FieldDto bookFieldInAuthor = fieldDto("book", ManyToManyRelationship.class);
    bookFieldInAuthor.addMetadata(new MetadataDto(RELATED_CLASS, "Book"));
    when(schemaHolder.getFields(book)).thenReturn(singletonList(authorFieldInBook));
    when(schemaHolder.getFields(author)).thenReturn(singletonList(bookFieldInAuthor));
    entity1 = new EntityDto("Entity1");
    entity2 = new EntityDto("Entity2");
    entity3 = new EntityDto("Entity3");
    FieldDto entity1Field = fieldDto("entity1", OneToOneRelationship.class);
    entity1Field.addMetadata(new MetadataDto(RELATED_CLASS, "Entity2"));
    FieldDto entity2Field = fieldDto("entity2", OneToOneRelationship.class);
    entity2Field.addMetadata(new MetadataDto(RELATED_CLASS, "Entity3"));
    when(schemaHolder.getFields(entity1)).thenReturn(singletonList(entity1Field));
    when(schemaHolder.getFields(entity2)).thenReturn(singletonList(entity2Field));
    parentEntity = new EntityDto("Parent");
    childEntity = new EntityDto("Child");
    childEntity.setSuperClass("Parent");
    binaryTree = new EntityDto("Binary tree");
    FieldDto leftChild = fieldDto("leftChild", "Left child", OneToOneRelationship.class);
    leftChild.addMetadata(new MetadataDto(RELATED_CLASS, "Binary tree"));
    FieldDto rightChild = fieldDto("rightChild", "Right child", OneToOneRelationship.class);
    rightChild.addMetadata(new MetadataDto(RELATED_CLASS, "Binary tree"));
    when(schemaHolder.getFields(binaryTree)).thenReturn(asList(leftChild, rightChild));
    entity1.setRecordHistory(true);
    entity2.setRecordHistory(true);
    entity3.setRecordHistory(true);
    book.setRecordHistory(true);
    author.setRecordHistory(true);
    parentEntity.setRecordHistory(true);
    childEntity.setRecordHistory(true);
    binaryTree.setRecordHistory(true);
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) ManyToManyRelationship(org.motechproject.mds.domain.ManyToManyRelationship) MetadataDto(org.motechproject.mds.dto.MetadataDto) FieldDto(org.motechproject.mds.dto.FieldDto) Before(org.junit.Before)

Example 60 with EntityDto

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

the class BaseInstanceIT method setUpEntity.

private void setUpEntity() throws Exception {
    String entityClass = getEntityClassName();
    entity = new EntityDto(entityClass);
    entity.setRecordHistory(true);
    entity = entityService.createEntity(entity);
    entityService.addFields(entity, getEntityFields());
    TrackingDto tracking = entityService.getAdvancedSettings(entity.getId(), true).getTracking();
    tracking.setAllowCreateEvent(false);
    tracking.setAllowUpdateEvent(false);
    tracking.setAllowDeleteEvent(false);
    entityService.updateTracking(entity.getId(), tracking);
    SchemaHolder schemaHolder = entityService.getSchema();
    mdsConstructor.constructEntities(schemaHolder);
    PersistenceManagerFactory factory = getDataPersistenceManagerFactory();
    if (null == factory.getMetadata(entityClass)) {
        factory.registerMetadata(metadataHolder.getJdoMetadata());
    }
    CtClass ctClass = MotechClassPool.getDefault().get(getRepositoryClass());
    MDSClassLoader.getInstance().safeDefineClass(getRepositoryClass(), ctClass.toBytecode());
    ctClass = MotechClassPool.getDefault().get(getInterfaceClass());
    MDSClassLoader.getInstance().safeDefineClass(getInterfaceClass(), ctClass.toBytecode());
    ctClass = MotechClassPool.getDefault().get(getServiceClass());
    MDSClassLoader.getInstance().safeDefineClass(getServiceClass(), ctClass.toBytecode());
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) CtClass(javassist.CtClass) SchemaHolder(org.motechproject.mds.dto.SchemaHolder) PersistenceManagerFactory(javax.jdo.PersistenceManagerFactory) TrackingDto(org.motechproject.mds.dto.TrackingDto)

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