Search in sources :

Example 1 with PluginManager

use of org.hotswap.agent.config.PluginManager in project HotswapAgent by HotswapProjects.

the class PluginManagerTest method testInit.

@Test
public void testInit() throws Exception {
    PluginManager pluginManager = PluginManager.getInstance();
    context.checking(new Expectations() {

        {
            allowing(instrumentation).addTransformer(with(any(ClassFileTransformer.class)));
            allowing(annotationScanner).scanPlugins(with(any(ClassLoader.class)), with(any(String.class)));
            will(returnValue(Collections.singletonList(SimplePlugin.class.getName())));
            allowing(annotationProcessor).processAnnotations(with(any(Class.class)), with(any(Class.class)));
            will(returnValue(true));
        }
    });
    PluginRegistry pluginRegistry = pluginManager.getPluginRegistry();
    pluginRegistry.setAnnotationScanner(annotationScanner);
    pluginRegistry.setAnnotationProcessor(annotationProcessor);
    pluginManager.init(instrumentation);
    assertEquals("Plugin registered", pluginRegistry.getRegisteredPlugins().size(), 1);
    assertTrue("Plugin correct class", pluginRegistry.getRegisteredPlugins().keySet().iterator().next().equals(SimplePlugin.class));
}
Also used : PluginManager(org.hotswap.agent.config.PluginManager) Expectations(org.jmock.Expectations) ClassFileTransformer(java.lang.instrument.ClassFileTransformer) PluginRegistry(org.hotswap.agent.config.PluginRegistry) SimplePlugin(org.hotswap.agent.testData.SimplePlugin) Test(org.junit.Test)

Example 2 with PluginManager

use of org.hotswap.agent.config.PluginManager in project HotswapAgent by HotswapProjects.

the class InitHandlerTest method testInitMethod.

@Test
public void testInitMethod() throws Exception {
    PluginManager pluginManager = PluginManager.getInstance();
    SimplePlugin simplePlugin = new SimplePlugin();
    // register the plugin
    pluginManager.getPluginRegistry().getRegisteredPlugins().put(SimplePlugin.class, Collections.<ClassLoader, Object>singletonMap(getClass().getClassLoader(), simplePlugin));
    InitHandler initHandler = new InitHandler(pluginManager);
    Method method = SimplePlugin.class.getMethod("initPlugin", PluginManager.class);
    PluginAnnotation<Init> pluginAnnotation = new PluginAnnotation<Init>(SimplePlugin.class, simplePlugin, method.getAnnotation(Init.class), method);
    assertTrue("Init successful", initHandler.initMethod(pluginAnnotation));
}
Also used : PluginManager(org.hotswap.agent.config.PluginManager) Init(org.hotswap.agent.annotation.Init) SimplePlugin(org.hotswap.agent.testData.SimplePlugin) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

PluginManager (org.hotswap.agent.config.PluginManager)2 SimplePlugin (org.hotswap.agent.testData.SimplePlugin)2 Test (org.junit.Test)2 ClassFileTransformer (java.lang.instrument.ClassFileTransformer)1 Method (java.lang.reflect.Method)1 Init (org.hotswap.agent.annotation.Init)1 PluginRegistry (org.hotswap.agent.config.PluginRegistry)1 Expectations (org.jmock.Expectations)1