DefaultDSLRegistry implements Registry, BeanFactory, BeanFactoryProvider { public DtoContext dto(final Class dtoClass) { if (dtoClass == null) { throw new GeDARuntimeException("dtoClass must not be null"); } final int hash = dtoClass.hashCode(); if (contexts.containsKey(hash)) { return contexts.get(hash); } final DtoContext ctx = new DtoContextByClass(dtoClass, beanFactory); contexts.put(hash, ctx); return ctx; } @Deprecated  DefaultDSLRegistry();  DefaultDSLRegistry(final ExtensibleBeanFactory beanFactory); DtoContext has(final Class dtoClass); DtoContext dto(final Class dtoClass); DtoContext dto(final Object dtoInstance); DtoContext dto(final String beanKey); Class getClazz(final String entityBeanKey); Object get(final String entityBeanKey); BeanFactory getBeanFactory(); void releaseResources();  }
@Test public void testWithSameFieldsByInterface() 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); ctrl.replay(); registry .dto(MyDtoWithSameFieldsClass.class).forEntity(MyEntityWithSameFieldsInterface.class) .withFieldsSameAsIn(MyEntityWithSameFieldsInterface.class); 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)); assertEquals(toEntity.getField5(), 5); assertEquals(toEntity.getField6(), Long.valueOf(6L)); assertEquals(toEntity.getField7(), 7L); assertEquals(toEntity.getField8(), Double.valueOf(8D)); assertEquals(toEntity.getField9(), 9D, 0); assertEquals(BigDecimal.TEN.compareTo(toEntity.getField10()), 0); assertSame(toEntity.getField11(), field11Obj); assertNull(toEntity.getWrongNameOnEntity()); assertNull(toEntity.getWrongType()); ctrl.verify(); }
@Test public void testWithSameFieldsByInterfaceExcluding() 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); ctrl.replay(); registry .dto(MyDtoWithSameFieldsClass.class).forEntity(MyEntityWithSameFieldsInterface.class) .withFieldsSameAsIn(MyEntityWithSameFieldsInterface.class, "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()); ctrl.verify(); ctrl.reset(); dto.setField4(Integer.valueOf(4)); dto.setField5(5); dto.setField6(Long.valueOf(6L)); dto.setField7(7L); ctrl.replay(); final MyEntityWithSameFieldsInterface toEntity = new MyEntityWithSameFieldsClass(); asm.assembleEntity(dto, toEntity, null, bf); assertEquals(toEntity.getField1(), "field1"); assertTrue(toEntity.getField2()); assertTrue(toEntity.getField3()); assertNull(toEntity.getField4()); assertEquals(toEntity.getField5(), 0); assertNull(toEntity.getField6()); assertEquals(toEntity.getField7(), 0L); assertEquals(toEntity.getField8(), Double.valueOf(8D)); assertEquals(toEntity.getField9(), 9D, 0); assertEquals(BigDecimal.TEN.compareTo(toEntity.getField10()), 0); assertSame(toEntity.getField11(), field11Obj); assertNull(toEntity.getWrongNameOnEntity()); assertNull(toEntity.getWrongType()); ctrl.verify(); }
@Test public void testWithSameFieldsByClass() 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); ctrl.replay(); registry .dto(MyDtoWithSameFieldsClass.class).forEntity(MyEntityWithSameFieldsInterface.class) .withFieldsSameAsIn(MyEntityWithSameFieldsClass.class); 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)); assertEquals(toEntity.getField5(), 5); assertEquals(toEntity.getField6(), Long.valueOf(6L)); assertEquals(toEntity.getField7(), 7L); assertEquals(toEntity.getField8(), Double.valueOf(8D)); assertEquals(toEntity.getField9(), 9D, 0); assertEquals(BigDecimal.TEN.compareTo(toEntity.getField10()), 0); assertSame(toEntity.getField11(), field11Obj); assertNull(toEntity.getWrongNameOnEntity()); assertNull(toEntity.getWrongType()); ctrl.verify(); }
@Test public void testWithSameFieldsByClassExcluding() 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); ctrl.replay(); registry .dto(MyDtoWithSameFieldsClass.class).forEntity(MyEntityWithSameFieldsInterface.class) .withFieldsSameAsIn(MyEntityWithSameFieldsClass.class, "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()); ctrl.verify(); ctrl.reset(); dto.setField4(Integer.valueOf(4)); dto.setField5(5); dto.setField6(Long.valueOf(6L)); dto.setField7(7L); ctrl.replay(); final MyEntityWithSameFieldsInterface toEntity = new MyEntityWithSameFieldsClass(); asm.assembleEntity(dto, toEntity, null, bf); assertEquals(toEntity.getField1(), "field1"); assertTrue(toEntity.getField2()); assertTrue(toEntity.getField3()); assertNull(toEntity.getField4()); assertEquals(toEntity.getField5(), 0); assertNull(toEntity.getField6()); assertEquals(toEntity.getField7(), 0L); assertEquals(toEntity.getField8(), Double.valueOf(8D)); assertEquals(toEntity.getField9(), 9D, 0); assertEquals(BigDecimal.TEN.compareTo(toEntity.getField10()), 0); assertSame(toEntity.getField11(), field11Obj); assertNull(toEntity.getWrongNameOnEntity()); assertNull(toEntity.getWrongType()); ctrl.verify(); }
@Test public void testWithSameFieldsByClassInheritance() 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); ctrl.replay(); registry .dto(MyDtoWithSameFieldsClass.class).forEntity(MyEntityWithSameFieldsInterface.class) .withFieldsSameAsIn(MyEntityWithSameFieldsClassInherited.class); final Assembler asm = DTOAssembler.newAssembler(MyDtoWithSameFieldsClass.class, MyEntityWithSameFieldsInterface.class, registry); final MyEntityWithSameFieldsInterface fromEntity = new MyEntityWithSameFieldsClassInherited(); 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)); assertEquals(toEntity.getField5(), 5); assertEquals(toEntity.getField6(), Long.valueOf(6L)); assertEquals(toEntity.getField7(), 7L); assertEquals(toEntity.getField8(), Double.valueOf(8D)); assertEquals(toEntity.getField9(), 9D, 0); assertEquals(BigDecimal.TEN.compareTo(toEntity.getField10()), 0); assertSame(toEntity.getField11(), field11Obj); assertNull(toEntity.getWrongNameOnEntity()); assertNull(toEntity.getWrongType()); ctrl.verify(); }