Search in sources :

Example 31 with JacksonSerder

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

the class RestProxyXMLTests method canDeserializeXMLWithAttributes.

@Test
public void canDeserializeXMLWithAttributes() throws Exception {
    JacksonSerder serializer = new JacksonSerder();
    final HttpPipeline pipeline = new HttpPipelineBuilder().httpClient(new MockXMLHTTPClient()).build();
    MyXMLServiceWithAttributes myXMLService = RestProxy.create(MyXMLServiceWithAttributes.class, pipeline, serializer);
    final SlideshowOrError slideshowOrError = new SlideshowOrError();
    CountDownLatch latch = new CountDownLatch(1);
    myXMLService.getSlideshow(new Callback<Response<Slideshow>>() {

        @Override
        public void onSuccess(Response<Slideshow> response) {
            try {
                slideshowOrError.slideshow = response.getValue();
            } finally {
                latch.countDown();
            }
        }

        @Override
        public void onFailure(Throwable error) {
            try {
                slideshowOrError.error = error;
            } finally {
                latch.countDown();
            }
        }
    });
    awaitOnLatch(latch, "canDeserializeXMLWithAttributes");
    if (slideshowOrError.error != null) {
        fail(slideshowOrError.error);
    } else {
        Slideshow slideshow = slideshowOrError.slideshow;
        assertEquals("Sample Slide Show", slideshow.title());
        assertEquals("Date of publication", slideshow.date());
        assertEquals("Yours Truly", slideshow.author());
        assertEquals(2, slideshow.slides().length);
        assertEquals("all", slideshow.slides()[0].type());
        assertEquals("Wake up to WonderWidgets!", slideshow.slides()[0].title());
        assertEquals(0, slideshow.slides()[0].items().length);
        assertEquals("all", slideshow.slides()[1].type());
        assertEquals("Overview", slideshow.slides()[1].title());
        assertEquals(3, slideshow.slides()[1].items().length);
        assertEquals("Why WonderWidgets are great", slideshow.slides()[1].items()[0]);
        assertEquals("", slideshow.slides()[1].items()[1]);
        assertEquals("Who buys WonderWidgets", slideshow.slides()[1].items()[2]);
        String xml = serializer.serialize(slideshow, SerdeEncoding.XML);
        Slideshow newSlideshow = serializer.deserialize(xml, Slideshow.class, SerdeEncoding.XML);
        String newXML = serializer.serialize(newSlideshow, SerdeEncoding.XML);
        assertEquals(xml, newXML);
    }
}
Also used : JacksonSerder(com.azure.android.core.serde.jackson.JacksonSerder) HttpPipelineBuilder(com.azure.android.core.http.HttpPipelineBuilder) CountDownLatch(java.util.concurrent.CountDownLatch) HttpResponse(com.azure.android.core.http.HttpResponse) HttpPipeline(com.azure.android.core.http.HttpPipeline) Test(org.junit.jupiter.api.Test)

Example 32 with JacksonSerder

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

the class SwaggerMethodParserTests method invalidCallbackParam.

@Test
public void invalidCallbackParam() throws NoSuchMethodException {
    Class<InvalidCallbackParamMethods> clazz = InvalidCallbackParamMethods.class;
    Method missingCallbackParamMethod = clazz.getDeclaredMethod("missingCallbackParam", Integer.class);
    IllegalStateException ex0 = null;
    try {
        new SwaggerMethodParser("https://raw.host.com", missingCallbackParamMethod, new JacksonSerder(), this.logger);
    } catch (IllegalStateException e) {
        ex0 = e;
    }
    Assertions.assertNotNull(ex0);
    Assertions.assertTrue(ex0.getMessage().contains("must have a com.azure.android.core.rest.Callback parameter, it must be the last parameter and parameterized"));
    Method callbackMissingTypeArgMethod = clazz.getDeclaredMethod("callbackMissingTypeArg", Integer.class, Callback.class);
    IllegalStateException ex1 = null;
    try {
        new SwaggerMethodParser("https://raw.host.com", callbackMissingTypeArgMethod, new JacksonSerder(), this.logger);
    } catch (IllegalStateException e) {
        ex1 = e;
    }
    Assertions.assertNotNull(ex1);
    Assertions.assertTrue(ex1.getMessage().contains("must have a com.azure.android.core.rest.Callback parameter, it must be the last parameter and parameterized"));
}
Also used : JacksonSerder(com.azure.android.core.serde.jackson.JacksonSerder) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

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