Search in sources :

Example 6 with IntHttpClient

use of com.synopsys.integration.rest.client.IntHttpClient 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 7 with IntHttpClient

use of com.synopsys.integration.rest.client.IntHttpClient 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)

Example 8 with IntHttpClient

use of com.synopsys.integration.rest.client.IntHttpClient in project hub-alert by blackducksoftware.

the class RestChannelUtilityTest method sendMessageSuccessTest.

@Test
public void sendMessageSuccessTest() throws IntegrationException {
    Response response = createMockResponse(HttpStatus.OK);
    IntHttpClient intHttpClient = createMockHttpClientWithResponse(response);
    RestChannelUtility restChannelUtility = new RestChannelUtility(intHttpClient);
    try {
        restChannelUtility.sendMessage(List.of(TEST_REQUEST, TEST_REQUEST), CLASS_NAME);
    } catch (AlertException e) {
        fail("Expected no exception to be thrown", e);
    }
}
Also used : Response(com.synopsys.integration.rest.response.Response) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Example 9 with IntHttpClient

use of com.synopsys.integration.rest.client.IntHttpClient in project hub-alert by blackducksoftware.

the class ChannelRestConnectionFactory method createIntHttpClient.

public IntHttpClient createIntHttpClient(String baseUrl, IntLogger intLogger, int timeout) {
    Optional<Boolean> alertTrustCertificate = alertProperties.getAlertTrustCertificate();
    ProxyInfo proxyInfo = proxyManager.createProxyInfoForHost(baseUrl);
    return new IntHttpClient(intLogger, gson, timeout, alertTrustCertificate.orElse(Boolean.FALSE), proxyInfo);
}
Also used : ProxyInfo(com.synopsys.integration.rest.proxy.ProxyInfo) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient)

Example 10 with IntHttpClient

use of com.synopsys.integration.rest.client.IntHttpClient in project hub-alert by blackducksoftware.

the class RestChannelUtilityTest method sendMessageAlertExceptionTest.

@Test
public void sendMessageAlertExceptionTest() throws IntegrationException {
    Response response = createMockResponse(HttpStatus.BAD_REQUEST);
    IntHttpClient intHttpClient = createMockHttpClientWithResponse(response);
    RestChannelUtility restChannelUtility = new RestChannelUtility(intHttpClient);
    try {
        restChannelUtility.sendMessage(List.of(TEST_REQUEST, TEST_REQUEST), CLASS_NAME);
        fail("Expected an exception to be thrown");
    } catch (AlertException e) {
    // Pass
    }
}
Also used : Response(com.synopsys.integration.rest.response.Response) IntHttpClient(com.synopsys.integration.rest.client.IntHttpClient) AlertException(com.synopsys.integration.alert.api.common.model.exception.AlertException) Test(org.junit.jupiter.api.Test)

Aggregations

IntHttpClient (com.synopsys.integration.rest.client.IntHttpClient)14 Request (com.synopsys.integration.rest.request.Request)7 Test (org.junit.jupiter.api.Test)6 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)5 ProxyInfo (com.synopsys.integration.rest.proxy.ProxyInfo)5 Response (com.synopsys.integration.rest.response.Response)5 JsonObject (com.google.gson.JsonObject)2 ChannelMessageSender (com.synopsys.integration.alert.api.channel.ChannelMessageSender)2 ChannelRestConnectionFactory (com.synopsys.integration.alert.api.channel.rest.ChannelRestConnectionFactory)2 RestChannelUtility (com.synopsys.integration.alert.api.channel.rest.RestChannelUtility)2 MessageResult (com.synopsys.integration.alert.common.message.model.MessageResult)2 DockerTagsResponseModel (com.synopsys.integration.alert.update.model.DockerTagsResponseModel)2 IntegrationException (com.synopsys.integration.exception.IntegrationException)2 IntLogger (com.synopsys.integration.log.IntLogger)2 HttpUrl (com.synopsys.integration.rest.HttpUrl)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2