1 16 package net.sf.dozer.util.mapping; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 import net.sf.dozer.util.mapping.vo.map.NestedObj; 22 import net.sf.dozer.util.mapping.vo.map.NestedObjPrime; 23 import net.sf.dozer.util.mapping.vo.map.SimpleObj; 24 import net.sf.dozer.util.mapping.vo.map.SimpleObjPrime; 25 26 27 30 public class MapTypeTest extends DozerTestBase { 31 32 public void testMapType_MapToVo() throws Exception { 33 mapper = getNewMapper(new String [] {"mapMapping2.xml"}); 35 36 NestedObj nestedObj = new NestedObj(); 37 nestedObj.setField1("nestedfield1value"); 38 Map src = new HashMap (); 39 src.put("field1", "mapnestedfield1value"); 40 src.put("nested", nestedObj); 41 42 SimpleObjPrime result = (SimpleObjPrime) mapper.map(src, SimpleObjPrime.class, "caseA"); 43 assertEquals(src.get("field1"), result.getField1()); 44 assertEquals(nestedObj.getField1(), result.getNested().getField1()); 45 46 } 51 52 public void testMapType_MapToVo_NoCustomMappings() throws Exception { 53 mapper = getNewMapper(new String [] {"mapMapping2.xml"}); 55 Map src = new HashMap (); 56 src.put("field1", "field1value"); 57 src.put("field2", "field2value"); 58 59 SimpleObjPrime result = (SimpleObjPrime) mapper.map(src, SimpleObjPrime.class, "caseB"); 60 assertNull(result.getField1()); 61 assertEquals(src.get("field2"), result.getField2()); 62 } 63 64 public void testMapType_MapToVoUsingMapId() { 65 mapper = super.getNewMapper(new String []{"mapMapping.xml"}); 67 Map src = new HashMap (); 68 src.put("field1", "field1value"); 69 70 NestedObjPrime dest = (NestedObjPrime) mapper.map(src, NestedObjPrime.class, "caseB"); 71 assertEquals(src.get("field1"), dest.getField1()); 72 } 73 74 public void testMapType_NestedMapToVoUsingMapId() { 75 mapper = super.getNewMapper(new String []{"mapMapping.xml"}); 77 78 Map nested2 = new HashMap (); 79 nested2.put("field1", "field1MapValue"); 80 81 SimpleObj src = new SimpleObj(); 82 src.setNested2(nested2); 83 84 SimpleObjPrime result = (SimpleObjPrime) mapper.map(src, SimpleObjPrime.class, "caseA2"); 85 86 assertNull(result.getNested2().getField1()); 87 } 88 } | Popular Tags |