Search in sources :

Example 1 with ArkBootRunner

use of com.alipay.sofa.ark.springboot.runner.ArkBootRunner in project sofa-ark by alipay.

the class ArkBootRunnerTest method test.

@Test
public void test() {
    Assert.assertNotNull(sampleService);
    Assert.assertNotNull(pluginManagerService);
    Assert.assertTrue("SampleService".equals(sampleService.say()));
    ArkBootRunner runner = new ArkBootRunner(ArkBootRunnerTest.class);
    Field field = ReflectionUtils.findField(ArkBootRunner.class, "runner");
    Assert.assertNotNull(field);
    ReflectionUtils.makeAccessible(field);
    BlockJUnit4ClassRunner springRunner = (BlockJUnit4ClassRunner) ReflectionUtils.getField(field, runner);
    Assert.assertTrue(springRunner.getClass().getCanonicalName().equals(SpringRunner.class.getCanonicalName()));
    ClassLoader loader = springRunner.getTestClass().getJavaClass().getClassLoader();
    Assert.assertTrue(loader.getClass().getCanonicalName().equals(TestClassLoader.class.getCanonicalName()));
    Assert.assertEquals(0, TestValueHolder.getTestValue());
    eventAdminService.sendEvent(new ArkEvent() {

        @Override
        public String getTopic() {
            return "test-event-A";
        }
    });
    Assert.assertEquals(10, TestValueHolder.getTestValue());
    eventAdminService.sendEvent(new ArkEvent() {

        @Override
        public String getTopic() {
            return "test-event-B";
        }
    });
    Assert.assertEquals(20, TestValueHolder.getTestValue());
}
Also used : Field(java.lang.reflect.Field) BlockJUnit4ClassRunner(org.junit.runners.BlockJUnit4ClassRunner) ArkBootRunner(com.alipay.sofa.ark.springboot.runner.ArkBootRunner) TestClassLoader(com.alipay.sofa.ark.container.test.TestClassLoader) ArkEvent(com.alipay.sofa.ark.spi.event.ArkEvent) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

TestClassLoader (com.alipay.sofa.ark.container.test.TestClassLoader)1 ArkEvent (com.alipay.sofa.ark.spi.event.ArkEvent)1 ArkBootRunner (com.alipay.sofa.ark.springboot.runner.ArkBootRunner)1 Field (java.lang.reflect.Field)1 Test (org.junit.Test)1 BlockJUnit4ClassRunner (org.junit.runners.BlockJUnit4ClassRunner)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1