InterceptorManager Class
- java.
lang. Object - com.
azure. core. test. InterceptorManager
- com.
Implements
public class InterceptorManager
implements AutoCloseable
A class that keeps track of network calls by either reading the data from an existing test session record or recording the network calls in memory. Test session records are saved or read from: "session-records/testName
.json"
- If the
testMode
is PLAYBACK, the manager tries to find an existing test session record to read network calls from. - If the
testMode
is RECORD, the manager creates a new test session record and saves all the network calls to it. - If the
testMode
is LIVE, the manager won't attempt to read or create a test session record.
When the InterceptorManager is disposed, if the testMode
is RECORD, the network calls that were recorded are persisted to: "session-records/testName
.json"
Constructor Summary
Constructor | Description |
---|---|
InterceptorManager(TestContextManager testContextManager) |
Creates a new Interceptor |
InterceptorManager(String testName, TestMode testMode) |
Deprecated Creates a new Interceptor |
InterceptorManager(String testName, Map<String,String> textReplacementRules) |
Deprecated
Use InterceptorManager(String testName, Map<String,String> textReplacementRules, boolean doNotRecord) instead.
Creates a new Interceptor |
InterceptorManager(String testName, Map<String,String> textReplacementRules, boolean doNotRecord) |
Deprecated Creates a new Interceptor |
InterceptorManager(String testName, Map<String,String> textReplacementRules, boolean doNotRecord, String playbackRecordName) |
Creates a new Interceptor |
Method Summary
Modifier and Type | Method and Description |
---|---|
void |
addMatchers(TestProxyRequestMatcher[] testProxyRequestMatchers)
Add matcher rules to match recorded data in playback. |
void |
addMatchers(List<TestProxyRequestMatcher> testProxyMatchers)
Add matcher rules to match recorded data in playback. |
void |
addSanitizers(TestProxySanitizer[] testProxySanitizers)
Add sanitizer rule for sanitization during record or playback. |
void |
addSanitizers(List<TestProxySanitizer> testProxySanitizers)
Add sanitizer rule for sanitization during record or playback. |
void |
addTextReplacementRule(String regex, String replacement)
Add text replacement rule (regex as key, the replacement text as value) into InterceptorManager#textReplacementRules |
void |
close()
Disposes of resources used by this Interceptor |
Http |
getPlaybackClient()
Gets a new HTTP client that plays back test session records managed by InterceptorManager. |
String |
getPlaybackRecordName()
Gets the name of the playback record. |
Consumer<String> |
getProxyVariableConsumer()
Get a Consumer for adding variables used in test proxy tests. |
Supplier<String> |
getProxyVariableSupplier()
A Supplier for retrieving a variable from a test proxy recording. |
Http |
getRecordPolicy()
Gets a new HTTP pipeline policy that records network calls and its data is managed by InterceptorManager. |
Http |
getRecordPolicy(List<Function<String,String>> recordingRedactors)
Gets a new HTTP pipeline policy that records network calls. |
Recorded |
getRecordedData()
Gets the recorded data Interceptor |
String |
getRecordingFileLocation()
Get the recording file location in assets repo. |
String |
getTestName()
Gets the name of the running test. |
boolean |
isLiveMode()
Gets whether this Interceptor |
boolean |
isPlaybackMode()
Gets whether this Interceptor |
boolean |
isRecordMode()
Gets whether this Interceptor |
void |
removeSanitizers(String[] testProxySanitizersId)
Disable common sanitizer rule for sanitization during record or playback. |
void |
setProxyRecordingOptions(TestProxyRecordingOptions testProxyRecordingOptions)
Sets the recording options for the proxy. |
Methods inherited from java.lang.Object
Constructor Details
InterceptorManager
public InterceptorManager(TestContextManager testContextManager)
Creates a new InterceptorManager that either replays test-session records or saves them.
- If
testMode
is PLAYBACK, the manager tries to find an existing test session record to read network calls from. - If
testMode
is RECORD, the manager creates a new test session record and saves all the network calls to it. - If
testMode
is LIVE, the manager won't attempt to read or create a test session record.
The test session records are persisted in the path: "session-records/testName
.json"
Parameters:
InterceptorManager
@Deprecated
public InterceptorManager(String testName, TestMode testMode)
Deprecated
Creates a new InterceptorManager that either replays test-session records or saves them.
- If
testMode
is PLAYBACK, the manager tries to find an existing test session record to read network calls from. - If
testMode
is RECORD, the manager creates a new test session record and saves all the network calls to it.
The test session records are persisted in the path: "session-records/testName
.json"
Parameters:
InterceptorManager
@Deprecated
public InterceptorManager(String testName, Map
Deprecated
Creates a new InterceptorManager that replays test session records. It takes a set of textReplacementRules
, that can be used by PlaybackClient to replace values in a getResponse(). The test session records are read from: "session-records/testName
.json"
Parameters:
InterceptorManager
@Deprecated
public InterceptorManager(String testName, Map
Deprecated
Creates a new InterceptorManager that replays test session records. It takes a set of textReplacementRules
, that can be used by PlaybackClient to replace values in a getResponse(). The test session records are read from: "session-records/testName
.json"
Parameters:
InterceptorManager
public InterceptorManager(String testName, Map
Creates a new InterceptorManager that replays test session records. It takes a set of textReplacementRules
, that can be used by PlaybackClient to replace values in a getResponse(). The test session records are read from: "session-records/testName
.json"
Parameters:
Method Details
addMatchers
public void addMatchers(TestProxyRequestMatcher[] testProxyRequestMatchers)
Add matcher rules to match recorded data in playback. Matchers are only applied for playback session and so this will be a noop when invoked in RECORD/LIVE mode.
Parameters:
addMatchers
public void addMatchers(List
Add matcher rules to match recorded data in playback. Matchers are only applied for playback session and so this will be a noop when invoked in RECORD/LIVE mode.
Parameters:
addSanitizers
public void addSanitizers(TestProxySanitizer[] testProxySanitizers)
Add sanitizer rule for sanitization during record or playback.
Parameters:
addSanitizers
public void addSanitizers(List
Add sanitizer rule for sanitization during record or playback.
Parameters:
addTextReplacementRule
public void addTextReplacementRule(String regex, String replacement)
Add text replacement rule (regex as key, the replacement text as value) into InterceptorManager#textReplacementRules
Parameters:
close
public void close()
Disposes of resources used by this InterceptorManager. If testMode
is RECORD, all the network calls are persisted to: "session-records/testName
.json"
getPlaybackClient
public HttpClient getPlaybackClient()
Gets a new HTTP client that plays back test session records managed by InterceptorManager.
Returns:
getPlaybackRecordName
public String getPlaybackRecordName()
Gets the name of the playback record.
The playback record name is equivalent to .[]
.
Returns:
getProxyVariableConsumer
public Consumer
Get a Consumer for adding variables used in test proxy tests.
Returns:
getProxyVariableSupplier
public Supplier
A Supplier for retrieving a variable from a test proxy recording.
Returns:
getRecordPolicy
public HttpPipelinePolicy getRecordPolicy()
Gets a new HTTP pipeline policy that records network calls and its data is managed by InterceptorManager.
Returns:
getRecordPolicy
public HttpPipelinePolicy getRecordPolicy(List
Gets a new HTTP pipeline policy that records network calls. The recorded content is redacted by the given list of redactor functions to hide sensitive information.
Parameters:
Returns:
getRecordedData
public RecordedData getRecordedData()
Gets the recorded data InterceptorManager is keeping track of.
Returns:
getRecordingFileLocation
public String getRecordingFileLocation()
Get the recording file location in assets repo.
Returns:
getTestName
public String getTestName()
Gets the name of the running test.
Returns:
isLiveMode
public boolean isLiveMode()
Gets whether this InterceptorManager is in live mode.
Returns:
isPlaybackMode
public boolean isPlaybackMode()
Gets whether this InterceptorManager is in playback mode.
Returns:
isRecordMode
public boolean isRecordMode()
Gets whether this InterceptorManager is in record mode.
Returns:
removeSanitizers
public void removeSanitizers(String[] testProxySanitizersId)
Disable common sanitizer rule for sanitization during record or playback.
Parameters:
setProxyRecordingOptions
public void setProxyRecordingOptions(TestProxyRecordingOptions testProxyRecordingOptions)
Sets the recording options for the proxy.
Parameters:
Applies to
Azure SDK for Java