Search in sources :

Example 56 with MaterialConfigs

use of com.thoughtworks.go.config.materials.MaterialConfigs in project gocd by gocd.

the class GoConfigServiceIntegrationTest method shouldThrowUpOnConfigSavePostValidationError_ViaMergeFlow.

@Test
public void shouldThrowUpOnConfigSavePostValidationError_ViaMergeFlow() throws Exception {
    // User 1 adds a pipeline
    configHelper.addPipelineWithGroup("defaultGroup", "up_pipeline", "up_stage", "up_job");
    configHelper.addPipelineWithGroup("anotherGroup", "random_pipeline", "random_stage", "random_job");
    CruiseConfig user1SeeingConfig = configHelper.load();
    String user1SeeingMd5 = user1SeeingConfig.getMd5();
    // User 2 edits config
    configHelper.removePipeline("up_pipeline");
    // User 1 edits old config
    MaterialConfigs materialConfigs = new MaterialConfigs();
    materialConfigs.add(MaterialConfigsMother.dependencyMaterialConfig("up_pipeline", "up_stage"));
    new GoConfigMother().addPipelineWithGroup(user1SeeingConfig, "anotherGroup", "down_pipeline", materialConfigs, "down_stage", "down_job");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    configHelper.getXml(user1SeeingConfig, os);
    // User 1 saves edited config
    String xml = os.toString();
    GoConfigService.XmlPartialSaver saver = goConfigService.fileSaver(false);
    GoConfigValidity validity = saver.saveXml(xml, user1SeeingMd5);
    assertThat(validity.isValid(), is(false));
    assertThat(validity.toString(), validity.isType(GoConfigValidity.VT_MERGE_POST_VALIDATION_ERROR), is(true));
    assertThat(validity.errorMessage(), is("Pipeline \"up_pipeline\" does not exist. It is used from pipeline \"down_pipeline\"."));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) Matchers.containsString(org.hamcrest.Matchers.containsString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) GoConfigValidity(com.thoughtworks.go.config.validation.GoConfigValidity) Test(org.junit.Test)

Example 57 with MaterialConfigs

use of com.thoughtworks.go.config.materials.MaterialConfigs in project gocd by gocd.

the class GoConfigServiceIntegrationTest method shouldInternallyGetGoConfigInvalidExceptionOnValidationErrorAndFailWithATopLevelConfigError.

@Test
public void shouldInternallyGetGoConfigInvalidExceptionOnValidationErrorAndFailWithATopLevelConfigError() throws Exception {
    String oldMd5 = goConfigService.getConfigForEditing().getMd5();
    CruiseConfig user1SeeingConfig = configHelper.load();
    // Setup a pipeline group in the config
    new GoConfigMother().addPipelineWithGroup(user1SeeingConfig, "defaultGroup", "user1_pipeline", "user1_stage", "user1_job");
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    configHelper.getXml(user1SeeingConfig, os);
    GoConfigService.XmlPartialSaver saver = goConfigService.fileSaver(false);
    saver.saveXml(os.toString(), oldMd5);
    CruiseConfig configBeforePipelineGroupWasAddedAtBeginning = configHelper.load();
    String md5BeforeAddingGroupAtBeginning = configBeforePipelineGroupWasAddedAtBeginning.getMd5();
    // User 1 edits config XML and adds a pipeline group before the first group in config
    String configXMLWithGroupAddedAtBeginning = os.toString().replace("</pipelines>", "</pipelines><pipelines group=\"first_group\"/>");
    saver.saveXml(configXMLWithGroupAddedAtBeginning, md5BeforeAddingGroupAtBeginning);
    // User 2 adds another pipeline group, with the same name, through UI, but using the older MD5.
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    ConfigUpdateResponse response = goConfigService.updateConfigFromUI(new UpdateConfigFromUI() {

        public void checkPermission(CruiseConfig cruiseConfig, LocalizedOperationResult result) {
        }

        public Validatable node(CruiseConfig cruiseConfig) {
            return cruiseConfig;
        }

        public Validatable updatedNode(CruiseConfig cruiseConfig) {
            return node(cruiseConfig);
        }

        public void update(Validatable config) {
            CruiseConfig cruiseConfig = (CruiseConfig) config;
            MaterialConfigs materials = new MaterialConfigs(MaterialConfigsMother.mockMaterialConfigs("file:///tmp/foo"));
            new GoConfigMother().addPipelineWithGroup(cruiseConfig, "first_group", "up_pipeline", materials, "down_stage", "down_job");
        }

        public Validatable subject(Validatable node) {
            return node;
        }

        public Validatable updatedSubject(Validatable updatedNode) {
            return subject(updatedNode);
        }
    }, md5BeforeAddingGroupAtBeginning, new Username(new CaseInsensitiveString("admin")), result);
    CruiseConfig config = response.getCruiseConfig();
    assertThat(config.getMd5(), is(md5BeforeAddingGroupAtBeginning));
    assertThat(result.isSuccessful(), is(false));
    assertThat(result.httpCode(), is(SC_CONFLICT));
    assertThat(result.message(localizer), is("Save failed. Duplicate unique value [first_group] declared for identity constraint \"uniquePipelines\" of element \"cruise\"."));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) Matchers.containsString(org.hamcrest.Matchers.containsString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GoConfigMother(com.thoughtworks.go.helper.GoConfigMother) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) LocalizedOperationResult(com.thoughtworks.go.server.service.result.LocalizedOperationResult) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) ConfigUpdateResponse(com.thoughtworks.go.config.update.ConfigUpdateResponse) UpdateConfigFromUI(com.thoughtworks.go.config.update.UpdateConfigFromUI) Test(org.junit.Test)

