Search in sources :

Example 26 with Modifications

use of com.thoughtworks.go.domain.materials.Modifications in project gocd by gocd.

the class PackageMaterialTest method shouldNotThrowUpWhenAdditionalDataIsRandomJunkAndNotJSON.

@Test
public void shouldNotThrowUpWhenAdditionalDataIsRandomJunkAndNotJSON() {
    PackageMaterial material = new PackageMaterial();
    PackageRepository repository = PackageRepositoryMother.create("repo-id", "tw-dev", "pluginid", "version", new Configuration(ConfigurationPropertyMother.create("k1", false, "v1")));
    material.setPackageDefinition(PackageDefinitionMother.create("p-id", "go-agent", new Configuration(ConfigurationPropertyMother.create("k2", false, "v2")), repository));
    material.setName(new CaseInsensitiveString("tw-dev:go-agent"));
    Modifications modifications = new Modifications(new Modification("loser", "comment", "email", new Date(), "revision-123", "salkdfjdsa-jjgkj!!!vcxknbvkjk"));
    EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext();
    material.populateEnvironmentContext(environmentVariableContext, new MaterialRevision(material, modifications), null);
    assertThat(environmentVariableContext.getProperty("GO_PACKAGE_TW_DEV_GO_AGENT_LABEL"), is("revision-123"));
    assertThat(environmentVariableContext.getProperty("GO_REPO_TW_DEV_GO_AGENT_K1"), is("v1"));
    assertThat(environmentVariableContext.getProperty("GO_PACKAGE_TW_DEV_GO_AGENT_K2"), is("v2"));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) Modification(com.thoughtworks.go.domain.materials.Modification) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) PackageMaterialRevision(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) Test(org.junit.Test)

Example 27 with Modifications

use of com.thoughtworks.go.domain.materials.Modifications in project gocd by gocd.

the class PackageMaterialTest method shouldPopulateEnvironmentContextWithEnvironmentVariablesCreatedOutOfAdditionalDataFromModification.

@Test
public void shouldPopulateEnvironmentContextWithEnvironmentVariablesCreatedOutOfAdditionalDataFromModification() {
    PackageMaterial material = new PackageMaterial();
    PackageRepository repository = PackageRepositoryMother.create("repo-id", "tw-dev", "pluginid", "version", new Configuration(ConfigurationPropertyMother.create("k1", false, "v1")));
    material.setPackageDefinition(PackageDefinitionMother.create("p-id", "go-agent", new Configuration(ConfigurationPropertyMother.create("k2", false, "v2")), repository));
    material.setName(new CaseInsensitiveString("tw-dev:go-agent"));
    HashMap<String, String> map = new HashMap<>();
    map.put("MY_NEW_KEY", "my_value");
    Modification modification = new Modification("loser", "comment", "email", new Date(), "revision-123", JsonHelper.toJsonString(map));
    Modifications modifications = new Modifications(modification);
    EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext();
    material.populateEnvironmentContext(environmentVariableContext, new MaterialRevision(material, modifications), null);
    assertThat(environmentVariableContext.getProperty("GO_PACKAGE_TW_DEV_GO_AGENT_LABEL"), is("revision-123"));
    assertThat(environmentVariableContext.getProperty("GO_REPO_TW_DEV_GO_AGENT_K1"), is("v1"));
    assertThat(environmentVariableContext.getProperty("GO_PACKAGE_TW_DEV_GO_AGENT_K2"), is("v2"));
    assertThat(environmentVariableContext.getProperty("GO_PACKAGE_TW_DEV_GO_AGENT_MY_NEW_KEY"), is("my_value"));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) Modification(com.thoughtworks.go.domain.materials.Modification) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) PackageMaterialRevision(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) Test(org.junit.Test)

Example 28 with Modifications

use of com.thoughtworks.go.domain.materials.Modifications in project gocd by gocd.

the class PackageMaterialTest method shouldNotThrowUpWhenAdditionalDataIsNull.

