Package ma.glasnost.orika

Examples of ma.glasnost.orika.MapperFactory


     
      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 BooleanTestCase {
   
    @Test
    public void testPrimtiveToWrapper() {
        MapperFactory factory = MappingUtil.getMapperFactory();
       
        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);
View Full Code Here

       
    }
   
    @Test
    public void testWrapperToPrimtive() {
        MapperFactory factory = MappingUtil.getMapperFactory();
       
        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);
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

    }
   
    @Test
    public void shouldMapBigDecimalToPrimtiveDouble() {
       
        MapperFactory factory = MappingUtil.getMapperFactory();
        factory.getConverterFactory().registerConverter(new CustomConverter<BigDecimal, Double>() {
           
            public Double convert(BigDecimal source, Type<? extends Double> destinationType) {
                return new Double(source.doubleValue());
            }
           
        });
       
        A source = new A();
        source.setValue(BigDecimal.TEN);
        B dest = factory.getMapperFacade().map(source, B.class);
       
        Assert.assertEquals(new Double(10), (Double) dest.getValue());
       
    }
View Full Code Here

    public void testPassThroughConverter() {
       
      PassThroughConverter ptc = new PassThroughConverter(A.class);
     
     
      MapperFactory factory = MappingUtil.getMapperFactory();
       
        factory.getConverterFactory().registerConverter(ptc);
       
       
        A a = new A();
        a.setId(42L);
        B b = new B();
        b.setString("Hello");
        C c = new C();
        c.setA(a);
        c.setB(b);
       
        D d = factory.getMapperFacade().map(c, D.class);
       
        Assert.assertEquals(c.getA(), d.getA());
        Assert.assertEquals(c.getB(), d.getB());
        Assert.assertSame(c.getA(), d.getA());
        Assert.assertNotSame(c.getB(), d.getB());
View Full Code Here

       * Note: we register the generic Holder<?> and pass it a Holder<Wrapper<B>>
       * we expect that it should be passed-through
       *
       */
      PassThroughConverter ptc = new PassThroughConverter(new TypeBuilder<Holder<?>>(){}.build());
      MapperFactory factory = MappingUtil.getMapperFactory();
       
        factory.getConverterFactory().registerConverter(ptc);
       
        B b = new B();
        b.setString("Hello");
        Holder<B> holder = new Holder<B>();
        holder.setHeld(b);
        Wrapper<Holder<B>> wrapper = new Wrapper<Holder<B>>();
        wrapper.setHeld(holder);
       
        Type<Wrapper<Holder<B>>> fromType = new TypeBuilder<Wrapper<Holder<B>>>(){}.build();
        Type<Decorator<Holder<B>>> toType = new TypeBuilder<Decorator<Holder<B>>>(){}.build();
       
       
        Decorator<Holder<B>> d = factory.getMapperFacade().map(wrapper, fromType, toType);
       
        Assert.assertEquals(wrapper.getHeld(), d.getHeld());
        Assert.assertSame(wrapper.getHeld(), d.getHeld());   
    }
View Full Code Here

      /*
       * Note: we register the specific Holder<Wrapper<A>> and pass it a Holder<Wrapper<B>>;
       * we expect that it should not be passed through
       */
      PassThroughConverter ptc = new PassThroughConverter(new TypeBuilder<Holder<Wrapper<A>>>(){}.build());
      MapperFactory factory = MappingUtil.getMapperFactory();
       
        factory.getConverterFactory().registerConverter(ptc);
       
        B b = new B();
        b.setString("Hello");
        Holder<B> holder = new Holder<B>();
        holder.setHeld(b);
        Wrapper<Holder<B>> wrapper = new Wrapper<Holder<B>>();
        wrapper.setHeld(holder);
       
        Type<Wrapper<Holder<B>>> fromType = new TypeBuilder<Wrapper<Holder<B>>>(){}.build();
        Type<Decorator<Holder<B>>> toType = new TypeBuilder<Decorator<Holder<B>>>(){}.build();
       
       
        Decorator<Holder<B>> d = factory.getMapperFacade().map(wrapper, fromType, toType);
       
        Assert.assertEquals(wrapper.getHeld(), d.getHeld());
        Assert.assertNotSame(wrapper.getHeld(), d.getHeld());   
    }
View Full Code Here

    adminAuthotityId = getSession().save(adminAuthority);

    DefaultMapperFactory.Builder builder = new DefaultMapperFactory.Builder();
    builder.unenhanceStrategy(new HibernateUnenhanceStrategy());
    builder.compilerStrategy(new EclipseJdtCompilerStrategy());
    MapperFactory factory = builder.build();
    mapperFacade = factory.getMapperFacade();

    getSession().flush();
    getSession().clear();
  }
View Full Code Here

public class RegexPropertyResolverTestCase {
   
    @Test
    public void testRegexResolution() {
       
        MapperFactory factory =
                new DefaultMapperFactory.Builder()
                    .propertyResolverStrategy(
                            new RegexPropertyResolver(
                                    "readThe([\\w]+)ForThisBean",
                                    "assignThe([\\w]+)",
                                    true, true))
                    .build();
        factory.registerClassMap(
                factory.classMap(A.class, B.class)
                    .field("name.firstName", "givenName")
                    .field("name.lastName", "sirName")
                    .field("address.city", "city")
                    .field("address.street", "street")
                    .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");
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.