Search in sources :

Example 1 with ProviderRegistrationInterceptor

use of com.microsoft.azure.management.resources.fluentcore.utils.ProviderRegistrationInterceptor in project azure-sdk-for-java by Azure.

the class TestBase method setup.

@Before
public void setup() throws Exception {
    addTextReplacementRule("https://management.azure.com/", this.mockUri() + "/");
    setupTest(name.getMethodName());
    ApplicationTokenCredentials credentials;
    RestClient restClient;
    String defaultSubscription;
    if (IS_MOCKED) {
        credentials = new AzureTestCredentials();
        restClient = buildRestClient(new RestClient.Builder().withBaseUrl(this.mockUri() + "/").withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withCredentials(credentials).withLogLevel(LogLevel.BODY_AND_HEADERS).withNetworkInterceptor(this.interceptor()), true);
        defaultSubscription = MOCK_SUBSCRIPTION;
        System.out.println(this.mockUri());
        out = System.out;
        System.setOut(new PrintStream(new OutputStream() {

            public void write(int b) {
            //DO NOTHING
            }
        }));
    } else {
        final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
        credentials = ApplicationTokenCredentials.fromFile(credFile);
        restClient = buildRestClient(new RestClient.Builder().withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER).withSerializerAdapter(new AzureJacksonAdapter()).withResponseBuilderFactory(new AzureResponseBuilder.Factory()).withInterceptor(new ProviderRegistrationInterceptor(credentials)).withCredentials(credentials).withLogLevel(LogLevel.BODY_AND_HEADERS).withReadTimeout(3, TimeUnit.MINUTES).withNetworkInterceptor(this.interceptor()), false);
        defaultSubscription = credentials.defaultSubscriptionId();
        addTextReplacementRule(defaultSubscription, MOCK_SUBSCRIPTION);
    }
    initializeClients(restClient, defaultSubscription, credentials.domain());
}
Also used : PrintStream(java.io.PrintStream) AzureResponseBuilder(com.microsoft.azure.AzureResponseBuilder) AzureJacksonAdapter(com.microsoft.azure.serializer.AzureJacksonAdapter) OutputStream(java.io.OutputStream) RestClient(com.microsoft.rest.RestClient) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) File(java.io.File) ProviderRegistrationInterceptor(com.microsoft.azure.management.resources.fluentcore.utils.ProviderRegistrationInterceptor) Before(org.junit.Before)

Aggregations

AzureResponseBuilder (com.microsoft.azure.AzureResponseBuilder)1 ApplicationTokenCredentials (com.microsoft.azure.credentials.ApplicationTokenCredentials)1 ProviderRegistrationInterceptor (com.microsoft.azure.management.resources.fluentcore.utils.ProviderRegistrationInterceptor)1 AzureJacksonAdapter (com.microsoft.azure.serializer.AzureJacksonAdapter)1 RestClient (com.microsoft.rest.RestClient)1 File (java.io.File)1 OutputStream (java.io.OutputStream)1 PrintStream (java.io.PrintStream)1 Before (org.junit.Before)1