use of org.hotswap.agent.testData.SimplePlugin 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));
}
use of org.hotswap.agent.testData.SimplePlugin in project HotswapAgent by HotswapProjects.
the class OnClassLoadEventHandlerTest method testInitMethod.
@Test
public void testInitMethod() throws Exception {
final ClassLoader appClassLoader = getClass().getClassLoader();
context.checking(new Expectations() {
{
allowing(pluginManager).getHotswapTransformer();
will(returnValue(hotswapTransformer));
allowing(pluginManager).getPluginRegistry();
will(returnValue(pluginRegistry));
allowing(pluginRegistry).getAppClassLoader(with(any(Object.class)));
will(returnValue(appClassLoader));
oneOf(hotswapTransformer).registerTransformer(with(appClassLoader), with("org.hotswap.example.type"), with(any(ClassFileTransformer.class)));
}
});
OnClassLoadedHandler onClassLoadedHandler = new OnClassLoadedHandler(pluginManager);
SimplePlugin simplePlugin = new SimplePlugin();
Method method = SimplePlugin.class.getMethod("transform");
PluginAnnotation<OnClassLoadEvent> pluginAnnotation = new PluginAnnotation<OnClassLoadEvent>(SimplePlugin.class, simplePlugin, method.getAnnotation(OnClassLoadEvent.class), method);
assertTrue("Init successful", onClassLoadedHandler.initMethod(pluginAnnotation));
}
use of org.hotswap.agent.testData.SimplePlugin in project HotswapAgent by HotswapProjects.
the class AnnotationProcessorTest method testProcess.
@Test
public void testProcess() throws Exception {
context.checking(new Expectations() {
{
allowing(pluginManager).getHotswapTransformer();
will(returnValue(hotswapTransformer));
// two @Init annotations in SimplePlugin
exactly(2).of(initHandler).initMethod(with(any(PluginAnnotation.class)));
will(returnValue(true));
// @OnClassLoadEvent
exactly(1).of(onClassLoadedHandler).initMethod(with(any(PluginAnnotation.class)));
will(returnValue(true));
// Not satisfied, because invoked via reflection
// oneOf(simplePlugin).initPlugin();
// oneOf(simplePlugin).initPlugin(pluginManager);
}
});
final AnnotationProcessor annotationProcessor = new AnnotationProcessor(pluginManager);
annotationProcessor.addAnnotationHandler(Init.class, initHandler);
annotationProcessor.addAnnotationHandler(OnClassLoadEvent.class, onClassLoadedHandler);
annotationProcessor.processAnnotations(new SimplePlugin());
context.assertIsSatisfied();
}
use of org.hotswap.agent.testData.SimplePlugin in project HotswapAgent by HotswapProjects.
the class PluginManagerInvokerTest method testBuildCallPluginMethod.
@Test
public void testBuildCallPluginMethod() throws Exception {
SimplePlugin plugin = new SimplePlugin();
registerPlugin(plugin);
// plugin.init(PluginManager.getInstance());
String s = PluginManagerInvoker.buildCallPluginMethod(plugin.getClass(), "callPluginMethod", "Boolean.TRUE", "java.lang.Boolean");
ClassPool classPool = ClassPool.getDefault();
classPool.appendSystemPath();
CtClass clazz = classPool.makeClass("Test");
clazz.addMethod(CtNewMethod.make("public void test() {" + s + "}", clazz));
Class<?> testClass = clazz.toClass();
Method testMethod = testClass.getDeclaredMethod("test");
testMethod.invoke(testClass.newInstance());
}
Aggregations