Search in sources :

Example 1 with Test5Service

use of test5.container.Test5Service in project odata-client by davidmoten.

the class CustomRequestTest method testCustomRequestGet.

@Test
public void testCustomRequestGet() {
    Test5Service client = // 
    Test5Service.test().expectRequest(// 
    "/Products/1").withResponse(// 
    "/response-product-1.json").withRequestHeaders(RequestHeader.ACCEPT_JSON, // 
    RequestHeader.ODATA_VERSION).build();
    Product p = client._custom().get("https://testing.com/Products/1", Product.class, HttpRequestOptions.EMPTY);
    System.out.println(p);
    assertEquals(1, (int) p.getID().get());
}
Also used : Product(test5.entity.Product) Test5Service(test5.container.Test5Service) Test(org.junit.Test)

Example 2 with Test5Service

use of test5.container.Test5Service in project odata-client by davidmoten.

the class Test5ServiceTest method testStreamGet.

@Test
public void testStreamGet() throws IOException {
    Test5Service client = // 
    Test5Service.test().expectRequest(// 
    "/Products/2").withResponse(// 
    "/response-get-stream.json").withRequestHeaders(RequestHeader.ACCEPT_JSON_METADATA_FULL, // 
    RequestHeader.ODATA_VERSION).expectRequest(// 
    "/Photos(123)/%24value").withResponse(// 
    "/response-get-stream.txt").build();
    StreamProvider stream = client.products(2).metadataFull().get().getStream().get();
    assertEquals("image/jpeg", stream.contentType());
    try (InputStream is = stream.get()) {
        byte[] bytes = getBytes(is);
        assertEquals("some bytes", new String(bytes));
    }
}
Also used : StreamProvider(com.github.davidmoten.odata.client.StreamProvider) InputStream(java.io.InputStream) Test5Service(test5.container.Test5Service) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 Test5Service (test5.container.Test5Service)2 StreamProvider (com.github.davidmoten.odata.client.StreamProvider)1 InputStream (java.io.InputStream)1 Product (test5.entity.Product)1