Search in sources :

Example 46 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class MaterialUpdateServiceTest method shouldReturnImplementerOfSvnPostCommitHookAndPerformMaterialUpdate_WhenInvokingPostCommitHookMaterialUpdate.

@Test
public void shouldReturnImplementerOfSvnPostCommitHookAndPerformMaterialUpdate_WhenInvokingPostCommitHookMaterialUpdate() {
    final HashMap params = new HashMap();
    params.put(MaterialUpdateService.TYPE, "svn");
    when(goConfigService.isUserAdmin(username)).thenReturn(true);
    final CruiseConfig cruiseConfig = new BasicCruiseConfig(PipelineConfigMother.createGroup("groupName", "pipeline1", "pipeline2"));
    when(goConfigService.currentCruiseConfig()).thenReturn(cruiseConfig);
    when(postCommitHookMaterialType.toType("svn")).thenReturn(validMaterialType);
    final PostCommitHookImplementer svnPostCommitHookImplementer = mock(PostCommitHookImplementer.class);
    final Material svnMaterial = mock(Material.class);
    when(svnPostCommitHookImplementer.prune(anySet(), eq(params))).thenReturn(new HashSet(Arrays.asList(svnMaterial)));
    when(validMaterialType.getImplementer()).thenReturn(svnPostCommitHookImplementer);
    service.notifyMaterialsForUpdate(username, params, result);
    verify(svnPostCommitHookImplementer).prune(anySet(), eq(params));
    Mockito.verify(queue, times(1)).post(matchMaterialUpdateMessage(svnMaterial));
    HttpLocalizedOperationResult acceptedResult = new HttpLocalizedOperationResult();
    acceptedResult.accepted(LocalizedMessage.string("MATERIAL_SCHEDULE_NOTIFICATION_ACCEPTED"));
    assertThat(result, is(acceptedResult));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) PostCommitHookImplementer(com.thoughtworks.go.server.materials.postcommit.PostCommitHookImplementer) Test(org.junit.Test)

Example 47 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class MaterialUpdateServiceTest method shouldReturn404WhenThereAreNoMaterialsToSchedule_WhenInvokingPostCommitHookMaterialUpdate.

@Test
public void shouldReturn404WhenThereAreNoMaterialsToSchedule_WhenInvokingPostCommitHookMaterialUpdate() {
    when(goConfigService.isUserAdmin(username)).thenReturn(true);
    PostCommitHookMaterialType materialType = mock(PostCommitHookMaterialType.class);
    when(postCommitHookMaterialType.toType("type")).thenReturn(materialType);
    PostCommitHookImplementer hookImplementer = mock(PostCommitHookImplementer.class);
    when(materialType.getImplementer()).thenReturn(hookImplementer);
    when(materialType.isKnown()).thenReturn(true);
    CruiseConfig config = mock(BasicCruiseConfig.class);
    when(goConfigService.currentCruiseConfig()).thenReturn(config);
    when(config.getGroups()).thenReturn(new PipelineGroups());
    when(hookImplementer.prune(anySet(), anyMap())).thenReturn(new HashSet<Material>());
    final HashMap params = new HashMap();
    params.put(MaterialUpdateService.TYPE, "type");
    service.notifyMaterialsForUpdate(username, params, result);
    HttpLocalizedOperationResult operationResult = new HttpLocalizedOperationResult();
    operationResult.notFound(LocalizedMessage.string("MATERIAL_SUITABLE_FOR_NOTIFICATION_NOT_FOUND"), HealthStateType.general(HealthStateScope.GLOBAL));
    assertThat(result, is(operationResult));
    verify(hookImplementer).prune(anySet(), anyMap());
}
Also used : PipelineGroups(com.thoughtworks.go.domain.PipelineGroups) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) ScmMaterial(com.thoughtworks.go.config.materials.ScmMaterial) PostCommitHookImplementer(com.thoughtworks.go.server.materials.postcommit.PostCommitHookImplementer) PostCommitHookMaterialType(com.thoughtworks.go.server.materials.postcommit.PostCommitHookMaterialType) Test(org.junit.Test)

Example 48 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class MaterialUpdateServiceTest method shouldReturn400WhenTypeIsMissing_WhenInvokingPostCommitHookMaterialUpdate.

@Test
public void shouldReturn400WhenTypeIsMissing_WhenInvokingPostCommitHookMaterialUpdate() {
    when(goConfigService.isUserAdmin(username)).thenReturn(true);
    service.notifyMaterialsForUpdate(username, new HashMap(), result);
    HttpLocalizedOperationResult badRequestResult = new HttpLocalizedOperationResult();
    badRequestResult.badRequest(LocalizedMessage.string("API_BAD_REQUEST"));
    assertThat(result, is(badRequestResult));
    verify(goConfigService).isUserAdmin(username);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.Test)

Example 49 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class MaterialUpdateServiceTest method shouldReturn400WhenTypeIsInvalid_WhenInvokingPostCommitHookMaterialUpdate.

@Test
public void shouldReturn400WhenTypeIsInvalid_WhenInvokingPostCommitHookMaterialUpdate() {
    when(goConfigService.isUserAdmin(username)).thenReturn(true);
    when(postCommitHookMaterialType.toType("some_invalid_type")).thenReturn(invalidMaterialType);
    final HashMap params = new HashMap();
    params.put(MaterialUpdateService.TYPE, "some_invalid_type");
    service.notifyMaterialsForUpdate(username, params, result);
    HttpLocalizedOperationResult badRequestResult = new HttpLocalizedOperationResult();
    badRequestResult.badRequest(LocalizedMessage.string("API_BAD_REQUEST"));
    assertThat(result, is(badRequestResult));
    verify(goConfigService).isUserAdmin(username);
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.Test)

Example 50 with HttpLocalizedOperationResult

use of com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult in project gocd by gocd.

the class GoConfigServiceTest method shouldFindConfigChangesForGivenConfigMd5.

@Test
public void shouldFindConfigChangesForGivenConfigMd5() throws Exception {
    goConfigService.configChangesFor("md5-5", "md5-4", new HttpLocalizedOperationResult());
    verify(configRepo).configChangesFor("md5-5", "md5-4");
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.Test)

Aggregations

HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)437 Test (org.junit.Test)394 Username (com.thoughtworks.go.server.domain.Username)168 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)41 ArrayList (java.util.ArrayList)27 Before (org.junit.Before)26 SecurityAuthConfig (com.thoughtworks.go.config.SecurityAuthConfig)24 Pipeline (com.thoughtworks.go.domain.Pipeline)24 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)20 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)20 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)19 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)18 ConfigUpdateResponse (com.thoughtworks.go.config.update.ConfigUpdateResponse)17 AgentInstance (com.thoughtworks.go.domain.AgentInstance)17 UserSearchModel (com.thoughtworks.go.presentation.UserSearchModel)17 GoCipher (com.thoughtworks.go.security.GoCipher)16 Matchers.containsString (org.hamcrest.Matchers.containsString)16 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)15 TriStateSelection (com.thoughtworks.go.presentation.TriStateSelection)14 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)14