Search in sources :

Example 1 with OctaneResultAbridged

use of com.hp.octane.integrations.dto.connectivity.OctaneResultAbridged in project octane-ci-java-sdk by MicroFocus.

the class TaskingServiceTests method testJobsNoParamsAPI.

@Test
public void testJobsNoParamsAPI() {
    TasksProcessor tasksProcessor = client.getTasksProcessor();
    Assert.assertNotNull(tasksProcessor);
    OctaneTaskAbridged taskAbridged = dtoFactory.newDTO(OctaneTaskAbridged.class).setId(UUID.randomUUID().toString()).setUrl(OctaneSPEndpointSimulator.getSimulatorUrl() + APIPrefix + "/jobs?parameters=false");
    OctaneResultAbridged resultAbridged = tasksProcessor.execute(taskAbridged);
    runCommonAsserts(resultAbridged, taskAbridged.getId(), HttpStatus.SC_OK);
    CIJobsList ciJobsList = dtoFactory.dtoFromJson(resultAbridged.getBody(), CIJobsList.class);
    Assert.assertNotNull(ciJobsList);
    Assert.assertNotNull(ciJobsList.getJobs());
    Assert.assertEquals(3, ciJobsList.getJobs().length);
    for (PipelineNode ciJob : ciJobsList.getJobs()) {
        Assert.assertNotNull(ciJob);
        Assert.assertTrue(ciJob.getName().startsWith("Job "));
        Assert.assertTrue(ciJob.getJobCiId().startsWith("job-"));
        Assert.assertNotNull(ciJob.getParameters());
        Assert.assertTrue(ciJob.getParameters().isEmpty());
    }
}
Also used : CIJobsList(com.hp.octane.integrations.dto.general.CIJobsList) OctaneResultAbridged(com.hp.octane.integrations.dto.connectivity.OctaneResultAbridged) PipelineNode(com.hp.octane.integrations.dto.pipelines.PipelineNode) OctaneTaskAbridged(com.hp.octane.integrations.dto.connectivity.OctaneTaskAbridged) Test(org.junit.Test)

Example 2 with OctaneResultAbridged

use of com.hp.octane.integrations.dto.connectivity.OctaneResultAbridged in project octane-ci-java-sdk by MicroFocus.

the class TaskingServiceTests method testJobsWithParamsAPI.

@Test
public void testJobsWithParamsAPI() {
    TasksProcessor tasksProcessor = client.getTasksProcessor();
    Assert.assertNotNull(tasksProcessor);
    OctaneTaskAbridged taskAbridged = dtoFactory.newDTO(OctaneTaskAbridged.class).setId(UUID.randomUUID().toString()).setUrl(OctaneSPEndpointSimulator.getSimulatorUrl() + APIPrefix + "/jobs");
    OctaneResultAbridged resultAbridged = tasksProcessor.execute(taskAbridged);
    runCommonAsserts(resultAbridged, taskAbridged.getId(), HttpStatus.SC_OK);
    CIJobsList ciJobsList = dtoFactory.dtoFromJson(resultAbridged.getBody(), CIJobsList.class);
    Assert.assertNotNull(ciJobsList);
    Assert.assertNotNull(ciJobsList.getJobs());
    Assert.assertEquals(3, ciJobsList.getJobs().length);
    for (PipelineNode ciJob : ciJobsList.getJobs()) {
        Assert.assertNotNull(ciJob);
        Assert.assertTrue(ciJob.getName().startsWith("Job "));
        Assert.assertTrue(ciJob.getJobCiId().startsWith("job-"));
        Assert.assertNotNull(ciJob.getParameters());
        Assert.assertEquals(3, ciJob.getParameters().size());
        for (CIParameter ciParameter : ciJob.getParameters()) {
            Assert.assertNotNull(ciParameter);
            Assert.assertNotNull(ciParameter.getName());
            Assert.assertNotNull(ciParameter.getType());
            Assert.assertNotNull(ciParameter.getValue());
        }
    }
}
Also used : CIJobsList(com.hp.octane.integrations.dto.general.CIJobsList) OctaneResultAbridged(com.hp.octane.integrations.dto.connectivity.OctaneResultAbridged) PipelineNode(com.hp.octane.integrations.dto.pipelines.PipelineNode) OctaneTaskAbridged(com.hp.octane.integrations.dto.connectivity.OctaneTaskAbridged) CIParameter(com.hp.octane.integrations.dto.parameters.CIParameter) Test(org.junit.Test)

Example 3 with OctaneResultAbridged

use of com.hp.octane.integrations.dto.connectivity.OctaneResultAbridged 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 4 with OctaneResultAbridged

