Search in sources :

Example 1 with PluginFileDetails

use of com.thoughtworks.go.plugin.infra.monitor.PluginFileDetails in project gocd by gocd.

the class DefaultPluginJarChangeListenerTest method pluginDescriptorAwareCallbackErrorShouldNotBeFatal.

@Test
public void pluginDescriptorAwareCallbackErrorShouldNotBeFatal() throws Exception {
    String pluginJarFileName = "descriptor-aware-test-plugin.jar";
    File pluginJarFile = new File(PLUGIN_DIR, pluginJarFileName);
    copyPluginToTheDirectory(PLUGIN_DIR, pluginJarFileName);
    GoPluginDescriptor descriptor = new GoPluginDescriptor("some.old.id", "1.0", new GoPluginDescriptor.About(null, null, null, null, null, null), null, new File(pluginJarFileName), false);
    when(systemEnvironment.getOperatingSystemFamilyName()).thenReturn("Windows");
    when(goPluginDescriptorBuilder.build(pluginJarFile, true)).thenReturn(descriptor);
    when(osgiFramework.hasReferenceFor(PluginDescriptorAware.class, descriptor.id())).thenReturn(true);
    doThrow(new RuntimeException("Exception in plugin descriptor")).when(osgiFramework).doOnAllForPlugin(eq(PluginDescriptorAware.class), eq(descriptor.id()), Matchers.<Action<PluginDescriptorAware>>anyObject());
    listener = new DefaultPluginJarChangeListener(registry, osgiManifestGenerator, osgiFramework, goPluginDescriptorBuilder, systemEnvironment);
    listener.pluginJarAdded(new PluginFileDetails(pluginJarFile, true));
    verify(registry, times(1)).loadPlugin(descriptor);
    verify(osgiFramework, times(1)).loadPlugin(descriptor);
    verify(osgiFramework, times(1)).hasReferenceFor(PluginDescriptorAware.class, descriptor.id());
    verify(osgiFramework, times(1)).doOnAllWithExceptionHandlingForPlugin(eq(PluginDescriptorAware.class), eq(descriptor.id()), Matchers.<Action<PluginDescriptorAware>>anyObject(), Matchers.<ExceptionHandler<PluginDescriptorAware>>anyObject());
}
Also used : PluginDescriptorAware(com.thoughtworks.go.plugin.api.info.PluginDescriptorAware) PluginFileDetails(com.thoughtworks.go.plugin.infra.monitor.PluginFileDetails) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) File(java.io.File) Test(org.junit.Test)

Example 2 with PluginFileDetails

use of com.thoughtworks.go.plugin.infra.monitor.PluginFileDetails in project gocd by gocd.

the class DefaultPluginJarChangeListenerTest method shouldNotThrowExceptionIfThePluginImplementsDescriptorAwareIsNotAvailable.

@Test
public void shouldNotThrowExceptionIfThePluginImplementsDescriptorAwareIsNotAvailable() throws Exception {
    String pluginJarFileName = "descriptor-aware-test-plugin.jar";
    File pluginJarFile = new File(PLUGIN_DIR, pluginJarFileName);
    copyPluginToTheDirectory(PLUGIN_DIR, pluginJarFileName);
    GoPluginDescriptor descriptor = new GoPluginDescriptor("some.old.id", "1.0", new GoPluginDescriptor.About(null, null, null, null, null, null), null, new File(pluginJarFileName), false);
    when(systemEnvironment.getOperatingSystemFamilyName()).thenReturn("Windows");
    when(goPluginDescriptorBuilder.build(pluginJarFile, true)).thenReturn(descriptor);
    when(osgiFramework.hasReferenceFor(PluginDescriptorAware.class, descriptor.id())).thenReturn(false);
    doThrow(new GoPluginFrameworkException("Failed to find service reference")).when(osgiFramework).doOnAllForPlugin(eq(PluginDescriptorAware.class), eq(descriptor.id()), Matchers.<Action<PluginDescriptorAware>>anyObject());
    listener = new DefaultPluginJarChangeListener(registry, osgiManifestGenerator, osgiFramework, goPluginDescriptorBuilder, systemEnvironment);
    listener.pluginJarAdded(new PluginFileDetails(pluginJarFile, true));
    verify(registry, times(1)).loadPlugin(descriptor);
    verify(osgiFramework, times(1)).loadPlugin(descriptor);
    verify(osgiFramework, times(1)).hasReferenceFor(PluginDescriptorAware.class, descriptor.id());
    verify(osgiFramework, never()).doOnAllForPlugin(eq(PluginDescriptorAware.class), eq(descriptor.id()), Matchers.<Action<PluginDescriptorAware>>anyObject());
}
Also used : PluginDescriptorAware(com.thoughtworks.go.plugin.api.info.PluginDescriptorAware) PluginFileDetails(com.thoughtworks.go.plugin.infra.monitor.PluginFileDetails) GoPluginFrameworkException(com.thoughtworks.go.plugin.infra.GoPluginFrameworkException) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) File(java.io.File) Test(org.junit.Test)

Example 3 with PluginFileDetails

use of com.thoughtworks.go.plugin.infra.monitor.PluginFileDetails in project gocd by gocd.

the class DefaultPluginJarChangeListenerTest method shouldNotProvidePluginDescriptorIfThePluginIsInvalidatedDuringLoad.

