Search in sources :

Example 1 with GoPluginIdentifier

use of com.thoughtworks.go.plugin.api.GoPluginIdentifier in project gocd by gocd.

the class DefaultPluginManagerTest method shouldNotFindPluginIsOfGivenExtensionWhenReferenceNotFoundAndExtensionDoNotMatch.

@Test
public void shouldNotFindPluginIsOfGivenExtensionWhenReferenceNotFoundAndExtensionDoNotMatch() throws Exception {
    final String pluginThatDoesNotImplement = "plugin-that-does-not-implement";
    GoPluginIdentifier pluginIdentifier = new GoPluginIdentifier("another-extension-type", asList("1.0"));
    final GoPlugin goPlugin = mock(GoPlugin.class);
    final GoPluginDescriptor descriptor = mock(GoPluginDescriptor.class);
    when(goPluginOSGiFramework.hasReferenceFor(GoPlugin.class, pluginThatDoesNotImplement)).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(pluginThatDoesNotImplement), any(ActionWithReturn.class));
    when(goPlugin.pluginIdentifier()).thenReturn(pluginIdentifier);
    DefaultPluginManager pluginManager = new DefaultPluginManager(monitor, registry, goPluginOSGiFramework, jarChangeListener, pluginRequestProcessorRegistry, pluginWriter, pluginValidator, systemEnvironment, pluginsZipUpdater, pluginsListListener);
    assertFalse(pluginManager.isPluginOfType("extension-type", pluginThatDoesNotImplement));
    verify(goPluginOSGiFramework).doOn(eq(GoPlugin.class), eq(pluginThatDoesNotImplement), any(ActionWithReturn.class));
}
Also used : GoPluginIdentifier(com.thoughtworks.go.plugin.api.GoPluginIdentifier) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GoPlugin(com.thoughtworks.go.plugin.api.GoPlugin) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) GoPluginApiResponse(com.thoughtworks.go.plugin.api.response.GoPluginApiResponse) Test(org.junit.Test)

Example 2 with GoPluginIdentifier

use of com.thoughtworks.go.plugin.api.GoPluginIdentifier 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));
}
Also used : GoPluginIdentifier(com.thoughtworks.go.plugin.api.GoPluginIdentifier) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GoPlugin(com.thoughtworks.go.plugin.api.GoPlugin) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) GoPluginApiResponse(com.thoughtworks.go.plugin.api.response.GoPluginApiResponse) Test(org.junit.Test)

Example 3 with GoPluginIdentifier

use of com.thoughtworks.go.plugin.api.GoPluginIdentifier in project gocd by gocd.

the class DefaultPluginManagerTest method shouldResolveToCorrectExtensionVersion.

@Test
public void shouldResolveToCorrectExtensionVersion() throws Exception {
    String pluginId = "plugin-id";
    GoPlugin goPlugin = mock(GoPlugin.class);
    GoPlugginOSGiFrameworkStub osGiFrameworkStub = new GoPlugginOSGiFrameworkStub(goPlugin);
    osGiFrameworkStub.addHasReferenceFor(GoPlugin.class, pluginId, true);
    when(goPlugin.pluginIdentifier()).thenReturn(new GoPluginIdentifier("sample-extension", asList("1.0", "2.0")));
    DefaultPluginManager pluginManager = new DefaultPluginManager(monitor, registry, osGiFrameworkStub, jarChangeListener, pluginRequestProcessorRegistry, pluginWriter, pluginValidator, systemEnvironment, pluginsZipUpdater, pluginsListListener);
    assertThat(pluginManager.resolveExtensionVersion(pluginId, asList("1.0", "2.0", "3.0")), is("2.0"));
}
Also used : GoPluginIdentifier(com.thoughtworks.go.plugin.api.GoPluginIdentifier) GoPlugin(com.thoughtworks.go.plugin.api.GoPlugin) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) Test(org.junit.Test)

Example 4 with GoPluginIdentifier

use of com.thoughtworks.go.plugin.api.GoPluginIdentifier in project gocd by gocd.

the class DefaultPluginManagerTest method shouldThrowExceptionIfMatchingExtensionVersionNotFound.

@Test
public void shouldThrowExceptionIfMatchingExtensionVersionNotFound() throws Exception {
    String pluginId = "plugin-id";
    GoPlugin goPlugin = mock(GoPlugin.class);
    GoPlugginOSGiFrameworkStub osGiFrameworkStub = new GoPlugginOSGiFrameworkStub(goPlugin);
    osGiFrameworkStub.addHasReferenceFor(GoPlugin.class, pluginId, true);
    when(goPlugin.pluginIdentifier()).thenReturn(new GoPluginIdentifier("sample-extension", asList("1.0", "2.0")));
    DefaultPluginManager pluginManager = new DefaultPluginManager(monitor, registry, osGiFrameworkStub, jarChangeListener, pluginRequestProcessorRegistry, pluginWriter, pluginValidator, systemEnvironment, pluginsZipUpdater, pluginsListListener);
    try {
        pluginManager.resolveExtensionVersion(pluginId, asList("3.0", "4.0"));
        fail("should have thrown exception for not finding matching extension version");
    } catch (Exception e) {
        assertThat(e.getMessage(), is("Could not find matching extension version between Plugin[plugin-id] and Go"));
    }
}
Also used : GoPluginIdentifier(com.thoughtworks.go.plugin.api.GoPluginIdentifier) GoPlugin(com.thoughtworks.go.plugin.api.GoPlugin) Matchers.isEmptyString(org.hamcrest.Matchers.isEmptyString) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

GoPlugin (com.thoughtworks.go.plugin.api.GoPlugin)4 GoPluginIdentifier (com.thoughtworks.go.plugin.api.GoPluginIdentifier)4 Matchers.isEmptyString (org.hamcrest.Matchers.isEmptyString)4 Test (org.junit.Test)4 GoPluginApiResponse (com.thoughtworks.go.plugin.api.response.GoPluginApiResponse)2 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1