Search in sources :

Example 1 with MockHttpResponse

use of com.azure.core.test.http.MockHttpResponse in project ApplicationInsights-Java by microsoft.

the class IntegrationTests method setup.

@BeforeEach
public void setup() throws Exception {
    HttpClient mockedClient = mock(HttpClient.class);
    if (testWithException) {
        when(mockedClient.send(any(HttpRequest.class), any(Context.class))).then(invocation -> Mono.error(() -> new Exception("this is expected to be logged by the operation logger")));
    } else {
        // 401, 403, 408, 429, 500, and 503 response codes result in storing to disk
        when(mockedClient.send(any(HttpRequest.class), any(Context.class))).then(invocation -> Mono.just(new MockHttpResponse(invocation.getArgument(0, HttpRequest.class), 500)));
    }
    HttpPipelineBuilder pipelineBuilder = new HttpPipelineBuilder().httpClient(mockedClient);
    localFileCache = new LocalFileCache(tempFolder);
    localFileLoader = new LocalFileLoader(localFileCache, tempFolder, null);
    StatsbeatModule statsbeatModule = Mockito.mock(StatsbeatModule.class);
    when(statsbeatModule.getNetworkStatsbeat()).thenReturn(Mockito.mock(NetworkStatsbeat.class));
    telemetryChannel = new TelemetryChannel(pipelineBuilder.build(), new URL("http://foo.bar"), new LocalFileWriter(localFileCache, tempFolder, null), statsbeatModule, false);
}
Also used : HttpRequest(com.azure.core.http.HttpRequest) Context(com.azure.core.util.Context) NetworkStatsbeat(com.microsoft.applicationinsights.agent.internal.statsbeat.NetworkStatsbeat) HttpPipelineBuilder(com.azure.core.http.HttpPipelineBuilder) TelemetryChannel(com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryChannel) URL(java.net.URL) HttpClient(com.azure.core.http.HttpClient) StatsbeatModule(com.microsoft.applicationinsights.agent.internal.statsbeat.StatsbeatModule) MockHttpResponse(com.azure.core.test.http.MockHttpResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

HttpClient (com.azure.core.http.HttpClient)1 HttpPipelineBuilder (com.azure.core.http.HttpPipelineBuilder)1 HttpRequest (com.azure.core.http.HttpRequest)1 MockHttpResponse (com.azure.core.test.http.MockHttpResponse)1 Context (com.azure.core.util.Context)1 NetworkStatsbeat (com.microsoft.applicationinsights.agent.internal.statsbeat.NetworkStatsbeat)1 StatsbeatModule (com.microsoft.applicationinsights.agent.internal.statsbeat.StatsbeatModule)1 TelemetryChannel (com.microsoft.applicationinsights.agent.internal.telemetry.TelemetryChannel)1 URL (java.net.URL)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1