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);
}
}
Aggregations