Search in sources :

Example 1 with OctaneSDKGeneralException

use of com.hp.octane.integrations.exceptions.OctaneSDKGeneralException in project octane-ci-java-sdk by MicroFocus.

the class SSCIntegrationTest method initSPEPSimulatorsForSSC.

private Map<String, OctaneSPEndpointSimulator> initSPEPSimulatorsForSSC(Set<String> spIDs, Map<String, List<String>> preflightRequestsCollectors, Map<String, List<String>> pushRequestCollectors) {
    Map<String, OctaneSPEndpointSimulator> result = new LinkedHashMap<>();
    for (String spID : spIDs) {
        OctaneSPEndpointSimulator simulator = OctaneSPEndpointSimulator.addInstance(spID);
        // vulnerabilities preflight API
        simulator.installApiHandler(HttpMethod.GET, "^.*/vulnerabilities/preflight$", request -> {
            try {
                // retrieve query parameters
                request.mergeQueryParameters("", request.getQueryString(), false);
                preflightRequestsCollectors.computeIfAbsent(spID, sid -> new LinkedList<>()).add(request.getQueryParameters().getString("instance-id") + "|" + request.getQueryParameters().getString("job-ci-id") + "|" + request.getQueryParameters().getString("build-ci-id"));
                request.getResponse().setStatus(HttpStatus.SC_OK);
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat(DateUtils.octaneFormat);
                request.getResponse().getWriter().write(getOctaneInput().baseline == null ? "true" : simpleDateFormat.format(getOctaneInput().baseline));
                request.getResponse().getWriter().flush();
            } catch (IOException ioe) {
                throw new OctaneSDKGeneralException("failed to write response", ioe);
            }
        });
        // vulnerabilities push API
        simulator.installApiHandler(HttpMethod.POST, "^.*/vulnerabilities$", request -> {
            try {
                String rawVulnerabilitiesBody = CIPluginSDKUtils.inputStreamToUTF8String(new GZIPInputStream(request.getInputStream()));
                pushRequestCollectors.computeIfAbsent(spID, sid -> new LinkedList<>()).add(rawVulnerabilitiesBody);
                request.getResponse().setStatus(HttpStatus.SC_ACCEPTED);
                request.getResponse().getWriter().write("{\"status\": \"queued\"}");
                request.getResponse().getWriter().flush();
            } catch (IOException ioe) {
                throw new OctaneSDKGeneralException("failed to write response", ioe);
            }
        });
        // vulnerabilities push API
        simulator.installApiHandler(HttpMethod.GET, "^.*/vulnerabilities/remote-issue-ids.*", request -> {
            try {
                request.getResponse().setStatus(HttpStatus.SC_OK);
                request.getResponse().getWriter().write(SSCTestUtils.getJson(this.getOctaneInput().remoteIds));
                request.getResponse().getWriter().flush();
            } catch (IOException ioe) {
                throw new OctaneSDKGeneralException("failed to write response", ioe);
            }
        });
        result.put(spID, simulator);
    }
    return result;
}
Also used : java.util(java.util) GZIPInputStream(java.util.zip.GZIPInputStream) OctaneSDKGeneralException(com.hp.octane.integrations.exceptions.OctaneSDKGeneralException) HttpStatus(org.apache.http.HttpStatus) SimpleDateFormat(java.text.SimpleDateFormat) IOException(java.io.IOException) GeneralTestUtils(com.hp.octane.integrations.testhelpers.GeneralTestUtils) CIPluginSDKUtils(com.hp.octane.integrations.utils.CIPluginSDKUtils) Collectors(java.util.stream.Collectors) SSCServerSimulator(com.hp.octane.integrations.testhelpers.SSCServerSimulator) HttpMethod(org.eclipse.jetty.http.HttpMethod) OctaneSDK(com.hp.octane.integrations.OctaneSDK) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) OctaneConfiguration(com.hp.octane.integrations.OctaneConfiguration) OctaneConfigurationIntern(com.hp.octane.integrations.OctaneConfigurationIntern) OctaneSPEndpointSimulator(com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator) Assert(org.junit.Assert) LogManager(org.apache.logging.log4j.LogManager) OctaneClient(com.hp.octane.integrations.OctaneClient) GZIPInputStream(java.util.zip.GZIPInputStream) OctaneSDKGeneralException(com.hp.octane.integrations.exceptions.OctaneSDKGeneralException) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) OctaneSPEndpointSimulator(com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator)

Example 2 with OctaneSDKGeneralException

use of com.hp.octane.integrations.exceptions.OctaneSDKGeneralException in project octane-ci-java-sdk by MicroFocus.

the class VulnerabilitiesServiceFunctionalityTest method initSPEPSimulatorsForSSC.

