Examples of Mapper


Examples of org.dozer.Mapper

  /**
   * test mapping of a generic field with inheritance
   */
  @Test
  public void testSimpleGenericsInheritance() {
    Mapper mapper = new DozerBeanMapper();

    B b = new B();
    b.setId(15);

    AA aa = mapper.map(b, AA.class);
    Assert.assertEquals((Long) b.getId().longValue(), aa.getId());

    AA aa2 = mapper.map(b, AA.class);
    Assert.assertEquals((Long) b.getId().longValue(), aa2.getId());

  }
View Full Code Here

Examples of org.dozer.Mapper

   * Test mapping for deepn generic inheritance
   * @throws Exception
   */
  @Test
  public void testDeepGenericInheritanceTest() throws Exception {
    Mapper mapper = new DozerBeanMapper();

    B b = new B();
    b.setId(12345);
    C c1 = mapper.map(b, C.class);
    Assert.assertEquals(c1.getId().longValue(), 12345L);
  }
View Full Code Here

Examples of org.dozer.Mapper

  /**
   * test mapping of an object with three type parameters
   */
  @Test
  public void testGenericsWithSeveralTypes() {
    Mapper mapper = new DozerBeanMapper();

    GenericTestType testType = new GenericTestType();
    testType.setA(15L);
    testType.setB("test");
    testType.setC(7);

    GenericTestType testType2 = mapper.map(testType, GenericTestType.class);
    Assert.assertEquals(testType.getA(), testType2.getA());
    Assert.assertEquals(testType.getB(), testType2.getB());
    Assert.assertEquals(testType.getC(), testType2.getC());
  }
View Full Code Here

Examples of org.dozer.Mapper

    assertEquals(src, mappedSrc);
  }

  @Test
  public void testMapToMap() throws Exception {
    Mapper mapper = getMapper(new String[] { "mapInterfaceMapping.xml", "dozerBeanMapping.xml" });
    TestObject to = newInstance(TestObject.class);
    to.setOne("one");
    TestObject to2 = newInstance(TestObject.class);
    to2.setTwo(new Integer(2));
    Map<String, TestObject> map = newInstance(HashMap.class);
    map.put("to", to);
    map.put("to2", to2);

    Map<String, TestObject> map2 = newInstance(HashMap.class);
    map2.put("to", to);
    map2.put("to2", to2);

    MapToMap mtm = new MapToMap(map, map2);

    MapToMapPrime mtmp = mapper.map(mtm, MapToMapPrime.class);
    assertEquals("one", ((TestObject) mtmp.getStandardMap().get("to")).getOne());
    assertEquals(2, ((TestObject) mtmp.getStandardMap().get("to2")).getTwo().intValue());
    // verify that we transformed from object to object prime
    assertEquals("one", ((TestObjectPrime) mtmp.getStandardMapWithHint().get("to")).getOnePrime());
    assertEquals(2, ((TestObjectPrime) mtmp.getStandardMapWithHint().get("to2")).getTwoPrime().intValue());
View Full Code Here

Examples of org.dozer.Mapper

    assertEquals(2, ((TestObjectPrime) mtmp.getStandardMapWithHint().get("to2")).getTwoPrime().intValue());
  }

  @Test
  public void testMapToMapExistingDestination() throws Exception {
    Mapper mapper = getMapper(new String[] { "mapInterfaceMapping.xml", "dozerBeanMapping.xml" });
    TestObject to = newInstance(TestObject.class);
    to.setOne("one");
    TestObject to2 = newInstance(TestObject.class);
    to2.setTwo(new Integer(2));
    Map<String, TestObject> map = newInstance(HashMap.class);
    map.put("to", to);
    map.put("to2", to2);
    MapToMap mtm = newInstance(MapToMap.class);
    mtm.setStandardMap(map);

    // create an existing map and set a value so we can test if it exists after
    // mapping
    MapToMapPrime mtmp = newInstance(MapToMapPrime.class);
    Map<String, Serializable> map2 = newInstance(Hashtable.class);
    map2.put("toDest", to);
    mtmp.setStandardMap(map2);

    mapper.map(mtm, mtmp);
    assertEquals("one", ((TestObject) mtmp.getStandardMap().get("to")).getOne());
    assertEquals(2, ((TestObject) mtmp.getStandardMap().get("to2")).getTwo().intValue());
    assertEquals("one", ((TestObject) mtmp.getStandardMap().get("toDest")).getOne());
  }
View Full Code Here

