Package com.inspiresoftware.lib.dto.geda.assembler

Examples of com.inspiresoftware.lib.dto.geda.assembler.Assembler


        eColl.getItems().add(eItem1);
        eColl.getItems().add(eItem2);

        final DtoMapIterface dMap = new DtoMapToCollectionClass();

        final Assembler assembler = DTOAssembler.newAssembler(dMap.getClass(), eColl.getClass());

        assembler.assembleDto(dMap, eColl, null, new BeanFactory() {

            public Class getClazz(final String entityBeanKey) {
                if ("dtoItem".equals(entityBeanKey)) {
                    return DtoItemClass.class;
                }
                return null;
            }

            public Object get(final String entityBeanKey) {
                if ("dtoItem".equals(entityBeanKey)) {
                    return new DtoItemClass();
                }
                return null;
            }

        });

        assertNotNull(dMap.getItems());
        assertEquals(2, dMap.getItems().size());
        final Set<String> keys = dMap.getItems().keySet();
        for (String key : keys) {
            if ("itm1".equals(key)) {
                assertEquals("itm1", dMap.getItems().get(key).getName());
            } else if ("itm2".equals(key)) {
                assertEquals("itm2", dMap.getItems().get(key).getName());
            } else {
                fail("Unknown key");
            }
        }

        final DtoItemClass dto3 = new DtoItemClass();
        dto3.setName("itm3");
        dMap.getItems().put("itm3", dto3);

        dMap.getItems().remove("itm1"); // first

        assembler.assembleEntity(dMap, eColl, null, new BeanFactory() {

            public Class getClazz(final String entityBeanKey) {
                if ("entityItem".equals(entityBeanKey)) {
                    return EntityItemInterface.class;
                }
View Full Code Here


        final EntityChainLv1Class entity = new EntityChainLv1Class();
        entity.setWrapper(new EntityChainLv2Class());
        entity.getWrapper().setWrapper(new EntityChainLv3Class());
        entity.getWrapper().getWrapper().setName("Name");

        final Assembler assembler =
                DTOAssembler.newAssembler(DtoChainClass.class, EntityChainLv1Class.class);

        assembler.assembleDto(dto, entity, null, null);

        assertEquals(entity.getWrapper().getWrapper().getName(), dto.getNestedString());

        dto.setNestedString("Another Name");

        assembler.assembleEntity(dto, entity, null, null);

        assertEquals("Another Name", entity.getWrapper().getWrapper().getName());

    }
View Full Code Here

        eMap.getItems().put("itm1", eItem1);
        eMap.getItems().put("itm2", eItem2);

        final DtoMapIterface dMap = new DtoMapToMapClass();

        final Assembler assembler = DTOAssembler.newAssembler(dMap.getClass(), eMap.getClass());

        assembler.assembleDto(dMap, eMap, null, new BeanFactory() {

            public Class getClazz(final String entityBeanKey) {
                if ("dtoItem".equals(entityBeanKey)) {
                    return DtoItemClass.class;
                }
                return null;
            }

            public Object get(final String entityBeanKey) {
                if ("dtoItem".equals(entityBeanKey)) {
                    return new DtoItemClass();
                }
                return null;
            }

        });

        assertNotNull(dMap.getItems());
        assertEquals(2, dMap.getItems().size());
        final Set<String> keys = dMap.getItems().keySet();
        for (String key : keys) {
            if ("itm1".equals(key)) {
                assertEquals("itm1", dMap.getItems().get(key).getName());
            } else if ("itm2".equals(key)) {
                assertEquals("itm2", dMap.getItems().get(key).getName());
            } else {
                fail("Unknown key");
            }
        }

        final DtoItemClass dto3 = new DtoItemClass();
        dto3.setName("itm3");
        dMap.getItems().put("itm3", dto3);

        dMap.getItems().remove("itm1"); // first

        assembler.assembleEntity(dMap, eMap, null, new BeanFactory() {

            public Class getClazz(final String entityBeanKey) {
                if ("entityItem".equals(entityBeanKey)) {
                    return EntityItemInterface.class;
                }
View Full Code Here

                .dto(MyDtoWithSameFieldsClass.class).forEntity("myEntityWithSameFields")
                // map all same name same type fields by key
                .withFieldsSameAsIn("myEntityWithSameFields");


        final Assembler asm = DTOAssembler.newAssembler(MyDtoWithSameFieldsClass.class, MyEntityWithSameFieldsInterface.class, registry);

        final MyEntityWithSameFieldsInterface fromEntity = new MyEntityWithSameFieldsClass();

        fromEntity.setField1("field1");
        fromEntity.setField2(Boolean.TRUE);
        fromEntity.setField3(true);
        fromEntity.setField4(Integer.valueOf(4));
        fromEntity.setField5(5);
        fromEntity.setField6(Long.valueOf(6L));
        fromEntity.setField7(7L);
        fromEntity.setField8(Double.valueOf(8D));
        fromEntity.setField9(9D);
        fromEntity.setField10(BigDecimal.TEN);
        final Object field11Obj = new Object();
        fromEntity.setField11(field11Obj);
        fromEntity.setWrongNameOnEntity("wrongNameOnEntity");
        fromEntity.setWrongType(Double.valueOf(20D));

        final MyDtoWithSameFieldsClass dto = new MyDtoWithSameFieldsClass();

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

        assertEquals(dto.getField1(), "field1");
        assertTrue(dto.getField2());
        assertTrue(dto.getField3());
        assertEquals(dto.getField4(), Integer.valueOf(4));
        assertEquals(dto.getField5(), 5);
        assertEquals(dto.getField6(), Long.valueOf(6L));
        assertEquals(dto.getField7(), 7L);
        assertEquals(dto.getField8(), Double.valueOf(8D));
        assertEquals(dto.getField9(), 9D, 0);
        assertEquals(BigDecimal.TEN.compareTo(dto.getField10()), 0);
        assertSame(dto.getField11(), field11Obj);
        assertNull(dto.getWrongName());
        assertNull(dto.getWrongType());

        final MyEntityWithSameFieldsInterface toEntity = new MyEntityWithSameFieldsClass();

        asm.assembleEntity(dto, toEntity, null, bf);

        assertEquals(toEntity.getField1(), "field1");
        assertTrue(toEntity.getField2());
        assertTrue(toEntity.getField3());
        assertEquals(toEntity.getField4(), Integer.valueOf(4));
View Full Code Here

                .dto(MyDtoWithSameFieldsClass.class).forEntity("myEntityWithSameFields")
                // map all same name same type fields by key but not field4, field5, field6, field7
                .withFieldsSameAsIn("myEntityWithSameFields", "field4", "field5", "field6", "field7");


        final Assembler asm = DTOAssembler.newAssembler(MyDtoWithSameFieldsClass.class, MyEntityWithSameFieldsInterface.class, registry);

        final MyEntityWithSameFieldsInterface fromEntity = new MyEntityWithSameFieldsClass();

        fromEntity.setField1("field1");
        fromEntity.setField2(Boolean.TRUE);
        fromEntity.setField3(true);
        fromEntity.setField4(Integer.valueOf(4));
        fromEntity.setField5(5);
        fromEntity.setField6(Long.valueOf(6L));
        fromEntity.setField7(7L);
        fromEntity.setField8(Double.valueOf(8D));
        fromEntity.setField9(9D);
        fromEntity.setField10(BigDecimal.TEN);
        final Object field11Obj = new Object();
        fromEntity.setField11(field11Obj);
        fromEntity.setWrongNameOnEntity("wrongNameOnEntity");
        fromEntity.setWrongType(Double.valueOf(20D));

        final MyDtoWithSameFieldsClass dto = new MyDtoWithSameFieldsClass();

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

        assertEquals(dto.getField1(), "field1");
        assertTrue(dto.getField2());
        assertTrue(dto.getField3());
        assertNull(dto.getField4());
        assertEquals(dto.getField5(), 0);
        assertNull(dto.getField6());
        assertEquals(dto.getField7(), 0L);
        assertEquals(dto.getField8(), Double.valueOf(8D));
        assertEquals(dto.getField9(), 9D, 0);
        assertEquals(BigDecimal.TEN.compareTo(dto.getField10()), 0);
        assertSame(dto.getField11(), field11Obj);
        assertNull(dto.getWrongName());
        assertNull(dto.getWrongType());


        dto.setField4(Integer.valueOf(4));
        dto.setField5(5);
        dto.setField6(Long.valueOf(6L));
        dto.setField7(7L);


        final MyEntityWithSameFieldsInterface toEntity = new MyEntityWithSameFieldsClass();

        asm.assembleEntity(dto, toEntity, null, bf);

        assertEquals(toEntity.getField1(), "field1");
        assertTrue(toEntity.getField2());
        assertTrue(toEntity.getField3());
        assertNull(toEntity.getField4());
View Full Code Here

                    personDAO.lookUpAddress(person)
            });

        }

        final Assembler asm = DTOAssembler.newCompositeAssembler(
                ContactDTOImpl.class, new Class[] { Person.class, Address.class });

        final List<ContactDTO> dtos = new ArrayList<ContactDTO>();

        asm.assembleDtos(dtos, entities, null, null);

        return dtos;
    }
View Full Code Here

    public void inheritanceMapping() throws GeDAException {

        final SimpleDtoClass dto = new SimpleDtoClass();
        final SimpleEntityClass entity = createTestEntity2();

        final Assembler assembler =
                DTOAssembler.newAssembler(SimpleDtoClass.class, SimpleEntityClass.class);
        assembler.assembleDto(dto, entity, null, null);
        assertEquals(entity.getEntityId(), dto.getMyLong());
        assertEquals(entity.getName(), dto.getMyString());
        assertEquals(entity.getNumber(), dto.getMyDouble());
        assertEquals(entity.getDecision(), dto.getMyBoolean());

        dto.setMyLong(0L);
        dto.setMyBoolean(false);

        assembler.assembleEntity(dto, entity, null, null);
        assertEquals(Long.valueOf(0L), entity.getEntityId());
        assertEquals(Boolean.FALSE, entity.getDecision());

    }
View Full Code Here

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

        asm.assembleEntity(dto, toEntity, conv, bf);

        assertNull(toEntity.getField1()); // it is read only

        assertNotNull(toEntity.getField2());
        assertEquals(toEntity.getField2().getSubField1(), "my sub data 1");
View Full Code Here

        entity.setDecision(true);
        final ValueConverter conv3toDto = new Converter();
        final Map<String, Object> converters = new HashMap<String, Object>();
        converters.put("boolToEnum", conv3toDto);

        final Assembler assembler =
                DTOAssembler.newAssembler(DtoClass.class, EntityClass.class);

        assembler.assembleDto(dto, entity, converters, null);

        assertEquals(DtoClass.Decision.Decided, dto.getMyEnum());

        dto.setMyEnum(DtoClass.Decision.Undecided);

        assembler.assembleEntity(dto, entity, converters, null);

    }
