use of com.thoughtworks.go.plugin.api.GoPlugin in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldLoadAValidPluginWithMultipleExtensions_ImplementingDifferentExtensions.
@Test
void shouldLoadAValidPluginWithMultipleExtensions_ImplementingDifferentExtensions() throws Exception {
final GoPluginBundleDescriptor bundleDescriptor = new GoPluginBundleDescriptor(getPluginDescriptor("valid-plugin-with-multiple-extensions", validMultipleExtensionPluginBundleDir));
registry.loadPlugin(bundleDescriptor);
Bundle bundle = pluginOSGiFramework.loadPlugin(bundleDescriptor);
assertThat(bundle.getState()).isEqualTo(Bundle.ACTIVE);
BundleContext context = bundle.getBundleContext();
String taskExtensionFilter = String.format("(&(%s=%s)(%s=%s))", "PLUGIN_ID", "valid-plugin-with-multiple-extensions", Constants.BUNDLE_CATEGORY, "task");
String analyticsExtensionFilter = String.format("(&(%s=%s)(%s=%s))", "PLUGIN_ID", "valid-plugin-with-multiple-extensions", Constants.BUNDLE_CATEGORY, "analytics");
ServiceReference<?>[] taskExtensionServiceReferences = context.getServiceReferences(GoPlugin.class.getCanonicalName(), taskExtensionFilter);
assertThat(taskExtensionServiceReferences.length).isEqualTo(1);
assertThat(((GoPlugin) context.getService(taskExtensionServiceReferences[0])).pluginIdentifier().getExtension()).isEqualTo("task");
ServiceReference<?>[] analyticsExtensionServiceReferences = context.getServiceReferences(GoPlugin.class.getCanonicalName(), analyticsExtensionFilter);
assertThat(analyticsExtensionServiceReferences.length).isEqualTo(1);
assertThat(((GoPlugin) context.getService(analyticsExtensionServiceReferences[0])).pluginIdentifier().getExtension()).isEqualTo("analytics");
}
use of com.thoughtworks.go.plugin.api.GoPlugin in project gocd by gocd.
the class DefaultPluginManagerTest method shouldSayPluginIsOfGivenExtensionTypeWhenReferenceIsFound.
@Test
void shouldSayPluginIsOfGivenExtensionTypeWhenReferenceIsFound() {
String pluginId = "plugin-id";
String extensionType = "sample-extension";
GoPluginIdentifier pluginIdentifier = new GoPluginIdentifier(extensionType, asList("1.0"));
final GoPlugin goPlugin = mock(GoPlugin.class);
final GoPluginDescriptor descriptor = mock(GoPluginDescriptor.class);
when(goPluginOSGiFramework.hasReferenceFor(GoPlugin.class, pluginId, extensionType)).thenReturn(true);
lenient().doAnswer(invocationOnMock -> {
ActionWithReturn<GoPlugin, GoPluginApiResponse> action = (ActionWithReturn<GoPlugin, GoPluginApiResponse>) invocationOnMock.getArguments()[2];
return action.execute(goPlugin, descriptor);
}).when(goPluginOSGiFramework).doOn(eq(GoPlugin.class), eq(pluginId), eq(extensionType), any(ActionWithReturn.class));
lenient().when(goPlugin.pluginIdentifier()).thenReturn(pluginIdentifier);
DefaultPluginManager pluginManager = new DefaultPluginManager(monitor, registry, goPluginOSGiFramework, jarChangeListener, pluginRequestProcessorRegistry, systemEnvironment, pluginLoader);
assertThat(pluginManager.isPluginOfType(extensionType, pluginId)).isTrue();
}
use of com.thoughtworks.go.plugin.api.GoPlugin in project gocd by gocd.
the class DefaultPluginManagerTest method shouldThrowExceptionIfMatchingExtensionVersionNotFound.
@Test
void shouldThrowExceptionIfMatchingExtensionVersionNotFound() {
String pluginId = "plugin-id";
String extensionType = "sample-extension";
GoPlugin goPlugin = mock(GoPlugin.class);
GoPlugginOSGiFrameworkStub osGiFrameworkStub = new GoPlugginOSGiFrameworkStub(goPlugin);
osGiFrameworkStub.addHasReferenceFor(GoPlugin.class, pluginId, extensionType, true);
when(goPlugin.pluginIdentifier()).thenReturn(new GoPluginIdentifier(extensionType, asList("1.0", "2.0")));
DefaultPluginManager pluginManager = new DefaultPluginManager(monitor, registry, osGiFrameworkStub, jarChangeListener, pluginRequestProcessorRegistry, systemEnvironment, pluginLoader);
try {
pluginManager.resolveExtensionVersion(pluginId, extensionType, asList("3.0", "4.0"));
fail("should have thrown exception for not finding matching extension version");
} catch (Exception e) {
assertThat(e.getMessage()).isEqualTo("Could not find matching extension version between Plugin[plugin-id] and Go");
}
}
use of com.thoughtworks.go.plugin.api.GoPlugin in project gocd by gocd.
the class DefaultPluginManagerTest method shouldResolveToCorrectExtensionVersion.
@Test
void shouldResolveToCorrectExtensionVersion() {
String pluginId = "plugin-id";
String extensionType = "sample-extension";
GoPlugin goPlugin = mock(GoPlugin.class);
GoPlugginOSGiFrameworkStub osGiFrameworkStub = new GoPlugginOSGiFrameworkStub(goPlugin);
osGiFrameworkStub.addHasReferenceFor(GoPlugin.class, pluginId, extensionType, true);
when(goPlugin.pluginIdentifier()).thenReturn(new GoPluginIdentifier(extensionType, asList("1.0", "2.0")));
DefaultPluginManager pluginManager = new DefaultPluginManager(monitor, registry, osGiFrameworkStub, jarChangeListener, pluginRequestProcessorRegistry, systemEnvironment, pluginLoader);
assertThat(pluginManager.resolveExtensionVersion(pluginId, extensionType, asList("1.0", "2.0", "3.0"))).isEqualTo("2.0");
}
use of com.thoughtworks.go.plugin.api.GoPlugin in project gocd by gocd.
the class DefaultPluginManagerTest method shouldSubmitPluginApiRequestToGivenPlugin.
@Test
void shouldSubmitPluginApiRequestToGivenPlugin() throws Exception {
String extensionType = "sample-extension";
GoPluginApiRequest request = mock(GoPluginApiRequest.class);
GoPluginApiResponse expectedResponse = mock(GoPluginApiResponse.class);
final GoPlugin goPlugin = mock(GoPlugin.class);
final GoPluginDescriptor descriptor = mock(GoPluginDescriptor.class);
when(goPlugin.handle(request)).thenReturn(expectedResponse);
ArgumentCaptor<PluginAwareDefaultGoApplicationAccessor> captor = ArgumentCaptor.forClass(PluginAwareDefaultGoApplicationAccessor.class);
doNothing().when(goPlugin).initializeGoApplicationAccessor(captor.capture());
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocationOnMock) {
ActionWithReturn<GoPlugin, GoPluginApiResponse> action = (ActionWithReturn<GoPlugin, GoPluginApiResponse>) invocationOnMock.getArguments()[3];
return action.execute(goPlugin, descriptor);
}
}).when(goPluginOSGiFramework).doOn(eq(GoPlugin.class), eq("plugin-id"), eq(extensionType), any(ActionWithReturn.class));
DefaultPluginManager pluginManager = new DefaultPluginManager(monitor, registry, goPluginOSGiFramework, jarChangeListener, pluginRequestProcessorRegistry, systemEnvironment, pluginLoader);
GoPluginApiResponse actualResponse = pluginManager.submitTo("plugin-id", extensionType, request);
assertThat(actualResponse).isEqualTo(expectedResponse);
PluginAwareDefaultGoApplicationAccessor accessor = captor.getValue();
assertThat(accessor.pluginDescriptor()).isEqualTo(descriptor);
}
Aggregations