Package ma.glasnost.orika

Examples of ma.glasnost.orika.MapperFactory


        }
    }
   
    private static MapperFacade createMapperFacade() {
        DefaultMapperFactory.Builder builder = new DefaultMapperFactory.Builder();
        MapperFactory factory = builder.build();
       
        factory.registerMapper(new MergingMapper());
        return factory.getMapperFacade();
    }
View Full Code Here


public class DateAndTimeConvertersTestCase {

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

                }
            }
           
        };
       
        MapperFactory factory = MappingUtil.getMapperFactory();
        factory.registerMappingHint(myHint);
        factory.build();
       
        MapperFacade mapper = factory.getMapperFacade();
       
        Book book = createBook(BookParent.class);
        book.setAuthor(createAuthor(AuthorParent.class));
        Library lib = createLibrary(LibraryParent.class);
        lib.getBooks().add(book);
View Full Code Here

public class CustomMappingTestCase {
   
    @Test
    public void testCustomMapping() {
        MapperFactory factory = MappingUtil.getMapperFactory();
       
        factory.classMap(PersonDTO.class, Person.class)
                .customize(
                        new CustomMapper<PersonDTO, Person>() {
                            @Override
                            public void mapBtoA(Person b, PersonDTO a, MappingContext context) {
                                a.setName(b.getFirstName() + " " + b.getLastName());
                            }
                           
                        })
               .register();
       
        Person person = new Person();
        person.setFirstName("Abdelkrim");
        person.setLastName("EL KHETTABI");
       
        PersonDTO dto = factory.getMapperFacade().map(person, PersonDTO.class);
       
        Assert.assertEquals(dto.getName(), person.getFirstName() + " " + person.getLastName());
    }
View Full Code Here

        assertArrayEquals(new String[] { "5" }, a.getStrings());
    }

    @Test
    public void testIntArrayToListOfInteger() {
        MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

        mapperFactory.classMap(A.class, B.class).field("ints", "integers").byDefault().register();

        MapperFacade mapperFacade = mapperFactory.getMapperFacade();

        A a = new A();
        a.setInts(new int[] { 4 });

        B b = mapperFacade.map(a, B.class);
View Full Code Here

public class MapperTest extends AbstractMapperTest {
    private MapperFacade facade;
   
    @Before
    public void setUp() {
        MapperFactory mapperFactory = createMapperFactory();
        mapperFactory.registerClassMap(mapperFactory.classMap(Order.class, OrderData.class).byDefault().toClassMap());
        mapperFactory.registerClassMap(mapperFactory.classMap(Position.class, PositionData.class).byDefault().toClassMap());
        facade = mapperFactory.getMapperFacade();
    }
View Full Code Here

*/
public class ConverterResolutionTestCase {
   
    @Test
    public void testResolveSingleConverter() {
        MapperFactory factory = MappingUtil.getMapperFactory();
       
        factory.getConverterFactory().registerConverter(new NameToStringConverter());
        //factory.registerClassMap(factory.classMap(A.class, B.class).field("id", "string").toClassMap());
       
        Converter<?,?> converter = factory.getConverterFactory().getConverter(TypeFactory.valueOf(Name.class), TypeFactory.valueOf(String.class));
       
        Assert.assertEquals(NameToStringConverter.class, converter.getClass());
    }
View Full Code Here

   
    @Test
    public void testAutomaticCaseWithHint() throws Throwable {
       
        final SimpleDateFormat df = new SimpleDateFormat(DATE_PATTERN);
        MapperFactory factory = MappingUtil.getMapperFactory();
       
        factory.registerDefaultFieldMapper(new DefaultFieldMapper() {

          public String suggestMappedField(String fromProperty,
          Type<?> fromPropertyType) {
          if ("dateOfBirth".equals(fromProperty)) {
            return "date";
          } else if("date".equals(fromProperty)) {
            return "dateOfBirth";
          }
          return null;
        }
          });

        factory.getConverterFactory().registerConverter(new DateToStringConverter(DATE_PATTERN));
       
       
        Person person = new Person();
        person.setFirstName("Abdelkrim");
        person.setLastName("EL KHETTABI");
        person.setDate(df.parse("01/01/1980"));
        person.setAge(31L);
       
        PersonVO vo = factory.getMapperFacade().map(person, PersonVO.class);
       
        Assert.assertEquals(person.getFirstName(), vo.getFirstName());
        Assert.assertEquals(person.getLastName(), vo.getLastName());
        Assert.assertTrue(person.getAge() == vo.getAge());
        Assert.assertEquals("01/01/1980", vo.getDateOfBirth());
View Full Code Here

        assertEquals(Integer.valueOf(4), b.getIntegers().get(0));
    }

    @Test
    public void testListOfIntegerToIntArray() {
        MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build();

        mapperFactory.classMap(A.class, B.class).field("ints", "integers").byDefault().register();

        MapperFacade mapperFacade = mapperFactory.getMapperFacade();

        B b = new B();
        b.setIntegers(asList(Integer.valueOf(6)));

        A a = mapperFacade.map(b, A.class);
View Full Code Here

        Assert.assertEquals(NameToStringConverter.class, converter.getClass());
    }
   
    @Test
    public void testResolveMultipleConverters() {
        MapperFactory factory = MappingUtil.getMapperFactory();
       
        factory.getConverterFactory().registerConverter(new ExtendedNameToStringConverter());
        factory.getConverterFactory().registerConverter(new NameToStringConverter());
       
        Converter<?,?> converter = factory.getConverterFactory().getConverter(TypeFactory.valueOf(ExtendedName.class), TypeFactory.valueOf(String.class));
       
        Assert.assertEquals(ExtendedNameToStringConverter.class, converter.getClass());
    }
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.