Search in sources :

Example 21 with HttpPipelineBuilder

use of com.azure.android.core.http.HttpPipelineBuilder 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)

Aggregations

HttpPipelineBuilder (com.azure.android.core.http.HttpPipelineBuilder)21 HttpPipeline (com.azure.android.core.http.HttpPipeline)19 CountDownLatch (java.util.concurrent.CountDownLatch)18 HttpResponse (com.azure.android.core.http.HttpResponse)17 HttpRequest (com.azure.android.core.http.HttpRequest)15 Test (org.junit.jupiter.api.Test)15 HttpCallback (com.azure.android.core.http.HttpCallback)14 CancellationToken (com.azure.android.core.util.CancellationToken)13 HttpHeaders (com.azure.android.core.http.HttpHeaders)4 HttpClient (com.azure.android.core.http.HttpClient)3 HttpPipelinePolicy (com.azure.android.core.http.HttpPipelinePolicy)3 JacksonSerder (com.azure.android.core.serde.jackson.JacksonSerder)3 ArrayList (java.util.ArrayList)3 ResourceLock (org.junit.jupiter.api.parallel.ResourceLock)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 HttpCallDispatcher (com.azure.android.core.http.HttpCallDispatcher)2 HttpLogOptions (com.azure.android.core.http.policy.HttpLogOptions)2 HttpLoggingPolicy (com.azure.android.core.http.policy.HttpLoggingPolicy)2 CookiePolicy (com.azure.android.core.http.policy.CookiePolicy)1