@Test
public void shouldNotProvidePluginDescriptorIfThePluginIsInvalidatedDuringLoad() throws Exception {
    String pluginJarFileName = "descriptor-aware-test-plugin.jar";
    File pluginJarFile = new File(PLUGIN_DIR, pluginJarFileName);
    copyPluginToTheDirectory(PLUGIN_DIR, pluginJarFileName);
    final GoPluginDescriptor descriptor = new GoPluginDescriptor("some.old.id", "1.0", new GoPluginDescriptor.About(null, null, null, null, null, null), null, new File(pluginJarFileName), false);
    when(systemEnvironment.getOperatingSystemFamilyName()).thenReturn("Windows");
    when(goPluginDescriptorBuilder.build(pluginJarFile, true)).thenReturn(descriptor);
    when(osgiFramework.hasReferenceFor(PluginDescriptorAware.class, descriptor.id())).thenReturn(true);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            descriptor.markAsInvalid(Arrays.asList("Marking invalid for test"), new Exception("dummy test exception"));
            return null;
        }
    }).when(osgiFramework).loadPlugin(descriptor);
    listener = new DefaultPluginJarChangeListener(registry, osgiManifestGenerator, osgiFramework, goPluginDescriptorBuilder, systemEnvironment);
    listener.pluginJarAdded(new PluginFileDetails(pluginJarFile, true));
    verify(registry, times(1)).loadPlugin(descriptor);
    verify(osgiFramework, times(1)).loadPlugin(descriptor);
    verify(osgiFramework, never()).hasReferenceFor(PluginDescriptorAware.class, descriptor.id());
    verify(osgiFramework, never()).doOnAllForPlugin(eq(PluginDescriptorAware.class), eq(descriptor.id()), Matchers.<Action<PluginDescriptorAware>>anyObject());
}
Also used : URISyntaxException(java.net.URISyntaxException) GoPluginFrameworkException(com.thoughtworks.go.plugin.infra.GoPluginFrameworkException) IOException(java.io.IOException) PluginDescriptorAware(com.thoughtworks.go.plugin.api.info.PluginDescriptorAware) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PluginFileDetails(com.thoughtworks.go.plugin.infra.monitor.PluginFileDetails) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) File(java.io.File) Test(org.junit.Test)

Example 4 with PluginFileDetails

use of com.thoughtworks.go.plugin.infra.monitor.PluginFileDetails in project gocd by gocd.

the class DefaultPluginJarChangeListenerTest method shouldLoadAPluginAndProvidePluginDescriptorIfThePluginImplementsDescriptorAware.

@Test
public void shouldLoadAPluginAndProvidePluginDescriptorIfThePluginImplementsDescriptorAware() throws Exception {
    String pluginJarFileName = "descriptor-aware-test-plugin.jar";
    File pluginJarFile = new File(PLUGIN_DIR, pluginJarFileName);
    copyPluginToTheDirectory(PLUGIN_DIR, pluginJarFileName);
    GoPluginDescriptor descriptor = new GoPluginDescriptor("some.old.id", "1.0", new GoPluginDescriptor.About(null, null, null, null, null, null), null, new File(pluginJarFileName), false);
    when(systemEnvironment.getOperatingSystemFamilyName()).thenReturn("Windows");
    when(goPluginDescriptorBuilder.build(pluginJarFile, true)).thenReturn(descriptor);
    when(osgiFramework.hasReferenceFor(PluginDescriptorAware.class, descriptor.id())).thenReturn(true);
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
            return null;
        }
    }).when(osgiFramework).doOnAllWithExceptionHandlingForPlugin(eq(PluginDescriptorAware.class), eq(descriptor.id()), Matchers.<Action<PluginDescriptorAware>>anyObject(), Matchers.<ExceptionHandler<PluginDescriptorAware>>anyObject());
    listener = new DefaultPluginJarChangeListener(registry, osgiManifestGenerator, osgiFramework, goPluginDescriptorBuilder, systemEnvironment);
    listener.pluginJarAdded(new PluginFileDetails(pluginJarFile, true));
    verify(registry, times(1)).loadPlugin(descriptor);
    verify(osgiFramework, times(1)).loadPlugin(descriptor);
    verify(osgiFramework, times(1)).hasReferenceFor(PluginDescriptorAware.class, descriptor.id());
    verify(osgiFramework, times(1)).doOnAllWithExceptionHandlingForPlugin(eq(PluginDescriptorAware.class), eq(descriptor.id()), Matchers.<Action<PluginDescriptorAware>>anyObject(), Matchers.<ExceptionHandler<PluginDescriptorAware>>anyObject());
}
Also used : PluginDescriptorAware(com.thoughtworks.go.plugin.api.info.PluginDescriptorAware) Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) PluginFileDetails(com.thoughtworks.go.plugin.infra.monitor.PluginFileDetails) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) File(java.io.File) Test(org.junit.Test)

Aggregations

PluginDescriptorAware (com.thoughtworks.go.plugin.api.info.PluginDescriptorAware)4 PluginFileDetails (com.thoughtworks.go.plugin.infra.monitor.PluginFileDetails)4 GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)4 File (java.io.File)4 Test (org.junit.Test)4 GoPluginFrameworkException (com.thoughtworks.go.plugin.infra.GoPluginFrameworkException)2 Mockito.doAnswer (org.mockito.Mockito.doAnswer)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 IOException (java.io.IOException)1 URISyntaxException (java.net.URISyntaxException)1