Sdílet prostřednictvím


TestProxyUtils Class

  • java.lang.Object
    • com.azure.core.test.utils.TestProxyUtils

public class TestProxyUtils

Utility functions for interaction with the test proxy.

Field Summary

Modifier and Type Field and Description
static final String HOST_NAME_REGEX

Constructor Summary

Constructor Description
TestProxyUtils()

Method Summary

Modifier and Type Method and Description
static void changeHeaders(HttpRequest request, URL proxyUrl, String xRecordingId, String mode, boolean skipRecordingRequestBody)

Adds headers required for communication with the test proxy.

static void checkForTestProxyErrors(HttpResponse httpResponse)

Checks the return from a request through the test proxy for special error headers.

static HttpRequest createAddSanitizersRequest(List<TestProxySanitizer> sanitizers, URL proxyUrl)

Creates a request to bulk add sanitizers to the test proxy server.

static String getAssetJsonFile(File recordFile, Path testClassPath)

Get the assets json file path if it exists.

static List<HttpRequest> getMatcherRequests(List<TestProxyRequestMatcher> matchers, URL proxyUrl)

Creates a List of HttpRequest to be sent to the test proxy to register matchers.

static String getProxyProcessName()

Gets the process name of the test proxy binary.

static URL getProxyUrl()

Gets the current URL for the test proxy.

static HttpRequest getRemoveSanitizerRequest()

Creates a request to remove sanitizers from the request.

static List<HttpRequest> getSanitizerRequests(List<TestProxySanitizer> sanitizers, URL proxyUrl)

Deprecated

Use createAddSanitizersRequest(List<TestProxySanitizer> sanitizers, URL proxyUrl) instead as this will create a bulk HttpRequest for setting the sanitizers for a test proxy session instead of a request per sanitizer.

Creates a list of sanitizer requests to be sent to the test proxy server.

static String getTestProxyVersion(Path testClassPath)

Finds the test proxy version in the source tree.

static List<TestProxySanitizer> loadSanitizers()

Registers the default set of sanitizers for sanitizing request and responses

static HttpResponse resetTestProxyData(HttpResponse response)

Sets the response URL back to the original URL before returning it through the pipeline.

static HttpRequest setCompareBodiesMatcher()

Set comparing bodies to false when running in playback and RecordWithoutRequestBody is set for the test.

Methods inherited from java.lang.Object

Field Details

HOST_NAME_REGEX

public static final String HOST_NAME_REGEX

Constructor Details

TestProxyUtils

public TestProxyUtils()

Method Details

changeHeaders

public static void changeHeaders(HttpRequest request, URL proxyUrl, String xRecordingId, String mode, boolean skipRecordingRequestBody)

Adds headers required for communication with the test proxy.

Parameters:

request - The request to add headers to.
proxyUrl - The URL the proxy lives at.
xRecordingId - The x-recording-id value for the current session.
mode - The current test proxy mode.
skipRecordingRequestBody - Flag indicating to skip recording request bodies when tests run in Record mode.

checkForTestProxyErrors

public static void checkForTestProxyErrors(HttpResponse httpResponse)

Checks the return from a request through the test proxy for special error headers.

Parameters:

httpResponse - The HttpResponse from the test proxy.

createAddSanitizersRequest

public static HttpRequest createAddSanitizersRequest(List sanitizers, URL proxyUrl)

Creates a request to bulk add sanitizers to the test proxy server.

For more information about adding bulk sanitizers see the Passing Sanitizers in Bulk wiki.

Parameters:

sanitizers - The list of sanitizers to be added.
proxyUrl - The proxyUrl to use when constructing requests.

Returns:

The HttpRequest to be sent.

getAssetJsonFile

public static String getAssetJsonFile(File recordFile, Path testClassPath)

Get the assets json file path if it exists.

Parameters:

recordFile - the record/playback file
testClassPath - the test class path

Returns:

the assets json file path if it exists.

getMatcherRequests

public static List getMatcherRequests(List matchers, URL proxyUrl)

Creates a List of HttpRequest to be sent to the test proxy to register matchers.

Parameters:

matchers - The TestProxyRequestMatchers to encode into requests.
proxyUrl - The proxyUrl to use when constructing requests.

Returns:

The HttpRequests to send to the proxy.

getProxyProcessName

public static String getProxyProcessName()

Gets the process name of the test proxy binary.

Returns:

The platform specific process name.

getProxyUrl

public static URL getProxyUrl()

Gets the current URL for the test proxy.

Returns:

The URL location of the test proxy.

getRemoveSanitizerRequest

public static HttpRequest getRemoveSanitizerRequest()

Creates a request to remove sanitizers from the request.

Returns:

The HttpRequest to be sent.

getSanitizerRequests

@Deprecated
public static List getSanitizerRequests(List sanitizers, URL proxyUrl)

Deprecated

Use createAddSanitizersRequest(List<TestProxySanitizer> sanitizers, URL proxyUrl) instead as this will create a bulk HttpRequest for setting the sanitizers for a test proxy session instead of a request per sanitizer.

Creates a list of sanitizer requests to be sent to the test proxy server.

Parameters:

sanitizers - the list of sanitizers to be added.
proxyUrl - The proxyUrl to use when constructing requests.

Returns:

the list of sanitizer HttpRequest to be sent.

getTestProxyVersion

public static String getTestProxyVersion(Path testClassPath)

Finds the test proxy version in the source tree.

Parameters:

testClassPath - the test class path

Returns:

The version string to use.

loadSanitizers

public static List loadSanitizers()

Registers the default set of sanitizers for sanitizing request and responses

Returns:

the list of default sanitizers to be added.

resetTestProxyData

public static HttpResponse resetTestProxyData(HttpResponse response)

Sets the response URL back to the original URL before returning it through the pipeline.

Parameters:

response - The HttpResponse to modify.

Returns:

The modified response.

setCompareBodiesMatcher

public static HttpRequest setCompareBodiesMatcher()

Set comparing bodies to false when running in playback and RecordWithoutRequestBody is set for the test.

Returns:

the HttpRequest for setting compare bodies matcher to false.

Applies to