Package ma.glasnost.orika

Examples of ma.glasnost.orika.MapperFacade


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


  public void testBooleanMapping() {
    SpecialCase sc = new SpecialCase();
    sc.setChecked(true);
    sc.totalCost = new BigDecimal("42.50");
   
    MapperFacade mapper = MappingUtil.getMapperFactory().getMapperFacade();
    SpecialCaseDto dto = mapper.map(sc, SpecialCaseDto.class);
   
    Assert.assertEquals(sc.isChecked(), Boolean.valueOf(dto.isChecked()));
    //Assert.assertEquals(sc.totalCost.doubleValue(), dto.getTotalCost(), 0.01d);
  }
View Full Code Here

       
        factory.registerClassMap(ClassMapBuilder.map(Primitive.class, Wrapper.class).field("primitive", "wrapper").toClassMap());
       
        factory.build();
       
        MapperFacade mapper = factory.getMapperFacade();
       
        Wrapper source = new Wrapper();
        source.setWrapper(true);
       
        Primitive destination = mapper.map(source, Primitive.class);
        Assert.assertEquals(Boolean.TRUE, destination.isPrimitive());
       
    }
View Full Code Here

       
        factory.registerClassMap(ClassMapBuilder.map(Wrapper.class, Primitive.class).field("wrapper", "primitive").toClassMap());
       
        factory.build();
       
        MapperFacade mapper = factory.getMapperFacade();
       
        Primitive source = new Primitive();
        source.setPrimitive(true);
       
        Wrapper destination = mapper.map(source, Wrapper.class);
        Assert.assertEquals(true, destination.getWrapper());
       
    }
View Full Code Here

                    .field("address.postalCode", "postalCode")
                    .field("address.country", "country")
                );
       
       
        MapperFacade mapper = factory.getMapperFacade();
       
        A a = new A();
        Name name = new Name();
        name.setFirstName("Albert");
        name.setLastName("Einstein");
        a.assignTheName(name);
        Address address = new Address();
        address.city = "Somewhere";
        address.country = "Germany";
        address.postalCode = "A1234FG";
        address.street = "1234 Easy St.";
        a.setAddress(address);
       
       
        B b = mapper.map(a, B.class);
       
        Assert.assertNotNull(b);
       
        A mapBack = mapper.map(b, A.class);
       
        Assert.assertEquals(a, mapBack);
       
    }
View Full Code Here

                    }
                   
                };
        MapperFactory factory = MappingUtil.getMapperFactory();
        factory.registerDefaultFieldMapper(myHint);
        MapperFacade mapper = factory.getMapperFacade();
       
        Book book = createBook(BookChild.class);
        book.setAuthor(createAuthor(AuthorChild.class));
       
        BookMyDTO mappedBook = mapper.map(book, BookMyDTO.class);
        Book mapBack = mapper.map(mappedBook, Book.class);
       
        Assert.assertNotNull(mappedBook);
        Assert.assertNotNull(mapBack);
       
        Assert.assertEquals(book.getAuthor().getName(), mappedBook.getMyAuthor().getMyName());
View Full Code Here

       
        Order order = new Order();
        order.setNumber("CPC6128");
        order.setCustomer(customer);
       
        MapperFacade mapperFacade = mapperFactory.getMapperFacade();
        OrderDTO orderDto = mapperFacade.map(order, OrderDTO.class);
       
        Assert.assertEquals(address.line1 + " " + address.line2, orderDto.getShippingAddress());
    }
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("title", "myTitle")
                .field("author", "myAuthor")
                .byDefault()
                .toClassMap());
       
        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("title", "myTitle")
                .field("author", "myAuthor")
                .byDefault()
                .toClassMap());
       
        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

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.