use of com.microsoft.rest.credentials.BasicAuthenticationCredentials in project autorest.java by Azure.
the class LRORetrysTests method setup.
@BeforeClass
public static void setup() {
client = new AutoRestLongRunningOperationTestServiceImpl("http://localhost:3000", new BasicAuthenticationCredentials(null, null));
client.getAzureClient().setLongRunningOperationRetryTimeout(0);
}
use of com.microsoft.rest.credentials.BasicAuthenticationCredentials in project autorest.java by Azure.
the class LROsCustomHeaderTests method setup.
@BeforeClass
public static void setup() {
client = new AutoRestLongRunningOperationTestServiceImpl("http://localhost:3000", new BasicAuthenticationCredentials(null, null));
client.restClient().headers().addHeader("x-ms-client-request-id", "9C4D50EE-2D56-4CD3-8152-34347DC9F2B0");
client.getAzureClient().setLongRunningOperationRetryTimeout(0);
}
use of com.microsoft.rest.credentials.BasicAuthenticationCredentials in project autorest-clientruntime-for-java by Azure.
the class RestClientTests method newBuilderClonesProperties.
@Test
public void newBuilderClonesProperties() {
RestClient restClient = new RestClient.Builder().withBaseUrl("http://localhost").withSerializerAdapter(new JacksonAdapter()).withResponseBuilderFactory(new ServiceResponseBuilder.Factory()).withCredentials(new TokenCredentials("Bearer", "token")).withLogLevel(LogLevel.BASIC.withPrettyJson(true)).withInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
return chain.proceed(chain.request());
}
}).withUserAgent("user").withNetworkInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
return chain.proceed(chain.request());
}
}).withConnectionTimeout(100, TimeUnit.MINUTES).build();
RestClient newClient = restClient.newBuilder().withBaseUrl("https://contoso.com").withCredentials(new BasicAuthenticationCredentials("user", "pass")).withLogLevel(LogLevel.BODY_AND_HEADERS).withUserAgent("anotheruser").withConnectionTimeout(200, TimeUnit.SECONDS).withSerializerAdapter(new SerializerAdapter<Object>() {
@Override
public Object serializer() {
return null;
}
@Override
public Converter.Factory converterFactory() {
return retrofit2.converter.jackson.JacksonConverterFactory.create();
}
@Override
public String serialize(Object object) throws IOException {
return null;
}
@Override
public String serializeRaw(Object object) {
return null;
}
@Override
public String serializeList(List<?> list, CollectionFormat format) {
return null;
}
@Override
public <U> U deserialize(String value, Type type) throws IOException {
return null;
}
}).withResponseBuilderFactory(new ResponseBuilder.Factory() {
@Override
public <T, E extends RestException> ResponseBuilder<T, E> newInstance(SerializerAdapter<?> serializerAdapter) {
return null;
}
}).build();
Assert.assertNotEquals(restClient.retrofit().baseUrl().toString(), newClient.retrofit().baseUrl().toString());
Assert.assertNotEquals(restClient.logLevel(), newClient.logLevel());
Assert.assertNotEquals(restClient.logLevel().isPrettyJson(), newClient.logLevel().isPrettyJson());
Assert.assertNotEquals(restClient.serializerAdapter(), newClient.serializerAdapter());
Assert.assertNotEquals(restClient.responseBuilderFactory(), newClient.responseBuilderFactory());
Assert.assertNotEquals(restClient.credentials(), newClient.credentials());
for (Interceptor interceptor : restClient.httpClient().interceptors()) {
if (interceptor instanceof UserAgentInterceptor) {
Assert.assertEquals("user", ((UserAgentInterceptor) interceptor).userAgent());
}
}
for (Interceptor interceptor : newClient.httpClient().interceptors()) {
if (interceptor instanceof UserAgentInterceptor) {
Assert.assertEquals("anotheruser", ((UserAgentInterceptor) interceptor).userAgent());
}
}
Assert.assertNotEquals(restClient.httpClient().connectTimeoutMillis(), newClient.httpClient().connectTimeoutMillis());
}
use of com.microsoft.rest.credentials.BasicAuthenticationCredentials in project autorest-clientruntime-for-java by Azure.
the class CredentialsTests method basicCredentialsTest.
@Test
public void basicCredentialsTest() throws Exception {
BasicAuthenticationCredentials credentials = new BasicAuthenticationCredentials("user", "pass");
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
credentials.applyCredentialsFilter(clientBuilder);
clientBuilder.addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
String header = chain.request().header("Authorization");
Assert.assertEquals("Basic dXNlcjpwYXNz", header);
return new Response.Builder().request(chain.request()).code(200).message("OK").protocol(Protocol.HTTP_1_1).body(ResponseBody.create(MediaType.parse("text/plain"), "azure rocks")).build();
}
});
ServiceClient serviceClient = new ServiceClient("http://localhost", clientBuilder, new Retrofit.Builder()) {
};
Response response = serviceClient.httpClient().newCall(new Request.Builder().url("http://localhost").build()).execute();
Assert.assertEquals(200, response.code());
}
use of com.microsoft.rest.credentials.BasicAuthenticationCredentials in project autorest.java by Azure.
the class LROSADsTests method setup.
@BeforeClass
public static void setup() {
client = new AutoRestLongRunningOperationTestServiceImpl("http://localhost:3000", new BasicAuthenticationCredentials(null, null));
client.getAzureClient().setLongRunningOperationRetryTimeout(0);
}
Aggregations