Search in sources :

Example 11 with OctaneConfiguration

use of com.hp.octane.integrations.OctaneConfiguration 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

OctaneConfiguration (com.hp.octane.integrations.OctaneConfiguration)11 OctaneConfigurationIntern (com.hp.octane.integrations.OctaneConfigurationIntern)6 OctaneClient (com.hp.octane.integrations.OctaneClient)5 OctaneSDK (com.hp.octane.integrations.OctaneSDK)4 OctaneSPEndpointSimulator (com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator)4 IOException (java.io.IOException)3 BeforeClass (org.junit.BeforeClass)3 Test (org.junit.Test)3 OctaneRequest (com.hp.octane.integrations.dto.connectivity.OctaneRequest)2 OctaneResponse (com.hp.octane.integrations.dto.connectivity.OctaneResponse)2 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 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