use of com.thoughtworks.go.plugin.api.GoPlugin in project gocd by gocd.
the class DefaultPluginManagerTest method shouldReturnTrueIfPluginIsOfGivenExtensionWhenReferenceFoundAndExtensionMatch.
@Test
public void shouldReturnTrueIfPluginIsOfGivenExtensionWhenReferenceFoundAndExtensionMatch() throws Exception {
String pluginId = "plugin-id";
GoPluginIdentifier pluginIdentifier = new GoPluginIdentifier("sample-extension", asList("1.0"));
final GoPlugin goPlugin = mock(GoPlugin.class);
final GoPluginDescriptor descriptor = mock(GoPluginDescriptor.class);
when(goPluginOSGiFramework.hasReferenceFor(GoPlugin.class, pluginId)).thenReturn(true);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
ActionWithReturn<GoPlugin, GoPluginApiResponse> action = (ActionWithReturn<GoPlugin, GoPluginApiResponse>) invocationOnMock.getArguments()[2];
return action.execute(goPlugin, descriptor);
}
}).when(goPluginOSGiFramework).doOn(eq(GoPlugin.class), eq(pluginId), any(ActionWithReturn.class));
when(goPlugin.pluginIdentifier()).thenReturn(pluginIdentifier);
DefaultPluginManager pluginManager = new DefaultPluginManager(monitor, registry, goPluginOSGiFramework, jarChangeListener, pluginRequestProcessorRegistry, pluginWriter, pluginValidator, systemEnvironment, pluginsZipUpdater, pluginsListListener);
assertTrue(pluginManager.isPluginOfType("sample-extension", pluginId));
}
use of com.thoughtworks.go.plugin.api.GoPlugin in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldLoadAValidGoPluginOSGiBundleAndShouldBeDiscoverableThroughSymbolicNameFilter.
@Test
public void shouldLoadAValidGoPluginOSGiBundleAndShouldBeDiscoverableThroughSymbolicNameFilter() throws Exception {
Bundle bundle = pluginOSGiFramework.loadPlugin(new GoPluginDescriptor(null, null, null, null, descriptorBundleDir, true));
assertThat(bundle.getState(), is(Bundle.ACTIVE));
String filterBySymbolicName = String.format("(%s=%s)", Constants.BUNDLE_SYMBOLICNAME, "testplugin.descriptorValidator");
BundleContext context = bundle.getBundleContext();
ServiceReference<?>[] allServiceReferences = context.getServiceReferences(GoPlugin.class.getCanonicalName(), filterBySymbolicName);
assertThat(allServiceReferences.length, is(1));
try {
GoPlugin service = (GoPlugin) context.getService(allServiceReferences[0]);
service.pluginIdentifier();
} catch (Exception e) {
fail(String.format("pluginIdentifier should have been called. Exception: %s", e.getMessage()));
}
}
use of com.thoughtworks.go.plugin.api.GoPlugin in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldSetCurrentThreadContextClassLoaderToBundleClassLoaderToAvoidDependenciesFromApplicationClassloaderMessingAroundWithThePluginBehavior.
@Test
void shouldSetCurrentThreadContextClassLoaderToBundleClassLoaderToAvoidDependenciesFromApplicationClassloaderMessingAroundWithThePluginBehavior() {
systemEnvironment.setProperty("gocd.plugins.classloader.old", "false");
final GoPluginDescriptor goPluginDescriptor = getPluginDescriptor("plugin.to.test.classloader", pluginToTestClassloadPluginBundleDir);
final GoPluginBundleDescriptor bundleDescriptor = new GoPluginBundleDescriptor(goPluginDescriptor);
registry.loadPlugin(bundleDescriptor);
Bundle bundle = pluginOSGiFramework.loadPlugin(bundleDescriptor);
assertThat(bundle.getState()).isEqualTo(Bundle.ACTIVE);
ActionWithReturn<GoPlugin, Object> action = (plugin, pluginDescriptor) -> {
assertThat(pluginDescriptor).isEqualTo(goPluginDescriptor);
assertThat(Thread.currentThread().getContextClassLoader().getClass().getCanonicalName()).isEqualTo(BundleClassLoader.class.getCanonicalName());
plugin.pluginIdentifier();
return null;
};
pluginOSGiFramework.doOn(GoPlugin.class, "plugin.to.test.classloader", "notification", action);
}
use of com.thoughtworks.go.plugin.api.GoPlugin in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldLoadAValidGoPluginOSGiBundleAndShouldBeDiscoverableThroughPluginIDFilter.
@Test
void shouldLoadAValidGoPluginOSGiBundleAndShouldBeDiscoverableThroughPluginIDFilter() throws Exception {
final GoPluginBundleDescriptor bundleDescriptor = new GoPluginBundleDescriptor(getPluginDescriptor(PLUGIN_ID, descriptorBundleDir));
registry.loadPlugin(bundleDescriptor);
Bundle bundle = pluginOSGiFramework.loadPlugin(bundleDescriptor);
assertThat(bundle.getState()).isEqualTo(Bundle.ACTIVE);
String filterByPluginID = String.format("(%s=%s)", "PLUGIN_ID", "testplugin.descriptorValidator");
BundleContext context = bundle.getBundleContext();
ServiceReference<?>[] allServiceReferences = context.getServiceReferences(GoPlugin.class.getCanonicalName(), filterByPluginID);
assertThat(allServiceReferences.length).isEqualTo(1);
try {
GoPlugin service = (GoPlugin) context.getService(allServiceReferences[0]);
service.pluginIdentifier();
} catch (Exception e) {
fail(String.format("pluginIdentifier should have been called. Exception: %s", e.getMessage()));
}
}
use of com.thoughtworks.go.plugin.api.GoPlugin in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldHandleErrorGeneratedByAValidGoPluginOSGiBundleAtUsageTime.
@Test
void shouldHandleErrorGeneratedByAValidGoPluginOSGiBundleAtUsageTime() {
final GoPluginBundleDescriptor bundleDescriptor = new GoPluginBundleDescriptor(getPluginDescriptor(PLUGIN_ID, errorGeneratingDescriptorBundleDir));
registry.loadPlugin(bundleDescriptor);
Bundle bundle = pluginOSGiFramework.loadPlugin(bundleDescriptor);
assertThat(bundle.getState()).isEqualTo(Bundle.ACTIVE);
assertThat(bundleDescriptor.isInvalid()).isFalse();
ActionWithReturn<GoPlugin, Object> action = (goPlugin, goPluginDescriptor) -> {
goPlugin.initializeGoApplicationAccessor(null);
return null;
};
try {
pluginOSGiFramework.doOn(GoPlugin.class, PLUGIN_ID, "extension-1", action);
fail("Should Throw An Exception");
} catch (Exception ex) {
ex.printStackTrace();
assertThat(ex.getCause() instanceof AbstractMethodError).isTrue();
}
}
Aggregations