Package org.dozer.vo

Examples of org.dozer.vo.TestObject


   */

  @Test(timeout = 35000)
  public void testMapping1() throws Exception {
    // TestObject --> TestObjectPrime
    TestObject src = testDataFactory.getInputGeneralMappingTestObject();
    runGeneric("testMapping1", src, TestObjectPrime.class);
  }
View Full Code Here


  @Test
  public void testCustomConverterHashMapMapping() throws Exception {
    mapper = getMapper(new String[] { "dozerBeanMapping.xml" });
    TestCustomConverterHashMapObject testCustomConverterHashMapObject = newInstance(TestCustomConverterHashMapObject.class);
    TestObject to = newInstance(TestObject.class);
    to.setOne("one");
    testCustomConverterHashMapObject.setTestObject(to);
    TestObjectPrime top = newInstance(TestObjectPrime.class);
    top.setOnePrime("onePrime");
    testCustomConverterHashMapObject.setTestObjectPrime(top);
    TestCustomConverterHashMapPrimeObject dest = mapper.map(testCustomConverterHashMapObject,
View Full Code Here

  @Test
  public void testXmlBeans() throws Exception {
    mapper = getMapper(new String[] { "xmlBeansMapping.xml" });
    // Map from TestObject to XMLBeans
    TestObject to = (TestObject) newInstance(TestObject.class);
    to.setOne("one");
    GetWeatherByZipCodeDocument doc = mapper.map(to, GetWeatherByZipCodeDocument.class);
    assertEquals(to.getOne(), doc.getGetWeatherByZipCode().getZipCode());

    // Map from XMLBeans to TestObject
    GetWeatherByZipCodeDocument res = GetWeatherByZipCodeDocument.Factory.newInstance();
    GetWeatherByZipCode zipCode = res.addNewGetWeatherByZipCode();
    zipCode.setZipCode("one");
    TestObject to2 = mapper.map(res, TestObject.class);
    assertEquals(res.getGetWeatherByZipCode().getZipCode(), to2.getOne());

    Set set = new HashSet();
    AnotherTestObject ato = new AnotherTestObject();
    ato.setDay("day");
    set.add(ato);
    to.setSetToArray(set);

    AnotherTestObject ato2 = new AnotherTestObject();
    ato2.setDay("day");
    to.addAnotherTestObject(ato2);
    GetWeatherByZipCodeResponseDocument responseDoc = mapper.map(to, GetWeatherByZipCodeResponseDocument.class);
    WeatherData[] weatherDataArray = responseDoc.getGetWeatherByZipCodeResponse().getWeatherDataArray();
    WeatherData[] weatherData2Array = responseDoc.getGetWeatherByZipCodeResponse().getWeatherData2Array();
    assertEquals(ato.getDay(), weatherDataArray[0].getDay());
    assertEquals(ato2.getDay(), weatherData2Array[0].getDay());

    // now take the xmlbeans array and map the other direction
    TestObject toResult = mapper.map(responseDoc, TestObject.class);
    assertEquals(weatherDataArray[0].getDay(), ((AnotherTestObject) toResult.getSetToArray().iterator().next()).getDay());
    assertEquals(weatherData2Array[0].getDay(), ((AnotherTestObject) toResult.getSetToArrayWithIterate().iterator().next())
        .getDay());
  }
View Full Code Here

    t3.join();
    t4.join();
  }

  private void mapSomething() {
    TestObject src = testDataFactory.getInputGeneralMappingTestObject();
    AnotherSubClass src2 = testDataFactory.getAnotherSubClass();

    mapper.map(src, TestObjectPrime.class);
    mapper.map(src2, AnotherSubClassPrime.class);
  }
View Full Code Here

  }

  @Test
  public void testFieldAccessible() throws Exception {
    Mapper mapper = getMapper(new String[] { "fieldAttributeMapping.xml" });
    TestObject to = newInstance(TestObject.class);
    to.setFieldAccessible("fieldAccessible");
    to.setFieldAccessiblePrimInt(2);
    InsideTestObject ito = newInstance(InsideTestObject.class);
    ito.setLabel("label");
    to.setFieldAccessibleComplexType(ito);
    String[] stringArray = new String[] { "one", "two" };
    to.setFieldAccessibleArrayToList(stringArray);
    TestObjectPrime top = mapper.map(to, TestObjectPrime.class);
    assertEquals("fieldAccessible", top.fieldAccessible);
    assertEquals("label", top.fieldAccessibleComplexType.getLabelPrime());
    assertEquals(2, top.fieldAccessiblePrimInt);
    assertEquals("one", top.fieldAccessibleArrayToList.get(0));
    assertEquals("two", top.fieldAccessibleArrayToList.get(1));

    // Map Back
    TestObject toDest = mapper.map(top, TestObject.class);
    assertEquals("fieldAccessible", toDest.getFieldAccessible());
    assertEquals("label", toDest.getFieldAccessibleComplexType().getLabel());
    assertEquals(2, toDest.getFieldAccessiblePrimInt());
    assertEquals("one", toDest.getFieldAccessibleArrayToList()[0]);
    assertEquals("two", toDest.getFieldAccessibleArrayToList()[1]);
  }
