Package ma.glasnost.orika

Examples of ma.glasnost.orika.MapperFactory


public class ReuseMappersTestCase {
   
    @Test
    public void testReuse() {
       
        MapperFactory factory = MappingUtil.getMapperFactory();
       
        {
            ClassMapBuilder<Location, LocationDTO> builder = factory.classMap(Location.class, LocationDTO.class);
            builder.field("x", "coordinateX").field("y", "coordinateY");
            factory.registerClassMap(builder.toClassMap());
           
        }
       
        {
            ClassMapBuilder<NamedLocation, NamedLocationDTO> builder = factory.classMap(NamedLocation.class, NamedLocationDTO.class);
            builder.use(Location.class, LocationDTO.class).field("name", "label");
            factory.registerClassMap(builder.toClassMap());
        }
       
        {
            ClassMapBuilder<City, CityDTO> builder = factory.classMap(City.class, CityDTO.class);
            builder.use(NamedLocation.class, NamedLocationDTO.class).byDefault();
            factory.registerClassMap(builder.toClassMap());
        }
       
       
        BoundMapperFacade<City, CityDTO> mapper = factory.getMapperFacade(City.class, CityDTO.class);
       
        City city = new City();
        city.setX(5);
        city.setY(7);
        city.setZipCode("78951123");
View Full Code Here


      books.add(new BookImpl("Book #3", author2));
      books.add(new BookImpl("Book #4", author2));
     
      Library library = new LibraryImpl("Library #1", books);
     
      MapperFactory factory = MappingUtil.getMapperFactory();
      MapperFacade mapper = factory.getMapperFacade();
     
      LibraryDTO mapped = mapper.map(library, LibraryDTO.class);
     
      assertValidMapping(library,mapped);
     
View Full Code Here

public class NestedInheritanceTestCase {
   
    @Test
    public void testNestedInheritance() {
        MapperFactory factory = MappingUtil.getMapperFactory();
       
        factory.registerClassMap(factory.classMap(Person.class, PersonDTO.class).byDefault().toClassMap());
        factory.registerClassMap(factory.classMap(Client.class, ClientDTO.class).byDefault().toClassMap());
        factory.registerClassMap(factory.classMap(Subscription.class, SubscriptionDTO.class).field("client", "person").toClassMap());
       
        Client client = new Client();
        client.setName("Khalil Gebran");
       
        Subscription subscription = new Subscription();
        subscription.setClient(client);
       
        SubscriptionDTO dto = factory.getMapperFacade().map(subscription, SubscriptionDTO.class);
       
        Assert.assertNotNull(dto);
        Assert.assertNotNull(dto.getPerson());
        Assert.assertEquals(client.getName(), dto.getPerson().getName());
    }
View Full Code Here

      books.add(new BookNested("Book #3", author2));
      books.add(new BookNested("Book #4", author2));
     
      LibraryNested library = new LibraryNested("Library #1", books);
     
      MapperFactory factory = MappingUtil.getMapperFactory();
      factory.registerClassMap(
          factory.classMap(AuthorNested.class, AuthorDTO.class)
            .field("name.fullName", "name").byDefault().toClassMap());
   
      MapperFacade mapper = factory.getMapperFacade();
     
      LibraryDTO mapped = mapper.map(library, LibraryDTO.class);
     
      assertValidMapping(library,mapped);
     
View Full Code Here

   
    @Test
    public void testSimpleFieldMap() {
        ClassMap<Address, AddressDTO> classMap = ClassMapBuilder.map(Address.class, AddressDTO.class).field("country", "countryName")
                .field("city", "cityName").toClassMap();
        MapperFactory factory = MappingUtil.getMapperFactory();
        factory.registerClassMap(classMap);
       
        factory.build();
       
        MapperFacade mapper = factory.getMapperFacade();
       
        Address adress = new Address();
        adress.setCountry("Morocco");
        adress.setCity("Marrakesh");
       
View Full Code Here

     
      NestedPrimitiveHolder primitiveHolder = new NestedPrimitiveHolder(numbers, Character.MAX_VALUE, Boolean.TRUE, Byte.MAX_VALUE);
     
      Holder holder = new Holder(primitiveHolder);
     
      MapperFactory factory = MappingUtil.getMapperFactory();
      factory.registerClassMap(
          factory.classMap(NestedPrimitiveHolder.class, PrimitiveWrapperHolder.class)
            .field("numbers.shortValue", "shortValue")
            .field("numbers.intValue", "intValue")
            .field("numbers.longValue", "longValue")
            .field("numbers.floatValue", "floatValue")
            .field("numbers.doubleValue", "doubleValue")
            .byDefault().toClassMap());
     
      WrapperHolder wrapper = factory.getMapperFacade().map(holder, WrapperHolder.class);
     
      assertValidMapping(holder, wrapper);
 
    }
View Full Code Here

*/
public class Issue61TestCase {
    @Test
    public void testAuthorityMap() {
        DefaultMapperFactory.Builder builder = new DefaultMapperFactory.Builder();
        MapperFactory factory = builder.build();
        MapperFacade mapperFacade = factory.getMapperFacade();
       
        MyEntity root = new MyEntity("root");
        MyEntity child = new MyEntity("child");
        root.getChildren().add(child);
        root.getChildren().add(root);
View Full Code Here

      public String spec;
    }
   
    @Test
    public void testConstructorsWithoutDebugInfo() {
      MapperFactory factory = MappingUtil.getMapperFactory();
      factory.registerClassMap(
          factory.classMap(URLDto1.class, URL.class)
            .field("protocolX", "protocol")
            .field("hostX", "host")
            .field("portX", "port")
            .field("fileX", "file"));
      MapperFacade mapper = factory.getMapperFacade();
     
      URLDto1 dto1 = new URLDto1();
      dto1.protocolX = "http";
      dto1.hostX = "somewhere.com";
      dto1.portX = 8080;
View Full Code Here

        Assert.assertEquals(client.getName(), dto.getPerson().getName());
    }
   
    @Test
    public void testNestedPolymorphicInheritance() {
        MapperFactory factory = MappingUtil.getMapperFactory();
       
        factory.registerClassMap(factory.classMap(Person.class, PersonDTO.class).byDefault().toClassMap());
        factory.registerClassMap(factory.classMap(Client.class, ClientDTO.class).byDefault().toClassMap());
        factory.registerClassMap(factory.classMap(Employee.class, EmployeeDTO.class).byDefault().toClassMap());
        factory.registerClassMap(factory.classMap(Subscription.class, SubscriptionDTO.class).field("client", "person").toClassMap());
       
        Client client = new Client();
        client.setName("Khalil Gebran");
       
        Employee employee = new Employee();
        employee.setName("Kuipje Anders");
       
        Subscription clientSubscription = new Subscription();
        clientSubscription.setClient(client);
       
        Subscription employeeSubscription = new Subscription();
        employeeSubscription.setClient(employee);
       
        List<Subscription> subscriptions = Arrays.asList(clientSubscription, employeeSubscription);
       
        List<SubscriptionDTO> dto = factory.getMapperFacade().mapAsList(subscriptions, SubscriptionDTO.class);
       
        Assert.assertNotNull(dto);
        Assert.assertEquals(2, dto.size());
        Assert.assertNotNull(dto.get(0).getPerson());
        Assert.assertEquals(client.getName(), dto.get(0).getPerson().getName());
View Full Code Here

public class NestedExpressionTestCase {
   
    @Test
    public void testNestedProperty() {
       
        MapperFactory factory = MappingUtil.getMapperFactory();
        factory.registerClassMap(ClassMapBuilder.map(Order.class, OrderDTO.class).field("product.state.type.label", "stateLabel")
                .field("product.name", "productName").toClassMap());
       
        StateType type = new StateType();
        type.setLabel("Open");
       
        State state = new State();
        state.setType(type);
       
        Product product = new Product();
        product.setState(state);
        product.setName("Glasnost Platform");
       
        Order order = new Order();
        order.setProduct(product);
       
        OrderDTO dto = factory.getMapperFacade().map(order, OrderDTO.class);
       
        Assert.assertEquals("Open", dto.getStateLabel());
       
        Order object = factory.getMapperFacade().map(dto, Order.class);
       
        Assert.assertEquals("Open", object.getProduct().getState().getType().getLabel());
       
    }
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.