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());
}
}
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));
}
}
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();
}
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));
}
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")));
}
Aggregations