Search in sources :

Example 1 with TestClassLoader

use of io.quarkus.deployment.TestClassLoader in project quarkus by quarkusio.

the class SimpleClassProxyTest method testProxyCreation.

@Test
public void testProxyCreation() throws InstantiationException, IllegalAccessException {
    SimpleInvocationHandler invocationHandler = new SimpleInvocationHandler();
    ProxyConfiguration<SimpleClass> proxyConfiguration = new ProxyConfiguration<SimpleClass>().setSuperClass(SimpleClass.class).setAnchorClass(SimpleClass.class).setProxyNameSuffix("$$Proxy1").setClassLoader(new TestClassLoader(SimpleClass.class.getClassLoader()));
    SimpleClass instance = new ProxyFactory<>(proxyConfiguration).newInstance(invocationHandler);
    assertMethod1(instance);
    assertMethod2(instance);
    assertMethod3(instance);
    assertMethod4(instance);
    assertThat(invocationHandler.invocationCount).isEqualTo(4);
}
Also used : TestClassLoader(io.quarkus.deployment.TestClassLoader) Test(org.junit.jupiter.api.Test)

Example 2 with TestClassLoader

use of io.quarkus.deployment.TestClassLoader in project quarkus by quarkusio.

the class BytecodeRecorderTestCase method runTest.

void runTest(Consumer<BytecodeRecorderImpl> generator, Object... expected) throws Exception {
    TestRecorder.RESULT.clear();
    TestClassLoader tcl = new TestClassLoader(getClass().getClassLoader());
    BytecodeRecorderImpl recorder = new BytecodeRecorderImpl(tcl, false, TEST_CLASS);
    generator.accept(recorder);
    recorder.writeBytecode(new TestClassOutput(tcl));
    StartupTask task = (StartupTask) tcl.loadClass(TEST_CLASS).getDeclaredConstructor().newInstance();
    task.deploy(new StartupContext());
    assertEquals(expected.length, TestRecorder.RESULT.size());
    for (Object i : expected) {
        if (i.getClass().isArray()) {
            if (i instanceof int[]) {
                assertArrayEquals((int[]) i, (int[]) TestRecorder.RESULT.poll());
            } else if (i instanceof double[]) {
                assertArrayEquals((double[]) i, (double[]) TestRecorder.RESULT.poll(), 0);
            } else if (i instanceof Object[]) {
                assertArrayEquals((Object[]) i, (Object[]) TestRecorder.RESULT.poll());
            } else {
                throw new RuntimeException("not implemented");
            }
        } else {
            assertEquals(i, TestRecorder.RESULT.poll());
        }
    }
}
Also used : StartupContext(io.quarkus.runtime.StartupContext) TestClassLoader(io.quarkus.deployment.TestClassLoader) StartupTask(io.quarkus.runtime.StartupTask)

Example 3 with TestClassLoader

use of io.quarkus.deployment.TestClassLoader in project quarkus by quarkusio.

the class BytecodeRecorderTestCase method testRecordingProxyToStringNotNull.

@Test
public void testRecordingProxyToStringNotNull() {
    TestClassLoader tcl = new TestClassLoader(getClass().getClassLoader());
    BytecodeRecorderImpl generator = new BytecodeRecorderImpl(tcl, false, TEST_CLASS);
    TestRecorder recorder = generator.getRecordingProxy(TestRecorder.class);
    assertNotNull(recorder.toString());
    assertTrue(recorder.toString().contains("$$RecordingProxyProxy"));
}
Also used : TestClassLoader(io.quarkus.deployment.TestClassLoader) Test(org.junit.jupiter.api.Test)

Aggregations

TestClassLoader (io.quarkus.deployment.TestClassLoader)3 Test (org.junit.jupiter.api.Test)2 StartupContext (io.quarkus.runtime.StartupContext)1 StartupTask (io.quarkus.runtime.StartupTask)1