use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldPerformPluginValidationsUsingMetaDataBeforeSavingPackageRepository.
@Test
public void shouldPerformPluginValidationsUsingMetaDataBeforeSavingPackageRepository() throws Exception {
// metadata setup
String pluginId = "yum";
PackageConfigurations repositoryConfiguration = new PackageConfigurations();
repositoryConfiguration.add(new PackageConfiguration("required").with(PackageConfiguration.REQUIRED, true));
repositoryConfiguration.add(new PackageConfiguration("required_secure").with(PackageConfiguration.REQUIRED, true).with(PackageConfiguration.SECURE, true));
repositoryConfiguration.add(new PackageConfiguration("secure").with(PackageConfiguration.SECURE, true).with(PackageConfiguration.REQUIRED, false));
repositoryConfiguration.add(new PackageConfiguration("not_required_not_secure"));
RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, repositoryConfiguration);
PackageRepository packageRepository = new PackageRepository();
packageRepository.setPluginConfiguration(new PluginConfiguration(pluginId, "1.0"));
packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("required", false, ""));
packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("required_secure", true, ""));
packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("secure", true, ""));
packageRepository.getConfiguration().add(ConfigurationPropertyMother.create("not_required_not_secure", false, ""));
when(packageRepositoryExtension.isRepositoryConfigurationValid(eq(pluginId), any(RepositoryConfiguration.class))).thenReturn(new ValidationResult());
when(pluginManager.getPluginDescriptorFor(pluginId)).thenReturn(new GoPluginDescriptor(pluginId, "1.0", null, null, null, true));
when(localizer.localize("MANDATORY_CONFIGURATION_FIELD")).thenReturn("mandatory field");
service.performPluginValidationsFor(packageRepository);
assertThat(packageRepository.getConfiguration().get(0).getConfigurationValue().errors().getAllOn("value"), is(Arrays.asList("mandatory field")));
assertThat(packageRepository.getConfiguration().get(1).getEncryptedConfigurationValue().errors().getAllOn("value"), is(Arrays.asList("mandatory field")));
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor in project gocd by gocd.
the class PackageRepositoryServiceTest method shouldUpdatePluginVersionWhenValid.
@Test
public void shouldUpdatePluginVersionWhenValid() {
String pluginId = "valid";
RepositoryMetadataStore.getInstance().addMetadataFor(pluginId, new PackageConfigurations());
when(pluginManager.getPluginDescriptorFor(pluginId)).thenReturn(new GoPluginDescriptor(pluginId, "1.0", null, null, null, true));
when(packageRepositoryExtension.isRepositoryConfigurationValid(eq(pluginId), any(RepositoryConfiguration.class))).thenReturn(new ValidationResult());
PackageRepository packageRepository = new PackageRepository();
packageRepository.setPluginConfiguration(new PluginConfiguration(pluginId, ""));
service.performPluginValidationsFor(packageRepository);
assertThat(packageRepository.getPluginConfiguration().getVersion(), is("1.0"));
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor in project gocd by gocd.
the class JobControllerIntegrationTest method jobDetailModel_shouldHaveTheElasticProfilePluginIdWhenAgentIsNotAssigned.
@Test
public void jobDetailModel_shouldHaveTheElasticProfilePluginIdWhenAgentIsNotAssigned() throws Exception {
Pipeline pipeline = fixture.createPipelineWithFirstStageAssigned();
Stage stage = pipeline.getFirstStage();
JobInstance job = stage.getFirstJob();
GoPluginDescriptor.About about = new GoPluginDescriptor.About("name", "0.1", "17.3.0", "desc", null, null);
GoPluginDescriptor descriptor = new GoPluginDescriptor("plugin_id", null, about, null, null, false);
ElasticAgentMetadataStore.instance().setPluginInfo(new ElasticAgentPluginInfo(descriptor, null, null, null, new Capabilities(false, true)));
fixture.addJobAgentMetadata(new JobAgentMetadata(job.getId(), new ElasticProfile("profile_id", "plugin_id", Collections.EMPTY_LIST)));
ModelAndView modelAndView = controller.jobDetail(pipeline.getName(), String.valueOf(pipeline.getCounter()), stage.getName(), String.valueOf(stage.getCounter()), job.getName());
assertThat(modelAndView.getModel().get("elasticAgentPluginId"), is("plugin_id"));
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor in project gocd by gocd.
the class AnalyticsPluginAssetsServiceTest method addAnalyticsPluginInfoToStore.
private void addAnalyticsPluginInfoToStore(String pluginId) {
GoPluginDescriptor goPluginDescriptor = new GoPluginDescriptor(pluginId, null, null, null, null, false);
AnalyticsPluginInfo analyticsPluginInfo = new AnalyticsPluginInfo(goPluginDescriptor, null, null, null);
metadataStore.setPluginInfo(analyticsPluginInfo);
}
use of com.thoughtworks.go.plugin.infra.plugininfo.GoPluginDescriptor in project gocd by gocd.
the class AnalyticsPluginAssetsServiceTest method onPluginMetadataLoad_shouldUpdateThePluginInfoWithAssetsPath.
@Test
public void onPluginMetadataLoad_shouldUpdateThePluginInfoWithAssetsPath() throws Exception {
railsRoot = temporaryFolder.newFolder();
Path pluginDirPath = Paths.get(railsRoot.getAbsolutePath(), "public", "assets", "plugins", PLUGIN_ID);
GoPluginDescriptor goPluginDescriptor = new GoPluginDescriptor(PLUGIN_ID, null, null, null, null, false);
AnalyticsPluginInfo analyticsPluginInfo = new AnalyticsPluginInfo(goPluginDescriptor, null, null, null);
metadataStore.setPluginInfo(analyticsPluginInfo);
Path dirtyPath = Paths.get(pluginDirPath.toString(), "dirty.txt");
FileUtils.forceMkdirParent(dirtyPath.toFile());
Files.write(dirtyPath, "hello".getBytes());
assertTrue(pluginDirPath.toFile().exists());
assertTrue(dirtyPath.toFile().exists());
when(servletContext.getInitParameter("rails.root")).thenReturn("rails-root");
when(servletContext.getRealPath("rails-root")).thenReturn(railsRoot.getAbsolutePath());
when(extension.canHandlePlugin(PLUGIN_ID)).thenReturn(true);
when(extension.getStaticAssets(PLUGIN_ID)).thenReturn(testDataZipArchive());
assetsService.onPluginMetadataCreate(PLUGIN_ID);
assertThat(analyticsPluginInfo.getStaticAssetsPath(), is(assetsService.assetPathFor(PLUGIN_ID)));
}
Aggregations