Example 58 with MaterialConfigs

use of com.thoughtworks.go.config.materials.MaterialConfigs in project gocd by gocd.

the class MaterialUpdateStatusNotifierTest method shouldBeAbleToUnregisterAListenerDuringACallback.

@Test
public void shouldBeAbleToUnregisterAListenerDuringACallback() throws Exception {
    final PipelineConfig pipelineConfig = new PipelineConfig(new CaseInsensitiveString("config"), new MaterialConfigs());
    Material material = new HgMaterial("url", null);
    pipelineConfig.addMaterialConfig(material.config());
    MaterialUpdateStatusListener statusListener = new MaterialUpdateStatusListener() {

        public void onMaterialUpdate(MaterialUpdateCompletedMessage message) {
            materialUpdateStatusNotifier.removeListenerFor(pipelineConfig);
        }

        public boolean isListeningFor(Material material) {
            return true;
        }
    };
    materialUpdateStatusNotifier.registerListenerFor(pipelineConfig, statusListener);
    materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(material, 123));
    assertThat(materialUpdateStatusNotifier.hasListenerFor(pipelineConfig), is(false));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Material(com.thoughtworks.go.domain.materials.Material) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 59 with MaterialConfigs

use of com.thoughtworks.go.config.materials.MaterialConfigs in project gocd by gocd.

the class MaterialUpdateStatusNotifierTest method shouldNotifyListenerWhenItsMaterialIsUpdatedEvenIfAnotherListenerThrowsAnException.

@Test
public void shouldNotifyListenerWhenItsMaterialIsUpdatedEvenIfAnotherListenerThrowsAnException() throws Exception {
    Material sharedMaterial = new HgMaterial("url", null);
    PipelineConfig pipelineConfig1 = new PipelineConfig(new CaseInsensitiveString("config"), new MaterialConfigs());
    pipelineConfig1.addMaterialConfig(sharedMaterial.config());
    PipelineConfig pipelineConfig2 = new PipelineConfig(new CaseInsensitiveString("another-config"), new MaterialConfigs());
    pipelineConfig2.addMaterialConfig(sharedMaterial.config());
    MaterialUpdateStatusListener badListener = Mockito.mock(MaterialUpdateStatusListener.class);
    Mockito.doThrow(new RuntimeException("foo")).when(badListener).onMaterialUpdate(new MaterialUpdateSuccessfulMessage(sharedMaterial, 123));
    MaterialUpdateStatusListener goodListener = Mockito.mock(MaterialUpdateStatusListener.class);
    when(badListener.isListeningFor(sharedMaterial)).thenReturn(true);
    when(goodListener.isListeningFor(sharedMaterial)).thenReturn(true);
    materialUpdateStatusNotifier.registerListenerFor(pipelineConfig1, badListener);
    materialUpdateStatusNotifier.registerListenerFor(pipelineConfig2, goodListener);
    materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(sharedMaterial, 123));
    Mockito.verify(badListener).onMaterialUpdate(new MaterialUpdateSuccessfulMessage(sharedMaterial, 123));
    Mockito.verify(goodListener).onMaterialUpdate(new MaterialUpdateSuccessfulMessage(sharedMaterial, 123));
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) Material(com.thoughtworks.go.domain.materials.Material) HgMaterial(com.thoughtworks.go.config.materials.mercurial.HgMaterial) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Example 60 with MaterialConfigs

