Search in sources :

Example 6 with OctaneSPEndpointSimulator

use of com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator in project octane-ci-java-sdk by MicroFocus.

the class TaskingServiceE2ETests method setupEnvironment.

@BeforeClass
public static void setupEnvironment() {
    // setup Octane simulator
    OctaneSPEndpointSimulator octaneSPEndpointSimulator = setupOctaneEPSimulator(sspId);
    Assert.assertNotNull(octaneSPEndpointSimulator);
    // setup Octane client
    OctaneConfiguration configuration = new OctaneConfigurationIntern(inId, OctaneSPEndpointSimulator.getSimulatorUrl(), sspId);
    client = OctaneSDK.addClient(configuration, TaskingTestPluginServicesTest.class);
}
Also used : OctaneConfiguration(com.hp.octane.integrations.OctaneConfiguration) OctaneConfigurationIntern(com.hp.octane.integrations.OctaneConfigurationIntern) OctaneSPEndpointSimulator(com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator) BeforeClass(org.junit.BeforeClass)

Example 7 with OctaneSPEndpointSimulator

use of com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator in project octane-ci-java-sdk by MicroFocus.

the class TaskingServiceE2ETests method setupOctaneEPSimulator.

private static OctaneSPEndpointSimulator setupOctaneEPSimulator(String sspId) {
    OctaneSPEndpointSimulator result = OctaneSPEndpointSimulator.addInstance(sspId);
    // remove default NOOP GET tasks API handler
    result.removeApiHandler(HttpMethod.GET, "^.*tasks$");
    // install GET tasks API handler
    result.installApiHandler(HttpMethod.GET, "^.*tasks$", request -> {
        try {
            Response response = request.getResponse();
            OctaneTaskAbridged task = tasks.poll(500, TimeUnit.MILLISECONDS);
            if (task != null) {
                logger.info("got task to dispatch to CI Server - " + task.getUrl() + " - " + task.getId() + "...");
                response.setStatus(HttpStatus.SC_OK);
                response.addHeader(CONTENT_TYPE, "application/json");
                response.getWriter().write(dtoFactory.dtoCollectionToJson(Collections.singletonList(task)));
                response.flushBuffer();
                logger.info("... task dispatched");
            } else {
                results.put("timeout_flow_verification_part", null);
                response.setStatus(HttpStatus.SC_REQUEST_TIMEOUT);
            }
        } catch (Exception e) {
            logger.error("failed during simulation of Octane EP - GET tasks", e);
        }
    });
    // install PUT results API handler
    result.installApiHandler(HttpMethod.PUT, "^.*result$", request -> {
        try {
            String rawBody = CIPluginSDKUtils.inputStreamToUTF8String(new GZIPInputStream(request.getInputStream()));
            OctaneResultAbridged taskResult = dtoFactory.dtoFromJson(rawBody, OctaneResultAbridged.class);
            logger.info("received and parsed result for task " + taskResult.getId());
            Assert.assertNotNull(taskResult);
            Assert.assertNotNull(taskResult.getId());
            results.put(taskResult.getId(), taskResult);
        } catch (Exception e) {
            logger.error("failed during simulation of Octane EP - PUT results", e);
        }
    });
    return result;
}
Also used : Response(org.eclipse.jetty.server.Response) GZIPInputStream(java.util.zip.GZIPInputStream) OctaneResultAbridged(com.hp.octane.integrations.dto.connectivity.OctaneResultAbridged) OctaneSPEndpointSimulator(com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator) OctaneTaskAbridged(com.hp.octane.integrations.dto.connectivity.OctaneTaskAbridged)

Example 8 with OctaneSPEndpointSimulator

use of com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator 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)

Example 9 with OctaneSPEndpointSimulator

use of com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator in project octane-ci-java-sdk by MicroFocus.

the class OctaneSDKBasicFunctionalityTest method testE2EFunctional.