Examples of org.dozer.Mapper

  @Test
  public void testNoMappingFilesSpecified() throws Exception {
    // Mapper can be used without specifying any mapping files. Fields that have the same name will be mapped
    // automatically.
    Mapper mapper = new DozerBeanMapper();

    assertCommon(mapper);
  }
View Full Code Here

Examples of org.dozer.Mapper

  }

  @Test
  public void testInjectMapperUsingSpring() throws Exception {
    // Try to get mapper from spring. Mapping files are injected via Spring config.
    Mapper mapper = (Mapper) ApplicationBeanFactory.getBean(Mapper.class);
    DozerBeanMapper mapperImpl = (DozerBeanMapper) mapper;

    Mapper cleanMapper = (Mapper) ApplicationBeanFactory.getBean("cleanMapper");

    assertNotNull("mapper should not be null", mapper);
    assertNotNull("mapping file names should not be null", mapperImpl.getMappingFiles());
    assertTrue("mapping file names should not be empty", mapperImpl.getMappingFiles().size() > 0);

    // Do some mapping so that the mapping files are actually loaded
    assertCommon(mapper);

    // make sure that the customconverter was injected
    Car car = new Car();
    Van van = cleanMapper.map(car, Van.class);
    assertEquals("injectedName", van.getName());
    // map back
    Car carDest = cleanMapper.map(van, Car.class);
    assertEquals("injectedName", carDest.getName());

    // test that we get customconverter even though it wasn't defined in the mapping file
    Moped moped = new Moped();
    Bus bus = cleanMapper.map(moped, Bus.class);
    assertEquals("injectedName", bus.getName());

    // map back
    Moped mopedDest = cleanMapper.map(bus, Moped.class);
    assertEquals("injectedName", mopedDest.getName());
  }
View Full Code Here

Examples of org.dozer.Mapper

  @Test
  public void testSpringNoMappingFilesSpecified() throws Exception {
    // Mapper can be used without specifying any mapping files. Fields that have the same name will be mapped
    // automatically.
    Mapper mapper = (Mapper) ApplicationBeanFactory.getBean("NoExplicitMappingsMapperIF");

    assertCommon(mapper);
  }
View Full Code Here

Examples of org.dozer.Mapper

    assertCommon(mapper);
  }

  @Test(expected=IllegalArgumentException.class)
  public void testDetectDuplicateMapping() throws Exception {
    Mapper myMapper = null;
    List<String> mappingFiles = new ArrayList<String>();
    mappingFiles.add("duplicateMapping.xml");
    myMapper = new DozerBeanMapper(mappingFiles);

    myMapper.map(new org.dozer.vo.SuperSuperSuperClass(), org.dozer.vo.SuperSuperSuperClassPrime.class);
    fail("should have thrown exception");
  }
View Full Code Here

Examples of org.dozer.Mapper

    // -----------------------------------------------------------
    // Test that java beans get created with explicitly specified
    // custom bean factory
    // -----------------------------------------------------------

    Mapper mapper = getNewMapper(new String[]{"customfactorymapping.xml"});

    TestObjectPrime prime = mapper.map(testDataFactory.getInputGeneralMappingTestObject(), TestObjectPrime.class);
    TestObject source = mapper.map(prime, TestObject.class);

    // The following asserts will verify that the ClassMap beanFactory attr gets applied to both classes
    assertNotNull("created by factory name should not be null", prime.getCreatedByFactoryName());
    assertNotNull("created by factory name should not be null", source.getCreatedByFactoryName());
    assertEquals(SampleCustomBeanFactory.class.getName(), prime.getCreatedByFactoryName());
    assertEquals(SampleCustomBeanFactory.class.getName(), source.getCreatedByFactoryName());

    // The following asserts will verify that default configuration is being applied
    assertNotNull("created by factory name should not be null", source.getThree().getCreatedByFactoryName());
    assertEquals(SampleDefaultBeanFactory.class.getName(), source.getThree().getCreatedByFactoryName());

    // The following asserts will verify that dest or src class level attr's override classMap and default config attr's
    assertNotNull("created by factory name should not be null", prime.getThreePrime().getCreatedByFactoryName());
    assertEquals(SampleCustomBeanFactory2.class.getName(), prime.getThreePrime().getCreatedByFactoryName());

    // test returning an Interface
    Van van = new Van();
    van.setName("testName");
    MetalThingyIF car = mapper.map(van, MetalThingyIF.class);
    assertEquals("testName", car.getName());
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.