use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class RestProxyXMLTests method canWriteXMLRequest.
@Test
public void canWriteXMLRequest() throws Exception {
URL url = getClass().getClassLoader().getResource("GetContainerACLs.xml");
byte[] bytes = Files.readAllBytes(Paths.get(url.toURI()));
HttpRequest request = new HttpRequest(HttpMethod.PUT, "http://unused/SetContainerACLs");
request.setBody(bytes);
SignedIdentifierInner si = new SignedIdentifierInner();
si.withId("MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=");
AccessPolicy ap = new AccessPolicy();
ap.withStart(OffsetDateTime.parse("2009-09-28T08:49:37.0000000Z"));
ap.withExpiry(OffsetDateTime.parse("2009-09-29T08:49:37.0000000Z"));
ap.withPermission("rwd");
si.withAccessPolicy(ap);
List<SignedIdentifierInner> expectedAcls = Collections.singletonList(si);
JacksonSerder serderAdapter = new JacksonSerder();
MockXMLReceiverClient httpClient = new MockXMLReceiverClient();
final HttpPipeline pipeline = new HttpPipelineBuilder().httpClient(httpClient).build();
MyXMLService myXMLService = RestProxy.create(MyXMLService.class, pipeline, serderAdapter);
SignedIdentifiersWrapper wrapper = new SignedIdentifiersWrapper(expectedAcls);
CountDownLatch latch = new CountDownLatch(1);
myXMLService.setContainerACLs(wrapper, new Callback<Response<Void>>() {
@Override
public void onSuccess(Response<Void> response) {
latch.countDown();
}
@Override
public void onFailure(Throwable error) {
latch.countDown();
}
});
awaitOnLatch(latch, "canWriteXMLRequest");
SignedIdentifiersWrapper actualAclsWrapped = serderAdapter.deserialize(new String(httpClient.receivedBytes, StandardCharsets.UTF_8), SignedIdentifiersWrapper.class, SerdeEncoding.XML);
List<SignedIdentifierInner> actualAcls = actualAclsWrapped.signedIdentifiers();
// Ideally we'd just check for "things that matter" about the XML-- e.g. the tag names, structure, and attributes needs to be the same,
// but it doesn't matter if one document has a trailing newline or has UTF-8 in the header instead of utf-8, or if comments are missing.
assertEquals(expectedAcls.size(), actualAcls.size());
assertEquals(expectedAcls.get(0).id(), actualAcls.get(0).id());
assertEquals(expectedAcls.get(0).accessPolicy().expiry(), actualAcls.get(0).accessPolicy().expiry());
assertEquals(expectedAcls.get(0).accessPolicy().start(), actualAcls.get(0).accessPolicy().start());
assertEquals(expectedAcls.get(0).accessPolicy().permission(), actualAcls.get(0).accessPolicy().permission());
}
use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class RestProxyXMLTests method canReadXMLResponse.
@Test
public void canReadXMLResponse() {
final HttpPipeline pipeline = new HttpPipelineBuilder().httpClient(new MockXMLHTTPClient()).build();
MyXMLService myXMLService = RestProxy.create(MyXMLService.class, pipeline, new JacksonSerder());
final SignedIdentifiersWrapperOrError wrapperOrError = new SignedIdentifiersWrapperOrError();
CountDownLatch latch = new CountDownLatch(1);
myXMLService.getContainerACLs(new Callback<Response<SignedIdentifiersWrapper>>() {
@Override
public void onSuccess(Response<SignedIdentifiersWrapper> response) {
try {
wrapperOrError.wrapper = response.getValue();
} finally {
latch.countDown();
}
}
@Override
public void onFailure(Throwable error) {
try {
wrapperOrError.error = error;
} finally {
latch.countDown();
}
}
});
awaitOnLatch(latch, "canReadXMLResponse");
if (wrapperOrError.error != null) {
fail(wrapperOrError.error);
} else {
assertNotNull(wrapperOrError.wrapper);
assertNotNull(wrapperOrError.wrapper.signedIdentifiers());
assertNotEquals(0, wrapperOrError.wrapper.signedIdentifiers().size());
}
}
use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class SwaggerMethodParserTests method cancellationTokenIndex.
@Test
public void cancellationTokenIndex() throws NoSuchMethodException {
Class<CancellationTokenParamMethods> clazz = CancellationTokenParamMethods.class;
Method cancellationTokenCorrectIndexMethod = clazz.getDeclaredMethod("cancellationTokenCorrectIndex", Integer.class, CancellationToken.class, Callback.class);
SwaggerMethodParser methodParser0 = new SwaggerMethodParser("https://raw.host.com", cancellationTokenCorrectIndexMethod, new JacksonSerder(), this.logger);
Assertions.assertEquals(1, methodParser0.cancellationTokenArgIndex);
Method cancellationTokenIncorrectIndexMethod = clazz.getDeclaredMethod("cancellationTokenIncorrectIndex", CancellationToken.class, Integer.class, Callback.class);
SwaggerMethodParser methodParser1 = new SwaggerMethodParser("https://raw.host.com", cancellationTokenIncorrectIndexMethod, new JacksonSerder(), this.logger);
// CancellationToken when present must be second last arg, its the contract, presence of
// it in any other index (like in this case) is ignored.
Assertions.assertEquals(-1, methodParser1.cancellationTokenArgIndex);
}
use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class HttpRequestMapperTests method formSubstitution.
@ParameterizedTest
@MethodSource("formSubstitutionSupplier")
public void formSubstitution(Method method, Object[] arguments, String expectedBodyContentType, Object expectedBody) {
HttpRequestMapper mapper = new HttpRequestMapper("https://raw.host.com", method, new JacksonSerder());
assertEquals(expectedBody, mapper.applyFormDataMapping(arguments));
}
use of com.azure.android.core.serde.jackson.JacksonSerder in project azure-sdk-for-android by Azure.
the class HttpRequestMapperTests method jsonBodySubstitution.
@ParameterizedTest
@MethodSource("jsonBodySubstitutionSupplier")
public void jsonBodySubstitution(Method method, Object[] arguments, String expectedBodyContentType, Object expectedBody) throws IOException {
HttpRequestMapper mapper = new HttpRequestMapper("https://raw.host.com", method, new JacksonSerder());
HttpRequest httpRequest = mapper.map(arguments);
byte[] content = httpRequest.getBody();
if (expectedBody == null) {
Assertions.assertNull(content);
} else {
assertEquals(expectedBodyContentType, httpRequest.getHeaders().getValue("Content-Type"));
assertEquals(expectedBody, new String(content, StandardCharsets.UTF_8));
}
}
Aggregations