Search in sources :

Example 1 with Response

use of com.synopsys.integration.rest.response.Response in project hub-alert by blackducksoftware.

the class DockerTagRetriever method getTagResponseModel.

private DockerTagsResponseModel getTagResponseModel(String pageUrl) {
    HttpUrl httpUrl;
    try {
        httpUrl = new HttpUrl(pageUrl);
    } catch (IntegrationException e) {
        logger.warn("Invalid url: " + pageUrl);
        return DockerTagsResponseModel.EMPTY;
    }
    Request dockerTagsRequest = new Request.Builder(httpUrl).build();
    try (Response tagsResponse = intHttpClient.execute(dockerTagsRequest)) {
        tagsResponse.throwExceptionForError();
        return gson.fromJson(tagsResponse.getContentString(), DockerTagsResponseModel.class);
    } catch (IOException | IntegrationException e) {
        logger.warn("Could not get docker tags from {}: {}", pageUrl, e.getMessage());
    }
    return DockerTagsResponseModel.EMPTY;
}
Also used : Response(com.synopsys.integration.rest.response.Response) IntegrationException(com.synopsys.integration.exception.IntegrationException) Request(com.synopsys.integration.rest.request.Request) IOException(java.io.IOException) HttpUrl(com.synopsys.integration.rest.HttpUrl)

Example 2 with Response

use of com.synopsys.integration.rest.response.Response in project hub-alert by blackducksoftware.

the class RestChannelUtility method sendGenericRequest.

private Response sendGenericRequest(Request request) throws IntegrationException {
    Response response = intHttpClient.execute(request);
    logger.trace("Response: {}", response);
    return response;
}
Also used : Response(com.synopsys.integration.rest.response.Response)

Example 3 with Response

use of com.synopsys.integration.rest.response.Response in project hub-alert by blackducksoftware.

the class DockerTagRetrieverTest method getTagsModelTest.

@Test
public void getTagsModelTest() throws IntegrationException {
    IntHttpClient intHttpClient = Mockito.mock(IntHttpClient.class);
    Response mockResponse = createMockResponse();
    Mockito.when(intHttpClient.execute(Mockito.any(Request.class))).thenReturn(mockResponse);
    DockerTagRetriever dockerTagRetriever = new DockerTagRetriever(gson, intHttpClient);
    DockerTagsResponseModel tagsModel = dockerTagRetriever.getTagsModel();
    assertEquals(TAGS_COUNT, tagsModel.getCount());
    assertEquals(TAGS_COUNT, tagsModel.getResults().size());
}
Also used : Response(com.synopsys.integration.rest.response.Response) DockerTagsResponseModel(com.synopsys.integration.alert.update.model.DockerTagsResponseModel) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) Request(com.synopsys.integration.rest.request.Request) Test(org.junit.jupiter.api.Test)

Example 4 with Response

use of com.synopsys.integration.rest.response.Response in project hub-alert by blackducksoftware.

the class DockerTagRetrieverTest method createMockResponse.

private Response createMockResponse() throws IntegrationException {
    Response mockResponse = Mockito.mock(Response.class);
    List<DockerTagModel> tagModels = List.of(createDockerTagModel("1.0.0"), createDockerTagModel("1.0.1"));
    DockerTagsResponseModel mockDockerTagsResponseModel = new DockerTagsResponseModel(TAGS_COUNT, null, null, tagModels);
    String jsonString = gson.toJson(mockDockerTagsResponseModel);
    Mockito.when(mockResponse.getContentString()).thenReturn(jsonString);
    Mockito.doNothing().when(mockResponse).throwExceptionForError();
    return mockResponse;
}
Also used : Response(com.synopsys.integration.rest.response.Response) DockerTagsResponseModel(com.synopsys.integration.alert.update.model.DockerTagsResponseModel) DockerTagModel(com.synopsys.integration.alert.update.model.DockerTagModel)

Example 5 with Response

use of com.synopsys.integration.rest.response.Response in project hub-alert by blackducksoftware.

the class DockerTagRetrieverTest method getTagsModelTestIT.

@Test
@Tags({ @Tag(TestTags.DEFAULT_INTEGRATION), @Tag(TestTags.CUSTOM_EXTERNAL_CONNECTION) })
public void getTagsModelTestIT() throws IntegrationException {
    IntLogger intLogger = new PrintStreamIntLogger(System.out, LogLevel.INFO);
    IntHttpClient intHttpClient = new IntHttpClient(intLogger, gson, 10, true, ProxyInfo.NO_PROXY_INFO);
    HttpUrl httpUrl = new HttpUrl("https://google.com");
    Request testRequest = new Request.Builder(httpUrl).build();
    try (Response googleResponse = intHttpClient.execute(testRequest)) {
        googleResponse.throwExceptionForError();
    } catch (IntegrationException | IOException e) {
        assumeTrue(null == e, "Could not connect. Skipping this test...");
    }
    DockerTagRetriever dockerTagRetriever = new DockerTagRetriever(gson, intHttpClient);
    DockerTagsResponseModel tagsModel = dockerTagRetriever.getTagsModel();
    assertFalse(tagsModel.isEmpty(), "Expected tags from the docker repo to exist");
}
Also used : Response(com.synopsys.integration.rest.response.Response) DockerTagsResponseModel(com.synopsys.integration.alert.update.model.DockerTagsResponseModel) PrintStreamIntLogger(com.synopsys.integration.log.PrintStreamIntLogger) IntegrationException(com.synopsys.integration.exception.IntegrationException) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) Request(com.synopsys.integration.rest.request.Request) IntLogger(com.synopsys.integration.log.IntLogger) PrintStreamIntLogger(com.synopsys.integration.log.PrintStreamIntLogger) IOException(java.io.IOException) HttpUrl(com.synopsys.integration.rest.HttpUrl) Test(org.junit.jupiter.api.Test) TestTags(com.synopsys.integration.alert.test.common.TestTags) Tags(org.junit.jupiter.api.Tags)

Aggregations

Response (com.synopsys.integration.rest.response.Response)11 Request (com.synopsys.integration.rest.request.Request)6 IntHttpClient (com.synopsys.integration.rest.client.IntHttpClient)5 Test (org.junit.jupiter.api.Test)4 DockerTagsResponseModel (com.synopsys.integration.alert.update.model.DockerTagsResponseModel)3 IntegrationException (com.synopsys.integration.exception.IntegrationException)3 HttpUrl (com.synopsys.integration.rest.HttpUrl)3 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)2 BodyContent (com.synopsys.integration.rest.body.BodyContent)2 StringBodyContent (com.synopsys.integration.rest.body.StringBodyContent)2 IOException (java.io.IOException)2 TestTags (com.synopsys.integration.alert.test.common.TestTags)1 DockerTagModel (com.synopsys.integration.alert.update.model.DockerTagModel)1 IntLogger (com.synopsys.integration.log.IntLogger)1 PrintStreamIntLogger (com.synopsys.integration.log.PrintStreamIntLogger)1 ProxyInfo (com.synopsys.integration.rest.proxy.ProxyInfo)1 Tags (org.junit.jupiter.api.Tags)1