Package com.inspiresoftware.lib.dto.geda.adapter

Examples of com.inspiresoftware.lib.dto.geda.adapter.ExtensibleBeanFactory


    }

    @Test(expected = IllegalArgumentException.class)
    public void testRegisterDtoNullClass() throws Exception {

        final ExtensibleBeanFactory fb = new ClassLoaderBeanFactory(ClassLoaderBeanFactoryTest.class.getClassLoader());

        fb.registerDto("myDto", null);

    }
View Full Code Here


    }

    @Test(expected = IllegalArgumentException.class)
    public void testRegisterDtoEmptyClass() throws Exception {

        final ExtensibleBeanFactory fb = new ClassLoaderBeanFactory(ClassLoaderBeanFactoryTest.class.getClassLoader());

        fb.registerDto("myDto", "");

    }
View Full Code Here

        final GeDAFacade facade =
                bundleContext.getService(facadeReference);
        assertNotNull(facade);

        final ExtensibleBeanFactory beanFactory = facade.createBeanFactory(this.getClass().getClassLoader());
        final DTOSupportAnnotationsService annotationsService = facade.getAnnService(this.getClass().getClassLoader());

        beanFactory.registerDto("SimpleDTO",
                "com.inspiresoftware.lib.dto.geda.osgi.test.SimpleDTOClass");
        beanFactory.registerEntity("SimpleEntity",
                "com.inspiresoftware.lib.dto.geda.osgi.test.SimpleEntityClass",
                "com.inspiresoftware.lib.dto.geda.osgi.test.SimpleEntity");
        beanFactory.registerDto("ComplexDTO",
                "com.inspiresoftware.lib.dto.geda.osgi.test.ComplexDTOClass");
        beanFactory.registerEntity("ComplexEntity",
                "com.inspiresoftware.lib.dto.geda.osgi.test.ComplexEntityClass",
                "com.inspiresoftware.lib.dto.geda.osgi.test.ComplexEntity");
        annotationsService.registerAdapter("EqualsByString", new EqualsByStringMatcher());

        final SimpleEntity inner = (SimpleEntity) beanFactory.get("SimpleEntity");
        inner.setString("aether");
        inner.setDecimal(new BigDecimal("28.97"));
        inner.setInteger(1);

        final SimpleEntity colItem = (SimpleEntity) beanFactory.get("SimpleEntity");
        colItem.setString("aqua");
        colItem.setDecimal(new BigDecimal("18.0153"));
        colItem.setInteger(2);
        final List<SimpleEntity> col = new ArrayList<SimpleEntity>();
        col.add(colItem);

        final SimpleEntity mapItem = (SimpleEntity) beanFactory.get("SimpleEntity");
        mapItem.setString("terra");
        mapItem.setDecimal(new BigDecimal("150"));
        mapItem.setInteger(3);
        final Map<String, SimpleEntity> map = new HashMap<String, SimpleEntity>();
        map.put(mapItem.getString(), mapItem);

        final ComplexEntity entity = (ComplexEntity) beanFactory.get("ComplexEntity");
        entity.setName("elements");
        entity.setInner(inner);
        entity.setCollection(col);
        entity.setMap(map);

        final ComplexDTO dto = (ComplexDTO) beanFactory.get("ComplexDTO");

        final DTOEventListener expectations = new ExpectationsDTOEventListener(new Object[] { dto, entity });

        annotationsService.addListener("onDtoAssembled", expectations);
