Search in sources :

Example 1 with EclipseLinkClassWriter

use of org.eclipse.persistence.dynamic.EclipseLinkClassWriter in project eclipselink by eclipse-ee4j.

the class DynamicClassLoaderTestSuite method createDynamicClass_Twice.

@Test
public void createDynamicClass_Twice() throws Exception {
    DynamicClassLoader dcl = new DynamicClassLoader(DynamicClassLoaderTestSuite.class.getClassLoader());
    assertNull(dcl.getClassWriter(MY_CLASSNAME));
    Class<?> dynamicClass = dcl.createDynamicClass(MY_CLASSNAME);
    assertNotNull(dynamicClass);
    assertEquals(MY_CLASSNAME, dynamicClass.getName());
    EclipseLinkClassWriter writer = dcl.getClassWriter(MY_CLASSNAME);
    assertNotNull(writer);
    Class<?> dynamicClass2 = dcl.createDynamicClass(MY_CLASSNAME);
    assertSame(dynamicClass, dynamicClass2);
    EclipseLinkClassWriter writer2 = dcl.getClassWriter(MY_CLASSNAME);
    assertNotNull(writer);
    assertSame(writer, writer2);
}
Also used : DynamicClassLoader(org.eclipse.persistence.dynamic.DynamicClassLoader) EclipseLinkClassWriter(org.eclipse.persistence.dynamic.EclipseLinkClassWriter) Test(org.junit.Test)

Example 2 with EclipseLinkClassWriter

use of org.eclipse.persistence.dynamic.EclipseLinkClassWriter in project eclipselink by eclipse-ee4j.

the class DynamicClassLoaderTestSuite method duplicateAddClassWithSameParent.

@Test
public void duplicateAddClassWithSameParent() throws Exception {
    DynamicClassLoader dcl = new DynamicClassLoader(Thread.currentThread().getContextClassLoader());
    dcl.addClass(MY_CLASSNAME, DefaultConstructor.class);
    Class<?> dynamicClass = dcl.loadClass(MY_CLASSNAME);
    assertNotNull(dynamicClass);
    assertSame(dynamicClass, dcl.loadClass(MY_CLASSNAME));
    assertSame(DefaultConstructor.class, dynamicClass.getSuperclass());
    EclipseLinkClassWriter firstWriter = dcl.getClassWriter(MY_CLASSNAME);
    DefaultConstructor entity = (DefaultConstructor) dynamicClass.getConstructor().newInstance();
    assertNotNull(entity);
    assertNotNull("DCL does not contain expected writer", dcl.getClassWriter(MY_CLASSNAME));
    dcl.addClass(MY_CLASSNAME, DefaultConstructor.class);
    EclipseLinkClassWriter secondWriter = dcl.getClassWriter(MY_CLASSNAME);
    assertSame(firstWriter, secondWriter);
}
Also used : DynamicClassLoader(org.eclipse.persistence.dynamic.DynamicClassLoader) EclipseLinkClassWriter(org.eclipse.persistence.dynamic.EclipseLinkClassWriter) Test(org.junit.Test)

Aggregations

DynamicClassLoader (org.eclipse.persistence.dynamic.DynamicClassLoader)2 EclipseLinkClassWriter (org.eclipse.persistence.dynamic.EclipseLinkClassWriter)2 Test (org.junit.Test)2