Search in sources :

Example 1 with OctaneClient

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

the class SSCIntegrationTest method runAsQueueItem.

public void runAsQueueItem() {
    try {
        // 
        // I
        // add one client and verify it works okay
        // 
        OctaneConfiguration configA = new OctaneConfigurationIntern(clientAInstanceId, OctaneSPEndpointSimulator.getSimulatorUrl(), spIdA);
        OctaneClient clientA = OctaneSDK.addClient(configA, VulnerabilitiesServicePluginServicesTest.class);
        VulnerabilitiesService vulnerabilitiesServiceA = clientA.getVulnerabilitiesService();
        vulnerabilitiesServiceA.enqueueRetrieveAndPushVulnerabilities("jobSSC1", "1", ToolType.SSC, System.currentTimeMillis(), 1, null, null);
        if (expectedOutput.expectNoPsuh) {
            CIPluginSDKUtils.doWait(2000);
        } else {
            GeneralTestUtils.waitAtMostFor(12000, () -> {
                if (pushVulnerabilitiesCollectors.get(spIdA) != null && pushVulnerabilitiesCollectors.get(spIdA).size() == 1) {
                    return true;
                } else {
                    return null;
                }
            });
        }
        Assert.assertEquals(clientAInstanceId + "|jobSSC1|1", preFlightRequestCollectors.get(spIdA).get(0));
        // 
        // III
        // remove one client and verify it is shut indeed and the second continue to work okay
        // 
        OctaneSDK.removeClient(clientA);
    } finally {
        // remove clients
        OctaneSDK.getClients().forEach(OctaneSDK::removeClient);
        // remove simulators
        if (simulators != null)
            removeSPEPSimulators(simulators.values());
    }
}
Also used : OctaneClient(com.hp.octane.integrations.OctaneClient) OctaneConfiguration(com.hp.octane.integrations.OctaneConfiguration) OctaneSDK(com.hp.octane.integrations.OctaneSDK) OctaneConfigurationIntern(com.hp.octane.integrations.OctaneConfigurationIntern)

Example 2 with OctaneClient

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

the class VulnerabilitiesServiceFunctionalityTest method testVulnerabilitiesFunctional.

