Package ma.glasnost.orika

Examples of ma.glasnost.orika.MapperFactory


                            return "my" + fromProperty.substring(0, 1).toUpperCase() + fromProperty.substring(1);
                        }
                    }
                   
                };
        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);
View Full Code Here


public class PolicyElementsTestCase {
   
    @Test
    public void test() {
        MapperFactory factory = MappingUtil.getMapperFactory();
        configureMapperFactory(factory);
       
        Policy policy = new Policy();
        Set<PolicyElement> elements = new HashSet<PolicyElement>();
        elements.add(new CustomerElement());
        elements.add(new ProductElement());
        elements.add(new OtherElement());
        elements.add(new OneOtherElement());
       
        policy.setElements(elements);
       
        PolicyDTO dto = factory.getMapperFacade().map(policy, PolicyDTO.class);
       
        Assert.assertEquals(elements.size(), dto.getElements().size());
    }
View Full Code Here

        factory.registerClassMap(ClassMapBuilder.map(OneOtherElement.class, OneOtherElementDTO.class).byDefault().toClassMap());
    }
   
    @Test
    public void testHibernateProxyLike() {
        MapperFactory factory = new DefaultMapperFactory.Builder().unenhanceStrategy(new UnenhanceStrategy() {
            @SuppressWarnings("unchecked")
            public <T> Type<T> unenhanceType(T object, Type<T> type) {
                if (object instanceof PolicyElementProxy)
                    return (Type<T>) ((PolicyElementProxy) object).getTargetClass();
                return type;
            }
           
            @SuppressWarnings("unchecked")
            public <T> T unenhanceObject(T object, Type<T> type) {
                if (object instanceof PolicyElementProxy)
                    return (T) ((PolicyElementProxy) object).getTarget();
                return object;
            }
           
        }).build();
        configureMapperFactory(factory);
       
        Policy policy = new Policy();
        Set<PolicyElement> elements = new HashSet<PolicyElement>();
        CustomerElement target = new CustomerElement();
        target.setName("Adil");
        elements.add(new PolicyElementProxy(target));
        elements.add(new ProductElement());
        elements.add(new OtherElement());
        elements.add(new OneOtherElement());
       
        policy.setElements(elements);
       
        PolicyDTO dto = factory.getMapperFacade().map(policy, PolicyDTO.class);
       
        Assert.assertEquals(elements.size(), dto.getElements().size());
       
        for (PolicyElementDTO element: dto.getElements()) {
            if (element instanceof CustomerElementDTO) {
View Full Code Here

public class ConverterWithNestedPropertyTestCase {
   
    @Test
    public void testConverterWithNestedProperty() {
        MapperFactory mapperFactory = MappingUtil.getMapperFactory();
       
        mapperFactory.getConverterFactory().registerConverter(new TypeConverter<Address, String>() {
            public String convert(Address source, Class<? extends String> destinationClass) {
                return source.getLine1() + " " + source.getLine2();
            }
        });
       
        ClassMapBuilder<Order, OrderDTO> classMapBuilder = ClassMapBuilder.map(Order.class, OrderDTO.class);
        classMapBuilder.fieldMap("customer.address", "shippingAddress").add();
       
        mapperFactory.registerClassMap(classMapBuilder.byDefault().toClassMap());
       
        mapperFactory.build();
       
        Address address = new Address();
        address.setLine1("5 rue Blida");
        address.setLine2("Casablanca");
       
        Customer customer = new Customer();
        customer.setName("Sidi Mohammed El Aatifi");
        customer.setAddress(address);
       
        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 testMappingInterfaceImplementationWithExistingDirectMapping() throws Exception {
       
        MapperFactory factory = MappingUtil.getMapperFactory();
       
        factory.registerClassMap(factory.classMap(Library.class, LibraryMyDTO.class)
                .field("title", "myTitle")
                .field("books", "myBooks")
                .byDefault()
                .toClassMap());
       
        factory.registerClassMap(factory.classMap(Author.class, AuthorMyDTO.class).field("name", "myName").byDefault().toClassMap());
        factory.registerClassMap(factory.classMap(Book.class, BookMyDTO.class)
                .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);
View Full Code Here

import org.junit.Test;

public class Issue28TestCase {
    @Test
    public void testMapping() {
        MapperFactory mapperFactory = MappingUtil.getMapperFactory();
        mapperFactory.getConverterFactory().registerConverter(new OrderIdConverter());
        ClassMapBuilder<Order, OrderData> builder = ClassMapBuilder.map(Order.class, OrderData.class);
        ClassMap<Order, OrderData> classMap = builder.field("id", "number").byDefault().toClassMap();
        mapperFactory.registerClassMap(classMap);
        MapperFacade facade = mapperFactory.getMapperFacade();
        OrderData data = new OrderData(1234l);
        Order order = facade.map(data, Order.class);
        Assert.assertEquals(Long.valueOf(1234l), order.getId());
    }
View Full Code Here

    }
   
    @Test
    public void testMappingInterfaceImplementationWithExistingInheritedMapping() throws Exception {
       
        MapperFactory factory = MappingUtil.getMapperFactory();
        factory.registerClassMap(factory.classMap(Library.class, LibraryMyDTO.class)
                .field("title", "myTitle")
                .field("books", "myBooks")
                .byDefault()
                .toClassMap());
       
        factory.registerClassMap(factory.classMap(Author.class, AuthorMyDTO.class).field("name", "myName").byDefault().toClassMap());
        factory.registerClassMap(factory.classMap(Book.class, BookMyDTO.class)
                .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));
View Full Code Here

    }
   
    @Test
    public void testMappingSubclassImplementationWithoutExistingMapping() throws Exception {
       
        MapperFactory factory = MappingUtil.getMapperFactory();
        DefaultFieldMapper myHint =
        /**
         * This sample hint converts "myProperty" to "property", and vis-versa.
         */
        new DefaultFieldMapper() {

            public String suggestMappedField(String fromProperty, Type<?> fromPropertyType) {
                if (fromProperty.startsWith("my")) {
                    return fromProperty.substring(2, 1).toLowerCase() + fromProperty.substring(3);
                } else {
                    return "my" + fromProperty.substring(0, 1).toUpperCase() + fromProperty.substring(1);
                }
            }
           
        };
        factory.registerDefaultFieldMapper(myHint);
       
        MapperFacade mapper = factory.getMapperFacade();
       
        Book book = createBook(BookChild.class);
        book.setAuthor(createAuthor(AuthorChild.class));
       
        BookMyDTO mappedBook = mapper.map(book, BookMyDTO.class);
View Full Code Here

    }
   
    @Test
    public void testMappingSubclassImplementationWithExistingMapping() throws Exception {
       
        MapperFactory factory = MappingUtil.getMapperFactory();
       
        factory.registerClassMap(factory.classMap(AuthorParent.class, AuthorMyDTO.class)
                .field("name", "myName")
                .byDefault()
                .toClassMap());
        factory.registerClassMap(factory.classMap(BookParent.class, BookMyDTO.class)
                .field("title", "myTitle")
                .field("author", "myAuthor")
                .byDefault()
                .toClassMap());
       
        MapperFacade mapper = factory.getMapperFacade();
       
        Book book = createBook(BookChild.class);
        book.setAuthor(createAuthor(AuthorChild.class));
       
        BookMyDTO mappedBook = mapper.map(book, BookMyDTO.class);
View Full Code Here

     * @throws Exception
     */
    @Test
    public void testSuperTypeForInaccessibleClassWithAccessibleSupertype() throws Exception {
       
        MapperFactory factory = MappingUtil.getMapperFactory();
        DefaultFieldMapper myHint =
        /**
         * This sample hint converts "myProperty" to "property", and vis-versa.
         */
        new DefaultFieldMapper() {
           
            public String suggestMappedField(String fromProperty, Type<?> fromPropertyType) {
                if (fromProperty.startsWith("my")) {
                    return fromProperty.substring(2, 3).toLowerCase() + fromProperty.substring(3);
                } else {
                    return "my" + fromProperty.substring(0, 1).toUpperCase() + fromProperty.substring(1);
                }
            }
           
        };
        factory.registerDefaultFieldMapper(myHint);

       
        BoundMapperFacade<Library, LibraryMyDTO> mapper = factory.getMapperFacade(Library.class, LibraryMyDTO.class);
       
        // -----------------------------------------------------------------------------
        File projectRoot = MavenProjectUtil.findProjectRoot();
       
        ClassLoader threadContextLoader = Thread.currentThread().getContextClassLoader();
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.