Search in sources :

Example 21 with JacksonSerder

use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.

the class HttpRequestMapperTests method querySubstitution.

@ParameterizedTest
@MethodSource("querySubstitutionSupplier")
public void querySubstitution(Method method, Object[] arguments, String expectedUrl) {
    HttpRequestMapper mapper = new HttpRequestMapper("https://raw.host.com", method, new JacksonSerder());
    UrlBuilder urlBuilder = UrlBuilder.parse("https://raw.host.com");
    mapper.applyQueryMappings(arguments, urlBuilder);
    assertEquals(expectedUrl, urlBuilder.toString());
}
Also used : JacksonSerder(com.azure.android.core.serde.jackson.JacksonSerder) UrlBuilder(com.azure.android.core.http.util.UrlBuilder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 22 with JacksonSerder

use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.

the class HttpRequestMapperTests method noHttpMethodAnnotation.

@Test
public void noHttpMethodAnnotation() throws NoSuchMethodException {
    Method noHttpMethodAnnotation = OperationMethods.class.getDeclaredMethod("noMethod");
    Exception ex = null;
    try {
        new HttpRequestMapper("s://raw.host.com", noHttpMethodAnnotation, new JacksonSerder());
    } catch (RuntimeException e) {
        ex = e;
    }
    Assertions.assertNotNull(ex);
    Assertions.assertTrue(ex.getMessage().contains("Either Get, Put, Head, Delete, Post or Patch " + "annotation must be defined on the method"));
}
Also used : JacksonSerder(com.azure.android.core.serde.jackson.JacksonSerder) Method(java.lang.reflect.Method) HttpMethod(com.azure.android.core.http.HttpMethod) IOException(java.io.IOException) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with JacksonSerder

use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.

the class HttpRequestMapperTests method formAndBody.

@Test
public void formAndBody() throws NoSuchMethodException {
    Class<FormAndBodyMethods> clazz = FormAndBodyMethods.class;
    Method formAndBodyMethod = clazz.getDeclaredMethod("formAndBody", String.class, String.class, Callback.class);
    RuntimeException ex = null;
    try {
        new HttpRequestMapper("https://raw.host.com", formAndBodyMethod, new JacksonSerder());
    } catch (RuntimeException e) {
        ex = e;
    }
    Assertions.assertNotNull(ex);
    Assertions.assertTrue(ex.getMessage().contains("'FormParam' and 'BodyParam' are mutually exclusive, but the method"));
}
Also used : JacksonSerder(com.azure.android.core.serde.jackson.JacksonSerder) Method(java.lang.reflect.Method) HttpMethod(com.azure.android.core.http.HttpMethod) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 24 with JacksonSerder

use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.

the class HttpRequestMapperTests method schemeSubstitution.

@ParameterizedTest
@MethodSource("schemeSubstitutionSupplier")
public void schemeSubstitution(Method method, String rawHost, Object[] arguments, String expectedUrl) {
    HttpRequestMapper mapper = new HttpRequestMapper(rawHost, method, new JacksonSerder());
    UrlBuilder urlBuilder = new UrlBuilder();
    mapper.applySchemeAndHostMapping(arguments, urlBuilder);
    assertEquals(expectedUrl, urlBuilder.toString());
}
Also used : JacksonSerder(com.azure.android.core.serde.jackson.JacksonSerder) UrlBuilder(com.azure.android.core.http.util.UrlBuilder) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 25 with JacksonSerder

use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.

the class HttpResponseMapperTests method base64EncodedContentList.

@Test
public void base64EncodedContentList() throws Throwable {
    Class<Base64EncodedContentMethods> clazz = Base64EncodedContentMethods.class;
    Method base64UrlListMethod = clazz.getDeclaredMethod("base64UrlList", Callback.class);
    HttpResponseMapper mapperBase64List = new HttpResponseMapper(base64UrlListMethod, extractCallbackType(base64UrlListMethod), logger);
    JacksonSerder jacksonSerder = new JacksonSerder();
    final String value0ToEncode = "hello azure android";
    final String value1ToEncode = "hello azure android again";
    List<String> base64EncodedBytesList = new ArrayList<>();
    base64EncodedBytesList.add(Base64Url.encode(value0ToEncode.getBytes()).toString());
    base64EncodedBytesList.add(Base64Url.encode(value1ToEncode.getBytes()).toString());
    String wireBase64EncodedList = jacksonSerder.serialize(base64EncodedBytesList, SerdeEncoding.JSON);
    MockHttpResponse httpResponseBase64EncodedBytesList = new MockHttpResponse(HttpMethod.GET, "https://raw.host.com", 200, new HttpHeaders(), wireBase64EncodedList.getBytes());
    Response<List<byte[]>> restResponseBase64DecodedBytesList = (Response<List<byte[]>>) mapperBase64List.map(httpResponseBase64EncodedBytesList, jacksonSerder);
    List<byte[]> decodedBytesList = restResponseBase64DecodedBytesList.getValue();
    assertNotNull(decodedBytesList);
    assertEquals(2, decodedBytesList.size());
    assertArrayEquals(value0ToEncode.getBytes(), decodedBytesList.get(0));
    assertArrayEquals(value1ToEncode.getBytes(), decodedBytesList.get(1));
}
Also used : HttpHeaders(com.azure.android.core.http.HttpHeaders) JacksonSerder(com.azure.android.core.serde.jackson.JacksonSerder) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) HttpMethod(com.azure.android.core.http.HttpMethod) HttpResponse(com.azure.android.core.http.HttpResponse) PagedResponse(com.azure.android.core.rest.util.paging.PagedResponse) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

JacksonSerder (com.azure.android.core.serde.jackson.JacksonSerder)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)27 Test (org.junit.jupiter.api.Test)23 Method (java.lang.reflect.Method)20 HttpMethod (com.azure.android.core.http.HttpMethod)18 HttpHeaders (com.azure.android.core.http.HttpHeaders)17 HttpResponse (com.azure.android.core.http.HttpResponse)16 PagedResponse (com.azure.android.core.rest.util.paging.PagedResponse)13 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 OffsetDateTime (org.threeten.bp.OffsetDateTime)6 HttpPipeline (com.azure.android.core.http.HttpPipeline)3 HttpPipelineBuilder (com.azure.android.core.http.HttpPipelineBuilder)3 HttpRequest (com.azure.android.core.http.HttpRequest)3 UrlBuilder (com.azure.android.core.http.util.UrlBuilder)3 DateTimeRfc1123 (com.azure.android.core.util.DateTimeRfc1123)3 UnixTime (com.azure.android.core.util.UnixTime)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Map (java.util.Map)3