ClassLoaderBeanFactory implements ExtensibleBeanFactory { public void registerDto(final String key, final String className) throws IllegalArgumentException { if (key != null && key.length() > 0 && className != null && className.length() > 0) { if (this.mappingClasses.containsKey(key)) { throw new IllegalArgumentException("key is already used: [key=" + key + ", className=" + className + "]"); } this.mappingClasses.put(key, className); this.mappingReps.put(key, className); } else { throw new IllegalArgumentException("all args are mandatory: [key=" + key + ", className=" + className + "]"); } } ClassLoaderBeanFactory(final ClassLoader classLoader);  ClassLoaderBeanFactory(final ClassLoader classLoader,
                                  final Map<String, String> mappingClasses,
                                  final Map<String, String> mappingEntityRepresentatives); void registerDto(final String key, final String className); void registerEntity(final String key, final String className, final String representative); Class getClazz(final String entityBeanKey); Object get(final String entityBeanKey); void releaseResources();  }
@Test public void testRegisterDto() throws Exception { final ExtensibleBeanFactory fb = new ClassLoaderBeanFactory(ClassLoaderBeanFactoryTest.class.getClassLoader()); fb.registerDto("myDto", DtoClass.class.getCanonicalName()); final Class myDtoClass = fb.getClazz("myDto"); assertNotNull(myDtoClass); assertEquals(myDtoClass, DtoClass.class); final Object myDtoInstance = fb.get("myDto"); assertNotNull(myDtoInstance); assertEquals(myDtoInstance.getClass(), DtoClass.class); }
@Test(expected = IllegalArgumentException.class) public void testRegisterDtoNullKey() throws Exception { final ExtensibleBeanFactory fb = new ClassLoaderBeanFactory(ClassLoaderBeanFactoryTest.class.getClassLoader()); fb.registerDto(null, DtoClass.class.getCanonicalName()); }
@Test(expected = IllegalArgumentException.class) public void testRegisterDtoEmptyKey() throws Exception { final ExtensibleBeanFactory fb = new ClassLoaderBeanFactory(ClassLoaderBeanFactoryTest.class.getClassLoader()); fb.registerDto("", DtoClass.class.getCanonicalName()); }
@Test(expected = IllegalArgumentException.class) public void testRegisterDtoNullClass() throws Exception { final ExtensibleBeanFactory fb = new ClassLoaderBeanFactory(ClassLoaderBeanFactoryTest.class.getClassLoader()); fb.registerDto("myDto", null); }
@Test(expected = IllegalArgumentException.class) public void testRegisterDtoEmptyClass() throws Exception { final ExtensibleBeanFactory fb = new ClassLoaderBeanFactory(ClassLoaderBeanFactoryTest.class.getClassLoader()); fb.registerDto("myDto", ""); }
@Test(expected = IllegalArgumentException.class) public void testRegisterDtoDuplicateKey() throws Exception { final ExtensibleBeanFactory fb = new ClassLoaderBeanFactory(ClassLoaderBeanFactoryTest.class.getClassLoader()); fb.registerDto("myDto", DtoClass.class.getCanonicalName()); fb.registerDto("myDto", DtoClass.class.getCanonicalName()); }