Search in sources :

Example 1 with WireMock

use of com.github.tomakehurst.wiremock.client.WireMock in project azure-sdk-for-java by Azure.

the class MockIntegrationTestBase method setupTest.

protected void setupTest(final String testName) throws Exception {
    if (currentTestName == null) {
        currentTestName = testName;
    } else {
        throw new Exception("Setting up another test in middle of a test");
    }
    SdkContext.setResourceNamerFactory(new TestResourceNamerFactory(this));
    SdkContext.setDelayProvider(new TestDelayProvider());
    SdkContext.setRxScheduler(Schedulers.trampoline());
    int retries = 10;
    while (retries > 0) {
        retries--;
        try {
            wireMock = new WireMock(HOST, wireMockRule.port());
            wireMock.resetMappings();
            break;
        } catch (Exception ex) {
            Thread.sleep(3000);
        }
    }
    if (IS_MOCKED) {
        File recordFile = getRecordFile();
        ObjectMapper mapper = new ObjectMapper();
        testRecord = mapper.readValue(recordFile, TestRecord.class);
        System.out.println("Total records " + testRecord.networkCallRecords.size());
    } else {
        testRecord = new TestRecord();
    }
    this.interceptor = new Interceptor() {

        @Override
        public Response intercept(Chain chain) throws IOException {
            if (IS_MOCKED) {
                return registerRecordedResponse(chain);
            }
            return recordRequestAndResponse(chain);
        }
    };
}
Also used : IOException(java.io.IOException) IOException(java.io.IOException) Response(okhttp3.Response) File(java.io.File) Interceptor(okhttp3.Interceptor) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) WireMock(com.github.tomakehurst.wiremock.client.WireMock)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 WireMock (com.github.tomakehurst.wiremock.client.WireMock)1 File (java.io.File)1 IOException (java.io.IOException)1 Interceptor (okhttp3.Interceptor)1 Response (okhttp3.Response)1