@Test(timeout = 20000)
public void testVulnerabilitiesFunctional() {
    Map<String, OctaneSPEndpointSimulator> simulators = null;
    try {
        String spIdA = UUID.randomUUID().toString();
        String spIdB = UUID.randomUUID().toString();
        String clientAInstanceId = UUID.randomUUID().toString();
        String clientBInstanceId = UUID.randomUUID().toString();
        Map<String, List<String>> preflightRequestCollectors = new LinkedHashMap<>();
        Map<String, List<String>> pushVulnerabilitiesCollectors = new LinkedHashMap<>();
        // init 2 shared space endpoints simulators
        simulators = initSPEPSimulators(Stream.of(spIdA, spIdB).collect(Collectors.toSet()), preflightRequestCollectors, pushVulnerabilitiesCollectors);
        // 
        // I
        // add one client and verify it works okay
        // 
        OctaneConfiguration configA = new OctaneConfigurationIntern(clientAInstanceId, OctaneSPEndpointSimulator.getSimulatorUrl(), spIdA);
        OctaneClient clientA = OctaneSDK.addClient(configA, VulnerabilitiesServicePluginServicesTest.class);
        VulnerabilitiesService vulnerabilitiesServiceA = clientA.getVulnerabilitiesService();
        Assert.assertFalse(preflightRequestCollectors.containsKey(spIdA));
        Assert.assertFalse(preflightRequestCollectors.containsKey(spIdB));
        // 
        // II
        // add one more client and verify they are both works okay
        // 
        OctaneConfiguration configB = new OctaneConfigurationIntern(clientBInstanceId, OctaneSPEndpointSimulator.getSimulatorUrl(), spIdB);
        OctaneClient clientB = OctaneSDK.addClient(configB, VulnerabilitiesServicePluginServicesTest.class);
        VulnerabilitiesService vulnerabilitiesServiceB = clientB.getVulnerabilitiesService();
        vulnerabilitiesServiceA.enqueueRetrieveAndPushVulnerabilities("job-preflight-true", "1", ToolType.SSC, System.currentTimeMillis(), 1, null, null);
        vulnerabilitiesServiceA.enqueueRetrieveAndPushVulnerabilities("job-preflight-false", "1", ToolType.SSC, System.currentTimeMillis(), 1, null, null);
        vulnerabilitiesServiceB.enqueueRetrieveAndPushVulnerabilities("job-preflight-true", "1", ToolType.SSC, System.currentTimeMillis(), 1, null, null);
        vulnerabilitiesServiceB.enqueueRetrieveAndPushVulnerabilities("job-preflight-false", "1", ToolType.SSC, System.currentTimeMillis(), 1, null, null);
        GeneralTestUtils.waitAtMostFor(12000, () -> {
            if (preflightRequestCollectors.get(spIdA) != null && preflightRequestCollectors.get(spIdA).size() == 2 && preflightRequestCollectors.get(spIdB) != null && preflightRequestCollectors.get(spIdB).size() == 2) {
                return true;
            } else {
                return null;
            }
        });
        Assert.assertEquals(clientAInstanceId + "|job-preflight-true|1", preflightRequestCollectors.get(spIdA).get(0));
        Assert.assertEquals(clientAInstanceId + "|job-preflight-false|1", preflightRequestCollectors.get(spIdA).get(1));
        Assert.assertEquals(clientBInstanceId + "|job-preflight-true|1", preflightRequestCollectors.get(spIdB).get(0));
        Assert.assertEquals(clientBInstanceId + "|job-preflight-false|1", preflightRequestCollectors.get(spIdB).get(1));
        // 
        // III
        // remove one client and verify it is shut indeed and the second continue to work okay
        // 
        OctaneSDK.removeClient(clientA);
        // 
        // IV
        // remove second client and ensure no interactions anymore
        // 
        OctaneSDK.removeClient(clientB);
    } finally {
        // remove clients
        OctaneSDK.getClients().forEach(OctaneSDK::removeClient);
        // remove simulators
        if (simulators != null)
            removeSPEPSimulators(simulators.values());
        SSCServerSimulator.instance().endSimulation();
    }
}
Also used : OctaneClient(com.hp.octane.integrations.OctaneClient) OctaneConfiguration(com.hp.octane.integrations.OctaneConfiguration) LinkedList(java.util.LinkedList) List(java.util.List) OctaneSDK(com.hp.octane.integrations.OctaneSDK) OctaneConfigurationIntern(com.hp.octane.integrations.OctaneConfigurationIntern) OctaneSPEndpointSimulator(com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 3 with OctaneClient

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

the class VulnerabilitiesServiceFunctionalityTest method testVulnerabilitiesFunctionalSSC.

@Test(timeout = 20000)
public void testVulnerabilitiesFunctionalSSC() {
    Map<String, OctaneSPEndpointSimulator> simulators = null;
    try {
        String spIdA = UUID.randomUUID().toString();
        String clientAInstanceId = UUID.randomUUID().toString();
        Map<String, List<String>> preflightRequestCollectors = new LinkedHashMap<>();
        Map<String, List<String>> pushVulnerabilitiesCollectors = new LinkedHashMap<>();
        simulators = initSPEPSimulatorsForSSC(Stream.of(spIdA).collect(Collectors.toSet()), preflightRequestCollectors, pushVulnerabilitiesCollectors);
        // 
        // I
        // add one client and verify it works okay
        // 
        OctaneConfiguration configA = new OctaneConfigurationIntern(clientAInstanceId, OctaneSPEndpointSimulator.getSimulatorUrl(), spIdA);
        OctaneClient clientA = OctaneSDK.addClient(configA, VulnerabilitiesServicePluginServicesTest.class);
        VulnerabilitiesService vulnerabilitiesServiceA = clientA.getVulnerabilitiesService();
        prepareSSCSimulator();
        vulnerabilitiesServiceA.enqueueRetrieveAndPushVulnerabilities("jobSSC1", "1", ToolType.SSC, System.currentTimeMillis(), 1, null, null);
        GeneralTestUtils.waitAtMostFor(12000, () -> {
            if (preflightRequestCollectors.get(spIdA) != null && preflightRequestCollectors.get(spIdA).size() == 1) {
                return true;
            } else {
                return null;
            }
        });
        Assert.assertEquals(clientAInstanceId + "|jobSSC1|1", preflightRequestCollectors.get(spIdA).get(0));
        OctaneSDK.removeClient(clientA);
    } finally {
        // remove clients
        OctaneSDK.getClients().forEach(OctaneSDK::removeClient);
        // remove simulators
        if (simulators != null)
            removeSPEPSimulators(simulators.values());
        SSCServerSimulator.instance().endSimulation();
    }
}
Also used : OctaneClient(com.hp.octane.integrations.OctaneClient) OctaneConfiguration(com.hp.octane.integrations.OctaneConfiguration) LinkedList(java.util.LinkedList) List(java.util.List) OctaneSDK(com.hp.octane.integrations.OctaneSDK) OctaneConfigurationIntern(com.hp.octane.integrations.OctaneConfigurationIntern) OctaneSPEndpointSimulator(com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 4 with OctaneClient

use of com.hp.octane.integrations.OctaneClient 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 5 with OctaneClient

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

the class MfMBTConverter method handleMbtDataRetrieval.

private void handleMbtDataRetrieval(List<TestToRunData> tests, Map<String, String> globalParameters) {
    if (shouldRetrieveMbtData(tests)) {
        OctaneClient octaneClient = OctaneSDK.getClientByInstanceId(globalParameters.get(OCTANE_CONFIG_ID_PARAMETER_NAME));
        OctaneConfiguration octaneConfig = octaneClient.getConfigurationService().getConfiguration();
        String url = octaneConfig.getUrl() + "/api" + "/shared_spaces/" + octaneConfig.getSharedSpace() + "/workspaces/" + globalParameters.get(OCTANE_WORKSPACE_PARAMETER_NAME) + "/suite_runs/" + globalParameters.get(SUITE_RUN_ID_PARAMETER_NAME) + "/get_suite_data";
        Map<String, String> headers = new HashMap<>();
        headers.put(ACCEPT_HEADER, ContentType.APPLICATION_JSON.getMimeType());
        headers.put(OctaneRestClient.CLIENT_TYPE_HEADER, OctaneRestClient.CLIENT_TYPE_VALUE);
        OctaneRequest request = DTOFactory.getInstance().newDTO(OctaneRequest.class).setMethod(HttpMethod.GET).setHeaders(headers).setUrl(url);
        try {
            OctaneResponse octaneResponse = octaneClient.getRestService().obtainOctaneRestClient().execute(request);
            if (octaneResponse != null && octaneResponse.getStatus() == HttpStatus.SC_OK) {
                Map<String, String> parsedResponse = parseSuiteRunDataJson(octaneResponse.getBody());
                if (parsedResponse != null) {
                    for (TestToRunData test : tests) {
                        String runID = test.getParameter(INNER_RUN_ID_PARAMETER);
                        test.addParameters(MBT_DATA, parsedResponse.get(runID));
                    }
                }
            } else {
                logger.error("Failed to get response {}", (octaneResponse != null ? octaneResponse.getStatus() : "(null)"));
                return;
            }
        } catch (IOException e) {
            logger.error("Failed to get response ", e);
            return;
        }
    }
}
Also used : OctaneClient(com.hp.octane.integrations.OctaneClient) OctaneConfiguration(com.hp.octane.integrations.OctaneConfiguration) OctaneResponse(com.hp.octane.integrations.dto.connectivity.OctaneResponse) OctaneRequest(com.hp.octane.integrations.dto.connectivity.OctaneRequest) TestToRunData(com.hp.octane.integrations.executor.TestToRunData)

Aggregations

OctaneClient (com.hp.octane.integrations.OctaneClient)6 OctaneConfiguration (com.hp.octane.integrations.OctaneConfiguration)5 OctaneSDK (com.hp.octane.integrations.OctaneSDK)4 OctaneConfigurationIntern (com.hp.octane.integrations.OctaneConfigurationIntern)3 OctaneSPEndpointSimulator (com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator)3 Test (org.junit.Test)3 LinkedHashMap (java.util.LinkedHashMap)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 DTOFactory (com.hp.octane.integrations.dto.DTOFactory)1 CIEventCause (com.hp.octane.integrations.dto.causes.CIEventCause)1 CIEventCauseType (com.hp.octane.integrations.dto.causes.CIEventCauseType)1 OctaneRequest (com.hp.octane.integrations.dto.connectivity.OctaneRequest)1 OctaneResponse (com.hp.octane.integrations.dto.connectivity.OctaneResponse)1 CoverageReportType (com.hp.octane.integrations.dto.coverage.CoverageReportType)1 CIEvent (com.hp.octane.integrations.dto.events.CIEvent)1 CIEventType (com.hp.octane.integrations.dto.events.CIEventType)1 CIEventsList (com.hp.octane.integrations.dto.events.CIEventsList)1 SCMData (com.hp.octane.integrations.dto.scm.SCMData)1 SCMRepository (com.hp.octane.integrations.dto.scm.SCMRepository)1