@Test(timeout = 60000)
public void testE2EFunctional() throws ExecutionException, InterruptedException {
    Map<String, OctaneSPEndpointSimulator> simulators = null;
    Map<String, List<CIEventsList>> eventsCollectors = new LinkedHashMap<>();
    Map<String, List<TestsResult>> testResultsCollectors = new LinkedHashMap<>();
    Map<String, List<String>> logsCollectors = new LinkedHashMap<>();
    Map<String, List<String>> coverageCollectors = new LinkedHashMap<>();
    OctaneClient clientA = null;
    try {
        String spIdA = UUID.randomUUID().toString();
        String spIdB = UUID.randomUUID().toString();
        String clientAInstanceId = UUID.randomUUID().toString();
        String clientBInstanceId = UUID.randomUUID().toString();
        // init 2 shared space endpoints simulators
        simulators = initSPEPSimulators(Stream.of(spIdA, spIdB).collect(Collectors.toSet()), eventsCollectors, testResultsCollectors, logsCollectors, coverageCollectors);
        // 
        // I
        // add one client and verify it works okay
        // 
        System.out.println("Scenario 1 - add one client and verify it works okay");
        clientA = OctaneSDK.addClient(new OctaneConfigurationBasicFunctionalityTest(clientAInstanceId, OctaneSPEndpointSimulator.getSimulatorUrl(), spIdA, "client_SP_A", "secret_SP_A"), PluginServicesBasicFunctionalityTest.class);
        clientA.getConfigurationService().addToOctaneRootsCache("job-a");
        clientA.getConfigurationService().getOctaneConnectivityStatus();
        simulateEventsCycleAllClients();
        simulatePushTestResultsCycleAllClients();
        simulatePushLogsCycleAllClients();
        simulatePushCoverageAllClients();
        // validate events
        GeneralTestUtils.waitAtMostFor(10000, () -> {
            if (eventsCollectors.containsKey(spIdA) && eventsCollectors.get(spIdA).stream().mapToInt(cil -> cil.getEvents().size()).sum() == 3) {
                eventsCollectors.get(spIdA).forEach(cil -> {
                    Assert.assertNotNull(cil);
                    Assert.assertNotNull(cil.getServer());
                    Assert.assertEquals(clientAInstanceId, cil.getServer().getInstanceId());
                    Assert.assertEquals("custom", cil.getServer().getType());
                    Assert.assertEquals("1.1.1", cil.getServer().getVersion());
                    Assert.assertEquals("http://localhost:9999", cil.getServer().getUrl());
                });
                // TODO: add deeper verification
                return true;
            } else {
                return null;
            }
        });
        // validate tests
        GeneralTestUtils.waitAtMostFor(5000, () -> {
            if (testResultsCollectors.containsKey(spIdA) && testResultsCollectors.get(spIdA).size() == 1) {
                // TODO: add deeper verification
                return true;
            } else {
                return null;
            }
        });
        // validate logs
        GeneralTestUtils.waitAtMostFor(5000, () -> {
            if (logsCollectors.containsKey(spIdA) && logsCollectors.get(spIdA).size() == 1) {
                // TODO: add deeper verification
                return true;
            } else {
                return null;
            }
        });
        // validate coverage
        GeneralTestUtils.waitAtMostFor(5000, () -> {
            if (coverageCollectors.containsKey(spIdA) && coverageCollectors.get(spIdA).size() == 2) {
                // TODO: add deeper verification
                return true;
            } else {
                return null;
            }
        });
        // 
        // II
        // add one more client and verify they are both works okay
        // 
        System.out.println("Scenario 2 - add one more client and verify they are both works okay");
        OctaneClient clientB = OctaneSDK.addClient(new OctaneConfigurationBasicFunctionalityTest(clientBInstanceId, OctaneSPEndpointSimulator.getSimulatorUrl(), spIdB, "client_SP_B", "secret_SP_B"), PluginServicesBasicFunctionalityTest.class);
        clientB.getConfigurationService().addToOctaneRootsCache("job-a");
        clientB.getConfigurationService().getOctaneConnectivityStatus();
        eventsCollectors.get(spIdA).clear();
        testResultsCollectors.get(spIdA).clear();
        logsCollectors.get(spIdA).clear();
        coverageCollectors.get(spIdA).clear();
        simulateEventsCycleAllClients();
        simulatePushTestResultsCycleAllClients();
        simulatePushLogsCycleAllClients();
        simulatePushCoverageAllClients();
        // validate events
        GeneralTestUtils.waitAtMostFor(5000, () -> {
            if (eventsCollectors.containsKey(spIdA) && eventsCollectors.get(spIdA).stream().mapToInt(cil -> cil.getEvents().size()).sum() == 3 && eventsCollectors.containsKey(spIdB) && eventsCollectors.get(spIdA).stream().mapToInt(cil -> cil.getEvents().size()).sum() == 3) {
                // client A
                eventsCollectors.get(spIdA).forEach(cil -> {
                    Assert.assertNotNull(cil);
                    Assert.assertNotNull(cil.getServer());
                    Assert.assertEquals(clientAInstanceId, cil.getServer().getInstanceId());
                    Assert.assertEquals("custom", cil.getServer().getType());
                    Assert.assertEquals("1.1.1", cil.getServer().getVersion());
                    Assert.assertEquals("http://localhost:9999", cil.getServer().getUrl());
                });
                // client B
                eventsCollectors.get(spIdB).forEach(cil -> {
                    Assert.assertNotNull(cil);
                    Assert.assertNotNull(cil.getServer());
                    Assert.assertEquals(clientBInstanceId, cil.getServer().getInstanceId());
                    Assert.assertEquals("custom", cil.getServer().getType());
                    Assert.assertEquals("1.1.1", cil.getServer().getVersion());
                    Assert.assertEquals("http://localhost:9999", cil.getServer().getUrl());
                });
                // TODO: add deeper verification
                return true;
            } else {
                return null;
            }
        });
        // validate tests
        GeneralTestUtils.waitAtMostFor(5000, () -> {
            if (testResultsCollectors.containsKey(spIdA) && testResultsCollectors.get(spIdA).size() == 1 && testResultsCollectors.containsKey(spIdB) && testResultsCollectors.get(spIdB).size() == 1) {
                // TODO: add deeper verification
                return true;
            } else {
                return null;
            }
        });
        // validate logs
        GeneralTestUtils.waitAtMostFor(5000, () -> {
            if (logsCollectors.containsKey(spIdA) && logsCollectors.get(spIdA).size() == 1 && logsCollectors.containsKey(spIdB) && logsCollectors.get(spIdB).size() == 1) {
                // TODO: add deeper verification
                return true;
            } else {
                return null;
            }
        });
        // validate coverages
        GeneralTestUtils.waitAtMostFor(5000, () -> {
            if (coverageCollectors.containsKey(spIdA) && coverageCollectors.get(spIdA).size() == 2 && coverageCollectors.containsKey(spIdB) && coverageCollectors.get(spIdB).size() == 2) {
                // TODO: add deeper verification
                return true;
            } else {
                return null;
            }
        });
        // 
        // III
        // remove one client and verify it is shut indeed and the second continue to work okay
        // 
        System.out.println("Scenario 3 - remove one client and verify it is shut indeed and the second continue to work okay");
        OctaneSDK.removeClient(clientA);
        eventsCollectors.get(spIdA).clear();
        eventsCollectors.get(spIdB).clear();
        testResultsCollectors.get(spIdA).clear();
        testResultsCollectors.get(spIdB).clear();
        logsCollectors.get(spIdA).clear();
        logsCollectors.get(spIdB).clear();
        coverageCollectors.get(spIdA).clear();
        coverageCollectors.get(spIdB).clear();
        simulateEventsCycleAllClients();
        simulatePushTestResultsCycleAllClients();
        simulatePushLogsCycleAllClients();
        simulatePushCoverageAllClients();
        // validate events
        GeneralTestUtils.waitAtMostFor(5000, () -> {
            if (eventsCollectors.containsKey(spIdB) && eventsCollectors.get(spIdB).stream().mapToInt(cil -> cil.getEvents().size()).sum() == 3) {
                Assert.assertTrue(eventsCollectors.get(spIdA).isEmpty());
                eventsCollectors.get(spIdB).forEach(cil -> {
                    Assert.assertNotNull(cil);
                    Assert.assertNotNull(cil.getServer());
                    Assert.assertEquals(clientBInstanceId, cil.getServer().getInstanceId());
                    Assert.assertEquals("custom", cil.getServer().getType());
                    Assert.assertEquals("1.1.1", cil.getServer().getVersion());
                    Assert.assertEquals("http://localhost:9999", cil.getServer().getUrl());
                });
                // TODO: add deeper verification
                return true;
            } else {
                return null;
            }
        });
        // validate tests
        GeneralTestUtils.waitAtMostFor(5000, () -> {
            if (testResultsCollectors.containsKey(spIdB) && testResultsCollectors.get(spIdB).size() == 1) {
                Assert.assertTrue(testResultsCollectors.get(spIdA).isEmpty());
                // TODO: add deeper verification
                return true;
            } else {
                return null;
            }
        });
        // validate logs
        GeneralTestUtils.waitAtMostFor(5000, () -> {
            if (logsCollectors.containsKey(spIdB) && logsCollectors.get(spIdB).size() == 1) {
                Assert.assertTrue(logsCollectors.get(spIdA).isEmpty());
                // TODO: add deeper verification
                return true;
            } else {
                return null;
            }
        });
        // validate coverages
        GeneralTestUtils.waitAtMostFor(5000, () -> {
            if (coverageCollectors.containsKey(spIdB) && coverageCollectors.get(spIdB).size() == 2) {
                Assert.assertTrue(coverageCollectors.get(spIdA).isEmpty());
                // TODO: add deeper verification
                return true;
            } else {
                return null;
            }
        });
        // 
        // IV
        // remove second client and ensure no interactions anymore
        // 
        System.out.println("Scenario 4 - remove second client and ensure no interactions anymore");
        OctaneSDK.removeClient(clientB);
        eventsCollectors.get(spIdB).clear();
        testResultsCollectors.get(spIdB).clear();
        logsCollectors.get(spIdB).clear();
        coverageCollectors.get(spIdB).clear();
        // events, tests, logs
        simulateEventsCycleAllClients();
        simulatePushTestResultsCycleAllClients();
        simulatePushLogsCycleAllClients();
        simulatePushCoverageAllClients();
        CIPluginSDKUtils.doWait(4000);
        Assert.assertTrue(eventsCollectors.get(spIdA).isEmpty());
        Assert.assertTrue(eventsCollectors.get(spIdB).isEmpty());
        Assert.assertTrue(testResultsCollectors.get(spIdA).isEmpty());
        Assert.assertTrue(testResultsCollectors.get(spIdB).isEmpty());
        Assert.assertTrue(logsCollectors.get(spIdA).isEmpty());
        Assert.assertTrue(logsCollectors.get(spIdB).isEmpty());
        Assert.assertTrue(coverageCollectors.get(spIdA).isEmpty());
        Assert.assertTrue(coverageCollectors.get(spIdB).isEmpty());
        // 
        // V
        // add clientA in with deactivated Mode
        // 
        System.out.println("Scenario 5 - add clientA in with deactivated Mode");
        clientA = OctaneSDK.addClient(new OctaneConfigurationBasicFunctionalityTest(clientAInstanceId, OctaneSPEndpointSimulator.getSimulatorUrl(), spIdA, "client_SP_A", "secret_SP_A"), PluginServicesBasicFunctionalityTest.class);
        clientA.getConfigurationService().getConfiguration().setSuspended(true);
        clientA.getConfigurationService().getOctaneConnectivityStatus();
        simulateEventsCycleAllClients();
        simulatePushTestResultsCycleAllClients();
        simulatePushLogsCycleAllClients();
        simulatePushCoverageAllClients();
        CIPluginSDKUtils.doWait(4000);
        Assert.assertTrue(eventsCollectors.get(spIdA).isEmpty());
        Assert.assertTrue(eventsCollectors.get(spIdB).isEmpty());
        Assert.assertTrue(testResultsCollectors.get(spIdA).isEmpty());
        Assert.assertTrue(testResultsCollectors.get(spIdB).isEmpty());
        Assert.assertTrue(logsCollectors.get(spIdA).isEmpty());
        Assert.assertTrue(logsCollectors.get(spIdB).isEmpty());
        Assert.assertTrue(coverageCollectors.get(spIdA).isEmpty());
        Assert.assertTrue(coverageCollectors.get(spIdB).isEmpty());
        OctaneSDK.removeClient(clientA);
        // 
        // 6
        // add client with parameter OCTANE_ROOTS_CACHE_ALLOWED=true with no pipeline root
        // 
        System.out.println("Scenario 6 - add client with parameter OCTANE_ROOTS_CACHE_ALLOWED=true with no pipeline root");
        OctaneConfiguration tempConf = new OctaneConfigurationBasicFunctionalityTest(clientAInstanceId, OctaneSPEndpointSimulator.getSimulatorUrl(), spIdA, "client_SP_A", "secret_SP_A");
        ConfigurationParameterFactory.addParameter(tempConf, "OCTANE_ROOTS_CACHE_ALLOWED", "true");
        clientA = OctaneSDK.addClient(tempConf, PluginServicesBasicFunctionalityTest.class);
        clientA.getConfigurationService().getOctaneConnectivityStatus();
        simulateEventsCycleAllClients();
        simulatePushTestResultsCycleAllClients();
        simulatePushLogsCycleAllClients();
        simulatePushCoverageAllClients();
        CIPluginSDKUtils.doWait(4000);
        Assert.assertTrue(eventsCollectors.get(spIdA).isEmpty());
        Assert.assertTrue(eventsCollectors.get(spIdB).isEmpty());
        Assert.assertTrue(testResultsCollectors.get(spIdA).isEmpty());
        Assert.assertTrue(testResultsCollectors.get(spIdB).isEmpty());
        Assert.assertTrue(logsCollectors.get(spIdA).isEmpty());
        Assert.assertTrue(logsCollectors.get(spIdB).isEmpty());
        Assert.assertTrue(coverageCollectors.get(spIdA).isEmpty());
        Assert.assertTrue(coverageCollectors.get(spIdB).isEmpty());
        // 
        // 7
        // add client with parameter OCTANE_ROOTS_CACHE_ALLOWED=true with one root
        // 
        System.out.println("Scenario 7 - add client with parameter OCTANE_ROOTS_CACHE_ALLOWED=true with one root");
        clientA.getConfigurationService().addToOctaneRootsCache("job-a");
        simulateEventsCycleAllClients();
        simulatePushTestResultsCycleAllClients();
        simulatePushLogsCycleAllClients();
        simulatePushCoverageAllClients();
        CIPluginSDKUtils.doWait(4000);
        // validate events
        GeneralTestUtils.waitAtMostFor(5000, () -> {
            if (eventsCollectors.containsKey(spIdA) && eventsCollectors.get(spIdA).stream().mapToInt(cil -> cil.getEvents().size()).sum() == 3) {
                eventsCollectors.get(spIdA).forEach(cil -> {
                    Assert.assertNotNull(cil);
                    Assert.assertNotNull(cil.getServer());
                    Assert.assertEquals(clientAInstanceId, cil.getServer().getInstanceId());
                    Assert.assertEquals("custom", cil.getServer().getType());
                    Assert.assertEquals("1.1.1", cil.getServer().getVersion());
                    Assert.assertEquals("http://localhost:9999", cil.getServer().getUrl());
                });
                // TODO: add deeper verification
                return true;
            } else {
                return null;
            }
        });
        // validate tests
        GeneralTestUtils.waitAtMostFor(5000, () -> {
            if (testResultsCollectors.containsKey(spIdA) && testResultsCollectors.get(spIdA).size() == 1) {
                // TODO: add deeper verification
                return true;
            } else {
                return null;
            }
        });
        // validate logs
        GeneralTestUtils.waitAtMostFor(5000, () -> {
            if (logsCollectors.containsKey(spIdA) && logsCollectors.get(spIdA).size() == 1) {
                // TODO: add deeper verification
                return true;
            } else {
                return null;
            }
        });
        // validate coverage
        GeneralTestUtils.waitAtMostFor(5000, () -> {
            if (coverageCollectors.containsKey(spIdA) && coverageCollectors.get(spIdA).size() == 2) {
                // TODO: add deeper verification
                return true;
            } else {
                return null;
            }
        });
    } finally {
        // remove clients
        OctaneSDK.getClients().forEach(OctaneSDK::removeClient);
        // remove simulators
        if (simulators != null)
            removeSPEPSimulators(simulators.values());
    }
}
Also used : java.util(java.util) GZIPInputStream(java.util.zip.GZIPInputStream) ConfigurationService(com.hp.octane.integrations.services.configuration.ConfigurationService) CIEventsList(com.hp.octane.integrations.dto.events.CIEventsList) HttpStatus(org.apache.http.HttpStatus) GeneralTestUtils(com.hp.octane.integrations.testhelpers.GeneralTestUtils) CIPluginSDKUtils(com.hp.octane.integrations.utils.CIPluginSDKUtils) OctaneSDK(com.hp.octane.integrations.OctaneSDK) CoverageReportType(com.hp.octane.integrations.dto.coverage.CoverageReportType) DTOFactory(com.hp.octane.integrations.dto.DTOFactory) CIEventCauseType(com.hp.octane.integrations.dto.causes.CIEventCauseType) SCMData(com.hp.octane.integrations.dto.scm.SCMData) TestsResult(com.hp.octane.integrations.dto.tests.TestsResult) OctaneClient(com.hp.octane.integrations.OctaneClient) HttpServletResponse(javax.servlet.http.HttpServletResponse) SCMRepository(com.hp.octane.integrations.dto.scm.SCMRepository) Test(org.junit.Test) IOException(java.io.IOException) CIEvent(com.hp.octane.integrations.dto.events.CIEvent) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) SCMType(com.hp.octane.integrations.dto.scm.SCMType) HttpMethod(org.eclipse.jetty.http.HttpMethod) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) OctaneConfiguration(com.hp.octane.integrations.OctaneConfiguration) CIEventCause(com.hp.octane.integrations.dto.causes.CIEventCause) OctaneSPEndpointSimulator(com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator) Assert(org.junit.Assert) ConfigurationParameterFactory(com.hp.octane.integrations.services.configurationparameters.factory.ConfigurationParameterFactory) LogManager(org.apache.logging.log4j.LogManager) CIEventType(com.hp.octane.integrations.dto.events.CIEventType) OctaneClient(com.hp.octane.integrations.OctaneClient) OctaneConfiguration(com.hp.octane.integrations.OctaneConfiguration) OctaneSDK(com.hp.octane.integrations.OctaneSDK) OctaneSPEndpointSimulator(com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator) CIEventsList(com.hp.octane.integrations.dto.events.CIEventsList) Test(org.junit.Test)

