Search in sources :

Example 1 with Test8Service

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());
}
Also used : Test8Service(test8.a.container.Test8Service) Test(org.junit.Test)

Example 2 with Test8Service

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,"));
    }
}
Also used : StreamProvider(com.github.davidmoten.odata.client.StreamProvider) Test8Service(test8.a.container.Test8Service) Test(org.junit.Test)

Example 3 with Test8Service

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());
}
Also used : StreamProvider(com.github.davidmoten.odata.client.StreamProvider) Test8Service(test8.a.container.Test8Service) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 Test8Service (test8.a.container.Test8Service)3 StreamProvider (com.github.davidmoten.odata.client.StreamProvider)2