Search in sources :

Example 6 with ClassLoaderServiceImpl

use of org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl in project hibernate-orm by hibernate.

the class MapProxyTest method shouldGenerateClassWithAppropriateSetter.

@Test
public void shouldGenerateClassWithAppropriateSetter() throws Exception {
    //given
    Map<String, Object> map = new HashMap<String, Object>();
    Map<String, Class<?>> properties = new HashMap<String, Class<?>>();
    properties.put("age", Integer.class);
    //when
    Class testClass = MapProxyTool.classForName("TestClass2", properties, new ClassLoaderServiceImpl());
    Object testClassInstance = testClass.getConstructor(Map.class).newInstance(map);
    //then
    Setter setter = ReflectionTools.getSetter(testClass, "age", "property", serviceRegistry);
    int ageExpected = 14;
    setter.set(testClassInstance, ageExpected, null);
    Object age = map.get("age");
    Assert.assertEquals(ageExpected, age);
}
Also used : HashMap(java.util.HashMap) Setter(org.hibernate.property.access.spi.Setter) ClassLoaderServiceImpl(org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 7 with ClassLoaderServiceImpl

use of org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl in project hibernate-orm by hibernate.

the class MapProxyTest method shouldGenerateClassWithAppropriateGetter.

@Test
public void shouldGenerateClassWithAppropriateGetter() throws Exception {
    //given
    Map<String, Object> map = new HashMap<String, Object>();
    int ageExpected = 14;
    map.put("age", ageExpected);
    Map<String, Class<?>> properties = new HashMap<String, Class<?>>();
    properties.put("age", Integer.class);
    //when
    Class testClass = MapProxyTool.classForName("TestClass1", properties, new ClassLoaderServiceImpl());
    Object testClassInstance = testClass.getConstructor(Map.class).newInstance(map);
    //then
    Getter getter = ReflectionTools.getGetter(testClass, "age", "property", serviceRegistry);
    int age = (Integer) getter.get(testClassInstance);
    Assert.assertEquals(ageExpected, age);
}
Also used : HashMap(java.util.HashMap) Getter(org.hibernate.property.access.spi.Getter) ClassLoaderServiceImpl(org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

ClassLoaderServiceImpl (org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl)7 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)2 Getter (org.hibernate.property.access.spi.Getter)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1 Entity (javax.persistence.Entity)1 MetadataSources (org.hibernate.boot.MetadataSources)1 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)1 ClassLoaderService (org.hibernate.boot.registry.classloading.spi.ClassLoaderService)1 BootstrapServiceRegistryImpl (org.hibernate.boot.registry.internal.BootstrapServiceRegistryImpl)1 IntegratorServiceImpl (org.hibernate.integrator.internal.IntegratorServiceImpl)1 Setter (org.hibernate.property.access.spi.Setter)1