use of test8.a.container.Test8Service in project odata-client by davidmoten.
the class Test8ServiceTest method testGetStreamPropertyWhenMetadataNotPresent.
@Test
public void testGetStreamPropertyWhenMetadataNotPresent() {
Test8Service client = //
Test8Service.test().expectRequest(//
"/Things/123").withMethod(//
HttpMethod.GET).withResponseStatusCode(//
200).withRequestHeadersStandard().withResponse(//
"/response-thing.json").build();
assertFalse(client.things(123).metadataMinimal().get().getPhoto().isPresent());
}
use of test8.a.container.Test8Service in project odata-client by davidmoten.
the class Test8ServiceTest method testGetStreamPropertyWhenMetadataPresent.
@Test
public void testGetStreamPropertyWhenMetadataPresent() {
Test8Service client = //
Test8Service.test().expectRequest(//
"/Things/123").withMethod(//
HttpMethod.GET).withResponseStatusCode(//
200).withRequestHeaders(//
RequestHeader.ACCEPT_JSON_METADATA_FULL, //
RequestHeader.ODATA_VERSION).withResponse(//
"/response-thing-full-metadata.json").build();
// note that odata-client fetches full metadata by default for Media Entities
// or Entities with stream properties
Optional<StreamProvider> photo = client.things(123).get().getPhoto();
assertTrue(photo.isPresent());
try {
// not pretty to use a try-catch but oh well
photo.get().getBytes();
Assert.fail();
} catch (Throwable t) {
assertTrue(t.getMessage().contains("response not found for url=https://thephoto,"));
}
}
use of test8.a.container.Test8Service in project odata-client by davidmoten.
the class Test8ServiceTest method testGetStreamPropertyWhenBase64Present.
@Test
public void testGetStreamPropertyWhenBase64Present() {
Test8Service client = //
Test8Service.test().expectRequest(//
"/Things/123").withMethod(//
HttpMethod.GET).withResponseStatusCode(//
200).withRequestHeadersStandard().withResponse(//
"/response-thing-inline-photo.json").build();
Optional<StreamProvider> photo = client.things(123).metadataMinimal().get().getPhoto();
assertTrue(photo.isPresent());
assertEquals("hello", photo.get().getStringUtf8());
}
Aggregations