use of com.hp.octane.integrations.dto.connectivity.OctaneResultAbridged in project octane-ci-java-sdk by MicroFocus.

the class TaskingServiceE2ETests method taskingE2ETest.

@Test
public void taskingE2ETest() {
    OctaneTaskAbridged task;
    // push task 1 - status
    String statusTaskId = UUID.randomUUID().toString();
    task = dtoFactory.newDTO(OctaneTaskAbridged.class).setId(statusTaskId).setServiceId(inId).setUrl(OctaneSPEndpointSimulator.getSimulatorUrl() + APIPrefix + "/status");
    tasks.add(task);
    // push task 2 - jobs list
    String jobsTaskId = UUID.randomUUID().toString();
    task = dtoFactory.newDTO(OctaneTaskAbridged.class).setId(jobsTaskId).setServiceId(inId).setUrl(OctaneSPEndpointSimulator.getSimulatorUrl() + APIPrefix + "/jobs");
    tasks.add(task);
    // wait for at least 2 tasks to arrive in results map
    GeneralTestUtils.waitAtMostFor(10000, () -> {
        if (results.size() < 3) {
            return null;
        } else {
            return true;
        }
    });
    // verify status task cycle
    Assert.assertTrue(results.containsKey(statusTaskId));
    OctaneResultAbridged statusResult = results.get(statusTaskId);
    Assert.assertNotNull(statusResult);
    Assert.assertEquals(inId, statusResult.getServiceId());
    Assert.assertEquals(HttpStatus.SC_OK, statusResult.getStatus());
    // verify jobs task cycle
    Assert.assertTrue(results.containsKey(jobsTaskId));
    OctaneResultAbridged jobsResult = results.get(jobsTaskId);
    Assert.assertNotNull(jobsResult);
    Assert.assertEquals(inId, jobsResult.getServiceId());
    Assert.assertEquals(HttpStatus.SC_OK, jobsResult.getStatus());
}
Also used : OctaneResultAbridged(com.hp.octane.integrations.dto.connectivity.OctaneResultAbridged) OctaneTaskAbridged(com.hp.octane.integrations.dto.connectivity.OctaneTaskAbridged) Test(org.junit.Test)

Example 5 with OctaneResultAbridged

use of com.hp.octane.integrations.dto.connectivity.OctaneResultAbridged in project octane-ci-java-sdk by MicroFocus.

the class TaskingServiceTests method testNonExistingAPI.

@Test
public void testNonExistingAPI() {
    TasksProcessor tasksProcessor = client.getTasksProcessor();
    Assert.assertNotNull(tasksProcessor);
    OctaneTaskAbridged taskAbridged = dtoFactory.newDTO(OctaneTaskAbridged.class).setId(UUID.randomUUID().toString()).setUrl(OctaneSPEndpointSimulator.getSimulatorUrl() + APIPrefix + "/some/non/existing/url");
    OctaneResultAbridged resultAbridged = tasksProcessor.execute(taskAbridged);
    Assert.assertNotNull(resultAbridged);
    Assert.assertEquals(HttpStatus.SC_NOT_FOUND, resultAbridged.getStatus());
    Assert.assertNotNull(resultAbridged.getHeaders());
    Assert.assertTrue(resultAbridged.getHeaders().isEmpty());
    Assert.assertEquals(taskAbridged.getId(), resultAbridged.getId());
    Assert.assertEquals(client.getInstanceId(), resultAbridged.getServiceId());
    Assert.assertNull(resultAbridged.getBody());
}
Also used : OctaneResultAbridged(com.hp.octane.integrations.dto.connectivity.OctaneResultAbridged) OctaneTaskAbridged(com.hp.octane.integrations.dto.connectivity.OctaneTaskAbridged) Test(org.junit.Test)

Aggregations

OctaneResultAbridged (com.hp.octane.integrations.dto.connectivity.OctaneResultAbridged)11 OctaneTaskAbridged (com.hp.octane.integrations.dto.connectivity.OctaneTaskAbridged)11 Test (org.junit.Test)10 PipelineNode (com.hp.octane.integrations.dto.pipelines.PipelineNode)3 CIJobsList (com.hp.octane.integrations.dto.general.CIJobsList)2 TaskProcessingErrorBody (com.hp.octane.integrations.dto.connectivity.TaskProcessingErrorBody)1 CIParameter (com.hp.octane.integrations.dto.parameters.CIParameter)1 OctaneSPEndpointSimulator (com.hp.octane.integrations.testhelpers.OctaneSPEndpointSimulator)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 Response (org.eclipse.jetty.server.Response)1