Package ma.glasnost.orika

Examples of ma.glasnost.orika.MapperFactory


    }
   
    @Test
    public void childBeforeParent() {

        MapperFactory factory = new DefaultMapperFactory.Builder().build();
        MapperFacade mapper = factory.getMapperFacade();

       
        A1 source2 = new A1();
        source2.field1 = "one";
        source2.field2 = "two";
View Full Code Here


        Assert.assertTrue(book2.getAuthor().getBooks().contains(book2));
    }
   
    @Test
    public void testInverseManyToManyMapping() {
        MapperFactory factory = MappingUtil.getMapperFactory();
       
        ClassMapBuilder<ReaderDTO, Reader> classMapBuilder = factory.classMap(ReaderDTO.class, Reader.class);
        classMapBuilder.fieldMap("books").bInverse("readers").add();
        factory.registerClassMap(classMapBuilder.byDefault().toClassMap());
       
        BoundMapperFacade<Reader, ReaderDTO> mapper = factory.getMapperFacade(Reader.class, ReaderDTO.class);
        BoundMapperFacade<ReaderDTO,Reader> mapper2 = factory.getMapperFacade(ReaderDTO.class, Reader.class);
       
        Set<BookDTO> bookDTOs = new HashSet<BookDTO>();
        BookDTO bookDTO = new BookDTO();
        bookDTO.setTitle("The Prophet");
        bookDTOs.add(bookDTO);
View Full Code Here

 
  @Test
  public void testMapping() {
   
   
    MapperFactory mapperFactory = MappingUtil.getMapperFactory();
        final ClassMapBuilder<R1, R2> builder = mapperFactory.classMap(R1.class, R2.class);

        mapperFactory.registerClassMap(builder.byDefault().toClassMap());
       
        final MapperFacade facade = mapperFactory.getMapperFacade();
       
       
       
        final R1 r1 = new R1();
        final List<L1> list = new ArrayList<L1>();
View Full Code Here

    @Test
    public void cloneableConverter() throws DatatypeConfigurationException {
       
        CloneableConverter cc = new CloneableConverter(SampleCloneable.class);
     
      MapperFactory factory = MappingUtil.getMapperFactory();
        factory.getConverterFactory().registerConverter(cc);
       
        GregorianCalendar cal = new GregorianCalendar();
        cal.add(Calendar.YEAR, 10);
        XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar((GregorianCalendar)cal);
        cal.add(Calendar.MONTH, 3);
       
        ClonableHolder source = new ClonableHolder();
        source.value = new SampleCloneable();
        source.value.id = 5L;
        source.date = new Date(System.currentTimeMillis() + 100000);
        source.timestamp = new Timestamp(System.currentTimeMillis() + 50000);
        source.calendar = cal;
        source.xmlCalendar = xmlCal;
       
        ClonableHolder dest = factory.getMapperFacade().map(source, ClonableHolder.class);
        Assert.assertEquals(source.value, dest.value);
        Assert.assertNotSame(source.value, dest.value);
        Assert.assertEquals(source.date, dest.date);
        Assert.assertNotSame(source.date, dest.date);
        Assert.assertEquals(source.timestamp, dest.timestamp);
View Full Code Here

    @Test
    public void overrideDefaultCloneableToImmutable() throws DatatypeConfigurationException {
       
        PassThroughConverter cc = new PassThroughConverter(Date.class, Calendar.class);
       
        MapperFactory factory = MappingUtil.getMapperFactory();
        factory.getConverterFactory().registerConverter(cc);
       
        GregorianCalendar cal = new GregorianCalendar();
        cal.add(Calendar.YEAR, 10);
        XMLGregorianCalendar xmlCal = DatatypeFactory.newInstance().newXMLGregorianCalendar((GregorianCalendar)cal);
        cal.add(Calendar.MONTH, 3);
       
        ClonableHolder source = new ClonableHolder();
        source.value = new SampleCloneable();
        source.value.id = 5L;
        source.date = new Date(System.currentTimeMillis() + 100000);
        source.calendar = cal;
        source.xmlCalendar = xmlCal;
       
        ClonableHolder dest = factory.getMapperFacade().map(source, ClonableHolder.class);
        Assert.assertEquals(source.value, dest.value);
        Assert.assertNotSame(source.value, dest.value);
        Assert.assertEquals(source.date, dest.date);
        Assert.assertSame(source.date, dest.date);
        Assert.assertEquals(source.calendar, dest.calendar);
View Full Code Here

   
   
    @Test
    public void verify() {
       
        MapperFactory factory = MappingUtil.getMapperFactory();
        MapperFacade mapper = factory.getMapperFacade();
       
        Source s = new Source();
        Map<String, String> map = new HashMap<String, String>();
        map.put("Kofi", "Annan");
        map.put("Julius", "Ceasar");
View Full Code Here

public class ObjectCollectionTestCase {
   
    @Test
    public void testMapOfCollection() {
        DefaultMapperFactory.Builder builder = new DefaultMapperFactory.Builder();
        MapperFactory factory = builder.build();
       
        BoundMapperFacade<DtoHolder, EntityHolder> mapperFacade = factory.getMapperFacade(DtoHolder.class, EntityHolder.class);
       
        List<Dto> dtos = new ArrayList<Dto>();
       
        Dto dto = new Dto();
        dto.setId(1L);
View Full Code Here

public class PrimitiveConversionTestCase {

  @Test
  public void testPrimitiveToWrapper() {
    MapperFactory factory = MappingUtil.getMapperFactory();
    factory.getConverterFactory().registerConverter(new CustomConverterBase<Double, BigDecimal>() {

      public BigDecimal convert(Double source,
              Class<? extends BigDecimal> destinationType) {
        return BigDecimal.valueOf(source);
      }
    });
   
    factory.getConverterFactory().registerConverter(new CustomConverterBase<BigDecimal, Double>() {

      public Double convert(BigDecimal source,
          Class<? extends Double> destinationType) {
        return source.doubleValue();
      }
    });
   
    factory.registerClassMap(ClassMapBuilder.map(A.class, B.class).byDefault().toClassMap());
   
   
    A source = new A();
    source.setValue(BigDecimal.TEN);
   
    B target = factory.getMapperFacade().map(source, B.class);
   
    Assert.assertTrue(target.getValue() == 10.0);
  }
View Full Code Here

 
  @SuppressWarnings("deprecation")
  @Test
  public void testMappingEmptyArray() {
   
    MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();
    mapperFactory.registerClassMap(ClassMapBuilder.map(Object.class,Object.class).byDefault().toClassMap());
    List<Object> listA = new ArrayList<Object>();
    List<Object> listB = mapperFactory.getMapperFacade().mapAsList(listA, Object.class);
   
    Assert.assertNotNull(listB);
    Assert.assertTrue(listB.isEmpty());
  }
View Full Code Here

public class Issue67TestCase {

  @Test
  public void simpleCase() {
    MapperFactory factory = new DefaultMapperFactory.Builder().build();
    factory.registerClassMap(factory.classMap(Bean.class, Bean.class)
        .byDefault().toClassMap());
    MapperFacade mapper = factory.getMapperFacade();
    Bean bean = new Bean();
    bean.setSize(20);
    bean.setName("Kidney");
    mapper.map(bean, Bean.class);
View Full Code Here

TOP

Related Classes of ma.glasnost.orika.MapperFactory

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.