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);
}
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);
}
Aggregations