Ejemplo n.º 1
0
  @Test
  public void shouldReturnTheRevisionsThatMatchTheGivenSearchString() {
    when(securityService.hasViewPermissionForPipeline("pavan", "pipeline")).thenReturn(true);
    LocalizedOperationResult operationResult = mock(LocalizedOperationResult.class);
    MaterialConfig materialConfig = mock(MaterialConfig.class);
    when(goConfigService.materialForPipelineWithFingerprint("pipeline", "sha"))
        .thenReturn(materialConfig);

    List<MatchedRevision> expected =
        Arrays.asList(
            new MatchedRevision(
                "23",
                "revision",
                "revision",
                "user",
                new DateTime(2009, 10, 10, 12, 0, 0, 0).toDate(),
                "comment"));
    when(materialRepository.findRevisionsMatching(materialConfig, "23")).thenReturn(expected);
    assertThat(
        materialService.searchRevisions(
            "pipeline",
            "sha",
            "23",
            new Username(new CaseInsensitiveString("pavan")),
            operationResult),
        is(expected));
  }
Ejemplo n.º 2
0
  @Test
  public void shouldReturnNotFoundIfTheMaterialDoesNotBelongToTheGivenPipeline() {
    when(securityService.hasViewPermissionForPipeline("pavan", "pipeline")).thenReturn(true);
    LocalizedOperationResult operationResult = mock(LocalizedOperationResult.class);

    when(goConfigService.materialForPipelineWithFingerprint("pipeline", "sha"))
        .thenThrow(new RuntimeException("Not found"));

    materialService.searchRevisions(
        "pipeline", "sha", "23", new Username(new CaseInsensitiveString("pavan")), operationResult);
    verify(operationResult)
        .notFound(
            LocalizedMessage.materialWithFingerPrintNotFound("pipeline", "sha"),
            HealthStateType.general(HealthStateScope.forPipeline("pipeline")));
  }
Ejemplo n.º 3
0
 @Test
 public void shouldNotBeAuthorizedToViewAPipeline() {
   when(securityService.hasViewPermissionForPipeline("pavan", "pipeline")).thenReturn(false);
   LocalizedOperationResult operationResult = mock(LocalizedOperationResult.class);
   materialService.searchRevisions(
       "pipeline",
       "sha",
       "search-string",
       new Username(new CaseInsensitiveString("pavan")),
       operationResult);
   verify(operationResult)
       .unauthorized(
           LocalizedMessage.cannotViewPipeline("pipeline"),
           HealthStateType.general(HealthStateScope.forPipeline("pipeline")));
 }