Package ma.glasnost.orika

Examples of ma.glasnost.orika.MapperFacade


    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>();
        final L1 l1 = new L1();
        final List<V1> v1List = new ArrayList<V1>();
        final V1 v1 = new V1();
        v1List.add(v1);
        l1.setList(v1List);
        list.add(l1);
        r1.setList(list);
       
        final R2 r2 = facade.map(r1, R2.class);

    Assert.assertNotNull(r2);
    Assert.assertNotNull(r2.getList());
    for (L2 l2: r2.getList()) {
      Assert.assertNotNull(l2);
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");
        s.setMap(map);
       
        List<String> list = new ArrayList<String>();
        list.add("apple");
        list.add("banana");
        s.setList(list);
       
        String[] array = new String[2];
        array[0] = "one";
        array[1] = "two";
        s.setArray(array);
       
        Destination d = mapper.map(s, Destination.class);
       
        Source mapBack = mapper.map(d, Source.class);
       
        Assert.assertEquals(s, mapBack);
       
    }
View Full Code Here

  @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);

    /* If map pass no need to check */
  }
 
View Full Code Here

 
  @Test
  public void testDateToCalendarConverter() {
    MapperFactory factory = MappingUtil.getMapperFactory();
    factory.getConverterFactory().registerConverter(new DateToCalendarConverter());
    MapperFacade mapper = factory.getMapperFacade();
   
    Date now = new Date();
    Calendar cal = mapper.map(now, Calendar.class);
    Assert.assertEquals(now, cal.getTime());
   
    Date reverse = mapper.map(cal, Date.class);
    Assert.assertEquals(now, reverse);
  }
View Full Code Here

 
  @Test
  public void testDateToXmlGregorianCalendarConverter() {
    MapperFactory factory = MappingUtil.getMapperFactory();
    factory.getConverterFactory().registerConverter(new DateToXmlGregorianCalendarConverter());
    MapperFacade mapper = factory.getMapperFacade();
   
    Date now = new Date();
    XMLGregorianCalendar xml = mapper.map(now, XMLGregorianCalendar.class);
    Assert.assertEquals(now, xml.toGregorianCalendar().getTime());
   
    Date reverse = mapper.map(xml, Date.class);
    Assert.assertEquals(now, reverse);
  }
View Full Code Here

    }
   
   
    @Test
    public void testMergingWithCustomMapper() {
        MapperFacade mapper = createMapperFacade();
       
        List<Dto> dtos = new ArrayList<Dto>();
       
        Dto dto = new Dto();
        dto.setId(1L);
        dto.setName("A");
        dtos.add(dto);
       
        Dto dto2 = new Dto();
        dto2.setId(2L);
        dto2.setName("B");
        dtos.add(dto2);
       
        dto = new Dto();
        dto.setId(3L);
        dto.setName("C");
        dtos.add(dto);
       
        DtoHolder source = new DtoHolder();
        source.setEntities(dtos);
       
        Type<?> typeOf_DtoHolder = TypeFactory.valueOf(DtoHolder.class);
        UtilityResolver.getDefaultPropertyResolverStrategy().getProperties(typeOf_DtoHolder);
       
        final EntityHolder entities = mapper.map(source, EntityHolder.class);
       
        Assert.assertNotNull(entities);
        Assert.assertEquals(3, entities.getEntities().size());
       
        final EntityHolder originalEntities = entities;
        source.getEntities().remove(dto2);
        dto2.setName("B-Changed");
        source.getEntities().add(dto2);
       
        mapper.map(source, entities);
       
        Assert.assertEquals(entities.getEntities().size(), originalEntities.getEntities().size());
       
        Iterator<Entity> entitiesIter = entities.getEntities().iterator();
        Iterator<Entity> originalIter = originalEntities.getEntities().iterator();
View Full Code Here

 
  @Test
  public void testCalendarToXmlGregorianCalendarConverter() {
    MapperFactory factory = MappingUtil.getMapperFactory();
    factory.getConverterFactory().registerConverter(new CalendarToXmlGregorianCalendarConverter());
    MapperFacade mapper = factory.getMapperFacade();
   
    Calendar cal = Calendar.getInstance();
    XMLGregorianCalendar xml = mapper.map(cal, XMLGregorianCalendar.class);
    Assert.assertEquals(cal.getTime(), xml.toGregorianCalendar().getTime());
   
    Calendar reverse = mapper.map(xml, Calendar.class);
    Assert.assertEquals(cal, reverse);
  }
View Full Code Here

        return factory.getMapperFacade();
    }
   
    @Test
    public void testMergingWithCustomMapperForChildren() {
        MapperFacade mapper = createMapperFacade();
       
        List<ChildDto> dtos = new ArrayList<ChildDto>();
       
        ChildDto dto = new ChildDto();
        dto.setId(1L);
        dto.setName("A");
        dtos.add(dto);
       
        ChildDto dto2 = new ChildDto();
        dto2.setId(2L);
        dto2.setName("B");
        dtos.add(dto2);
       
        dto = new ChildDto();
        dto.setId(3L);
        dto.setName("C");
        dtos.add(dto);
       
        AnotherDtoHolder source = new AnotherDtoHolder();
        source.setEntities(dtos);
       
        Type<?> typeOf_DtoHolder = TypeFactory.valueOf(DtoHolder.class);
        UtilityResolver.getDefaultPropertyResolverStrategy().getProperties(typeOf_DtoHolder);
       
        final AnotherEntityHolder entities = mapper.map(source, AnotherEntityHolder.class);
       
        Assert.assertNotNull(entities);
        Assert.assertEquals(3, entities.getEntities().size());
       
        final AnotherEntityHolder originalEntities = entities;
        source.getEntities().remove(dto2);
        dto2.setName("B-Changed");
        source.getEntities().add(dto2);
       
        mapper.map(source, entities);
       
        Assert.assertEquals(entities.getEntities().size(), originalEntities.getEntities().size());
       
        Iterator<ChildEntity> entitiesIter = entities.getEntities().iterator();
        Iterator<ChildEntity> originalIter = originalEntities.getEntities().iterator();
View Full Code Here

  @Test
  public void testLongToXmlGregorianCalendarConverter() {
    MapperFactory factory = MappingUtil.getMapperFactory();
    factory.getConverterFactory().registerConverter(new LongToXmlGregorianCalendarConverter());
    MapperFacade mapper = factory.getMapperFacade();
   
    long now = System.currentTimeMillis();
    XMLGregorianCalendar xml = mapper.map(now, XMLGregorianCalendar.class);
   
    Assert.assertEquals(now, xml.toGregorianCalendar().getTimeInMillis());
   
    long reverse = mapper.map(xml, Long.class);
    Assert.assertEquals(now, reverse);
  }
View Full Code Here

 
  @Test
  public void testLongToDateConverter() {
    MapperFactory factory = MappingUtil.getMapperFactory();
    factory.getConverterFactory().registerConverter(new LongToDateConverter());
    MapperFacade mapper = factory.getMapperFacade();
   
    long now = System.currentTimeMillis();
    Date date = mapper.map(now, Date.class);
    Assert.assertEquals(now, date.getTime());
   
    long reverse = mapper.map(date, Long.class);
    Assert.assertEquals(now, reverse);
  }
View Full Code Here

TOP

Related Classes of ma.glasnost.orika.MapperFacade

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.