Search in sources :

Example 1 with AnalyzeDeliverablesTask

use of org.jboss.pnc.bpm.task.AnalyzeDeliverablesTask in project pnc by project-ncl.

the class RestConnectorRequestSerializationTest method mockAnalyzeDeliverablesTask.

private AnalyzeDeliverablesTask mockAnalyzeDeliverablesTask() {
    String url1 = "http://hello.com";
    String url2 = "http://world.com";
    List<String> urls = new ArrayList<>();
    urls.add(url1);
    urls.add(url2);
    String operationId = Sequence.nextBase32Id();
    AnalyzeDeliverablesBpmRequest request = new AnalyzeDeliverablesBpmRequest(operationId, "id", urls);
    List<Request.Header> headers = new ArrayList<>();
    headers.add(new Request.Header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON));
    Request callback = new Request(Request.Method.POST, URI.create("http://mock.com/"), headers);
    AnalyzeDeliverablesTask task = new AnalyzeDeliverablesTask(request, callback);
    return task;
}
Also used : AnalyzeDeliverablesTask(org.jboss.pnc.bpm.task.AnalyzeDeliverablesTask) ArrayList(java.util.ArrayList) AnalyzeDeliverablesBpmRequest(org.jboss.pnc.bpm.model.AnalyzeDeliverablesBpmRequest) LoggedRequest(com.github.tomakehurst.wiremock.verification.LoggedRequest) Request(org.jboss.pnc.api.dto.Request) AnalyzeDeliverablesBpmRequest(org.jboss.pnc.bpm.model.AnalyzeDeliverablesBpmRequest)

Example 2 with AnalyzeDeliverablesTask

use of org.jboss.pnc.bpm.task.AnalyzeDeliverablesTask in project pnc by project-ncl.

the class RestConnectorRequestSerializationTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    // with
    AnalyzeDeliverablesTask task = mockAnalyzeDeliverablesTask();
    MDC.put(MDCKeys.REQUEST_CONTEXT_KEY, "Hello");
    // when
    connector.startProcess("analyzer", task, task.getRequest().getOperationId(), "accessToken");
    // then
    verify(postRequestedFor(urlMatching(".*/analyzer/.*")));
    List<LoggedRequest> requests = findAll(postRequestedFor(urlMatching(".*/analyzer/.*")));
    assertThat(requests.size()).isOne();
    JsonNode body = JsonOutputConverterMapper.getMapper().readTree(requests.get(0).getBodyAsString());
    assertThat(body.get("initData")).isNotNull();
    assertThat(body.get("initData").get("mdc")).isNotNull();
    assertThat(body.get("initData").get("mdc").get(MDCKeys.REQUEST_CONTEXT_KEY)).isNotNull();
    assertThat(body.get("initData").get("mdc").get(MDCKeys.REQUEST_CONTEXT_KEY).textValue()).isNotNull().isEqualTo("Hello");
    assertThat(body.get("initData").get("task")).isNotNull();
    assertThat(body.get("initData").get("task").get("request")).isNotNull();
    assertThat(body.get("initData").get("task").get("request").get("urls")).isNotEmpty();
    assertThat(body.get("initData").get("task").get("request").get("operationId").toString()).isNotEmpty();
    assertThat(body.get("initData").get("task").get("callback")).isNotNull();
}
Also used : LoggedRequest(com.github.tomakehurst.wiremock.verification.LoggedRequest) AnalyzeDeliverablesTask(org.jboss.pnc.bpm.task.AnalyzeDeliverablesTask) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.Test)

Example 3 with AnalyzeDeliverablesTask

use of org.jboss.pnc.bpm.task.AnalyzeDeliverablesTask in project pnc by project-ncl.

the class DeliverableAnalyzerManagerImpl method startAnalysis.

private void startAnalysis(String milestoneId, List<String> sourcesLink, Base32LongID operationId) {
    Request callback = operationsManager.getOperationCallback(operationId);
    String id = operationId.getId();
    try (RestConnector restConnector = new RestConnector(bpmConfig)) {
        AnalyzeDeliverablesBpmRequest bpmRequest = new AnalyzeDeliverablesBpmRequest(id, milestoneId, sourcesLink);
        AnalyzeDeliverablesTask analyzeTask = new AnalyzeDeliverablesTask(bpmRequest, callback);
        restConnector.startProcess(bpmConfig.getAnalyzeDeliverablesBpmProcessId(), analyzeTask, id, userService.currentUserToken());
        DeliverableAnalysisStatusChangedEvent analysisStatusChanged = DefaultDeliverableAnalysisStatusChangedEvent.started(id, milestoneId, sourcesLink);
        analysisStatusChangedEventNotifier.fire(analysisStatusChanged);
    } catch (ProcessManagerException e) {
        log.error("Error trying to start analysis of deliverables task for milestone: {}", milestoneId, e);
        throw new RuntimeException(e);
    }
}
Also used : RestConnector(org.jboss.pnc.bpm.RestConnector) ProcessManagerException(org.jboss.pnc.spi.exception.ProcessManagerException) AnalyzeDeliverablesTask(org.jboss.pnc.bpm.task.AnalyzeDeliverablesTask) AnalyzeDeliverablesBpmRequest(org.jboss.pnc.bpm.model.AnalyzeDeliverablesBpmRequest) Request(org.jboss.pnc.api.dto.Request) AnalyzeDeliverablesBpmRequest(org.jboss.pnc.bpm.model.AnalyzeDeliverablesBpmRequest)

Aggregations

AnalyzeDeliverablesTask (org.jboss.pnc.bpm.task.AnalyzeDeliverablesTask)3 LoggedRequest (com.github.tomakehurst.wiremock.verification.LoggedRequest)2 Request (org.jboss.pnc.api.dto.Request)2 AnalyzeDeliverablesBpmRequest (org.jboss.pnc.bpm.model.AnalyzeDeliverablesBpmRequest)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayList (java.util.ArrayList)1 RestConnector (org.jboss.pnc.bpm.RestConnector)1 ProcessManagerException (org.jboss.pnc.spi.exception.ProcessManagerException)1 Test (org.junit.Test)1