@Test
  public void shouldLockPipelineWhenSchedulingIt() throws Exception {
    scheduleAndCompleteInitialPipelines();

    configHelper.lockPipeline("mingle");

    Material stubMaterial = new TestingMaterial();
    mingleConfig.setMaterialConfigs(new MaterialConfigs(stubMaterial.config()));

    assertThat(pipelineLockService.isLocked("mingle"), is(false));

    MaterialRevisions revisions = new MaterialRevisions();
    revisions.addRevision(
        stubMaterial,
        ((TestingMaterial) stubMaterial)
            .modificationsSince(null, null, subprocessExecutionContext));
    BuildCause buildCause = BuildCause.createWithModifications(revisions, "");
    dbHelper.saveMaterials(buildCause.getMaterialRevisions());
    Pipeline pipeline =
        instanceFactory.createPipelineInstance(
            mingleConfig,
            buildCause,
            new DefaultSchedulingContext(DEFAULT_APPROVED_BY),
            md5,
            new TimeProvider());
    pipelineService.save(pipeline);

    assertThat(pipelineLockService.isLocked("mingle"), is(true));
  }
  @Test
  public void shouldLockPipelineWhenSchedulingStage() throws Exception {
    scheduleAndCompleteInitialPipelines();
    Pipeline pipeline = pipelineDao.mostRecentPipeline("mingle");

    configHelper.lockPipeline("mingle");

    assertThat(pipelineLockService.isLocked("mingle"), is(false));

    scheduleService.scheduleStage(
        pipeline,
        STAGE_NAME,
        "anonymous",
        new ScheduleService.NewStageInstanceCreator(goConfigService),
        new ScheduleService.ExceptioningErrorHandler());

    assertThat(pipelineLockService.isLocked("mingle"), is(true));
  }