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;
}
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;
}
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());
}
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;
}
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");
}
Aggregations