@Test
public void shouldNotThrowUpWhenAdditionalDataIsNull() {
    PackageMaterial material = new PackageMaterial();
    PackageRepository repository = PackageRepositoryMother.create("repo-id", "tw-dev", "pluginid", "version", new Configuration(ConfigurationPropertyMother.create("k1", false, "v1")));
    material.setPackageDefinition(PackageDefinitionMother.create("p-id", "go-agent", new Configuration(ConfigurationPropertyMother.create("k2", false, "v2")), repository));
    material.setName(new CaseInsensitiveString("tw-dev:go-agent"));
    Modifications modifications = new Modifications(new Modification("loser", "comment", "email", new Date(), "revision-123", null));
    EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext();
    material.populateEnvironmentContext(environmentVariableContext, new MaterialRevision(material, modifications), null);
    assertThat(environmentVariableContext.getProperty("GO_PACKAGE_TW_DEV_GO_AGENT_LABEL"), is("revision-123"));
    assertThat(environmentVariableContext.getProperty("GO_REPO_TW_DEV_GO_AGENT_K1"), is("v1"));
    assertThat(environmentVariableContext.getProperty("GO_PACKAGE_TW_DEV_GO_AGENT_K2"), is("v2"));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) Modification(com.thoughtworks.go.domain.materials.Modification) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) PackageMaterialRevision(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) Test(org.junit.Test)

Example 29 with Modifications

use of com.thoughtworks.go.domain.materials.Modifications in project gocd by gocd.

the class PackageMaterialTest method shouldMarkEnvironmentContextCreatedForAdditionalDataAsSecureIfTheValueContainsAnySpecialCharacters.

