예제 #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));
  }
예제 #2
0
  @Test
  public void shouldFailWhenDeleteIsNotSuccessful() throws Exception {
    SecurityService securityService = mock(SecurityService.class);
    AgentConfigService agentConfigService = mock(AgentConfigService.class);
    AgentInstance agentInstance = mock(AgentInstance.class);
    String uuid = "1234";
    Username username = new Username(new CaseInsensitiveString("test"));
    HttpOperationResult operationResult = mock(HttpOperationResult.class);

    when(securityService.hasOperatePermissionForAgents(username)).thenReturn(true);

    when(agentInstance.isNullAgent()).thenReturn(false);
    when(agentInstance.isDisabled()).thenReturn(true);
    when(agentInstance.isBuilding()).thenReturn(false);
    when(agentInstance.isCancelled()).thenReturn(false);

    doThrow(new RuntimeException()).when(agentConfigService).deleteAgents(agentInstance);

    when(agentInstances.findAgent(uuid)).thenReturn(agentInstance);

    AgentService agentService =
        new AgentService(
            agentConfigService,
            new SystemEnvironment(),
            agentInstances,
            mock(EnvironmentConfigService.class),
            mock(GoConfigService.class),
            securityService,
            agentDao,
            uuidGenerator,
            serverHealthService = mock(ServerHealthService.class));

    agentService.deleteAgents(username, operationResult, Arrays.asList(uuid));

    verify(operationResult).internalServerError(any(String.class), any(HealthStateType.class));
  }
예제 #3
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")));
  }
예제 #4
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")));
 }