Package ma.glasnost.orika

Examples of ma.glasnost.orika.MapperFacade


   *
   */
  @Test
  public void testResolveTypes2() {
   
    MapperFacade mapper = new MyMapper();
   
    Source src = new Source();
    src.name = "source 1";
    src.description = "source 1 description";
   
    SourceChild srcChild = new SourceChild();
    srcChild.name = "source 1";
    srcChild.description = "source 1 description";
   
   
    /*
     * Mapping Source to Dest2 causes a mapping to be created
     */
    Dest2 dest2 = mapper.map(src, Dest2.class);
    /*
     * SourceChild is able to use this mapping, so the resolved
     * type in this case for SourceChild is 'Source', which
     * gets cached in resolvedTypes
     */
    Dest2 dest2B = mapper.map(srcChild, Dest2.class);
   
   
    Assert.assertNotNull(dest2);
    Assert.assertNotNull(dest2B);
   
    /*
     * But now, since the resolvedType for 'SourceChild' has
     * been cached as 'Source', it cannot find the converter
     * which has been specifically created for 'SourceChild'
     */
    Dest1 dest1 = mapper.map(srcChild, Dest1.class);
    Assert.assertNotNull(dest1);
  }
View Full Code Here


    mapperFactory.registerClassMap(
            mapperFactory.classMap(Order.class, OrderData.class)
        .field("entityID", "orderId").byDefault().toClassMap());
 
    mapperFactory.getConverterFactory().registerConverter(new OrderIDConverter());
    MapperFacade facade = mapperFactory.getMapperFacade();
   
    OrderData data = new OrderData(1234l);
    Order order = facade.map(data, Order.class);
    Assert.assertEquals(new OrderID(1234l), order.getEntityID());
  }
View Full Code Here

   
    @Test
    public void testMapOfEnum() {
        DefaultMapperFactory.Builder builder = new DefaultMapperFactory.Builder();
        MapperFactory factory = builder.build();
        MapperFacade mapperFacade = factory.getMapperFacade();
        Entity entity = new Entity();
        entity.setState(State.B);
        final Dto dto = mapperFacade.map(entity, Dto.class);
        Assert.assertEquals(dto.getState(), entity.getState());
    }
View Full Code Here

   
    @Test(expected=CustomException.class)
    public void throwExceptions() {
       
        MapperFactory mapperFactory = MappingUtil.getMapperFactory();
        MapperFacade mapper = mapperFactory.getMapperFacade();
       
        DomainObjectDto dto = new DomainObjectDto();
        dto.setDate(new Date());
        dto.setValue(-2L);
       
        mapper.map(dto, DomainObject.class);
    }
View Full Code Here

    }
   
    @Test
    public void testMappingInterfaceImplementationNoExistingMapping() throws Exception {
       
        MapperFacade mapper = MappingUtil.getMapperFactory().getMapperFacade();
       
        Book book = createBook(BookChild.class);
        book.setAuthor(createAuthor(AuthorChild.class));
       
        BookMyDTO mappedBook = mapper.map(book, BookMyDTO.class);
       
        Assert.assertNotNull(mappedBook);
        Assert.assertNull(mappedBook.getMyTitle());
        Assert.assertNull(mappedBook.getMyAuthor());
    }
View Full Code Here

                .field("author", "myAuthor")
                .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.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

                .field("author", "myAuthor")
                .byDefault()
                .toClassMap());
        factory.build();
       
        MapperFacade mapper = factory.getMapperFacade();
       
        // BookChild, AuthorChild, LibraryChild don't directly
        // implement Book, Author and Library
        Book book = createBook(BookChild.class);
        book.setAuthor(createAuthor(AuthorChild.class));
        Library lib = createLibrary(LibraryChild.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

           
        };
        factory.registerMappingHint(myHint);
        factory.build();
       
        MapperFacade mapper = factory.getMapperFacade();
       
        Book book = createBook(BookChild.class);
        book.setAuthor(createAuthor(AuthorChild.class));
       
        BookMyDTO mappedBook = mapper.map(book, BookMyDTO.class);
       
        Assert.assertEquals(book.getTitle(), mappedBook.getMyTitle());
        Assert.assertEquals(book.getAuthor().getName(), mappedBook.getMyAuthor().getMyName());
    }
View Full Code Here

                .field("author", "myAuthor")
                .byDefault()
                .toClassMap());
        factory.build();
       
        MapperFacade mapper = factory.getMapperFacade();
       
        Book book = createBook(BookChild.class);
        book.setAuthor(createAuthor(AuthorChild.class));
       
        BookMyDTO mappedBook = mapper.map(book, BookMyDTO.class);
       
        Assert.assertEquals(book.getTitle(), mappedBook.getMyTitle());
        Assert.assertEquals(book.getAuthor().getName(), mappedBook.getMyAuthor().getMyName());
    }
View Full Code Here

   
    @Test
    public void testBigDecimalToDoubleConverter() {
        MapperFactory factory = MappingUtil.getMapperFactory();
        factory.getConverterFactory().registerConverter(new BigDecimalToDoubleConverter());
        MapperFacade mapper = factory.getMapperFacade();
       
        BigDecimal bd = new BigDecimal("5423.51478");
        Double db = mapper.map(bd, Double.class);
        Assert.assertEquals(bd.doubleValue(), db.doubleValue(), 0.00001d);
       
        BigDecimal reverse = mapper.map(db, BigDecimal.class);
        Assert.assertEquals(bd.doubleValue(), reverse.doubleValue(), 0.00001d);
    }
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.