View Full Code Here

        final GeDAFacade facade =
                bundleContext.getService(facadeReference);
        assertNotNull(facade);

        final ExtensibleBeanFactory beanFactory = facade.createBeanFactory(this.getClass().getClassLoader());
        final DTOSupportDSLService dslService = facade.getDSLService(this.getClass().getClassLoader());
        Registry basic = dslService.getRegistry("basic");
        if (basic == null) {
            basic = dslService.createRegistry("basic", beanFactory);
            basic.dto(SimpleDTOClass.class).alias("SimpleDTO").forEntityGeneric()
View Full Code Here

        final GeDAFacade facade =
                bundleContext.getService(facadeReference);
        assertNotNull(facade);

        final ExtensibleBeanFactory beanFactory = facade.createBeanFactory(this.getClass().getClassLoader());
        final DTOSupportDSLService dslService = facade.getDSLService(this.getClass().getClassLoader());
        Registry basic = dslService.getRegistry("basic");
        if (basic == null) {

            beanFactory.registerEntity("SimpleEntity",
                    "com.inspiresoftware.lib.dto.geda.osgi.test.SimpleEntityClass",
                    "com.inspiresoftware.lib.dto.geda.osgi.test.SimpleEntity");

            basic = dslService.createRegistry("basic", beanFactory);
            basic.dto(SimpleDTOClass.class).alias("SimpleDTO").forEntityGeneric()
View Full Code Here

     * Example of how an entity class can be aliased through key and interface.
     */
    public void byClassWithAlias() {


        final ExtensibleBeanFactory bf = new SimpleMapExtensibleBeanFactory();

        final com.inspiresoftware.lib.dto.geda.dsl.Registry registry = Registries.registry(bf);

        bf.registerDto("myDto", MyDtoClass.class.getCanonicalName());
        bf.registerDto("myDtoField3Dto", MyDtoField3Class.class.getCanonicalName());
        bf.registerEntity("myEntityField3Entity", MyEntityField3Class.class.getCanonicalName(), MyEntityField3Class.class.getCanonicalName());
        bf.registerDto("field4ParentDto", MyDtoField4Class.class.getCanonicalName());
        bf.registerEntity("field4ParentEntity", MyEntityField4Class.class.getCanonicalName(), MyEntityField4Class.class.getCanonicalName());
        bf.registerEntity("field2", MyEntityField2Class.class.getCanonicalName(), MyEntityField2Class.class.getCanonicalName());

        registry
                // main mapping
                .dto("myDto").forEntity(MyEntityClass.class).alias("myEntity", MyEntity.class)
                // field 1
View Full Code Here

    /**
     * Example of how DTO by key can be mapped to a specific entity interface.
     */
    public void byInterface() {

        final ExtensibleBeanFactory bf = new SimpleMapExtensibleBeanFactory();

        final com.inspiresoftware.lib.dto.geda.dsl.Registry registry = Registries.registry(bf);

        bf.registerDto("myDto", MyDtoClass.class.getCanonicalName());
        bf.registerEntity("myEntity", MyEntityClass.class.getCanonicalName(), MyEntity.class.getCanonicalName());
        bf.registerDto("myDtoField3Dto", MyDtoField3Class.class.getCanonicalName());
        bf.registerEntity("myEntityField3Entity", MyEntityField3Class.class.getCanonicalName(), MyEntityField3Class.class.getCanonicalName());
        bf.registerDto("field4ParentDto", MyDtoField4Class.class.getCanonicalName());
        bf.registerEntity("field4ParentEntity", MyEntityField4Class.class.getCanonicalName(), MyEntityField4Class.class.getCanonicalName());
        bf.registerEntity("field2", MyEntityField2Class.class.getCanonicalName(), MyEntityField2Class.class.getCanonicalName());

        registry
                // main mapping
                .dto("myDto").forEntity(MyEntity.class)
                // field 1
View Full Code Here

     * Example of most common use case for mapping to generic entity (i.e. full runtime discovery).
     */
    public void generic() {


        final ExtensibleBeanFactory bf = new SimpleMapExtensibleBeanFactory();

        final com.inspiresoftware.lib.dto.geda.dsl.Registry registry = Registries.registry(bf);

        bf.registerDto("myDto", MyDtoClass.class.getCanonicalName());
        bf.registerEntity("myEntity", MyEntityClass.class.getCanonicalName(), MyEntity.class.getCanonicalName());
        bf.registerDto("myDtoField3Dto", MyDtoField3Class.class.getCanonicalName());
        bf.registerEntity("myEntityField3Entity", MyEntityField3Class.class.getCanonicalName(), MyEntityField3Class.class.getCanonicalName());
        bf.registerDto("field4ParentDto", MyDtoField4Class.class.getCanonicalName());
        bf.registerEntity("field4ParentEntity", MyEntityField4Class.class.getCanonicalName(), MyEntityField4Class.class.getCanonicalName());
        bf.registerEntity("field2", MyEntityField2Class.class.getCanonicalName(), MyEntityField2Class.class.getCanonicalName());

        registry
                // main mapping
                .dto("myDto").forEntityGeneric()
                // field 1
View Full Code Here

    @Test
    public void testByReference() throws Exception {

        final IMocksControl ctrl = EasyMock.createControl();

        final ExtensibleBeanFactory bf = ctrl.createMock("bf", ExtensibleBeanFactory.class);

        final com.inspiresoftware.lib.dto.geda.dsl.Registry registry = new DefaultDSLRegistry(bf);

        expect(bf.getClazz("myDto")).andReturn(MyDtoClass.class);
        expect(bf.getClazz("myEntity")).andReturn(MyEntity.class);
        expect(bf.getClazz("myDtoField3Dto")).andReturn(MyDtoField3Class.class);
        expect(bf.getClazz("myEntityField3Entity")).andReturn(MyEntityField3Class.class);
        expect(bf.getClazz("field4ParentDto")).andReturn(MyDtoField4Class.class);
        expect(bf.getClazz("field4ParentEntity")).andReturn(MyEntityField4Class.class);
        expect(bf.get("myDtoField3Dto")).andReturn(new MyDtoField3Class());
        expect(bf.get("field4ParentDto")).andReturn(new MyDtoField4Class());

        ctrl.replay();

        registry
                // main mapping
                .dto("myDto").forEntity("myEntity")
                // field 1
                .withField("field1").forField("field1")
                    .readOnly()
                    .converter("field1Converter")
                // field 2
                .and()
                .withField("field2").forField("field2.subField1").entityBeanKeys("field2")
                // field 3
                .and()
                .withField("field3")
                    .dtoBeanKey("myDtoField3Dto")
                    .entityBeanKeys("myEntityField3Entity")
                // field 4
                .and()
                .withField("field4parent")
                    .dtoBeanKey("field4ParentDto")
                    .entityBeanKeys("field4ParentEntity")
                    .dtoParent("id")
                    .retriever("parentFieldEntityById")
                // field 5
                .and()
                .withField("field5virtual").forVirtual()
                    .converter("field5VirtualConverter")
                // field 6
                .and()
                .withCollection("field6").forField("field6")
                    .dtoBeanKey("field6CollectionDtoItem")
                    .entityBeanKeys("field6CollectionEntityItem")
                    .dtoToEntityMatcherKey("field6CollectionMatcher")
                // field 7
                .and()
                .withMap("field7").forField("field7")
                    .dtoBeanKey("field7MapDtoItem")
                    .entityBeanKeys("field7MapEntityItem")
                    .dtoToEntityMatcherKey("field7MapMatcher")
        ;

        registry
                .dto("myDtoField3Dto").forEntity("myEntityField3Entity")
                .withField("subField1")
        ;

        registry
                .dto("field4ParentDto").forEntity("field4ParentEntity")
                .withField("id")
                .and().withField("subField1")
        ;

        final Map<String, Object> conv = new HashMap<String, Object>();
        conv.put("field1Converter", new ValueConverter() {
            public Object convertToDto(final Object object, final BeanFactory beanFactory) {
                final MyEntity.Field1 field1 = (MyEntity.Field1) object;
                return Boolean.valueOf(field1 == MyEntity.Field1.YES);
            }

            public Object convertToEntity(final Object object, final Object oldEntity, final BeanFactory beanFactory) {
                if ((Boolean) object) {
                    return MyEntity.Field1.YES;
                }
                return MyEntity.Field1.NO;
            }
        });
        conv.put("field5VirtualConverter", new ValueConverter() {
            public Object convertToDto(final Object object, final BeanFactory beanFactory) {
                return String.valueOf(object.hashCode());
            }

            public Object convertToEntity(final Object object, final Object oldEntity, final BeanFactory beanFactory) {
                return null;
            }
        });
        conv.put("parentFieldEntityById", new EntityRetriever() {
            public Object retrieveByPrimaryKey(final Class entityInterface, final Class entityClass, final Object primaryKey) {
                final MyEntityField4Class parent = new MyEntityField4Class();
                parent.setId(99L);
                parent.setSubField1("Parent 99");
                return parent;
            }
        });

        final Assembler asm = DTOAssembler.newAssembler(MyDtoClass.class, MyEntity.class, registry);

        final MyEntity fromEntity = new MyEntityClass();

        fromEntity.setField1(MyEntity.Field1.YES);

        fromEntity.setField2(new MyEntityField2Class());
        fromEntity.getField2().setSubField1("my sub data 1");

        fromEntity.setField3(new MyEntityField3Class());
        fromEntity.getField3().setSubField1("my sub data 2");

        fromEntity.setField4parent(new MyEntityField4Class());
        fromEntity.getField4parent().setId(99L);
        fromEntity.getField4parent().setSubField1("Parent 99");

        final MyDtoClass dto = new MyDtoClass();

        asm.assembleDto(dto, fromEntity, conv, bf);

        assertTrue(dto.getField1());

        assertEquals(dto.getField2(), "my sub data 1");

        final MyDtoField3Class field3 = dto.getField3();
        assertNotNull(field3);
        assertEquals(field3.getSubField1(), "my sub data 2");

        final MyDtoField4Class field4 = dto.getField4parent();
        assertNotNull(field4);
        assertEquals(field4.getId(), Long.valueOf(99L));
        assertEquals(field4.getSubField1(), "Parent 99");

        assertEquals(dto.getField5virtual(), String.valueOf(fromEntity.hashCode()));

        ctrl.verify();

        ctrl.reset();

        expect(bf.get("field2")).andReturn(new MyEntityField2Class());
        expect(bf.get("myEntityField3Entity")).andReturn(new MyEntityField3Class());
        expect(bf.get("field4ParentEntity")).andReturn(new MyEntityField4Class());

        ctrl.replay();

        final MyEntity toEntity = new MyEntityClass();
View Full Code Here

     * Example of how mapping from one DTO-Entity context can be copied to
     * another DTO-Entity context to reduce code duplication.
     */
    public void reuseMapping() {

        final ExtensibleBeanFactory bf = new SimpleMapExtensibleBeanFactory();

        final com.inspiresoftware.lib.dto.geda.dsl.Registry registry = Registries.registry(bf);

        bf.registerDto("myDto", MyDtoClass.class.getCanonicalName());
        bf.registerDto("myDtoField3Dto", MyDtoField3Class.class.getCanonicalName());
        bf.registerEntity("myEntityField3Entity", MyEntityField3Class.class.getCanonicalName(), MyEntityField3Class.class.getCanonicalName());
        bf.registerDto("field4ParentDto", MyDtoField4Class.class.getCanonicalName());
        bf.registerEntity("field4ParentEntity", MyEntityField4Class.class.getCanonicalName(), MyEntityField4Class.class.getCanonicalName());

        registry
                // main mapping
                .dto("myDto").forEntity(MyEntity.class)
                // field 1
View Full Code Here

TOP

Related Classes of com.inspiresoftware.lib.dto.geda.adapter.ExtensibleBeanFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.