private Map<String, OctaneSPEndpointSimulator> initSPEPSimulatorsForSSC(Set<String> spIDs, Map<String, List<String>> preflightRequestsCollectors, Map<String, List<String>> pushRequestCollectors) {
    Map<String, OctaneSPEndpointSimulator> result = new LinkedHashMap<>();
    for (String spID : spIDs) {
        OctaneSPEndpointSimulator simulator = OctaneSPEndpointSimulator.addInstance(spID);
        // vulnerabilities preflight API
        simulator.installApiHandler(HttpMethod.GET, "^.*/vulnerabilities/preflight$", request -> {
            try {
                // retrieve query parameters
                request.mergeQueryParameters("", request.getQueryString(), false);
                preflightRequestsCollectors.computeIfAbsent(spID, sid -> new LinkedList<>()).add(request.getQueryParameters().getString("instance-id") + "|" + request.getQueryParameters().getString("job-ci-id") + "|" + request.getQueryParameters().getString("build-ci-id"));
                request.getResponse().setStatus(HttpStatus.SC_OK);
                request.getResponse().getWriter().write("true");
                request.getResponse().getWriter().flush();
            } catch (IOException ioe) {
                throw new OctaneSDKGeneralException("failed to write response", ioe);
            }
        });
        // vulnerabilities push API
        simulator.installApiHandler(HttpMethod.POST, "^.*/vulnerabilities$", request -> {
            try {
                String rawVulnerabilitiesBody = CIPluginSDKUtils.inputStreamToUTF8String(new GZIPInputStream(request.getInputStream()));
                pushRequestCollectors.computeIfAbsent(spID, sid -> new LinkedList<>()).add(rawVulnerabilitiesBody);
                request.getResponse().setStatus(HttpStatus.SC_ACCEPTED);
                request.getResponse().getWriter().write("{\"status\": \"queued\"}");
                request.getResponse().getWriter().flush();
            } catch (IOException ioe) {
                throw new OctaneSDKGeneralException("failed to write response", ioe);
            }
        });
        result.put(spID, simulator);
    }
    return result;
}
Also used : java.util(java.util) GZIPInputStream(java.util.zip.GZIPInputStream) HttpStatus(org.apache.http.HttpStatus) SimpleDateFormat(java.text.SimpleDateFormat) GeneralTestUtils(com.hp.octane.integrations.testhelpers.GeneralTestUtils) CIPluginSDKUtils(com.hp.octane.integrations.utils.CIPluginSDKUtils) SSCServerSimulator(com.hp.octane.integrations.testhelpers.SSCServerSimulator) LinkedHashMap(java.util.LinkedHashMap) OctaneSDK(com.hp.octane.integrations.OctaneSDK) Issues(com.hp.octane.integrations.services.vulnerabilities.ssc.dto.Issues) Map(java.util.Map) LinkedList(java.util.LinkedList) OctaneClient(com.hp.octane.integrations.OctaneClient) DateFormat(java.text.DateFormat) Collection(java.util.Collection) OctaneSDKGeneralException(com.hp.octane.integrations.exceptions.OctaneSDKGeneralException) Set(java.util.Set) Test(org.junit.Test) IOException(java.io.IOException) com.hp.octane.integrations.services.vulnerabilities.ssc(com.hp.octane.integrations.services.vulnerabilities.ssc) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) HttpMethod(org.eclipse.jetty.http.HttpMethod) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) OctaneConfiguration(com.hp.octane.integrations.OctaneConfiguration) OctaneConfigurationIntern(com.hp.octane.integrations.OctaneConfigurationIntern) OctaneSPEndpointSimulator(com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator) Assert(org.junit.Assert) LogManager(org.apache.logging.log4j.LogManager) GZIPInputStream(java.util.zip.GZIPInputStream) OctaneSDKGeneralException(com.hp.octane.integrations.exceptions.OctaneSDKGeneralException) IOException(java.io.IOException) OctaneSPEndpointSimulator(com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with OctaneSDKGeneralException

use of com.hp.octane.integrations.exceptions.OctaneSDKGeneralException in project octane-ci-java-sdk by MicroFocus.

the class VulnerabilitiesServiceFunctionalityTest method initSPEPSimulators.

private Map<String, OctaneSPEndpointSimulator> initSPEPSimulators(Set<String> spIDs, Map<String, List<String>> preflightRequestsCollectors, Map<String, List<String>> pushRequestCollectors) {
    Map<String, OctaneSPEndpointSimulator> result = new LinkedHashMap<>();
    for (String spID : spIDs) {
        OctaneSPEndpointSimulator simulator = OctaneSPEndpointSimulator.addInstance(spID);
        // vulnerabilities preflight API
        simulator.installApiHandler(HttpMethod.GET, "^.*/vulnerabilities/preflight$", request -> {
            try {
                // retrieve query parameters
                request.mergeQueryParameters("", request.getQueryString(), false);
                preflightRequestsCollectors.computeIfAbsent(spID, sid -> new LinkedList<>()).add(request.getQueryParameters().getString("instance-id") + "|" + request.getQueryParameters().getString("job-ci-id") + "|" + request.getQueryParameters().getString("build-ci-id"));
                request.getResponse().setStatus(HttpStatus.SC_OK);
                request.getResponse().getWriter().write(request.getQueryParameters().getString("job-ci-id").contains("true") ? "true" : "false");
                request.getResponse().getWriter().flush();
            } catch (IOException ioe) {
                throw new OctaneSDKGeneralException("failed to write response", ioe);
            }
        });
        // vulnerabilities push API
        simulator.installApiHandler(HttpMethod.POST, "^.*/vulnerabilities$", request -> {
            try {
                String rawVulnerabilitiesBody = CIPluginSDKUtils.inputStreamToUTF8String(new GZIPInputStream(request.getInputStream()));
                pushRequestCollectors.computeIfAbsent(spID, sid -> new LinkedList<>()).add(rawVulnerabilitiesBody);
                request.getResponse().setStatus(HttpStatus.SC_ACCEPTED);
                request.getResponse().getWriter().write("{\"status\": \"queued\"}");
                request.getResponse().getWriter().flush();
            } catch (IOException ioe) {
                throw new OctaneSDKGeneralException("failed to write response", ioe);
            }
        });
        result.put(spID, simulator);
    }
    return result;
}
Also used : java.util(java.util) GZIPInputStream(java.util.zip.GZIPInputStream) HttpStatus(org.apache.http.HttpStatus) SimpleDateFormat(java.text.SimpleDateFormat) GeneralTestUtils(com.hp.octane.integrations.testhelpers.GeneralTestUtils) CIPluginSDKUtils(com.hp.octane.integrations.utils.CIPluginSDKUtils) SSCServerSimulator(com.hp.octane.integrations.testhelpers.SSCServerSimulator) LinkedHashMap(java.util.LinkedHashMap) OctaneSDK(com.hp.octane.integrations.OctaneSDK) Issues(com.hp.octane.integrations.services.vulnerabilities.ssc.dto.Issues) Map(java.util.Map) LinkedList(java.util.LinkedList) OctaneClient(com.hp.octane.integrations.OctaneClient) DateFormat(java.text.DateFormat) Collection(java.util.Collection) OctaneSDKGeneralException(com.hp.octane.integrations.exceptions.OctaneSDKGeneralException) Set(java.util.Set) Test(org.junit.Test) IOException(java.io.IOException) com.hp.octane.integrations.services.vulnerabilities.ssc(com.hp.octane.integrations.services.vulnerabilities.ssc) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) HttpMethod(org.eclipse.jetty.http.HttpMethod) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) OctaneConfiguration(com.hp.octane.integrations.OctaneConfiguration) OctaneConfigurationIntern(com.hp.octane.integrations.OctaneConfigurationIntern) OctaneSPEndpointSimulator(com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator) Assert(org.junit.Assert) LogManager(org.apache.logging.log4j.LogManager) GZIPInputStream(java.util.zip.GZIPInputStream) OctaneSDKGeneralException(com.hp.octane.integrations.exceptions.OctaneSDKGeneralException) IOException(java.io.IOException) OctaneSPEndpointSimulator(com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

OctaneClient (com.hp.octane.integrations.OctaneClient)3 OctaneConfiguration (com.hp.octane.integrations.OctaneConfiguration)3 OctaneConfigurationIntern (com.hp.octane.integrations.OctaneConfigurationIntern)3 OctaneSDK (com.hp.octane.integrations.OctaneSDK)3 OctaneSDKGeneralException (com.hp.octane.integrations.exceptions.OctaneSDKGeneralException)3 GeneralTestUtils (com.hp.octane.integrations.testhelpers.GeneralTestUtils)3 OctaneSPEndpointSimulator (com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator)3 SSCServerSimulator (com.hp.octane.integrations.testhelpers.SSCServerSimulator)3 CIPluginSDKUtils (com.hp.octane.integrations.utils.CIPluginSDKUtils)3 IOException (java.io.IOException)3 SimpleDateFormat (java.text.SimpleDateFormat)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3 GZIPInputStream (java.util.zip.GZIPInputStream)3 HttpStatus (org.apache.http.HttpStatus)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 HttpMethod (org.eclipse.jetty.http.HttpMethod)3 Assert (org.junit.Assert)3