Exemplo n.º 1
0
  @Test
  public void shouldFailToAddDuplicatePipelineAlreadyDefinedInConfigRepo() {
    pipelines =
        new BasicPipelineConfigs(
            "group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1"));
    BasicCruiseConfig localCruiseConfig = new BasicCruiseConfig(pipelines);
    cruiseConfig =
        new BasicCruiseConfig(
            localCruiseConfig, PartialConfigMother.withPipelineInGroup("pipe2", "remote_group"));

    PipelineConfig pipe2Dup = PipelineConfigMother.pipelineConfig("pipe2");
    try {
      cruiseConfig.addPipeline("doesNotMatterWhichGroup", pipe2Dup);
    } catch (Exception ex) {
      assertThat(
          ex.getMessage(),
          is(
              "Pipeline called 'pipe2' is already defined in configuration repository http://some.git at 1234fed"));
    }

    assertThat(cruiseConfig.allPipelines().size(), is(2));
    assertThat(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe2")), is(true));

    assertThat(localCruiseConfig.allPipelines().size(), is(1));
    assertThat(localCruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe1")), is(true));
    assertThat(localCruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe2")), is(false));
  }
Exemplo n.º 2
0
 @Test
 public void shouldGetAllPipelinesList() {
   PipelineConfig pipeline1 = PipelineConfigMother.pipelineConfig("pipeline1");
   PipelineConfig pipeline2 = PipelineConfigMother.pipelineConfig("pipeline2");
   PipelineConfigs group = createWithPipelines(pipeline1, pipeline2);
   assertThat(group.getPipelines(), hasItem(pipeline1));
   assertThat(group.getPipelines(), hasItem(pipeline2));
 }
Exemplo n.º 3
0
 @Test
 public void shouldReturnIndexOfPipeline_When2Pipelines() {
   PipelineConfigs group =
       createWithPipelines(
           PipelineConfigMother.pipelineConfig("pipeline1"),
           PipelineConfigMother.pipelineConfig("pipeline2"));
   PipelineConfig pipelineConfig = group.findBy(new CaseInsensitiveString("pipeline2"));
   assertThat(group.indexOf(pipelineConfig), is(1));
 }
Exemplo n.º 4
0
  @Test
  public void shouldAddPipelineAtIndex() {
    PipelineConfigs group = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline0"));

    PipelineConfig p1 = PipelineConfigMother.pipelineConfig("pipeline1");
    group.add(1, p1);

    assertThat(group.get(1), is(p1));
  }
Exemplo n.º 5
0
  @Test
  public void shouldRemovePipeline() {
    PipelineConfig p0 = PipelineConfigMother.pipelineConfig("pipeline0");
    PipelineConfigs group = createWithPipeline(p0);

    PipelineConfig p1 = PipelineConfigMother.pipelineConfig("pipeline1");
    group.add(1, p1);

    group.remove(p0);

    assertThat(group.get(0), is(p1));
    assertThat(group.size(), is(1));
  }
Exemplo n.º 6
0
  @Test
  public void addPipeline_shouldAddPipelineToMain() {
    pipelines =
        new BasicPipelineConfigs(
            "group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1"));
    pipelines.setOrigin(new FileConfigOrigin());
    BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
    cruiseConfig =
        new BasicCruiseConfig(mainCruiseConfig, PartialConfigMother.withPipeline("pipe2"));
    cruiseConfig.addPipeline("group_main", PipelineConfigMother.pipelineConfig("pipe3"));

    assertThat(mainCruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe3")), is(true));
    assertThat(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe3")), is(true));
  }
Exemplo n.º 7
0
  @Test
  public void shouldReturnTheCorrectLocalizedMessageForDuplicatePipelinesInAnEnvironment() {
    BasicEnvironmentConfig environmentConfig = environmentConfig("uat");
    goConfigService.addPipeline(
        PipelineConfigMother.createPipelineConfig("foo", "dev", "job"), "foo-grp");
    environmentConfig.addPipeline(new CaseInsensitiveString("foo"));
    goConfigService.addEnvironment(environmentConfig);

    ArrayList<String> pipelines = new ArrayList<>();
    pipelines.add("foo");
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    service.createEnvironment(
        env("foo-env", pipelines, new ArrayList<Map<String, String>>(), new ArrayList<String>()),
        new Username(new CaseInsensitiveString("any")),
        result);

    result = new HttpLocalizedOperationResult();
    service.createEnvironment(
        env("env", pipelines, new ArrayList<Map<String, String>>(), new ArrayList<String>()),
        new Username(new CaseInsensitiveString("any")),
        result);
    assertThat(
        result.message(localizer),
        is(
            "Failed to add environment. Associating pipeline(s) which is already part of uat environment"));
  }
Exemplo n.º 8
0
  @Test
  public void
      shouldSetViewPermissionByDefaultIfNameIsPresentAndPermissionsAreOff_whileSettingAttributes() {
    PipelineConfigs group = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline1"));
    group.setConfigAttributes(
        m(
            BasicPipelineConfigs.AUTHORIZATION,
            a(
                m(
                    Authorization.NAME,
                    "user1",
                    Authorization.TYPE,
                    USER.toString(),
                    Authorization.PRIVILEGES,
                    privileges(OFF, OFF, OFF)),
                m(
                    Authorization.NAME,
                    "role1",
                    Authorization.TYPE,
                    ROLE.toString(),
                    Authorization.PRIVILEGES,
                    privileges(OFF, OFF, OFF)))));
    Authorization authorization = group.getAuthorization();

    assertThat(authorization.getViewConfig().size(), is(2));
    assertThat(
        authorization.getViewConfig(),
        hasItems(
            (Admin) new AdminRole(new CaseInsensitiveString("role1")),
            (Admin) new AdminUser(new CaseInsensitiveString("user1"))));

    assertThat(authorization.getOperationConfig().size(), is(0));
    assertThat(authorization.getAdminsConfig().size(), is(0));
  }
 @Test
 public void shouldCreateGroupForCurrentConfigIfItHasChanged() throws Exception {
   PipelineHistoryGroups historyGroups = preparePipelineHistoryGroups(pipelineConfig);
   PipelineConfig newConfig =
       PipelineConfigMother.createPipelineConfigWithStages("mingle", "stage1", "stage2");
   presenter =
       new PipelineHistoryJsonPresentationModel(
           pipelinePauseInfo,
           historyGroups,
           newConfig,
           pagination(),
           CAN_FORCE,
           hasForceBuildCause,
           hasModification,
           true);
   JsonTester jsonTester = new JsonTester(presenter.toJson());
   jsonTester.shouldContain(
       "{    'groups' : [ {"
           + "     'config' : {"
           + "         'stages' : [ "
           + "             {'name' : 'stage1', isAutoApproved : 'true'},"
           + "             {'name' : 'stage2', isAutoApproved : 'true'}"
           + "          ]"
           + "      }"
           + "    }, {"
           + "     'config' : {"
           + "         'stages' : [ "
           + "             {'name' : 'dev', isAutoApproved : 'true'},"
           + "             {'name' : 'ft', isAutoApproved : 'false'}"
           + "          ]"
           + "      }"
           + "    } ]"
           + "}");
 }
Exemplo n.º 10
0
 @Test
 public void shouldReturnFalseIfPipelineNotExist() {
   PipelineConfigs configs = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline1"));
   assertThat(
       "shouldReturnFalseIfPipelineNotExist",
       configs.hasPipeline(new CaseInsensitiveString("not-exist")),
       is(false));
 }
Exemplo n.º 11
0
 @Test
 public void shouldReturnIndexOfPipeline() {
   PipelineConfigs group = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline1"));
   PipelineConfig pipelineConfig = (PipelineConfig) group.get(0).clone();
   pipelineConfig.setLabelTemplate("blah");
   group.update(group.getGroup(), pipelineConfig, "pipeline1");
   assertThat(group.get(0).getLabelTemplate(), is("blah"));
 }
Exemplo n.º 12
0
 @Test
 public void hasViewPermissionDefinedShouldReturnFalseIfAuthorizationIsNotDefined() {
   PipelineConfigs group = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline1"));
   assertThat(
       "hasViewPermissionDefinedShouldReturnFalseIfAuthorizationIsNotDefined",
       group.hasViewPermissionDefined(),
       is(false));
 }
Exemplo n.º 13
0
 @Test
 public void hasViewPermissionDefinedShouldReturnTrueIfAuthorizationIsDefined() {
   PipelineConfigs group = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline1"));
   group.getAuthorization().getViewConfig().add(new AdminUser(new CaseInsensitiveString("jez")));
   assertThat(
       "hasViewPermissionDefinedShouldReturnTrueIfAuthorizationIsDefined",
       group.hasViewPermissionDefined(),
       is(true));
 }
Exemplo n.º 14
0
  @Test
  public void shouldValidateThatPipelineNameIsUnique() {
    PipelineConfig first = PipelineConfigMother.pipelineConfig("first");
    PipelineConfig second = PipelineConfigMother.pipelineConfig("second");
    PipelineConfigs group = createWithPipelines(first, second);
    PipelineConfig duplicate = PipelineConfigMother.pipelineConfig("first");
    group.addWithoutValidation(duplicate);

    group.validate(null);
    assertThat(
        duplicate.errors().on(PipelineConfig.NAME),
        is(
            "You have defined multiple pipelines called 'first'. Pipeline names are case-insensitive and must be unique."));
    assertThat(
        first.errors().on(PipelineConfig.NAME),
        is(
            "You have defined multiple pipelines called 'first'. Pipeline names are case-insensitive and must be unique."));
  }
Exemplo n.º 15
0
 @Test
 public void shouldReturnFalseIfViewPermissionIsNotDefined() {
   PipelineConfigs group = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline1"));
   group
       .getAuthorization()
       .getOperationConfig()
       .add(new AdminUser(new CaseInsensitiveString("jez")));
   assertThat(group.hasViewPermission(new CaseInsensitiveString("jez"), null), is(false));
 }
Exemplo n.º 16
0
 @Test
 public void shouldReturnTrueIfPipelineExist() {
   PipelineConfig pipelineConfig = PipelineConfigMother.pipelineConfig("pipeline1");
   PipelineConfigs configs = createWithPipeline(pipelineConfig);
   assertThat(
       "shouldReturnTrueIfPipelineExist",
       configs.hasPipeline(new CaseInsensitiveString("pipeline1")),
       is(true));
 }
Exemplo n.º 17
0
 @Test
 public void addPipeline_shouldFailToAddPipelineToMainWhenItExistsInPartialConfig() {
   pipelines =
       new BasicPipelineConfigs(
           "group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1"));
   pipelines.setOrigin(new FileConfigOrigin());
   BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
   cruiseConfig =
       new BasicCruiseConfig(mainCruiseConfig, PartialConfigMother.withPipeline("pipe2"));
   try {
     cruiseConfig.addPipeline("group_main", PipelineConfigMother.pipelineConfig("pipe2"));
     fail("should have thrown when trying to add pipe2 when it already exists in partial config");
   } catch (Exception ex) {
     assertThat(
         ex.getMessage(),
         containsString("Pipeline called 'pipe2' is already defined in configuration repository"));
   }
 }
Exemplo n.º 18
0
  @Test
  public void shouldReInitializeAuthorizationIfWeClearAllPermissions() {
    PipelineConfigs group = createWithPipeline(PipelineConfigMother.pipelineConfig("pipeline1"));
    group.setConfigAttributes(
        m(
            BasicPipelineConfigs.AUTHORIZATION,
            a(
                m(
                    Authorization.NAME,
                    "loser",
                    Authorization.TYPE,
                    USER.toString(),
                    Authorization.PRIVILEGES,
                    privileges(ON, DISABLED, DISABLED)),
                m(
                    Authorization.NAME,
                    "boozer",
                    Authorization.TYPE,
                    USER.toString(),
                    Authorization.PRIVILEGES,
                    privileges(OFF, ON, ON)),
                m(
                    Authorization.NAME,
                    "geezer",
                    Authorization.TYPE,
                    USER.toString(),
                    Authorization.PRIVILEGES,
                    privileges(DISABLED, OFF, ON)),
                m(
                    Authorization.NAME,
                    "gang_of_losers",
                    Authorization.TYPE,
                    ROLE.toString(),
                    Authorization.PRIVILEGES,
                    privileges(DISABLED, OFF, ON)),
                m(
                    Authorization.NAME,
                    "blinds",
                    Authorization.TYPE,
                    ROLE.toString(),
                    Authorization.PRIVILEGES,
                    privileges(ON, ON, OFF)))));
    Authorization authorization = group.getAuthorization();

    assertThat(authorization.getAdminsConfig().size(), is(2));
    assertThat(authorization.getOperationConfig().size(), is(2));
    assertThat(authorization.getViewConfig().size(), is(3));

    group.setConfigAttributes(m());

    authorization = group.getAuthorization();

    assertThat(authorization.getAdminsConfig().size(), is(0));
    assertThat(authorization.getOperationConfig().size(), is(0));
    assertThat(authorization.getViewConfig().size(), is(0));
  }
Exemplo n.º 19
0
 @Test
 public void shouldUpdateExistingEnvironment() throws Exception {
   BasicEnvironmentConfig uat = environmentConfig("uat");
   goConfigService.addPipeline(
       PipelineConfigMother.createPipelineConfig("foo", "dev", "job"), "foo-grp");
   goConfigService.addPipeline(
       PipelineConfigMother.createPipelineConfig("bar", "dev", "job"), "foo-grp");
   Username user = Username.ANONYMOUS;
   agentConfigService.addAgent(new AgentConfig("uuid-1", "host-1", "192.168.1.2"), user);
   agentConfigService.addAgent(new AgentConfig("uuid-2", "host-2", "192.168.1.3"), user);
   uat.addPipeline(new CaseInsensitiveString("foo"));
   uat.addAgent("uuid-2");
   uat.addEnvironmentVariable("env-one", "ONE");
   uat.addEnvironmentVariable("env-two", "TWO");
   goConfigService.addEnvironment(new BasicEnvironmentConfig(new CaseInsensitiveString("dev")));
   goConfigService.addEnvironment(new BasicEnvironmentConfig(new CaseInsensitiveString("qa")));
   goConfigService.addEnvironment(uat);
   goConfigService.addEnvironment(
       new BasicEnvironmentConfig(new CaseInsensitiveString("acceptance")));
   goConfigService.addEnvironment(
       new BasicEnvironmentConfig(new CaseInsensitiveString("function_testing")));
   EnvironmentConfig newUat = new BasicEnvironmentConfig(new CaseInsensitiveString("prod"));
   newUat.addPipeline(new CaseInsensitiveString("bar"));
   newUat.addAgent("uuid-1");
   newUat.addEnvironmentVariable("env-three", "THREE");
   HttpLocalizedOperationResult result =
       service.updateEnvironment(
           "uat",
           newUat,
           new Username(new CaseInsensitiveString("foo")),
           goConfigDao.md5OfConfigFile());
   EnvironmentConfig updatedEnv = service.named("prod");
   assertThat(updatedEnv.name(), is(new CaseInsensitiveString("prod")));
   assertThat(updatedEnv.getAgents().getUuids(), is(Arrays.asList("uuid-1")));
   assertThat(updatedEnv.getPipelineNames(), is(Arrays.asList(new CaseInsensitiveString("bar"))));
   EnvironmentVariablesConfig updatedVariables = new EnvironmentVariablesConfig();
   updatedVariables.add("env-three", "THREE");
   assertThat(updatedEnv.getVariables(), is(updatedVariables));
   EnvironmentsConfig currentEnvironments = goConfigService.getCurrentConfig().getEnvironments();
   assertThat(currentEnvironments.indexOf(updatedEnv), is(2));
   assertThat(currentEnvironments.size(), is(5));
 }
Exemplo n.º 20
0
  @Test
  public void shouldReturnFalseWhenHasNotPipelinesFrom2Parts() {
    pipelines =
        new BasicPipelineConfigs(
            "group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1"));
    BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
    cruiseConfig =
        new BasicCruiseConfig(mainCruiseConfig, PartialConfigMother.withPipeline("pipe2"));

    assertThat(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe3")), is(false));
  }
Exemplo n.º 21
0
  @Test
  public void shouldAddPipelineToExistingGroup_InMergeAndLocalScope() {
    pipelines =
        new BasicPipelineConfigs(
            "group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1"));
    BasicCruiseConfig localCruiseConfig = new BasicCruiseConfig(pipelines);
    cruiseConfig =
        new BasicCruiseConfig(
            localCruiseConfig, PartialConfigMother.withPipelineInGroup("pipe2", "remote_group"));

    PipelineConfig pipe3 = PipelineConfigMother.pipelineConfig("pipe3");
    cruiseConfig.addPipeline("remote_group", pipe3);

    assertThat(cruiseConfig.allPipelines().size(), is(3));
    assertThat(cruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe3")), is(true));

    assertThat(localCruiseConfig.allPipelines().size(), is(2));
    assertThat(localCruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe1")), is(true));
    assertThat(localCruiseConfig.hasPipelineNamed(new CaseInsensitiveString("pipe3")), is(true));
    assertThat(localCruiseConfig.pipelines("remote_group").contains(pipe3), is(true));
  }
Exemplo n.º 22
0
  @Test
  public void shouldReturnGroupsFrom2Parts() {
    pipelines =
        new BasicPipelineConfigs(
            "group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1"));
    BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
    cruiseConfig =
        new BasicCruiseConfig(
            mainCruiseConfig, PartialConfigMother.withPipelineInGroup("pipe2", "g2"));

    assertThat(cruiseConfig.hasPipelineGroup("g2"), is(true));
  }
  @Test
  public void shouldLoadShallowCloneFlagForGitMaterialsBaseOnTheirOwnPipelineConfig()
      throws IOException {
    GitTestRepo testRepo = new GitTestRepo();

    PipelineConfig shallowPipeline =
        PipelineConfigMother.pipelineConfig(
            "shallowPipeline",
            new StageConfig(
                new CaseInsensitiveString("stage"), new JobConfigs(new JobConfig("job-one"))));
    shallowPipeline.materialConfigs().clear();
    shallowPipeline.addMaterialConfig(
        new GitMaterialConfig(testRepo.projectRepositoryUrl(), null, true));
    configHelper.addPipeline(shallowPipeline);

    PipelineConfig fullPipeline =
        PipelineConfigMother.pipelineConfig(
            "fullPipeline",
            new StageConfig(
                new CaseInsensitiveString("stage"), new JobConfigs(new JobConfig("job-one"))));
    fullPipeline.materialConfigs().clear();
    fullPipeline.addMaterialConfig(
        new GitMaterialConfig(testRepo.projectRepositoryUrl(), null, false));
    configHelper.addPipeline(fullPipeline);

    Pipeline shallowPipelineInstance = createAndLoadModifyOneFilePipeline(shallowPipeline);
    MaterialRevisions shallowRevisions =
        shallowPipelineInstance.getBuildCause().getMaterialRevisions();
    assertThat(
        ((GitMaterial) shallowRevisions.getRevisions().get(0).getMaterial()).isShallowClone(),
        is(true));

    Pipeline fullPipelineInstance = createAndLoadModifyOneFilePipeline(fullPipeline);
    MaterialRevisions fullRevisions = fullPipelineInstance.getBuildCause().getMaterialRevisions();
    assertThat(
        ((GitMaterial) fullRevisions.getRevisions().get(0).getMaterial()).isShallowClone(),
        is(false));
  }
Exemplo n.º 24
0
  @Test
  public void shouldCollectOriginErrorsFromEnvironments_InMergedConfig() {
    pipelines =
        new BasicPipelineConfigs(
            "group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1"));
    BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
    PartialConfig partialConfig = PartialConfigMother.withPipelineInGroup("pipe2", "g2");
    partialConfig.getGroups().get(0).get(0).setOrigin(new RepoConfigOrigin());
    cruiseConfig = new BasicCruiseConfig(mainCruiseConfig, partialConfig);
    BasicEnvironmentConfig uat = new BasicEnvironmentConfig(new CaseInsensitiveString("UAT"));
    uat.addPipeline(new CaseInsensitiveString("pipe2"));
    cruiseConfig.addEnvironment(uat);

    List<ConfigErrors> allErrors = cruiseConfig.validateAfterPreprocess();
    assertThat(allErrors.size(), is(1));
    assertNotNull(allErrors.get(0).on("origin"));
  }
 @Test
 public void shouldEncodeStageLocator() {
   PipelineConfig pipelineConfig1 =
       PipelineConfigMother.createPipelineConfigWithStages("mingle-%", "stage1-%", "stage2");
   PipelineHistoryJsonPresentationModel presenter =
       new PipelineHistoryJsonPresentationModel(
           pipelinePauseInfo,
           preparePipelineHistoryGroups(pipelineConfig1),
           pipelineConfig1,
           pagination(),
           CAN_FORCE,
           hasForceBuildCause,
           hasModification,
           true);
   JsonValue json = JsonUtils.from(presenter.toJson());
   String stageLocator = json.getString("groups", 0, "history", 0, "stages", 0, "stageLocator");
   assertThat(stageLocator, is("mingle-%25/1/stage1-%25/1"));
 }
 @Before
 public void setUp() throws Exception {
   pipelineConfig =
       PipelineConfigMother.pipelineConfig(
           "mingle",
           StageConfigMother.custom("dev", "defaultJob"),
           StageConfigMother.manualStage("ft"));
   pipelinePauseInfo = PipelinePauseInfo.notPaused();
   presenter =
       new PipelineHistoryJsonPresentationModel(
           pipelinePauseInfo,
           preparePipelineHistoryGroups(pipelineConfig),
           pipelineConfig,
           pagination(),
           CAN_FORCE,
           hasForceBuildCause,
           hasModification,
           true);
 }
 private PipelineConfig setupPipelineWithScmMaterial(
     String pipelineName, String stageName, String jobName) {
   PluggableSCMMaterialConfig pluggableSCMMaterialConfig =
       MaterialConfigsMother.pluggableSCMMaterialConfigWithConfigProperties("url", "password");
   SCMPropertyConfiguration configuration = new SCMPropertyConfiguration();
   configuration.add(
       new SCMProperty("url", null).with(PackageConfiguration.PART_OF_IDENTITY, true));
   configuration.add(
       new SCMProperty("password", null).with(PackageConfiguration.PART_OF_IDENTITY, false));
   SCMMetadataStore.getInstance()
       .addMetadataFor(
           pluggableSCMMaterialConfig.getPluginId(), new SCMConfigurations(configuration), null);
   PipelineConfig pipelineConfig =
       PipelineConfigMother.pipelineConfig(
           pipelineName, stageName, new MaterialConfigs(pluggableSCMMaterialConfig), jobName);
   configHelper.addSCMConfig(pluggableSCMMaterialConfig.getSCMConfig());
   configHelper.addPipeline(pipelineConfig);
   return pipelineConfig;
 }
Exemplo n.º 28
0
  @Test
  public void shouldCollectOriginErrorsFromMaterialConfigs_InMergedConfig() {
    BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
    PartialConfig partialConfig = PartialConfigMother.withPipelineInGroup("pipe2", "g2");
    partialConfig.getGroups().get(0).get(0).setOrigin(new RepoConfigOrigin());
    cruiseConfig = new BasicCruiseConfig(mainCruiseConfig, partialConfig);
    PipelineConfig pipeline1 =
        goConfigMother.addPipeline(cruiseConfig, "pipeline1", "stage", "build");
    PipelineConfig pipeline2 =
        PipelineConfigMother.createPipelineConfigWithStage("pipeline2", "stage");
    pipeline2.setOrigin(new RepoConfigOrigin());
    partialConfig.getGroups().addPipeline("g2", pipeline2);

    goConfigMother.setDependencyOn(cruiseConfig, pipeline1, "pipeline2", "stage");

    List<ConfigErrors> allErrors = cruiseConfig.validateAfterPreprocess();
    assertThat(allErrors.size(), is(1));
    assertNotNull(allErrors.get(0).on("origin"));
  }
Exemplo n.º 29
0
  @Test
  public void shouldgetAllPipelineNamesFromAllParts() {
    pipelines =
        new BasicPipelineConfigs(
            "group_main", new Authorization(), PipelineConfigMother.pipelineConfig("pipe1"));
    BasicCruiseConfig mainCruiseConfig = new BasicCruiseConfig(pipelines);
    cruiseConfig =
        new BasicCruiseConfig(
            mainCruiseConfig,
            PartialConfigMother.withPipelineInGroup("pipe2", "g2"),
            PartialConfigMother.withPipelineInGroup("pipe3", "g3"));

    assertThat(
        cruiseConfig.getAllPipelineNames(),
        contains(
            new CaseInsensitiveString("pipe1"),
            new CaseInsensitiveString("pipe2"),
            new CaseInsensitiveString("pipe3")));
  }
  @Test
  public void shouldLoadPipelineAlongwithBuildCauseHavingMaterialPasswordsPopulated() {
    PipelineConfig pipelineConfig =
        PipelineConfigMother.pipelineConfig(
            "last",
            new StageConfig(
                new CaseInsensitiveString("stage"), new JobConfigs(new JobConfig("job-one"))));
    pipelineConfig.materialConfigs().clear();
    SvnMaterial onDirOne =
        MaterialsMother.svnMaterial("google.com", "dirOne", "loser", "boozer", false, "**/*.html");
    P4Material onDirTwo =
        MaterialsMother.p4Material(
            "host:987654321", "zoozer", "secret", "through-the-window", true);
    onDirTwo.setFolder("dirTwo");
    pipelineConfig.addMaterialConfig(onDirOne.config());
    pipelineConfig.addMaterialConfig(onDirTwo.config());

    configHelper.addPipeline(pipelineConfig);

    Pipeline building = PipelineMother.building(pipelineConfig);
    Pipeline pipeline = dbHelper.savePipelineWithMaterials(building);

    final long jobId = pipeline.getStages().get(0).getJobInstances().get(0).getId();
    Pipeline loadedPipeline =
        (Pipeline)
            transactionTemplate.execute(
                new TransactionCallback() {
                  public Object doInTransaction(TransactionStatus status) {
                    return loader.pipelineWithPasswordAwareBuildCauseByBuildId(jobId);
                  }
                });

    MaterialRevisions revisions = loadedPipeline.getBuildCause().getMaterialRevisions();
    assertThat(
        ((SvnMaterial) revisions.findRevisionFor(onDirOne).getMaterial()).getPassword(),
        is("boozer"));
    assertThat(
        ((P4Material) revisions.findRevisionFor(onDirTwo).getMaterial()).getPassword(),
        is("secret"));
  }