View Full Code Here

  }

  @Test
  public void testOverloadGetSetMethods() throws Exception {
    Mapper mapper = getMapper(new String[] { "fieldAttributeMapping.xml" });
    TestObject to = newInstance(TestObject.class);
    Date date = new Date();
    to.setOverloadGetField(new Date());
    TestObjectPrime top = mapper.map(to, TestObjectPrime.class);
    assertEquals(date, top.getOverloadSetField());

    // Map Back
    TestObject toDest = (TestObject) mapper.map(top, TestObject.class);
    assertEquals(date, toDest.getOverloadGetField());
  }
View Full Code Here

  }

  @Test
  public void testFieldCreateMethod() throws Exception {
    Mapper mapper = getMapper(new String[] { "fieldAttributeMapping.xml" });
    TestObject to = newInstance(TestObject.class);
    InsideTestObject ito = newInstance(InsideTestObject.class);
    // we did not set any values. this will be set in the 'createMethod'
    to.setCreateMethodType(ito);
    TestObjectPrime top = mapper.map(to, TestObjectPrime.class);
    assertEquals("myField", top.getCreateMethodType().getMyField());

    // Map Back
    TestObject toDest = mapper.map(top, TestObject.class);
    assertEquals("testCreateMethod", toDest.getCreateMethodType().getTestCreateMethod());
  }
View Full Code Here

  }

  @Test
  public void testIntegerToString() throws Exception {
    Mapper mapper = getMapper(new String[] { "fieldAttributeMapping.xml" });
    TestObject to = newInstance(TestObject.class);
    Integer[] array = new Integer[] { new Integer(1), new Integer(2) };
    to.setArrayForLists(array);
    TestObjectPrime top = mapper.map(to, TestObjectPrime.class);
    assertEquals("1", top.getListForArray().get(0));
  }
View Full Code Here

  @Test
  public void testMapNull_ClassLevel() throws Exception {
    Mapper mapper = getMapper(new String[] { "nullFieldMapping.xml" });
    // check that null does not override an existing value when map-null="false"
    TestObject src = newInstance(TestObject.class);
    src.setOne(null);
    TestObjectPrime2 dest = newInstance(TestObjectPrime2.class);
    dest.setOne("555");

    // dest field should remain unchanged
    mapper.map(src, dest);
    assertNotNull("dest should not be null", dest.getOne());
    assertEquals("invalid dest field value", "555", dest.getOne());

    // reverse mapping
    TestObjectPrime2 src2 = newInstance(TestObjectPrime2.class);
    src2.setOne(null);
    TestObject dest2 = newInstance(TestObject.class);
    dest2.setOne("555");

    // dest field should NOT remain unchanged
    mapper.map(src2, dest2);
    assertNull("dest should be null", dest2.getOne());
  }
View Full Code Here

  @Test
  public void testMapEmptyString_ClassLevel() throws Exception {
    Mapper mapper = getMapper(new String[] { "nullFieldMapping.xml" });
    // check that "" does not override an existing value when
    // map-empty-string="false"
    TestObject src = newInstance(TestObject.class);
    src.setOne("");
    TestObjectPrime2 dest = newInstance(TestObjectPrime2.class);
    dest.setOne("555");

    // dest field should remain unchanged
    mapper.map(src, dest);
    assertNotNull("dest should not be null", dest.getOne());
    assertEquals("invalid dest field value", "555", dest.getOne());

    // reverse mapping
    TestObjectPrime2 src2 = newInstance(TestObjectPrime2.class);
    src2.setOne("");
    TestObject dest2 = newInstance(TestObject.class);
    dest2.setOne("555");

    // dest field should NOT remain unchanged
    mapper.map(src2, dest2);
    assertNotNull("dest should not be null", dest2.getOne());
    assertEquals("dest should be an empty string", "", dest2.getOne());

  }
View Full Code Here

TOP

Related Classes of org.dozer.vo.TestObject

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.