Package ma.glasnost.orika

Examples of ma.glasnost.orika.MapperFacade


public class Issue53TestCase {
   
    @Test
    public void subClassSetterOrikaTest() {
        final MapperFactory mapperFactory = MappingUtil.getMapperFactory();/*new DefaultMapperFactory.Builder().build();*/
        final MapperFacade mapper = mapperFactory.getMapperFacade();
       
        final SearchRecord sr = new SearchRecord();
        sr.setScore(88);
       
        final Result result = new Result();
        result.setBaseRecords(new Record());
        result.setResult(sr);
       
        final Result2 mappedResult = mapper.map(result, Result2.class);
       
        assertEquals(88, mappedResult.getResult().getScore());
    }
View Full Code Here


  @Test
  public void testConvertToEnum() {
    MapperFactory factory = MappingUtil.getMapperFactory();
    factory.getConverterFactory().registerConverter(new FromStringConverter());
    MapperFacade mapper = factory.getMapperFacade();
   
    Fruit fruit = mapper.map("TOMATO", Fruit.class);
    Assert.assertEquals(Fruit.TOMATO, fruit);
   
  }
View Full Code Here

  @Test
  public void testConvertToPrimitive() {
   
    MapperFactory factory = MappingUtil.getMapperFactory();
    factory.getConverterFactory().registerConverter(new FromStringConverter());
    MapperFacade mapper = factory.getMapperFacade();
   
    int age = mapper.map("21", int.class);
    Assert.assertEquals(21, age);
  }
View Full Code Here

 
  @Test
  public void testConvertToWrapper() {
    MapperFactory factory = MappingUtil.getMapperFactory();
    factory.getConverterFactory().registerConverter(new FromStringConverter());
    MapperFacade mapper = factory.getMapperFacade();
   
    Integer age = mapper.map("21", Integer.class);
    Assert.assertEquals(Integer.valueOf(21), age);
  }
View Full Code Here

        factory.registerClassMap(ClassMapBuilder.map(A.class, B.class).fieldMap("date").converter("dateConverter1").add().toClassMap());
        factory.registerClassMap(ClassMapBuilder.map(A.class, C.class).fieldMap("date").converter("dateConverter2").add().toClassMap());
       
        factory.build();
       
        MapperFacade mapperFacade = factory.getMapperFacade();
       
        C c = new C();
        c.setDate(new Date());
       
        A a = mapperFacade.map(c, A.class);
       
        Assert.assertEquals(new SimpleDateFormat("dd-MM-yyyy").format(c.getDate()), a.getDate());
       
        B b = new B();
        b.setDate(new Date());
       
        a = mapperFacade.map(b, A.class);
       
        Assert.assertEquals(new SimpleDateFormat("dd/MM/yyyy").format(b.getDate()), a.getDate());
       
    }
View Full Code Here

        factory.registerClassMap(ClassMapBuilder.map(Author.class, AuthorMyDTO.class).byDefault().toClassMap());
       
        factory.registerClassMap(ClassMapBuilder.map(Book.class, BookMyDTO.class).byDefault().toClassMap());
       
        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);
       
        LibraryMyDTO mappedLib = mapper.map(lib, LibraryMyDTO.class);
       
        Assert.assertNotNull(mappedLib);
        Assert.assertTrue(mappedLib.getMyBooks().isEmpty());
    }
View Full Code Here

        factory.registerClassMap(ClassMapBuilder.map(Author.class, AuthorMyDTO.class).byDefault(myHint).toClassMap());
       
        factory.registerClassMap(ClassMapBuilder.map(Book.class, BookMyDTO.class).byDefault(myHint).toClassMap());
       
        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);
       
        LibraryMyDTO mappedLib = mapper.map(lib, LibraryMyDTO.class);
       
        Assert.assertEquals(lib.getTitle(), mappedLib.getMyTitle());
        Assert.assertEquals(book.getTitle(), mappedLib.getMyBooks().get(0).getMyTitle());
        Assert.assertEquals(book.getAuthor().getName(), mappedLib.getMyBooks().get(0).getMyAuthor().getMyName());
    }
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);
       
        LibraryMyDTO mappedLib = mapper.map(lib, LibraryMyDTO.class);
       
        Assert.assertEquals(lib.getTitle(), mappedLib.getMyTitle());
        Assert.assertEquals(book.getTitle(), mappedLib.getMyBooks().get(0).getMyTitle());
        Assert.assertEquals(book.getAuthor().getName(), mappedLib.getMyBooks().get(0).getMyAuthor().getMyName());
       
        // Now, map it back to the original...
       
        Library lib2 = mapper.map(mappedLib, Library.class);
        Assert.assertEquals(lib.getTitle(), lib2.getTitle());
        Assert.assertEquals(book.getTitle(), lib2.getBooks().get(0).getTitle());
        Assert.assertEquals(book.getAuthor().getName(), lib2.getBooks().get(0).getAuthor().getName());
       
    }
View Full Code Here

   
    @Test
    public void parentBeforeChild() {

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

        A source = new A();
        source.field1 = "one";
        source.field2 = "two";
       
        B dest = mapper.map(source, B.class);
       
        Assert.assertEquals(source.field1, dest.field1);
        Assert.assertEquals(source.field2, dest.field2);

        A1 source2 = new A1();
        source2.field1 = "one";
        source2.field2 = "two";
        source2.field3 = "three";
       
        dest = mapper.map(source2, B.class);
       
        Assert.assertEquals(source2.field1, dest.field1);
        Assert.assertEquals(source2.field2, dest.field2);
        Assert.assertEquals(source2.field3, dest.field3);
       
View Full Code Here

   
    @Test
    public void childBeforeParent() {

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

       
        A1 source2 = new A1();
        source2.field1 = "one";
        source2.field2 = "two";
        source2.field3 = "three";
       
      
        B dest = mapper.map(source2, B.class);
       
        Assert.assertEquals(source2.field1, dest.field1);
        Assert.assertEquals(source2.field2, dest.field2);
        Assert.assertEquals(source2.field3, dest.field3);
       
        A source = new A();
        source.field1 = "one";
        source.field2 = "two";
       
        dest = mapper.map(source, B.class);
       
        Assert.assertEquals(source.field1, dest.field1);
        Assert.assertEquals(source.field2, dest.field2);

    }
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.