Package ma.glasnost.orika

Examples of ma.glasnost.orika.MapperFacade


  }

  @Test
  public void testWrapperToPrimitives() {
    MapperFactory factory = MappingUtil.getMapperFactory();
    MapperFacade mapper = factory.getMapperFacade();

    WrapperAttributes source = new WrapperAttributes();

    source.setAge(27);
    source.setShortValue((short)27);
    source.setFloatValue(2.5f);
    source.setDoubleValue(22.4567d);
    source.setLongValue(System.currentTimeMillis());
    source.setName("PPPPP");
    source.setSex('H');
    source.setVip(true);

    PrimitiveAttributes destination = mapper.map(source, PrimitiveAttributes.class);

    Assert.assertEquals(source.getAge(), Integer.valueOf(destination.getAge()));
    Assert.assertEquals(source.getName(), destination.getName());
    Assert.assertEquals(source.getSex(), Character.valueOf(destination.getSex()));
    Assert.assertEquals(source.getVip(), destination.getVip());
View Full Code Here


public class ToStringConverterTestCase {

  @Test(expected=MappingException.class)
  public void testToString_withoutConverter() {
    MapperFactory factory = new DefaultMapperFactory.Builder().useBuiltinConverters(false).build();
    MapperFacade mapper = factory.getMapperFacade();
   
    Date now = new Date();
    String string = mapper.map(now, String.class);
    Assert.assertFalse(now.toString().equals(string));
  }
View Full Code Here

  }
 
  @Test
  public void testWrapperToWrapper() {
    MapperFactory factory = MappingUtil.getMapperFactory();
    MapperFacade mapper = factory.getMapperFacade();

    WrapperAttributes source = new WrapperAttributes();

    source.setAge(27);
    source.setShortValue((short)27);
    source.setFloatValue(2.5f);
    source.setDoubleValue(22.4567d);
    source.setLongValue(System.currentTimeMillis());
    source.setName("PPPPP");
    source.setSex('H');
    source.setVip(true);

    OtherWrapperAttributes destination = mapper.map(source, OtherWrapperAttributes.class);

    Assert.assertEquals(source.getAge(), Integer.valueOf(destination.getAge()));
    Assert.assertEquals(source.getName(), destination.getName());
    Assert.assertEquals(source.getSex(), Character.valueOf(destination.getSex()));
    Assert.assertEquals(source.getVip(), destination.getVip());
View Full Code Here

 
  @Test
  public void testToString() {
    MapperFactory factory = MappingUtil.getMapperFactory();
    factory.getConverterFactory().registerConverter(new ToStringConverter());
    MapperFacade mapper = factory.getMapperFacade();
   
    Date now = new Date();
    String string = mapper.map(now, String.class);
    Assert.assertEquals(now.toString(), string);
  }
View Full Code Here

  public void int_short() {
      ShortHolder source = new ShortHolder();
      source.value = 2;
     
      MapperFactory factory = MappingUtil.getMapperFactory();
        MapperFacade mapper = factory.getMapperFacade();
     
      IntHolder dest = mapper.map(source, IntHolder.class);
      assertEquals(source.value, dest.value);
     
      ShortHolder mapBack = mapper.map(dest, ShortHolder.class);
      assertEquals(source.value, mapBack.value);
  }
View Full Code Here

        }
       
      };
    factory.registerDefaultFieldMapper(fieldDefault);
   
    MapperFacade mapper = factory.getMapperFacade();
    LibraryMyDTO mappedLib;
    {
      File projectRoot = MavenProjectUtil.findProjectRoot();
     
      ClassLoader threadContextLoader = Thread.currentThread().getContextClassLoader();
     
      EclipseJdtCompiler complier = new EclipseJdtCompiler(threadContextLoader);
      ClassLoader childLoader = complier.compile(new File(projectRoot, "src/main/java-hidden"),threadContextLoader);
     
      @SuppressWarnings("unchecked")
      Class<? extends Author> hiddenAuthorType = (Class<? extends Author>)childLoader.loadClass("types.AuthorHidden");
      @SuppressWarnings("unchecked")
      Class<? extends Book> hiddenBookType = (Class<? extends Book>)childLoader.loadClass("types.BookHidden");
      @SuppressWarnings("unchecked")
      Class<? extends Library> hiddenLibraryType = (Class<? extends Library>)childLoader.loadClass("types.LibraryHidden");
     
      try {
        threadContextLoader.loadClass("types.LibraryHidden");
        Assert.fail("types.LibraryHidden should not be accessible to the thread context class loader");
      } catch (ClassNotFoundException e0) {
        try {
          threadContextLoader.loadClass("types.AuthorHidden");
          Assert.fail("types.AuthorHidden should not be accessible to the thread context class loader");
        } catch (ClassNotFoundException e1) {
          try {
            threadContextLoader.loadClass("types.BookHidden");
            Assert.fail("types.BookHidden should not be accessible to the thread context class loader");
          } catch (ClassNotFoundException e2) {
            /* good: all of these types should be inaccessible */
          }
        }
      }
      // Now, these types are hidden from the current class-loader, but they implement types
      // that are accessible to this loader
      // -----------------------------------------------------------------------------
     
      Book book = createBook(hiddenBookType);
      book.setAuthor(createAuthor(hiddenAuthorType));
      Library lib = createLibrary(hiddenLibraryType);
      lib.getBooks().add(book);
     
      mappedLib = mapper.map(lib, LibraryMyDTO.class);
     
      // Just to be sure things mapped as expected
      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

    public void long_short() {
        ShortHolder source = new ShortHolder();
        source.value = 2;
       
        MapperFactory factory = MappingUtil.getMapperFactory();
        MapperFacade mapper = factory.getMapperFacade();
       
        LongHolder dest = mapper.map(source, LongHolder.class);
        assertEquals(source.value, dest.value);
       
        ShortHolder mapBack = mapper.map(dest, ShortHolder.class);
        assertEquals(source.value, mapBack.value);
    }
View Full Code Here

    public void long_int() {
        IntHolder source = new IntHolder();
        source.value = 2;
       
        MapperFactory factory = MappingUtil.getMapperFactory();
        MapperFacade mapper = factory.getMapperFacade();
       
        LongHolder dest = mapper.map(source, LongHolder.class);
        assertEquals(source.value, dest.value);
       
        IntHolder mapBack = mapper.map(dest, IntHolder.class);
        assertEquals(source.value, mapBack.value);
    }
View Full Code Here

 
  @Test
  public void testStringBasedConstructor() {
    MapperFactory factory = MappingUtil.getMapperFactory();
    factory.getConverterFactory().registerConverter(new ConstructorConverter());
    MapperFacade mapper = factory.getMapperFacade();
   
    String urlString = "http://localhost:80/index.html";
    URL url = mapper.map(urlString, URL.class);
    Assert.assertNotNull(url);
    Assert.assertEquals(urlString, url.toExternalForm());
  }
View Full Code Here

 
  @Test
  public void testPrimitiveConstructor() {
    MapperFactory factory = MappingUtil.getMapperFactory();
    factory.getConverterFactory().registerConverter(new ConstructorConverter());
    MapperFacade mapper = factory.getMapperFacade();
   
    Double doubleValue = Double.valueOf("4.99");
    BigDecimal bd = mapper.map(doubleValue, BigDecimal.class);
    Assert.assertNotNull(bd);
    Assert.assertEquals(doubleValue, bd.doubleValue());
  }
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.