Search in sources :

Example 51 with GoPluginDescriptor

use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor in project gocd by gocd.

the class FelixGoPluginOSGiFrameworkTest method shouldMarkThePluginAsInvalidIfAnyExceptionOccursAfterLoad.

@Test
public void shouldMarkThePluginAsInvalidIfAnyExceptionOccursAfterLoad() throws BundleException {
    final Bundle bundle = mock(Bundle.class);
    spy.addPluginChangeListener(new PluginChangeListener() {

        @Override
        public void pluginLoaded(GoPluginDescriptor pluginDescriptor) {
            throw new RuntimeException("some error");
        }

        @Override
        public void pluginUnLoaded(GoPluginDescriptor pluginDescriptor) {
        }
    });
    when(bundleContext.installBundle(any(String.class))).thenReturn(bundle);
    final GoPluginDescriptor goPluginDescriptor = new GoPluginDescriptor(TEST_SYMBOLIC_NAME, "1.0", null, "location", new File(""), false);
    spy.start();
    try {
        spy.loadPlugin(goPluginDescriptor);
        fail("should throw exception");
    } catch (Exception e) {
        assertTrue(goPluginDescriptor.getStatus().isInvalid());
    }
}
Also used : GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) File(java.io.File) Test(org.junit.Test)

Example 52 with GoPluginDescriptor

use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor in project gocd by gocd.

the class PluginAwareDefaultGoApplicationAccessorTest method shouldHandleExceptionThrownByProcessor.

@Test
public void shouldHandleExceptionThrownByProcessor() throws Exception {
    String api = "api-uri";
    GoPluginApiRequestProcessor processor = mock(GoPluginApiRequestProcessor.class);
    GoApiRequest goApiRequest = mock(GoApiRequest.class);
    GoPluginDescriptor descriptor = mock(GoPluginDescriptor.class);
    when(goApiRequest.api()).thenReturn(api);
    Throwable cause = new RuntimeException("error");
    when(processor.process(descriptor, goApiRequest)).thenThrow(cause);
    PluginRequestProcessorRegistry pluginRequestProcessorRegistry = new PluginRequestProcessorRegistry();
    pluginRequestProcessorRegistry.registerProcessorFor(api, processor);
    PluginAwareDefaultGoApplicationAccessor accessor = new PluginAwareDefaultGoApplicationAccessor(descriptor, pluginRequestProcessorRegistry);
    try {
        accessor.submit(goApiRequest);
    } catch (Exception e) {
        assertThat(e.getMessage(), is(String.format("Error while processing request api %s", api)));
        assertThat(e.getCause(), is(cause));
    }
}
Also used : GoApiRequest(com.thoughtworks.go.plugin.api.request.GoApiRequest) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.Test)

Example 53 with GoPluginDescriptor

use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor in project gocd by gocd.

the class PluginsZipTest method shouldCreatePluginsWhenTaskPluginsAreAdded.

@Test
public void shouldCreatePluginsWhenTaskPluginsAreAdded() {
    GoPluginDescriptor plugin = new GoPluginDescriptor("curl-task-plugin", null, null, null, null, false);
    when(pluginManager.isPluginOfType("task", plugin.id())).thenReturn(true);
    pluginsZip.pluginLoaded(plugin);
    verify(pluginsZip, times(1)).create();
}
Also used : GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.Test)

Example 54 with GoPluginDescriptor

use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor in project gocd by gocd.

the class PackageLevelClassWithPublicInnerClass method shouldNotRegisterAsAnOSGiServiceAClassWhichIsNotPublic.

@Test
public void shouldNotRegisterAsAnOSGiServiceAClassWhichIsNotPublic() throws Exception {
    Bundle bundle = installBundleWithClasses(DummyTestPluginWhichIsNotPublic.class);
    assertThat(bundle.getState(), is(Bundle.UNINSTALLED));
    GoPluginDescriptor descriptor = registry.getPlugin(GO_TEST_DUMMY_SYMBOLIC_NAME);
    assertThat(descriptor.isInvalid(), is(true));
    assertThat(descriptor.getStatus().getMessages().contains(NO_EXT_ERR_MSG), is(true));
}
Also used : TinyBundle(org.ops4j.pax.tinybundles.core.TinyBundle) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) Test(org.junit.Test)

Example 55 with GoPluginDescriptor

use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor in project gocd by gocd.

the class PackageRepositoryServiceTest method shouldInvokePluginValidationsBeforeSavingPackageRepository.

@Test
public void shouldInvokePluginValidationsBeforeSavingPackageRepository() throws Exception {
    String pluginId = "yum";
    PackageRepository packageRepository = new PackageRepository();
    RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, new PackageConfigurations());
    packageRepository.setPluginConfiguration(new PluginConfiguration(pluginId, "1.0"));
    packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("url", false, "junk-url"));
    ArgumentCaptor<RepositoryConfiguration> packageConfigurationsArgumentCaptor = ArgumentCaptor.forClass(RepositoryConfiguration.class);
    ValidationResult expectedValidationResult = new ValidationResult();
    expectedValidationResult.addError(new ValidationError("url", "url format incorrect"));
    when(pluginManager.getPluginDescriptorFor(pluginId)).thenReturn(new GoPluginDescriptor("yum", "1.0", null, null, null, true));
    when(packageRepositoryExtension.isRepositoryConfigurationValid(eq(pluginId), packageConfigurationsArgumentCaptor.capture())).thenReturn(expectedValidationResult);
    service = new PackageRepositoryService(pluginManager, packageRepositoryExtension, goConfigService, securityService, entityHashingService, mock(Localizer.class));
    service.performPluginValidationsFor(packageRepository);
    assertThat(packageRepository.getConfiguration().get(0).getConfigurationValue().errors().getAllOn("value"), is(Arrays.asList("url format incorrect")));
}
Also used : PluginConfiguration(com.thoughtworks.go.domain.config.PluginConfiguration) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) GoPluginDescriptor(com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor) ValidationError(com.thoughtworks.go.plugin.api.response.validation.ValidationError) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) PackageConfigurations(com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations) Test(org.junit.Test)

Aggregations

GoPluginDescriptor (com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor)197 Test (org.junit.Test)155 File (java.io.File)17 PluginManager (com.thoughtworks.go.plugin.infra.PluginManager)16 TinyBundle (org.ops4j.pax.tinybundles.core.TinyBundle)15 PluggableInstanceSettings (com.thoughtworks.go.server.ui.plugins.PluggableInstanceSettings)14 Before (org.junit.Before)14 AnalyticsPluginInfo (com.thoughtworks.go.plugin.domain.analytics.AnalyticsPluginInfo)12 AuthorizationPluginInfo (com.thoughtworks.go.plugin.domain.authorization.AuthorizationPluginInfo)12 ElasticAgentPluginInfo (com.thoughtworks.go.plugin.domain.elastic.ElasticAgentPluginInfo)11 PluginView (com.thoughtworks.go.server.ui.plugins.PluginView)11 GoPlugin (com.thoughtworks.go.plugin.api.GoPlugin)10 TaskView (com.thoughtworks.go.plugin.api.task.TaskView)9 PluginInfo (com.thoughtworks.go.server.ui.plugins.PluginInfo)9 InvocationOnMock (org.mockito.invocation.InvocationOnMock)9 Answer (org.mockito.stubbing.Answer)9 TaskPreference (com.thoughtworks.go.plugin.access.pluggabletask.TaskPreference)8 TaskConfig (com.thoughtworks.go.plugin.api.task.TaskConfig)8 ArrayList (java.util.ArrayList)8 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)7