Examples of DozerBeanMapper


Examples of org.dozer.DozerBeanMapper

   * test mapping of a generic field
   */
  @Test
  public void testSimpleGenerics() {

    Mapper mapper = new DozerBeanMapper();

    A a = new A();
    a.setId(15L);

    B b = mapper.map(a, B.class);
    Assert.assertEquals((Integer) a.getId().intValue(), b.getId());

    A a2 = mapper.map(a, A.class);
    Assert.assertEquals(a.getId(), a2.getId());

  }
View Full Code Here

Examples of org.dozer.DozerBeanMapper

  /**
   * 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.DozerBeanMapper

   * 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.DozerBeanMapper

  /**
   * 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.DozerBeanMapper

  private DozerBeanMapper mapper;

  @Before
  public void setUp() {
    mapper = new DozerBeanMapper();
  }
View Full Code Here

Examples of org.dozer.DozerBeanMapper

    mapper.map("", NoNothing.class);
  }

  @Test(expected = IllegalArgumentException.class)
  public void shouldFailOnDuplicateMapping() {
    DozerBeanMapper mapper = new DozerBeanMapper();
    mapper.addMapping(new BeanMappingBuilder() {
      @Override
      protected void configure() {
        mapping(String.class, NoNothing.class);
      }
    });

    mapper.addMapping(new BeanMappingBuilder() {
      @Override
      protected void configure() {
        mapping(String.class, NoNothing.class);
      }
    });
   
    mapper.map("A", NoNothing.class);
  }
View Full Code Here

Examples of org.dozer.DozerBeanMapper

  private DozerBeanMapper beanMapper;

  @Before
  public void setUp() {
    beanMapper = new DozerBeanMapper();
  }
View Full Code Here

Examples of org.dozer.DozerBeanMapper

  @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.DozerBeanMapper

  @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
View Full Code Here

Examples of org.dozer.DozerBeanMapper

  @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
TOP
Copyright © 2015 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.