Search in sources :

Example 1 with BuildDriverResultRest

use of org.jboss.pnc.bpm.model.BuildDriverResultRest in project pnc by project-ncl.

the class BuildResultMapper method toDTO.

public BuildResultRest toDTO(BuildResult buildResult) {
    CompletionStatus completionStatus = buildResult.getCompletionStatus();
    ProcessException processException = buildResult.getProcessException().orElse(null);
    String processLog = buildResult.getProcessLog();
    BuildExecutionConfigurationRest buildExecutionConfiguration;
    if (buildResult.getBuildExecutionConfiguration().isPresent()) {
        BuildExecutionConfiguration bec = buildResult.getBuildExecutionConfiguration().get();
        buildExecutionConfiguration = new BuildExecutionConfigurationRest(bec);
    } else {
        buildExecutionConfiguration = null;
    }
    BuildDriverResultRest buildDriverResult;
    if (buildResult.getBuildDriverResult().isPresent()) {
        BuildDriverResult result = buildResult.getBuildDriverResult().get();
        buildDriverResult = new BuildDriverResultRest(result);
    } else {
        buildDriverResult = null;
    }
    RepositoryManagerResultRest repositoryManagerResult;
    if (buildResult.getRepositoryManagerResult().isPresent()) {
        RepositoryManagerResult result = buildResult.getRepositoryManagerResult().get();
        repositoryManagerResult = repositoryManagerResultMapper.toDTO(result);
    } else {
        repositoryManagerResult = null;
    }
    EnvironmentDriverResult environmentDriverResult;
    if (buildResult.getEnvironmentDriverResult().isPresent()) {
        environmentDriverResult = buildResult.getEnvironmentDriverResult().get();
    } else {
        environmentDriverResult = null;
    }
    RepourResult repourResult = buildResult.getRepourResult().orElse(null);
    return new BuildResultRest(completionStatus, processException, processLog, buildExecutionConfiguration, buildDriverResult, repositoryManagerResult, environmentDriverResult, repourResult);
}
Also used : BuildResultRest(org.jboss.pnc.bpm.model.BuildResultRest) ProcessException(org.jboss.pnc.spi.coordinator.ProcessException) BuildExecutionConfiguration(org.jboss.pnc.spi.executor.BuildExecutionConfiguration) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) RepositoryManagerResultRest(org.jboss.pnc.bpm.model.RepositoryManagerResultRest) EnvironmentDriverResult(org.jboss.pnc.spi.environment.EnvironmentDriverResult) CompletionStatus(org.jboss.pnc.spi.coordinator.CompletionStatus) RepositoryManagerResult(org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult) BuildExecutionConfigurationRest(org.jboss.pnc.bpm.model.BuildExecutionConfigurationRest) RepourResult(org.jboss.pnc.spi.repour.RepourResult) BuildDriverResultRest(org.jboss.pnc.bpm.model.BuildDriverResultRest)

Example 2 with BuildDriverResultRest

use of org.jboss.pnc.bpm.model.BuildDriverResultRest in project pnc by project-ncl.

the class BuildTaskEndpointTest method shouldAcceptCompletionResultAsSingleJson.

@Test
public void shouldAcceptCompletionResultAsSingleJson() throws RemoteResourceException {
    // given
    BuildDriverResult buildDriverResult = new DefaultBuildDriverResult("The log!", BuildStatus.SYSTEM_ERROR, java.util.Optional.of("12345"));
    BuildDriverResultRest buildDriverResultRest = new BuildDriverResultRest(buildDriverResult);
    BuildResultRest buildResultRest = new BuildResultRest();
    buildResultRest.setBuildDriverResult(buildDriverResultRest);
    // when
    HttpPost request = new HttpPost(url + BASE_REST_PATH + "/build-tasks/42/completed");
    request.addHeader(Credentials.USER.createAuthHeader(BasicHeader::new));
    request.addHeader("Content-type", MediaType.APPLICATION_JSON);
    String jsonBody = JsonOutputConverterMapper.apply(buildResultRest);
    log.debug("Json body: {}.", jsonBody);
    request.setEntity(new StringEntity(jsonBody, ContentType.APPLICATION_JSON));
    // then
    int statusCode = -1;
    try (CloseableHttpClient httpClient = HttpUtils.getPermissiveHttpClient()) {
        try (CloseableHttpResponse response = httpClient.execute(request)) {
            statusCode = response.getStatusLine().getStatusCode();
            Assert.assertEquals("Received error response code. Response: " + printEntity(response), // validation failure is expected; 500 when deserialization fails
            400, statusCode);
        }
    } catch (IOException e) {
        Assertions.fail("Cannot invoke remote endpoint.", e);
    }
}
Also used : BuildResultRest(org.jboss.pnc.bpm.model.BuildResultRest) HttpPost(org.apache.http.client.methods.HttpPost) StringEntity(org.apache.http.entity.StringEntity) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) DefaultBuildDriverResult(org.jboss.pnc.termdbuilddriver.DefaultBuildDriverResult) BuildDriverResult(org.jboss.pnc.spi.builddriver.BuildDriverResult) DefaultBuildDriverResult(org.jboss.pnc.termdbuilddriver.DefaultBuildDriverResult) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) IOException(java.io.IOException) BuildDriverResultRest(org.jboss.pnc.bpm.model.BuildDriverResultRest) ContainerTest(org.jboss.pnc.test.category.ContainerTest) Test(org.junit.Test)

Aggregations

BuildDriverResultRest (org.jboss.pnc.bpm.model.BuildDriverResultRest)2 BuildResultRest (org.jboss.pnc.bpm.model.BuildResultRest)2 BuildDriverResult (org.jboss.pnc.spi.builddriver.BuildDriverResult)2 IOException (java.io.IOException)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpPost (org.apache.http.client.methods.HttpPost)1 StringEntity (org.apache.http.entity.StringEntity)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 BuildExecutionConfigurationRest (org.jboss.pnc.bpm.model.BuildExecutionConfigurationRest)1 RepositoryManagerResultRest (org.jboss.pnc.bpm.model.RepositoryManagerResultRest)1 CompletionStatus (org.jboss.pnc.spi.coordinator.CompletionStatus)1 ProcessException (org.jboss.pnc.spi.coordinator.ProcessException)1 EnvironmentDriverResult (org.jboss.pnc.spi.environment.EnvironmentDriverResult)1 BuildExecutionConfiguration (org.jboss.pnc.spi.executor.BuildExecutionConfiguration)1 RepositoryManagerResult (org.jboss.pnc.spi.repositorymanager.RepositoryManagerResult)1 RepourResult (org.jboss.pnc.spi.repour.RepourResult)1 DefaultBuildDriverResult (org.jboss.pnc.termdbuilddriver.DefaultBuildDriverResult)1 ContainerTest (org.jboss.pnc.test.category.ContainerTest)1 Test (org.junit.Test)1