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