use of com.thoughtworks.go.config.materials.MaterialConfigs in project gocd by gocd.

the class FetchTaskBuilderTest method setUp.

@Before
public void setUp() {
    CruiseConfig config = GoConfigMother.configWithPipelines("random_pipeline", "uppest_lookalike", "uppest_stream", "upstreams_peer", "upstream", "downstream", "dummy");
    PipelineConfig randomPipeline = config.pipelineConfigByName(new CaseInsensitiveString("random_pipeline"));
    randomPipeline.add(StageConfigMother.stageConfig("random-stage1", new JobConfigs(new JobConfig("random-job1"))));
    PipelineConfig uppestLookalike = config.pipelineConfigByName(new CaseInsensitiveString("uppest_lookalike"));
    uppestLookalike.add(StageConfigMother.stageConfig("uppest-stage1", new JobConfigs(new JobConfig("uppest-job1"))));
    PipelineConfig uppestStream = config.pipelineConfigByName(new CaseInsensitiveString("uppest_stream"));
    uppestStream.add(StageConfigMother.stageConfig("uppest-stage1", new JobConfigs(new JobConfig("uppest-job1"))));
    uppestStream.add(StageConfigMother.stageConfig("uppest-stage2", new JobConfigs(new JobConfig("uppest-job2"))));
    uppestStream.add(StageConfigMother.stageConfig("uppest-stage3", new JobConfigs(new JobConfig("uppest-job3"))));
    PipelineConfig upstream = config.pipelineConfigByName(new CaseInsensitiveString("upstream"));
    upstream.setMaterialConfigs(new MaterialConfigs(MaterialConfigsMother.dependencyMaterialConfig("uppest_stream", "uppest-stage2")));
    upstream.add(StageConfigMother.stageConfig("up-stage1", new JobConfigs(new JobConfig("up-job1"))));
    upstream.add(StageConfigMother.stageConfig("up-stage2", new JobConfigs(new JobConfig("up-job2"))));
    PipelineConfig downstream = config.pipelineConfigByName(new CaseInsensitiveString("downstream"));
    downstream.setMaterialConfigs(new MaterialConfigs(MaterialConfigsMother.dependencyMaterialConfig("upstream", "up-stage1")));
    downstream.get(0).getJobs().get(0).addTask(new FetchTask(new CaseInsensitiveString("foo"), new CaseInsensitiveString("bar"), new CaseInsensitiveString("baz"), "abcd", "efg"));
    resolver = mock(UpstreamPipelineResolver.class);
    builderFactory = mock(BuilderFactory.class);
    fetchTaskBuilder = new FetchTaskBuilder();
}
Also used : MaterialConfigs(com.thoughtworks.go.config.materials.MaterialConfigs) UpstreamPipelineResolver(com.thoughtworks.go.server.service.UpstreamPipelineResolver) Before(org.junit.Before)

Aggregations

MaterialConfigs (com.thoughtworks.go.config.materials.MaterialConfigs)208 Test (org.junit.Test)160 PipelineConfig (com.thoughtworks.go.config.PipelineConfig)40 DependencyMaterialConfig (com.thoughtworks.go.config.materials.dependency.DependencyMaterialConfig)35 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)33 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)30 HgMaterial (com.thoughtworks.go.config.materials.mercurial.HgMaterial)26 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)24 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)23 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)22 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)20 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)18 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)18 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)15 ValueStreamMapPresentationModel (com.thoughtworks.go.server.presentation.models.ValueStreamMapPresentationModel)15 HgMaterialConfig (com.thoughtworks.go.config.materials.mercurial.HgMaterialConfig)14 Material (com.thoughtworks.go.domain.materials.Material)13 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)12 MaterialRevisions (com.thoughtworks.go.domain.MaterialRevisions)12 ArrayList (java.util.ArrayList)12