View Full Code Here

                .dto(MyDtoWithSameFieldsClass.class).forEntity("myEntityWithSameFields")
                // map all same name same type fields by key
                .withFieldsSameAsIn("myEntityWithSameFields");


        final Assembler asm = DTOAssembler.newAssembler(MyDtoWithSameFieldsClass.class, MyEntityWithSameFieldsInterface.class, registry);

        final MyEntityWithSameFieldsInterface fromEntity = new MyEntityWithSameFieldsClass();

        fromEntity.setField1("field1");
        fromEntity.setField2(Boolean.TRUE);
        fromEntity.setField3(true);
        fromEntity.setField4(Integer.valueOf(4));
        fromEntity.setField5(5);
        fromEntity.setField6(Long.valueOf(6L));
        fromEntity.setField7(7L);
        fromEntity.setField8(Double.valueOf(8D));
        fromEntity.setField9(9D);
        fromEntity.setField10(BigDecimal.TEN);
        final Object field11Obj = new Object();
        fromEntity.setField11(field11Obj);
        fromEntity.setWrongNameOnEntity("wrongNameOnEntity");
        fromEntity.setWrongType(Double.valueOf(20D));

        final MyDtoWithSameFieldsClass dto = new MyDtoWithSameFieldsClass();

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

        assertEquals(dto.getField1(), "field1");
        assertTrue(dto.getField2());
        assertTrue(dto.getField3());
        assertEquals(dto.getField4(), Integer.valueOf(4));
        assertEquals(dto.getField5(), 5);
        assertEquals(dto.getField6(), Long.valueOf(6L));
        assertEquals(dto.getField7(), 7L);
        assertEquals(dto.getField8(), Double.valueOf(8D));
        assertEquals(dto.getField9(), 9D, 0);
        assertEquals(BigDecimal.TEN.compareTo(dto.getField10()), 0);
        assertSame(dto.getField11(), field11Obj);
        assertNull(dto.getWrongName());
        assertNull(dto.getWrongType());

        ctrl.verify();

        ctrl.reset();

        ctrl.replay();

        final MyEntityWithSameFieldsInterface toEntity = new MyEntityWithSameFieldsClass();

        asm.assembleEntity(dto, toEntity, null, bf);

        assertEquals(toEntity.getField1(), "field1");
        assertTrue(toEntity.getField2());
        assertTrue(toEntity.getField3());
        assertEquals(toEntity.getField4(), Integer.valueOf(4));
View Full Code Here

TOP

Related Classes of com.inspiresoftware.lib.dto.geda.assembler.Assembler

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.