Package org.dozer

Examples of org.dozer.Mapper


    fail("We should have thrown TestException");

  }

  public void testAllowedExceptionsDoNotThrowException() throws Exception {
    Mapper mapper = getMapper(new String[] { "allowedExceptionsMapping.xml" });
    TestObject to2 = newInstance(TestObject.class);
    to2.setThrowNonAllowedExceptionOnMap("do not throw me");
    try {
      mapper.map(to2, TestObjectPrime.class);
    } catch (RuntimeException e) {
      fail("This should not have been thrown");
    }
  }
View Full Code Here


    }
  }

  @Test(expected=TestException.class)
  public void testAllowedExceptions_Implicit() throws Exception {
    Mapper mapper = getMapper(new String[] { "implicitAllowedExceptionsMapping.xml" });
    ThrowException to = newInstance(ThrowException.class);
    to.setThrowAllowedException("throw me");
    mapper.map(to, ThrowExceptionPrime.class);
    fail("We should have thrown TestException");


  }
View Full Code Here

    // For some reason the resulting SomeVO contains a Set with 4 objects. 2 SomeOtherDTO's and 2 SomeOtherVO's. I
    // believe it
    // should only contain 2 SomeOtherVO's. It has something to do with specifying the field name starting with cap in
    // the mapping file. If
    // you change the field mapping to start with lower case it seems to map correctly.
    Mapper mapper = getMapper(new String[] { "setMappingWithUpperCaseFieldName.xml" });

    SomeDTO someDto = newInstance(SomeDTO.class);
    someDto.setField1(new Integer("1"));

    SomeOtherDTO someOtherDto = newInstance(SomeOtherDTO.class);
    someOtherDto.setOtherField2(someDto);
    someOtherDto.setOtherField3("value1");

    SomeDTO someDto2 = newInstance(SomeDTO.class);
    someDto2.setField1(new Integer("2"));

    SomeOtherDTO someOtherDto2 = newInstance(SomeOtherDTO.class);
    someOtherDto2.setOtherField2(someDto2);
    someOtherDto2.setOtherField3("value2");

    SomeDTO src = newInstance(SomeDTO.class);
    src.setField2(new SomeOtherDTO[] { someOtherDto2, someOtherDto });

    SomeVO dest = mapper.map(src, SomeVO.class);

    assertEquals("incorrect resulting set size", src.getField2().length, dest.getField2().size());
    // TODO: add more asserts
  }
View Full Code Here

  }

  private static void performSomeMappings() {
    List<String> mappingFiles = new ArrayList<String>();
    mappingFiles.add("dozerBeanMapping.xml");
    Mapper mapper = new DozerBeanMapper(mappingFiles);

    try {
      mapper.map(new String("yo"), new String("y"));
    } catch (Throwable t) {
    }

    try {
      mapper.map(null, null);
    } catch (Throwable t) {
    }
    try {
      mapper.map(new String(), null);
    } catch (Throwable t) {
    }

    TestDataFactory testDataFactory = new TestDataFactory(NoProxyDataObjectInstantiator.INSTANCE);
    TestObject to = testDataFactory.getInputGeneralMappingTestObject();
    TestObjectPrime prime = mapper.map(to, TestObjectPrime.class);
    TestObject source = mapper.map(prime, TestObject.class);
    mapper.map(source, TestObjectPrime.class);

    int numIters = 4000;
    for (int i = 0; i < numIters; i++) {
      SimpleObj src = testDataFactory.getSimpleObj();
      mapper.map(src, SimpleObjPrime2.class);
    }

    mappingFiles = new ArrayList<String>();
    mappingFiles.add("arrayToStringCustomConverter.xml");
    mapper = new DozerBeanMapper(mappingFiles);

    for (int i = 0; i < 6000; i++) {
      SimpleObj simple = new SimpleObj();
      simple.setField1(String.valueOf(System.currentTimeMillis()));

      ArrayCustConverterObj src = new ArrayCustConverterObj();
      src.setField1(new SimpleObj[] { simple });

      mapper.map(src, ArrayCustConverterObjPrime.class);
    }
  }
View Full Code Here

    SomeVo request = newInstance(SomeVo.class);
    request.setUserName("yo");
    request.setAge("2");
    request.setColor("blue");

    Mapper mapper = getMapper(new String[] { "kmmapping.xml" });

    Super afterMapping = mapper.map(request, Super.class);

    assertNotNull("login name should not be null", afterMapping.getLoginName());
    assertNotNull("age should not be null", afterMapping.getAge());
    assertEquals("should map SuperClass.name to SubClassPrime userName.", request.getUserName(), afterMapping.getLoginName());
    assertEquals(request.getAge(), afterMapping.getAge());
View Full Code Here

    nestedProperty.setTestProperty("boo");
    property.setTestProperty("testProperty");
    property.setMapMe(nestedProperty);
    request.setProperty(property);

    Mapper mapper = getMapper(new String[] { "kmmapping.xml" });

    SomeVo afterMapping = mapper.map(request, SomeVo.class);

    assertNotNull("un should not be null", afterMapping.getUserName());
    assertNotNull("color should not be null", afterMapping.getColor());
    assertNotNull("age should not be null", afterMapping.getAge());
    assertEquals("should map SuperClass.name to SubClassPrime userName.", request.getLoginName(), afterMapping.getUserName());
View Full Code Here

    }

    @Test
    public void verifyCustomerMapping() throws Exception {

        Mapper mapper = DozerTestArtifactsFactory.createMapper();
        Customer service = createServiceCustomer();
        org.apache.camel.converter.dozer.model.Customer model = mapper.map(service, org.apache.camel.converter.dozer.model.Customer.class);
        Customer roundTrip = mapper.map(model, Customer.class);
        assertEquals(service, roundTrip);
    }
View Full Code Here

        assertMockEndpointsSatisfied();
    }

    @Test
    public void verifyCustomerMapping() throws Exception {
        Mapper mapper = DozerTestArtifactsFactory.createMapper();
        Customer service = createServiceCustomer();
        org.apache.camel.converter.dozer.model.Customer model = mapper.map(service, org.apache.camel.converter.dozer.model.Customer.class);
        Customer roundTrip = mapper.map(model, Customer.class);
        assertEquals(service, roundTrip);
    }
View Full Code Here

    SomeVo request = newInstance(SomeVo.class);
    request.setUserName("yo");
    request.setAge("2");
    request.setColor("blue");

    Mapper mapper = getMapper(new String[] { "kmmapping.xml" });

    Super afterMapping = mapper.map(request, Super.class);

    assertNotNull("login name should not be null", afterMapping.getLoginName());
    assertNotNull("age should not be null", afterMapping.getAge());
    assertEquals("should map SuperClass.name to SubClassPrime userName.", request.getUserName(), afterMapping.getLoginName());
    assertEquals(request.getAge(), afterMapping.getAge());
View Full Code Here

    nestedProperty.setTestProperty("boo");
    property.setTestProperty("testProperty");
    property.setMapMe(nestedProperty);
    request.setProperty(property);

    Mapper mapper = getMapper(new String[] { "kmmapping.xml" });

    SomeVo afterMapping = mapper.map(request, SomeVo.class);

    assertNotNull("un should not be null", afterMapping.getUserName());
    assertNotNull("color should not be null", afterMapping.getColor());
    assertNotNull("age should not be null", afterMapping.getAge());
    assertEquals("should map SuperClass.name to SubClassPrime userName.", request.getLoginName(), afterMapping.getUserName());
View Full Code Here

TOP

Related Classes of org.dozer.Mapper

Copyright © 2018 www.massapicom. 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.