Azure SDK for Java Reference Documentation

Current version is 1.14.1, click here for the index

Azure Core Test shared library for Java

Library containing core classes used to test Azure SDK client libraries.

Getting started

To use this package, add the following to your pom.xml.

<dependency>
  <groupId>com.azure</groupId>
  <artifactId>azure-core-test</artifactId>
  <version>1.14.1</version>
</dependency>

Key concepts

  • TestBase: Base test class that creates an InterceptorManager for each unit test and either plays back test session data or records the test session. Each session's file name is determined using the name of the test.
  • InterceptorManager: Main class used to record and playback NetworkCallRecords.

Examples

Create a test class to run live or playback tests

Use TestBase to easily create live and playback test cases. Extending from TestBase provides an interceptorManager that keeps track of all network calls.

/**
 * Set the AZURE_TEST_MODE environment variable to either PLAYBACK or RECORD to determine if tests are playback or
 * live. By default, tests are run in playback mode.
 */
public class SessionTests extends TestBase {

    /**
     * Use JUnit or TestNG annotation here for your testcase
     */
    public void fooTest() {
        // Do some network calls.
    }
}

Record network calls

Record network calls using RecordNetworkCallPolicy. Each HTTP request sent from the test client, is persisted to RecordedData.

/**
 * Sample code for recording network calls.
 */
public class Foo {
    public void recordNetworkCalls() {
        // All network calls are kept in the recordedData variable.
        RecordedData recordedData = new RecordedData();
        HttpPipeline pipeline = new HttpPipelineBuilder()
            .policies(new RecordNetworkCallPolicy(recordedData))
            .build();

        // Send requests through the HttpPipeline.
        pipeline.send(new HttpRequest(HttpMethod.GET, "http://bing.com"));

        // Get a record that was sent through the pipeline.
        NetworkCallRecord networkCall = recordedData.findFirstAndRemoveNetworkCall(record -> {
            return record.getUri().equals("http://bing.com");
        });
    }
}

Playback session records

Playback test session records by creating a RecordedData.

/**
 * Sample code for using playback to test.
 */
public class FooBar {
    public void playbackNetworkCalls() {
        RecordedData recordedData = new RecordedData();

        // Add some network calls to be replayed by playbackClient

        // Creates a HTTP client that plays back responses in recordedData.
        HttpClient playbackClient = new PlaybackClient(recordedData, null);

        // Send an HTTP GET request to http://bing.com. If recordedData contains a NetworkCallRecord with a matching HTTP
        // method and matching URL, it is returned as a response.
        Mono<HttpResponse> response = playbackClient.send(new HttpRequest(HttpMethod.GET, "http://bing.com"));
    }
}

Troubleshooting

If you encounter any bugs with these SDKs, please file issues via Issues or checkout StackOverflow for Azure Java SDK.

Next steps

Other useful packages are: * azure-core: Contains core classes and functionality used by all client libraries.

Contributing

For details on contributing to this repository, see the contributing guide.

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request
Packages
Package
Description
Package containing annotations for client side methods that maps to REST APIs.
This package contains interfaces that represent common cross-cutting aspects of functionality offered by libraries in the Azure SDK for Java.
Package containing basic credential classes for authentication purposes.
Package containing core cryptography interfaces.
Package containing core exception classes.
Package containing HTTP abstractions between the AnnotationParser, RestProxy, and HTTP client.
Package containing HttpPipelinePolicy interface and its implementations.
Package containing REST-related APIs.
Package containing core model classes.
Package containing common test classes for Azure client libraries.
Package containing core utility classes.
Package containing utilities for client builders.
Package containing APIs for IO operations.
Package containing logging APIs.
Package containing core utility classes.
Package containing paging abstraction.
Package containing API for long running operations.
Package containing interfaces describing serialization and deserialization contract.
Package containing API for tracing.