@Test public void shouldGetLatestModificationForPackageMaterial() { PackageMaterial material = new PackageMaterial(); PackageDefinition packageDefinition = create( "id", "package", new Configuration(), PackageRepositoryMother.create( "id", "name", "plugin-id", "plugin-version", new Configuration())); material.setPackageDefinition(packageDefinition); when(pluginManager.doOn( eq(PackageMaterialProvider.class), eq("plugin-id"), any(ActionWithReturn.class))) .thenReturn(new PackageRevision("blah-123", new Date(), "user")); List<Modification> modifications = materialService.latestModification(material, null, null); assertThat(modifications.get(0).getRevision(), is("blah-123")); }
@Test public void shouldUpdatePackageMaterialConfigurationOfMaterialsOnPipeline() throws Exception { String jobName = "job-one"; PipelineConfig pipelineConfig = setupPipelineWithPackageMaterial("pipeline_with_pluggable_scm_mat", "stage", jobName); final Pipeline previousSuccessfulBuildWithOlderPackageConfig = simulateSuccessfulPipelineRun(pipelineConfig); PipelineConfig updatedPipelineConfig = configHelper.updatePipeline( pipelineConfig.name(), new GoConfigFileHelper.Updater<PipelineConfig>() { @Override public void update(PipelineConfig config) { PackageMaterialConfig materialConfig = (PackageMaterialConfig) config.materialConfigs().first(); materialConfig .getPackageDefinition() .getConfiguration() .getProperty("package-key2") .setConfigurationValue(new ConfigurationValue("package-updated-value")); materialConfig .getPackageDefinition() .getRepository() .getConfiguration() .getProperty("repo-key2") .setConfigurationValue(new ConfigurationValue("repo-updated-value")); } }); final long jobId = rerunJob(jobName, pipelineConfig, previousSuccessfulBuildWithOlderPackageConfig); Pipeline loadedPipeline = (Pipeline) transactionTemplate.execute( new TransactionCallback() { public Object doInTransaction(TransactionStatus status) { return loader.pipelineWithPasswordAwareBuildCauseByBuildId(jobId); } }); MaterialRevisions revisions = loadedPipeline.getBuildCause().getMaterialRevisions(); PackageMaterial updatedMaterial = (PackageMaterial) revisions .findRevisionFor(updatedPipelineConfig.materialConfigs().first()) .getMaterial(); Configuration updatedConfiguration = updatedMaterial.getPackageDefinition().getConfiguration(); assertThat(updatedConfiguration.size(), is(2)); assertThat( updatedConfiguration.getProperty("package-key2").getConfigurationValue(), is(new ConfigurationValue("package-updated-value"))); assertThat( updatedMaterial.getPackageDefinition().getRepository().getConfiguration().size(), is(2)); assertThat( updatedMaterial .getPackageDefinition() .getRepository() .getConfiguration() .getProperty("repo-key2") .getConfigurationValue(), is(new ConfigurationValue("repo-updated-value"))); }