@Test
public void shouldMarkEnvironmentContextCreatedForAdditionalDataAsSecureIfTheValueContainsAnySpecialCharacters() throws UnsupportedEncodingException {
    PackageMaterial material = new PackageMaterial();
    PackageRepository repository = PackageRepositoryMother.create("repo-id", "tw-dev", "pluginid", "version", new Configuration(ConfigurationPropertyMother.create("k1", false, "v1")));
    material.setPackageDefinition(PackageDefinitionMother.create("p-id", "go-agent", new Configuration(ConfigurationPropertyMother.create("k2", true, "!secure_value:with_special_chars"), ConfigurationPropertyMother.create("k3", true, "secure_value_with_regular_chars")), repository));
    material.setName(new CaseInsensitiveString("tw-dev:go-agent"));
    HashMap<String, String> map = new HashMap<>();
    map.put("ADDITIONAL_DATA_ONE", "foobar:!secure_value:with_special_chars");
    map.put("ADDITIONAL_DATA_URL_ENCODED", "something:%21secure_value%3Awith_special_chars");
    map.put("ADDITIONAL_DATA_TWO", "foobar:secure_value_with_regular_chars");
    Modification modification = new Modification("loser", "comment", "email", new Date(), "revision-123", JsonHelper.toJsonString(map));
    Modifications modifications = new Modifications(modification);
    EnvironmentVariableContext environmentVariableContext = new EnvironmentVariableContext();
    material.populateEnvironmentContext(environmentVariableContext, new MaterialRevision(material, modifications), null);
    assertThat(environmentVariableContext.getProperty("GO_PACKAGE_TW_DEV_GO_AGENT_LABEL"), is("revision-123"));
    assertThat(environmentVariableContext.getProperty("GO_REPO_TW_DEV_GO_AGENT_K1"), is("v1"));
    assertThat(environmentVariableContext.getProperty("GO_PACKAGE_TW_DEV_GO_AGENT_K2"), is("!secure_value:with_special_chars"));
    assertThat(environmentVariableContext.getPropertyForDisplay("GO_PACKAGE_TW_DEV_GO_AGENT_K2"), is("********"));
    assertThat(environmentVariableContext.getProperty("GO_PACKAGE_TW_DEV_GO_AGENT_ADDITIONAL_DATA_ONE"), is("foobar:!secure_value:with_special_chars"));
    assertThat(environmentVariableContext.getPropertyForDisplay("GO_PACKAGE_TW_DEV_GO_AGENT_ADDITIONAL_DATA_ONE"), is("foobar:!secure_value:with_special_chars"));
    assertThat(environmentVariableContext.getPropertyForDisplay("GO_PACKAGE_TW_DEV_GO_AGENT_ADDITIONAL_DATA_TWO"), is("foobar:secure_value_with_regular_chars"));
    assertThat(environmentVariableContext.getProperty("GO_PACKAGE_TW_DEV_GO_AGENT_ADDITIONAL_DATA_URL_ENCODED"), is("something:%21secure_value%3Awith_special_chars"));
    assertThat(environmentVariableContext.getPropertyForDisplay("GO_PACKAGE_TW_DEV_GO_AGENT_ADDITIONAL_DATA_URL_ENCODED"), is("********"));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) Modification(com.thoughtworks.go.domain.materials.Modification) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) EnvironmentVariableContext(com.thoughtworks.go.util.command.EnvironmentVariableContext) PackageMaterialRevision(com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Date(java.util.Date) Test(org.junit.Test)

Example 30 with Modifications

use of com.thoughtworks.go.domain.materials.Modifications in project gocd by gocd.

the class ChangesetServiceIntegrationTest method shouldSkipBisectPipelineCountersWhenThereIsABisectBetweenToAndFromCounters.

@Test
public void shouldSkipBisectPipelineCountersWhenThereIsABisectBetweenToAndFromCounters() {
    Username loser = new Username(new CaseInsensitiveString("loser"));
    ManualBuild build = new ManualBuild(loser);
    DateTime now = new DateTime();
    Pipeline firstPipeline = dbHelper.checkinRevisionsToBuild(build, pipelineConfig, dbHelper.addRevisionsWithModifications(hg, checkinWithComment("1", "#3518 - hg - foo", now.toDate())));
    Modification bisectModification = checkinWithComment("3", "#4750 - Rev 3", now.plusDays(3).toDate());
    dbHelper.checkinRevisionsToBuild(build, pipelineConfig, dbHelper.addRevisionsWithModifications(hg, checkinWithComment("2", "#3750 - Rev 2", now.plusDays(2).toDate()), bisectModification, checkinWithComment("4", "#4750 - Rev 4", now.plusDays(4).toDate())));
    dbHelper.checkinRevisionsToBuild(build, pipelineConfig, dbHelper.addRevisionsWithModifications(hg, checkinWithComment("5", "#5750 - Rev 5", now.plusDays(5).toDate())));
    dbHelper.checkinRevisionsToBuild(build, pipelineConfig, new MaterialRevision(hg, bisectModification));
    Pipeline lastPipeline = dbHelper.checkinRevisionsToBuild(build, pipelineConfig, dbHelper.addRevisionsWithModifications(hg, checkinWithComment("6", "#6760 - Rev 6", now.plusDays(6).toDate())));
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    List<MaterialRevision> revisionsBetween = changesetService.revisionsBetween("foo-bar", firstPipeline.getCounter(), lastPipeline.getCounter(), new Username(new CaseInsensitiveString("loser")), result, true, false);
    assertThat(result.isSuccessful(), is(true));
    assertThat(revisionsBetween.size(), is(1));
    Modifications actualMods = revisionsBetween.get(0).getModifications();
    assertThat(actualMods.size(), is(5));
}
Also used : Modifications(com.thoughtworks.go.domain.materials.Modifications) Modification(com.thoughtworks.go.domain.materials.Modification) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PipelineMaterialRevision(com.thoughtworks.go.domain.PipelineMaterialRevision) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) DateTime(org.joda.time.DateTime) Pipeline(com.thoughtworks.go.domain.Pipeline) Test(org.junit.Test)

Aggregations

Modifications (com.thoughtworks.go.domain.materials.Modifications)35 Test (org.junit.Test)29 Modification (com.thoughtworks.go.domain.materials.Modification)21 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)15 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)12 Date (java.util.Date)12 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)10 EnvironmentVariableContext (com.thoughtworks.go.util.command.EnvironmentVariableContext)10 MaterialInstance (com.thoughtworks.go.domain.MaterialInstance)9 File (java.io.File)8 HashMap (java.util.HashMap)6 LinkedHashMap (java.util.LinkedHashMap)6 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)5 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)5 PackageMaterialRevision (com.thoughtworks.go.domain.materials.packagematerial.PackageMaterialRevision)5 PluggableSCMMaterialRevision (com.thoughtworks.go.domain.materials.scm.PluggableSCMMaterialRevision)5 SCM (com.thoughtworks.go.domain.scm.SCM)5 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)4 TransactionStatus (org.springframework.transaction.TransactionStatus)4 TransactionCallback (org.springframework.transaction.support.TransactionCallback)4