KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > dozer > util > mapping > util > DestBeanCreatorTest


1 /*
2  * Copyright 2005-2007 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package net.sf.dozer.util.mapping.util;
17
18 import net.sf.dozer.util.mapping.DozerTestBase;
19 import net.sf.dozer.util.mapping.fieldmap.ClassMap;
20 import net.sf.dozer.util.mapping.fieldmap.DozerClass;
21 import net.sf.dozer.util.mapping.vo.TestObject;
22 import net.sf.dozer.util.mapping.vo.TestObjectPrime;
23
24 /**
25  * @author tierney.matt
26  */

27 public class DestBeanCreatorTest extends DozerTestBase {
28   private final DestBeanCreator destBeanCreator = new DestBeanCreator(MappingUtils.storedFactories);
29   
30   public void testCreatDestBeanNoFactory() throws Exception JavaDoc {
31     ClassMap classMap = new ClassMap();
32     DozerClass destClass = new DozerClass();
33     destClass.setName(TestObject.class.getName());
34     classMap.setDestClass(destClass);
35
36     TestObject bean = (TestObject) destBeanCreator.create(null, classMap, null);
37
38     assertNotNull(bean);
39     assertNull(bean.getCreatedByFactoryName());
40   }
41
42   public void testCreatBeanFromFactory() throws Exception JavaDoc {
43     DozerClass destClass = new DozerClass();
44     String JavaDoc factoryName = "net.sf.dozer.util.mapping.factories.SampleCustomBeanFactory";
45     destClass.setName(TestObject.class.getName());
46     destClass.setBeanFactory(factoryName);
47
48     DozerClass srcClass = new DozerClass();
49     srcClass.setName(TestObjectPrime.class.getName());
50     srcClass.setBeanFactory(factoryName);
51
52     ClassMap classMap = new ClassMap();
53     classMap.setDestClass(destClass);
54     classMap.setSourceClass(srcClass);
55
56     TestObject bean = (TestObject) destBeanCreator.create(new TestObjectPrime(), classMap, null);
57
58     assertNotNull(bean);
59     assertEquals(factoryName, bean.getCreatedByFactoryName());
60   }
61     
62 }
63
Popular Tags