use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldLoadAValidGoPluginOSGiBundle.
@Test
void shouldLoadAValidGoPluginOSGiBundle() throws Exception {
final GoPluginBundleDescriptor bundleDescriptor = new GoPluginBundleDescriptor(getPluginDescriptor(PLUGIN_ID, descriptorBundleDir));
registry.loadPlugin(bundleDescriptor);
Bundle bundle = pluginOSGiFramework.loadPlugin(bundleDescriptor);
assertThat(bundle.getState()).isEqualTo(Bundle.ACTIVE);
BundleContext context = bundle.getBundleContext();
ServiceReference<?>[] allServiceReferences = context.getServiceReferences(GoPlugin.class.getCanonicalName(), null);
assertThat(allServiceReferences.length).isEqualTo(1);
try {
GoPlugin service = (GoPlugin) context.getService(allServiceReferences[0]);
service.pluginIdentifier();
assertThat(getIntField(service, "loadCalled")).as("@Load should have been called").isEqualTo(1);
} catch (Exception e) {
fail(String.format("pluginIdentifier should have been called. Exception: %s", e.getMessage()));
}
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.
the class FelixGoPluginOSGiFrameworkIntegrationTest method shouldUnloadALoadedPlugin.
@Test
void shouldUnloadALoadedPlugin() throws Exception {
GoPluginBundleDescriptor bundleDescriptor = new GoPluginBundleDescriptor(getPluginDescriptor(PLUGIN_ID, descriptorBundleDir));
registry.loadPlugin(bundleDescriptor);
Bundle bundle = pluginOSGiFramework.loadPlugin(bundleDescriptor);
BundleContext context = bundle.getBundleContext();
ServiceReference<?>[] allServiceReferences = context.getServiceReferences(GoPlugin.class.getCanonicalName(), null);
assertThat(allServiceReferences.length).isEqualTo(1);
GoPlugin service = (GoPlugin) context.getService(allServiceReferences[0]);
assertThat(getIntField(service, "loadCalled")).as("@Load should have been called").isEqualTo(1);
bundleDescriptor.setBundle(bundle);
pluginOSGiFramework.unloadPlugin(bundleDescriptor);
assertThat(bundle.getState()).isEqualTo(Bundle.UNINSTALLED);
assertThat(getIntField(service, "unloadCalled")).as("@UnLoad should have been called").isEqualTo(1);
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.
the class ElasticAgentInformationMigratorImplTest method setUp.
@BeforeEach
void setUp() {
goPluginDescriptor = GoPluginDescriptor.builder().id(PLUGIN_ID).build();
goPluginDescriptor.setBundleDescriptor(new GoPluginBundleDescriptor(goPluginDescriptor));
elasticAgentInformationMigrator = new ElasticAgentInformationMigratorImpl(pluginSqlMapDao, clusterProfilesService, elasticProfileService, elasticAgentExtension, pluginManager, goConfigService);
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.
the class ConfigRepositoryInitializerTest method setUp.
@BeforeEach
void setUp() {
yamlPluginDescriptor = GoPluginDescriptor.builder().id(YAML_PLUGIN_ID).build();
yamlPluginDescriptor.setBundleDescriptor(new GoPluginBundleDescriptor(yamlPluginDescriptor));
jsonPluginDescriptor = GoPluginDescriptor.builder().id(JSON_PLUGIN_ID).build();
jsonPluginDescriptor.setBundleDescriptor(new GoPluginBundleDescriptor(jsonPluginDescriptor));
groovyPluginDescriptor = GoPluginDescriptor.builder().id(GROOVY_PLUGIN_ID).build();
groovyPluginDescriptor.setBundleDescriptor(new GoPluginBundleDescriptor(groovyPluginDescriptor));
configRepositoryInitializer = new ConfigRepositoryInitializer(pluginManager, configRepoService, materialRepository, goConfigRepoConfigDataSource, goConfigService, systemEnvironment);
repoConfigs = new ConfigReposConfig();
ConfigRepoConfig repoConfig1 = new ConfigRepoConfig();
repoConfig1.setId("repo1");
repoConfig1.setPluginId(YAML_PLUGIN_ID);
repoConfig1.setRepo(MaterialConfigsMother.git("git-repo"));
repoConfigs.add(repoConfig1);
lenient().when(configRepoService.getConfigRepos()).thenReturn(repoConfigs);
lenient().when(pluginManager.isPluginOfType(CONFIG_REPO_EXTENSION, YAML_PLUGIN_ID)).thenReturn(true);
lenient().when(pluginManager.isPluginOfType(CONFIG_REPO_EXTENSION, JSON_PLUGIN_ID)).thenReturn(true);
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginBundleDescriptor in project gocd by gocd.
the class PluginsZipTest method shouldCreateAZipWithOneCopyOfEachJar_ForAPluginBundleWithMultiplePluginsInIt.
@Test
void shouldCreateAZipWithOneCopyOfEachJar_ForAPluginBundleWithMultiplePluginsInIt() throws IOException {
File bundledPluginJarLocation = createPluginFile(bundledPluginsDir, "bundled-multi-plugin-1.jar", "Bundled1");
File externalPluginJarLocation = createPluginFile(externalPluginsDir, "external-multi-plugin-1.jar", "External1");
bundledTaskPlugin = new GoPluginBundleDescriptor(getPluginDescriptor("bundled-plugin-1", bundledPluginJarLocation, true), getPluginDescriptor("bundled-plugin-2", bundledPluginJarLocation, true));
externalTaskPlugin = new GoPluginBundleDescriptor(getPluginDescriptor("external-plugin-1", externalPluginJarLocation, false), getPluginDescriptor("external-plugin-2", externalPluginJarLocation, false));
when(pluginManager.plugins()).thenReturn(Arrays.asList(bundledTaskPlugin.descriptors().get(0), bundledTaskPlugin.descriptors().get(1), externalTaskPlugin.descriptors().get(0), externalTaskPlugin.descriptors().get(1)));
when(pluginManager.isPluginOfType("task", "bundled-plugin-1")).thenReturn(true);
when(pluginManager.isPluginOfType("scm", "bundled-plugin-2")).thenReturn(true);
when(pluginManager.isPluginOfType("task", "external-plugin-1")).thenReturn(true);
when(pluginManager.isPluginOfType("artifact", "external-plugin-2")).thenReturn(true);
pluginsZip = spy(new PluginsZip(systemEnvironment, pluginManager));
pluginsZip.create();
try (ZipFile zipFile = new ZipFile(expectedZipPath)) {
assertThat(new File(expectedZipPath).exists()).as(expectedZipPath + " should exist").isTrue();
assertThat(EnumerationUtils.toList(zipFile.entries()).size()).isEqualTo(2);
assertThat(zipFile.getEntry("bundled/bundled-multi-plugin-1.jar")).isNotNull();
assertThat(zipFile.getEntry("external/external-multi-plugin-1.jar")).isNotNull();
}
}
Aggregations