Search in sources :

Example 1 with PostCommitHookMaterialType

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

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

the class MaterialUpdateService method notifyMaterialsForUpdate.

public void notifyMaterialsForUpdate(Username username, Object params, HttpLocalizedOperationResult result) {
    if (!goConfigService.isUserAdmin(username)) {
        result.unauthorized(LocalizedMessage.string("API_ACCESS_UNAUTHORIZED"), HealthStateType.unauthorised());
        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(LocalizedMessage.string("API_BAD_REQUEST"));
            return;
        }
        final PostCommitHookImplementer materialTypeImplementer = materialType.getImplementer();
        final CruiseConfig cruiseConfig = goConfigService.currentCruiseConfig();
        Set<Material> allUniquePostCommitSchedulableMaterials = materialConfigConverter.toMaterials(cruiseConfig.getAllUniquePostCommitSchedulableMaterials());
        final Set<Material> prunedMaterialList = materialTypeImplementer.prune(allUniquePostCommitSchedulableMaterials, attributes);
        if (prunedMaterialList.isEmpty()) {
            result.notFound(LocalizedMessage.string("MATERIAL_SUITABLE_FOR_NOTIFICATION_NOT_FOUND"), HealthStateType.general(HealthStateScope.GLOBAL));
            return;
        }
        for (Material material : prunedMaterialList) {
            updateMaterial(material);
        }
        result.accepted(LocalizedMessage.string("MATERIAL_SCHEDULE_NOTIFICATION_ACCEPTED"));
    } else {
        result.badRequest(LocalizedMessage.string("API_BAD_REQUEST"));
    }
}
Also used : Material(com.thoughtworks.go.domain.materials.Material) DependencyMaterial(com.thoughtworks.go.config.materials.dependency.DependencyMaterial) 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)

Example 3 with PostCommitHookMaterialType

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

the class MaterialUpdateServiceTest method setUp.

@Before
public void setUp() throws Exception {
    queue = mock(MaterialUpdateQueue.class);
    configQueue = mock(ConfigMaterialUpdateQueue.class);
    watchList = mock(GoConfigWatchList.class);
    completed = mock(MaterialUpdateCompletedTopic.class);
    goConfigService = mock(GoConfigService.class);
    postCommitHookMaterialType = mock(PostCommitHookMaterialTypeResolver.class);
    serverHealthService = mock(ServerHealthService.class);
    systemEnvironment = new SystemEnvironment();
    scmMaterialSource = mock(SCMMaterialSource.class);
    dependencyMaterialUpdateNotifier = mock(DependencyMaterialUpdateNotifier.class);
    materialConfigConverter = mock(MaterialConfigConverter.class);
    MDUPerformanceLogger mduPerformanceLogger = mock(MDUPerformanceLogger.class);
    dependencyMaterialUpdateQueue = mock(DependencyMaterialUpdateQueue.class);
    service = new MaterialUpdateService(queue, configQueue, completed, watchList, goConfigService, systemEnvironment, serverHealthService, postCommitHookMaterialType, mduPerformanceLogger, materialConfigConverter, dependencyMaterialUpdateQueue);
    service.registerMaterialSources(scmMaterialSource);
    service.registerMaterialUpdateCompleteListener(scmMaterialSource);
    service.registerMaterialUpdateCompleteListener(dependencyMaterialUpdateNotifier);
    HashSet<MaterialConfig> materialConfigs = new HashSet(Collections.singleton(MATERIAL_CONFIG));
    HashSet<Material> materials = new HashSet(Collections.singleton(svnMaterial));
    when(goConfigService.getSchedulableMaterials()).thenReturn(materialConfigs);
    when(materialConfigConverter.toMaterials(materialConfigs)).thenReturn(materials);
    username = new Username(new CaseInsensitiveString("loser"));
    result = new HttpLocalizedOperationResult();
    validMaterialType = mock(PostCommitHookMaterialType.class);
    when(validMaterialType.isKnown()).thenReturn(true);
    when(validMaterialType.isValid(anyString())).thenReturn(true);
    invalidMaterialType = mock(PostCommitHookMaterialType.class);
    when(invalidMaterialType.isKnown()).thenReturn(false);
    when(invalidMaterialType.isValid(anyString())).thenReturn(false);
}
Also used : MDUPerformanceLogger(com.thoughtworks.go.server.perf.MDUPerformanceLogger) 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) MaterialConfigConverter(com.thoughtworks.go.server.service.MaterialConfigConverter) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) MaterialConfig(com.thoughtworks.go.domain.materials.MaterialConfig) SvnMaterialConfig(com.thoughtworks.go.config.materials.svn.SvnMaterialConfig) PostCommitHookMaterialTypeResolver(com.thoughtworks.go.server.materials.postcommit.PostCommitHookMaterialTypeResolver) PostCommitHookMaterialType(com.thoughtworks.go.server.materials.postcommit.PostCommitHookMaterialType) Before(org.junit.Before)

Aggregations

DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)3 Material (com.thoughtworks.go.domain.materials.Material)3 PostCommitHookMaterialType (com.thoughtworks.go.server.materials.postcommit.PostCommitHookMaterialType)3 ScmMaterial (com.thoughtworks.go.config.materials.ScmMaterial)2 SvnMaterial (com.thoughtworks.go.config.materials.svn.SvnMaterial)2 PostCommitHookImplementer (com.thoughtworks.go.server.materials.postcommit.PostCommitHookImplementer)2 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)2 CruiseConfig (com.thoughtworks.go.config.CruiseConfig)1 SvnMaterialConfig (com.thoughtworks.go.config.materials.svn.SvnMaterialConfig)1 PipelineGroups (com.thoughtworks.go.domain.PipelineGroups)1 MaterialConfig (com.thoughtworks.go.domain.materials.MaterialConfig)1 Username (com.thoughtworks.go.server.domain.Username)1 PostCommitHookMaterialTypeResolver (com.thoughtworks.go.server.materials.postcommit.PostCommitHookMaterialTypeResolver)1 MDUPerformanceLogger (com.thoughtworks.go.server.perf.MDUPerformanceLogger)1 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)1 MaterialConfigConverter (com.thoughtworks.go.server.service.MaterialConfigConverter)1 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Before (org.junit.Before)1