Search in sources :

Example 1 with PostCommitHookImplementer

use of com.thoughtworks.go.server.materials.postcommit.PostCommitHookImplementer 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 2 with PostCommitHookImplementer

use of com.thoughtworks.go.server.materials.postcommit.PostCommitHookImplementer 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 3 with PostCommitHookImplementer

use of com.thoughtworks.go.server.materials.postcommit.PostCommitHookImplementer in project gocd by gocd.

the class MaterialUpdateService method notifyMaterialsForUpdate.

public void notifyMaterialsForUpdate(Username username, Object params, HttpLocalizedOperationResult result) {
    if (!goConfigService.isUserAdmin(username)) {
        result.forbidden("Unauthorized to access this API.", HealthStateType.forbidden());
        return;
    }
    final Map attributes = (Map) params;
    if (attributes.containsKey(MaterialUpdateService.TYPE)) {
        PostCommitHookMaterialType materialType = postCommitHookMaterialType.toType((String) attributes.get(MaterialUpdateService.TYPE));
        if (!materialType.isKnown()) {
            result.badRequest("The request could not be understood by Go Server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.");
            return;
        }
        final PostCommitHookImplementer materialTypeImplementer = materialType.getImplementer();
        final CruiseConfig cruiseConfig = goConfigService.currentCruiseConfig();
        Set<Material> allUniquePostCommitSchedulableMaterials = materialConfigConverter.toMaterials(cruiseConfig.getAllUniquePostCommitSchedulableMaterials());
        resolveSecretForSvnMaterials(allUniquePostCommitSchedulableMaterials);
        final Set<Material> prunedMaterialList = materialTypeImplementer.prune(allUniquePostCommitSchedulableMaterials, attributes);
        if (prunedMaterialList.isEmpty()) {
            result.notFound("Unable to find material. Materials must be configured not to poll for new changes before they can be used with the notification mechanism.", HealthStateType.general(HealthStateScope.GLOBAL));
            return;
        }
        for (Material material : prunedMaterialList) {
            updateMaterial(material);
        }
        result.accepted("The material is now scheduled for an update. Please check relevant pipeline(s) for status.");
    } else {
        result.badRequest("The request could not be understood by Go Server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.");
    }
}
Also used : Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) GitMaterial(com.thoughtworks.go.config.materials.git.GitMaterial) SvnMaterial(com.thoughtworks.go.config.materials.svn.SvnMaterial) PluggableSCMMaterial(com.thoughtworks.go.config.materials.PluggableSCMMaterial) ConcurrentMap(java.util.concurrent.ConcurrentMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) PostCommitHookImplementer(com.thoughtworks.go.server.materials.postcommit.PostCommitHookImplementer) PostCommitHookMaterialType(com.thoughtworks.go.server.materials.postcommit.PostCommitHookMaterialType) CruiseConfig(com.thoughtworks.go.config.CruiseConfig)

Aggregations

DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)3 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)3 Material (com.thoughtworks.go.domain.materials.Material)3 PostCommitHookImplementer (com.thoughtworks.go.server.materials.postcommit.PostCommitHookImplementer)3 ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)2 PostCommitHookMaterialType (com.thoughtworks.go.server.materials.postcommit.PostCommitHookMaterialType)2 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)2 Test (org.junit.Test)2 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)1 PluggableSCMMaterial (com.thoughtworks.go.config.materials.PluggableSCMMaterial)1 GitMaterial (com.thoughtworks.go.config.materials.git.GitMaterial)1 PipelineGroups (com.thoughtworks.go.domain.PipelineGroups)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1