Example 10 with OctaneSPEndpointSimulator

use of com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator in project octane-ci-java-sdk by MicroFocus.

the class OctaneSDKTestConfigurationTests method testA1.

@Test
public void testA1() throws IOException {
    String spId = "1001";
    OctaneSPEndpointSimulator simulator = OctaneSPEndpointSimulator.addInstance(spId);
    simulator.installApiHandler(HttpMethod.GET, "^.*/analytics/ci/servers/connectivity/status$", request -> {
        request.getResponse().setStatus(HttpServletResponse.SC_OK);
        try {
            request.getResponse().getWriter().write("{}");
            request.getResponse().flushBuffer();
        } catch (IOException ioe) {
            logger.error("failed to process status request in MOCK server", ioe);
        }
    });
    simulator.installApiHandler(HttpMethod.GET, "^.*/workspaces?.*$", request -> {
        request.getResponse().setStatus(HttpServletResponse.SC_OK);
        try {
            request.getResponse().getWriter().write("{\"total_count\":1,\"data\":[{\"type\":\"workspace\",\"id\":\"1002\"}],\"exceeds_total_count\":false}");
            request.getResponse().flushBuffer();
        } catch (IOException ioe) {
            logger.error("failed to process status request in MOCK server", ioe);
        }
    });
    OctaneSDK.testOctaneConfigurationAndFetchAvailableWorkspaces(OctaneSPEndpointSimulator.getSimulatorUrl(), spId, "client", "secret", PluginServices.class);
    OctaneSPEndpointSimulator.removeInstance(spId);
}
Also used : IOException(java.io.IOException) OctaneSPEndpointSimulator(com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator) Test(org.junit.Test)

Aggregations

OctaneSPEndpointSimulator (com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator)10 OctaneConfiguration (com.hp.octane.integrations.OctaneConfiguration)8 OctaneClient (com.hp.octane.integrations.OctaneClient)7 OctaneSDK (com.hp.octane.integrations.OctaneSDK)7 Test (org.junit.Test)7 OctaneConfigurationIntern (com.hp.octane.integrations.OctaneConfigurationIntern)6 IOException (java.io.IOException)6 GZIPInputStream (java.util.zip.GZIPInputStream)6 GeneralTestUtils (com.hp.octane.integrations.testhelpers.GeneralTestUtils)5 CIPluginSDKUtils (com.hp.octane.integrations.utils.CIPluginSDKUtils)5 java.util (java.util)5 Collectors (java.util.stream.Collectors)5 Stream (java.util.stream.Stream)5 HttpStatus (org.apache.http.HttpStatus)5 LogManager (org.apache.logging.log4j.LogManager)5 Logger (org.apache.logging.log4j.Logger)5 HttpMethod (org.eclipse.jetty.http.HttpMethod)5 Assert (org.junit.Assert)5 LinkedHashMap (java.util.LinkedHashMap)4 LinkedList (java.util.LinkedList)4