http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/547725d7/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
----------------------------------------------------------------------
diff --git
a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
index 6af2b29..3547b50 100644
---
a/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
+++
b/lib/server-core-ext/src/test/java/org/apache/olingo/server/example/TripPinServiceTest.java
@@ -19,19 +19,31 @@
package org.apache.olingo.server.example;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import org.apache.catalina.Context;
import org.apache.catalina.startup.Tomcat;
+import org.apache.commons.io.IOUtils;
+import org.apache.http.Header;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
+import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.entity.ContentType;
+import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.util.EntityUtils;
+import org.apache.olingo.commons.core.Encoder;
import org.junit.AfterClass;
import org.junit.BeforeClass;
+import org.junit.Ignore;
import org.junit.Test;
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -55,10 +67,10 @@ public class TripPinServiceTest {
public static void beforeTest() throws Exception {
tomcat.setPort(TOMCAT_PORT);
File baseDir = new File(System.getProperty("java.io.tmpdir"));
- Context cxt = tomcat.addContext("/", baseDir.getAbsolutePath());
+ Context cxt = tomcat.addContext("/trippin", baseDir.getAbsolutePath());
Tomcat.addServlet(cxt, "trippin", new TripPinServlet());
cxt.addServletMapping("/*", "trippin");
- baseURL = "http://" + tomcat.getHost().getName() + ":"+ TOMCAT_PORT;
+ baseURL = "http://" + tomcat.getHost().getName() + ":"+
TOMCAT_PORT+"/trippin";
tomcat.start();
}
@@ -70,15 +82,41 @@ public class TripPinServiceTest {
private HttpHost getLocalhost() {
return new HttpHost(tomcat.getHost().getName(), 9900);
}
+
+ private HttpResponse httpGET(String url, int expectedStatus) throws
Exception{
+ HttpRequest request = new HttpGet(url);
+ return httpSend(request, expectedStatus);
+ }
+
+ private HttpResponse httpSend(HttpRequest request, int expectedStatus)
throws Exception{
+ HttpResponse response = http.execute(getLocalhost(), request);
+ assertEquals(expectedStatus, response.getStatusLine().getStatusCode());
+ return response;
+ }
+
+ private JsonNode getJSONNode(HttpResponse response) throws IOException,
+ JsonProcessingException {
+ ObjectMapper objectMapper = new ObjectMapper();
+ JsonNode node = objectMapper.readTree(response.getEntity().getContent());
+ return node;
+ }
+
+ private String getHeader(HttpResponse response, String header) {
+ Header[] headers = response.getAllHeaders();
+ for (int i = 0; i < headers.length; i++) {
+ if (headers[i].getName().equalsIgnoreCase(header)) {
+ return headers[i].getValue();
+ }
+ }
+ return null;
+ }
@Test
public void testEntitySet() throws Exception {
- HttpRequest req = new HttpGet("/People");
+ HttpRequest req = new HttpGet(baseURL+"/People");
req.setHeader("Content-Type", "application/json;odata.metadata=minimal");
- HttpResponse response = http.execute(getLocalhost(), req);
- assertEquals(200, response.getStatusLine().getStatusCode());
-
+ HttpResponse response = httpSend(req, 200);
JsonNode node = getJSONNode(response);
assertEquals("$metadata#People", node.get("@odata.context").asText());
@@ -88,710 +126,570 @@ public class TripPinServiceTest {
assertEquals("russellwhyte", person.get("UserName").asText());
}
+ @Test
+ public void testReadEntitySetWithPaging() throws Exception {
+ String url = baseURL+"/People";
+ HttpRequest request = new HttpGet(url);
+ request.setHeader("Prefer", "odata.maxpagesize=10");
+ HttpResponse response = httpSend(request, 200);
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People", node.get("@odata.context").asText());
+ assertEquals(baseURL+"/People?$skiptoken=10",
node.get("@odata.nextLink").asText());
- private JsonNode getJSONNode(HttpResponse response) throws IOException,
- JsonProcessingException {
- ObjectMapper objectMapper = new ObjectMapper();
- JsonNode node = objectMapper.readTree(response.getEntity().getContent());
- return node;
+ JsonNode person = ((ArrayNode)node.get("value")).get(0);
+ assertEquals("russellwhyte", person.get("UserName").asText());
+ assertEquals("odata.maxpagesize=10", getHeader(response,
"Preference-Applied"));
+ }
+
+ @Test
+ public void testReadEntityWithKey() throws Exception {
+ HttpResponse response = httpGET(baseURL + "/Airlines('AA')", 200);
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#Airlines/$entity",
node.get("@odata.context").asText());
+ assertEquals("American Airlines", node.get("Name").asText());
+ }
+
+ @Test
+ public void testReadEntityWithNonExistingKey() throws Exception {
+ HttpResponse response = httpGET(baseURL + "/Airlines('OO')", 404);
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
+
+ @Test
+ public void testRead$Count() throws Exception {
+ HttpResponse response = httpGET(baseURL + "/Airlines/$count", 200);
+ assertEquals("15", IOUtils.toString(response.getEntity().getContent()));
+ }
+
+ @Test
+ public void testReadPrimitiveProperty() throws Exception {
+ HttpResponse response = httpGET(baseURL + "/Airlines('AA')/Name", 200);
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#Airlines('AA')/Name",
node.get("@odata.context").asText());
+ assertEquals("American Airlines", node.get("value").asText());
+ }
+
+ @Test
+ public void testReadNonExistentProperty() throws Exception {
+ HttpResponse response = httpGET(baseURL + "/Airlines('AA')/Unknown", 404);
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
+
+ @Test
+ public void testReadPrimitiveArrayProperty() throws Exception {
+ HttpResponse response = httpGET(baseURL +
"/People('russellwhyte')/Emails", 200);
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Emails",
node.get("@odata.context").asText());
+ assertTrue(node.get("value").isArray());
+ assertEquals("[email protected]",
((ArrayNode)node.get("value")).get(0).asText());
+ assertEquals("[email protected]",
((ArrayNode)node.get("value")).get(1).asText());
+ }
+
+ @Test
+ public void testReadPrimitivePropertyValue() throws Exception {
+ HttpResponse response = httpGET(baseURL + "/Airlines('AA')/Name/$value",
200);
+ assertEquals("American Airlines",
IOUtils.toString(response.getEntity().getContent()));
+ }
+
+ @Test @Ignore
+ // TODO: Support geometry types to make this run
+ public void testReadComplexProperty() throws Exception {
+ //HttpResponse response = httpGET(baseURL + "/Airports('KSFO')/Location");
+ //fail("support geometry type");
+ }
+
+ @Test
+ public void testReadComplexArrayProperty() throws Exception {
+ HttpResponse response = httpGET(baseURL +
"/People('russellwhyte')/AddressInfo", 200);
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/AddressInfo",
node.get("@odata.context").asText());
+ assertTrue(node.get("value").isArray());
+ assertEquals("187 Suffolk Ln.",
((ArrayNode)node.get("value")).get(0).get("Address").asText());
+ }
+
+ @Test
+ public void testReadMedia() throws Exception {
+ HttpResponse response = httpGET(baseURL + "/Photos(1)/$value", 200);
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
+
+ @Test
+ public void testCreateMedia() throws Exception {
+ // treating update and create as same for now, as there is details about
+ // how entity payload and media payload can be sent at same time in
request's body
+ String editUrl = baseURL + "/Photos(1)/$value";
+ HttpPut request = new HttpPut(editUrl);
+ request.setEntity(new ByteArrayEntity("bytecontents".getBytes(),
ContentType.APPLICATION_OCTET_STREAM));
+ HttpResponse response = httpSend(request, 204);
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
+
+ @Test
+ public void testDeleteMedia() throws Exception {
+ // treating update and create as same for now, as there is details about
+ // how entity payload and media payload can be sent at same time in
request's body
+ String editUrl = baseURL + "/Photos(1)/$value";
+ HttpDelete request = new HttpDelete(editUrl);
+ HttpResponse response = httpSend(request, 204);
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
+
+ @Test
+ public void testCreateStream() throws Exception {
+ // treating update and create as same for now, as there is details about
+ // how entity payload and media payload can be sent at same time in
request's body
+ String editUrl = baseURL + "/Airlines('AA')/Picture";
+ HttpPost request = new HttpPost(editUrl);
+ request.setEntity(new ByteArrayEntity("bytecontents".getBytes(),
ContentType.APPLICATION_OCTET_STREAM));
+ // method not allowed
+ HttpResponse response = httpSend(request, 405);
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
+
+ @Test
+ public void testCreateStream2() throws Exception {
+ // treating update and create as same for now, as there is details about
+ // how entity payload and media payload can be sent at same time in
request's body
+ String editUrl = baseURL + "/Airlines('AA')/Picture";
+ HttpPut request = new HttpPut(editUrl);
+ request.setEntity(new ByteArrayEntity("bytecontents".getBytes(),
ContentType.APPLICATION_OCTET_STREAM));
+ HttpResponse response = httpSend(request, 204);
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
+
+ @Test
+ public void testDeleteStream() throws Exception {
+ // treating update and create as same for now, as there is details about
+ // how entity payload and media payload can be sent at same time in
request's body
+ String editUrl = baseURL + "/Airlines('AA')/Picture";
+ HttpDelete request = new HttpDelete(editUrl);
+ HttpResponse response = httpSend(request, 204);
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
+
+ @Test
+ public void testReadStream() throws Exception {
+ // treating update and create as same for now, as there is details about
+ // how entity payload and media payload can be sent at same time in
request's body
+ String editUrl = baseURL + "/Airlines('AA')/Picture";
+ HttpResponse response = httpGET(editUrl, 200);
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
+
+ @Test
+ public void testLambdaAny() throws Exception {
+ // this is just testing to see the labba expresions are going through the
+ // framework, none of the system options are not implemented in example
service
+ String query = "Friends/any(d:d/UserName eq 'foo')";
+ HttpResponse response = httpGET(baseURL +
"/People?$filter="+Encoder.encode(query), 200);
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
+
+ @Test
+ public void testSingleton() throws Exception {
+ HttpResponse response = httpGET(baseURL + "/Me", 200);
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#Me", node.get("@odata.context").asText());
+ assertEquals("russellwhyte", node.get("UserName").asText());
+ }
+
+ @Test
+ public void testSelectOption() throws Exception {
+ HttpResponse response = httpGET(baseURL +
"/People('russellwhyte')?$select=FirstName,LastName", 200);
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People(FirstName,LastName)/$entity",
node.get("@odata.context").asText());
+ assertEquals("Russell", node.get("FirstName").asText());
+ }
+
+ @Test
+ public void testActionImportWithNoResponse() throws Exception {
+ HttpPost request = new HttpPost(baseURL + "/ResetDataSource");
+ HttpResponse response = httpSend(request, 204);
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
+
+ @Test @Ignore
+ public void testFunctionImport() throws Exception {
+ //TODO: fails because of lack of geometery support
+ HttpResponse response = httpGET(baseURL +
"/GetNearestAirport(lat=23.0,lon=34.0)", 200);
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
+
+ @Test
+ public void testBadReferences() throws Exception {
+ HttpResponse response = httpGET(baseURL + "/People('russelwhyte')/$ref",
405);
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
+
+ @Test
+ public void testReadReferences() throws Exception {
+ HttpResponse response = httpGET(baseURL +
"/People('russellwhyte')/Friends/$ref", 200);
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#Collection($ref)",
node.get("@odata.context").asText());
+ assertTrue(node.get("value").isArray());
+ assertEquals("/People('scottketchum')",
((ArrayNode)node.get("value")).get(0).get("@odata.id").asText());
+ }
+
+ @Test
+ public void testAddCollectionReferences() throws Exception {
+ //GET
+ HttpResponse response = httpGET(baseURL +
"/People('kristakemp')/Friends/$ref", 200);
+ JsonNode node = getJSONNode(response);
+
+ assertTrue(node.get("value").isArray());
+ assertEquals("/People('genevievereeves')",
((ArrayNode)node.get("value")).get(0).get("@odata.id").asText());
+ assertNull(((ArrayNode)node.get("value")).get(1));
+
+ //ADD
+ String payload = "{\n" +
+ " \"@odata.context\": \""+baseURL+"/$metadata#Collection($ref)\",\n" +
+ " \"value\": [\n" +
+ " { \"@odata.id\": \"People('russellwhyte')\" },\n" +
+ " { \"@odata.id\": \"People('scottketchum')\" } \n" +
+ " ]\n" +
+ "}";
+ HttpPost postRequest = new HttpPost(baseURL +
"/People('kristakemp')/Friends/$ref");
+ postRequest.setEntity(new StringEntity(payload,
ContentType.APPLICATION_JSON));
+ response = httpSend(postRequest, 204);
+
+ //GET
+ response = httpGET(baseURL + "/People('kristakemp')/Friends/$ref", 200);
+ node = getJSONNode(response);
+
+ assertTrue(node.get("value").isArray());
+ assertEquals("/People('genevievereeves')",
((ArrayNode)node.get("value")).get(0).get("@odata.id").asText());
+ assertEquals("/People('russellwhyte')",
((ArrayNode)node.get("value")).get(1).get("@odata.id").asText());
+ assertEquals("/People('scottketchum')",
((ArrayNode)node.get("value")).get(2).get("@odata.id").asText());
+ }
+
+
+ @Test
+ public void testEntityId() throws Exception {
+ HttpResponse response = httpGET(baseURL+"/$entity?$id="+baseURL +
"/People('kristakemp')", 200);
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People/$entity",
node.get("@odata.context").asText());
+ assertEquals("kristakemp", node.get("UserName").asText());
+
+ // using relative URL
+ response = httpGET(baseURL+"/$entity?$id="+"People('kristakemp')", 200);
+ node = getJSONNode(response);
+ assertEquals("$metadata#People/$entity",
node.get("@odata.context").asText());
+ assertEquals("kristakemp", node.get("UserName").asText());
+ }
+
+ @Test
+ public void testCreateReadDeleteEntity() throws Exception {
+ String payload = "{\n" +
+ " \"UserName\":\"olingodude\",\n" +
+ " \"FirstName\":\"Olingo\",\n" +
+ " \"LastName\":\"Apache\",\n" +
+ " \"Emails\":[\n" +
+ " \"[email protected]\"\n" +
+ " ],\n" +
+ " \"AddressInfo\":[\n" +
+ " {\n" +
+ " \"Address\":\"100 apache Ln.\",\n" +
+ " \"City\":{\n" +
+ " \"CountryRegion\":\"United States\",\n" +
+ " \"Name\":\"Boise\",\n" +
+ " \"Region\":\"ID\"\n" +
+ " }\n" +
+ " }\n" +
+ " ],\n" +
+ " \"Gender\":\"0\",\n" +
+ " \"Concurrency\":635585295719432047\n" +
+ "}";
+ HttpPost postRequest = new HttpPost(baseURL + "/People");
+ postRequest.setEntity(new StringEntity(payload,
ContentType.APPLICATION_JSON));
+ postRequest.addHeader("Prefer", "return=minimal");
+
+ HttpResponse response = httpSend(postRequest, 204);
+ // the below woud be 204, if minimal was not supplied
+ assertEquals("/People('olingodude')", getHeader(response, "Location"));
+ assertEquals("return=minimal", getHeader(response, "Preference-Applied"));
+
+ String location = baseURL+getHeader(response, "Location");
+ response = httpGET(location, 200);
+ EntityUtils.consumeQuietly(response.getEntity());
+
+ HttpDelete deleteRequest = new HttpDelete(location);
+ response = httpSend(deleteRequest, 204);
+ EntityUtils.consumeQuietly(response.getEntity());
+
+ response = httpGET(location, 404);
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
+
+
+ @Test
+ public void testCreateEntityWithLinkToRelatedEntities() throws Exception {
+ String payload = "{\n" +
+ " \"UserName\":\"olingo\",\n" +
+ " \"FirstName\":\"Olingo\",\n" +
+ " \"LastName\":\"Apache\",\n" +
+ " \"Emails\":[\n" +
+ " \"[email protected]\"\n" +
+ " ],\n" +
+ " \"AddressInfo\":[\n" +
+ " {\n" +
+ " \"Address\":\"100 apache Ln.\",\n" +
+ " \"City\":{\n" +
+ " \"CountryRegion\":\"United States\",\n" +
+ " \"Name\":\"Boise\",\n" +
+ " \"Region\":\"ID\"\n" +
+ " }\n" +
+ " }\n" +
+ " ],\n" +
+ " \"Gender\":\"0\",\n" +
+ " \"Concurrency\":635585295719432047,\n" +
+ "\"[email protected]\":[\"" +
+ baseURL+"/People('russellwhyte')\",\""+
+ baseURL+"/People('scottketchum')\""+
+ "]"+
+ "}";
+ HttpPost postRequest = new HttpPost(baseURL + "/People");
+ postRequest.setEntity(new StringEntity(payload,
ContentType.APPLICATION_JSON));
+ postRequest.setHeader("Prefer", "return=minimal");
+ HttpResponse response = httpSend(postRequest, 204);
+ EntityUtils.consumeQuietly(response.getEntity());
+
+ response = httpGET(baseURL+"/People('olingo')/Friends", 200);
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People", node.get("@odata.context").asText());
+ assertTrue(node.get("value").isArray());
+ assertEquals("scottketchum",
((ArrayNode)node.get("value")).get(1).get("UserName").asText());
+ }
+
+ @Test
+ public void testUpdatePrimitiveProperty() throws Exception {
+ String payload = "{"
+ + " \"value\":\"Pilar Ackerman\""
+ + "}";
+
+ String editUrl = baseURL + "/People('russellwhyte')/FirstName";
+ HttpPut postRequest = new HttpPut(editUrl);
+ postRequest.setEntity(new StringEntity(payload,
ContentType.APPLICATION_JSON));
+ HttpResponse response = httpSend(postRequest, 204);
+ EntityUtils.consumeQuietly(response.getEntity());
+
+ response = httpGET(editUrl, 200);
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/FirstName",
node.get("@odata.context").asText());
+ assertEquals("Pilar Ackerman", node.get("value").asText());
+ }
+
+ @Test
+ public void testUpdatePrimitiveArrayProperty() throws Exception {
+ String payload = "{"
+ + " \"value\": [\n" +
+ " \"[email protected]\"\n" +
+ " ]"
+ + "}";
+
+ String editUrl = baseURL + "/People('russellwhyte')/Emails";
+ HttpPut postRequest = new HttpPut(editUrl);
+ postRequest.setEntity(new StringEntity(payload,
ContentType.APPLICATION_JSON));
+ HttpResponse response = httpSend(postRequest, 204);
+ EntityUtils.consumeQuietly(response.getEntity());
+
+ response = httpGET(editUrl, 200);
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Emails",
node.get("@odata.context").asText());
+ assertTrue(node.get("value").isArray());
+ assertEquals("[email protected]",
((ArrayNode)node.get("value")).get(0).asText());
+ }
+
+ @Test
+ public void testDeleteProperty() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/FirstName";
+ HttpResponse response = httpGET(editUrl, 200);
+ JsonNode node = getJSONNode(response);
+ assertEquals("Russell", node.get("value").asText());
+
+ HttpDelete deleteRequest = new HttpDelete(editUrl);
+ response = httpSend(deleteRequest, 204);
+ EntityUtils.consumeQuietly(response.getEntity());
+
+ response = httpGET(editUrl, 204);
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityCollection() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Friends";
+ HttpResponse response = httpGET(editUrl, 200);
+
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People", node.get("@odata.context").asText());
+
+ JsonNode person = ((ArrayNode)node.get("value")).get(0);
+ assertEquals("scottketchum", person.get("UserName").asText());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityCollection2() throws Exception {
+ String editUrl = baseURL +
"/People('russellwhyte')/Friends('scottketchum')/Trips";
+ HttpResponse response = httpGET(editUrl, 200);
+ JsonNode node = getJSONNode(response);
+
assertEquals("$metadata#People('russellwhyte')/Friends('scottketchum')/Trips",
+ node.get("@odata.context").asText());
+ assertTrue(node.get("value").isArray());
+ assertEquals("1001",
((ArrayNode)node.get("value")).get(0).get("TripId").asText());
}
-// private static Server server = new Server();
-// private static String baseURL;
-// private static HttpClient http = new HttpClient();
-//
-// @BeforeClass
-// public static void beforeTest() throws Exception {
-// ServerConnector connector = new ServerConnector(server);
-// server.setConnectors(new Connector[] { connector });
-//
-// ServletContextHandler context = new ServletContextHandler();
-// context.setContextPath("/trippin");
-// context.addServlet(new ServletHolder(new TripPinServlet()), "/*");
-// server.setHandler(context);
-// server.start();
-// int port = connector.getLocalPort();
-// http.start();
-// baseURL = "http://localhost:"+port+"/trippin";
-// }
-//
-// @AfterClass
-// public static void afterTest() throws Exception {
-// server.stop();
-// }
-//
-// @Test
-// public void testEntitySet() throws Exception {
-// ContentResponse response = http.newRequest(baseURL + "/People")
-// .header("Content-Type", "application/json;odata.metadata=minimal")
-// .method(HttpMethod.GET)
-// .send();
-// assertEquals(200, response.getStatus());
-//
-// JsonNode node = getJSONNode(response);
-//
-// assertEquals("$metadata#People", node.get("@odata.context").asText());
-// assertEquals(baseURL+"/People?$skiptoken=8",
node.get("@odata.nextLink").asText());
-//
-// JsonNode person = ((ArrayNode)node.get("value")).get(0);
-// assertEquals("russellwhyte", person.get("UserName").asText());
-// }
-//
-// private JsonNode getJSONNode(ContentResponse response) throws IOException,
-// JsonProcessingException {
-// ObjectMapper objectMapper = new ObjectMapper();
-// JsonNode node = objectMapper.readTree(response.getContent());
-// return node;
-// }
-//
-// @Test
-// public void testReadEntitySetWithPaging() throws Exception {
-// ContentResponse response = http.newRequest(baseURL + "/People")
-// .header("Prefer", "odata.maxpagesize=10").send();
-//
-// assertEquals(200, response.getStatus());
-//
-// JsonNode node = getJSONNode(response);
-// assertEquals("$metadata#People", node.get("@odata.context").asText());
-// assertEquals(baseURL+"/People?$skiptoken=10",
node.get("@odata.nextLink").asText());
-//
-// JsonNode person = ((ArrayNode)node.get("value")).get(0);
-// assertEquals("russellwhyte", person.get("UserName").asText());
-//
-// assertNotNull(response.getHeaders().get("Preference-Applied"));
-// }
-//
-// @Test
-// public void testReadEntityWithKey() throws Exception {
-// ContentResponse response = http.GET(baseURL + "/Airlines('AA')");
-// assertEquals(200, response.getStatus());
-// JsonNode node = getJSONNode(response);
-// assertEquals("$metadata#Airlines/$entity",
node.get("@odata.context").asText());
-// assertEquals("American Airlines", node.get("Name").asText());
-// }
-//
-// @Test
-// public void testReadEntityWithNonExistingKey() throws Exception {
-// ContentResponse response = http.GET(baseURL + "/Airlines('OO')");
-// assertEquals(404, response.getStatus());
-// }
-//
-// @Test
-// public void testRead$Count() throws Exception {
-// ContentResponse response = http.GET(baseURL + "/Airlines/$count");
-// assertEquals(200, response.getStatus());
-// assertEquals("15", response.getContentAsString());
-// }
-//
-// @Test
-// public void testReadPrimitiveProperty() throws Exception {
-// ContentResponse response = http.GET(baseURL + "/Airlines('AA')/Name");
-// assertEquals(200, response.getStatus());
-// JsonNode node = getJSONNode(response);
-// assertEquals("$metadata#Airlines('AA')/Name",
node.get("@odata.context").asText());
-// assertEquals("American Airlines", node.get("value").asText());
-// }
-//
-// @Test
-// public void testReadNonExistentProperty() throws Exception {
-// ContentResponse response = http.GET(baseURL + "/Airlines('AA')/Unknown");
-// assertEquals(404, response.getStatus());
-// }
-//
-// @Test
-// public void testReadPrimitiveArrayProperty() throws Exception {
-// ContentResponse response = http.GET(baseURL +
"/People('russellwhyte')/Emails");
-// assertEquals(200, response.getStatus());
-// JsonNode node = getJSONNode(response);
-// assertEquals("$metadata#People('russellwhyte')/Emails",
node.get("@odata.context").asText());
-// assertTrue(node.get("value").isArray());
-// assertEquals("[email protected]",
((ArrayNode)node.get("value")).get(0).asText());
-// assertEquals("[email protected]",
((ArrayNode)node.get("value")).get(1).asText());
-// }
-//
-// @Test
-// public void testReadPrimitivePropertyValue() throws Exception {
-// ContentResponse response = http.GET(baseURL +
"/Airlines('AA')/Name/$value");
-// assertEquals(200, response.getStatus());
-// assertEquals("American Airlines", response.getContentAsString());
-// }
-//
-// @Test @Ignore
-// // TODO: Support geometry types to make this run
-// public void testReadComplexProperty() throws Exception {
-// ContentResponse response = http.GET(baseURL +
"/Airports('KSFO')/Location");
-// fail("support geometry type");
-// }
-//
-// @Test
-// public void testReadComplexArrayProperty() throws Exception {
-// ContentResponse response = http.GET(baseURL +
"/People('russellwhyte')/AddressInfo");
-// assertEquals(200, response.getStatus());
-// JsonNode node = getJSONNode(response);
-// assertEquals("$metadata#People('russellwhyte')/AddressInfo",
node.get("@odata.context").asText());
-// assertTrue(node.get("value").isArray());
-// assertEquals("187 Suffolk Ln.",
((ArrayNode)node.get("value")).get(0).get("Address").asText());
-// }
-//
-// @Test
-// public void testReadMedia() throws Exception {
-// ContentResponse response = http.GET(baseURL + "/Photos(1)/$value");
-// assertEquals(200, response.getStatus());
-// }
-//
-// @Test
-// public void testCreateMedia() throws Exception {
-// // treating update and create as same for now, as there is details about
-// // how entity payload and media payload can be sent at same time in
request's body
-// String editUrl = baseURL + "/Photos(1)/$value";
-// ContentResponse response = http.newRequest(editUrl)
-// .content(content("bytecontents"), "image/jpeg")
-// .method(HttpMethod.PUT)
-// .send();
-// assertEquals(204, response.getStatus());
-// }
-//
-// @Test
-// public void testDeleteMedia() throws Exception {
-// // treating update and create as same for now, as there is details about
-// // how entity payload and media payload can be sent at same time in
request's body
-// String editUrl = baseURL + "/Photos(1)/$value";
-// ContentResponse response = http.newRequest(editUrl)
-// .content(content("bytecontents"), "image/jpeg")
-// .method(HttpMethod.DELETE)
-// .send();
-// assertEquals(204, response.getStatus());
-// }
-//
-// @Test
-// public void testCreateStream() throws Exception {
-// // treating update and create as same for now, as there is details about
-// // how entity payload and media payload can be sent at same time in
request's body
-// String editUrl = baseURL + "/Airlines('AA')/Picture";
-// ContentResponse response = http.newRequest(editUrl)
-// .content(content("bytecontents"), "image/jpeg")
-// .method(HttpMethod.POST)
-// .send();
-// // method not allowed
-// assertEquals(405, response.getStatus());
-// }
-//
-// @Test
-// public void testCreateStream2() throws Exception {
-// // treating update and create as same for now, as there is details about
-// // how entity payload and media payload can be sent at same time in
request's body
-// String editUrl = baseURL + "/Airlines('AA')/Picture";
-// ContentResponse response = http.newRequest(editUrl)
-// .content(content("bytecontents"), "image/jpeg")
-// .method(HttpMethod.PUT)
-// .send();
-// assertEquals(204, response.getStatus());
-// }
-//
-// @Test
-// public void testDeleteStream() throws Exception {
-// // treating update and create as same for now, as there is details about
-// // how entity payload and media payload can be sent at same time in
request's body
-// String editUrl = baseURL + "/Airlines('AA')/Picture";
-// ContentResponse response = http.newRequest(editUrl)
-// .method(HttpMethod.DELETE)
-// .send();
-// assertEquals(204, response.getStatus());
-// }
-//
-// @Test
-// public void testReadStream() throws Exception {
-// // treating update and create as same for now, as there is details about
-// // how entity payload and media payload can be sent at same time in
request's body
-// String editUrl = baseURL + "/Airlines('AA')/Picture";
-// ContentResponse response = http.newRequest(editUrl)
-// .method(HttpMethod.GET)
-// .send();
-// assertEquals(200, response.getStatus());
-// }
-//
-// @Test
-// public void testLambdaAny() throws Exception {
-// // this is just testing to see the labba expresions are going through the
-// // framework, none of the system options are not implemented in example
service
-// String query = "Friends/any(d:d/UserName eq 'foo')";
-// ContentResponse response = http.newRequest(baseURL +
"/People?$filter="+Encoder.encode(query))
-// .method(HttpMethod.GET)
-// .send();
-// assertEquals(200, response.getStatus());
-// }
-//
-// @Test
-// public void testSingleton() throws Exception {
-// ContentResponse response = http.GET(baseURL + "/Me");
-// assertEquals(200, response.getStatus());
-// JsonNode node = getJSONNode(response);
-// assertEquals("$metadata#Me", node.get("@odata.context").asText());
-// assertEquals("russellwhyte", node.get("UserName").asText());
-// }
-//
-// @Test
-// public void testSelectOption() throws Exception {
-// ContentResponse response = http.GET(baseURL +
"/People('russellwhyte')?$select=FirstName,LastName");
-// assertEquals(200, response.getStatus());
-// JsonNode node = getJSONNode(response);
-// assertEquals("$metadata#People(FirstName,LastName)/$entity",
node.get("@odata.context").asText());
-// assertEquals("Russell", node.get("FirstName").asText());
-// }
-//
-// @Test
-// public void testActionImportWithNoResponse() throws Exception {
-// ContentResponse response = http.POST(baseURL +
"/ResetDataSource").send();
-// assertEquals(204, response.getStatus());
-// }
-//
-// @Test
-// public void testFunctionImport() throws Exception {
-// //TODO: fails because of lack of geometery support
-// ContentResponse response = http.GET(baseURL +
"/GetNearestAirport(lat=23.0,lon=34.0)");
-// }
-//
-// @Test
-// public void testBadReferences() throws Exception {
-// ContentResponse response = http.GET(baseURL +
"/People('russelwhyte')/$ref");
-// assertEquals(405, response.getStatus());
-// }
-//
-// @Test
-// public void testReadReferences() throws Exception {
-// ContentResponse response = http.GET(baseURL +
"/People('russellwhyte')/Friends/$ref");
-// assertEquals(200, response.getStatus());
-// JsonNode node = getJSONNode(response);
-// assertEquals("$metadata#Collection($ref)",
node.get("@odata.context").asText());
-// assertTrue(node.get("value").isArray());
-// assertEquals("/People('scottketchum')",
((ArrayNode)node.get("value")).get(0).get("@odata.id").asText());
-// }
-//
-// @Test
-// public void testAddCollectionReferences() throws Exception {
-// //GET
-// ContentResponse response = http.GET(baseURL +
"/People('kristakemp')/Friends/$ref");
-// assertEquals(200, response.getStatus());
-// JsonNode node = getJSONNode(response);
-//
-// assertTrue(node.get("value").isArray());
-// assertEquals("/People('genevievereeves')",
((ArrayNode)node.get("value")).get(0).get("@odata.id").asText());
-// assertNull(((ArrayNode)node.get("value")).get(1));
-//
-// //ADD
-// String payload = "{\n" +
-// " \"@odata.context\":
\""+baseURL+"/$metadata#Collection($ref)\",\n" +
-// " \"value\": [\n" +
-// " { \"@odata.id\": \"People('russellwhyte')\" },\n" +
-// " { \"@odata.id\": \"People('scottketchum')\" } \n" +
-// " ]\n" +
-// "}";
-// response = http.POST(baseURL + "/People('kristakemp')/Friends/$ref")
-// .content(content(payload), "application/json")
-// .send();
-// assertEquals(204, response.getStatus());
-//
-// //GET
-// response = http.GET(baseURL + "/People('kristakemp')/Friends/$ref");
-// assertEquals(200, response.getStatus());
-// node = getJSONNode(response);
-//
-// assertTrue(node.get("value").isArray());
-// assertEquals("/People('genevievereeves')",
((ArrayNode)node.get("value")).get(0).get("@odata.id").asText());
-// assertEquals("/People('russellwhyte')",
((ArrayNode)node.get("value")).get(1).get("@odata.id").asText());
-// assertEquals("/People('scottketchum')",
((ArrayNode)node.get("value")).get(2).get("@odata.id").asText());
-// }
-//
-//
-// @Test
-// public void testEntityId() throws Exception {
-// ContentResponse response = http.GET(baseURL+"/$entity?$id="+baseURL +
"/People('kristakemp')");
-// assertEquals(200, response.getStatus());
-// JsonNode node = getJSONNode(response);
-// assertEquals("$metadata#People/$entity",
node.get("@odata.context").asText());
-// assertEquals("kristakemp", node.get("UserName").asText());
-//
-// // using relative URL
-// response = http.GET(baseURL+"/$entity?$id="+"People('kristakemp')");
-// assertEquals(200, response.getStatus());
-// node = getJSONNode(response);
-// assertEquals("$metadata#People/$entity",
node.get("@odata.context").asText());
-// assertEquals("kristakemp", node.get("UserName").asText());
-// }
-//
-// @Test
-// public void testCreateReadDeleteEntity() throws Exception {
-// String payload = "{\n" +
-// " \"UserName\":\"olingodude\",\n" +
-// " \"FirstName\":\"Olingo\",\n" +
-// " \"LastName\":\"Apache\",\n" +
-// " \"Emails\":[\n" +
-// " \"[email protected]\"\n" +
-// " ],\n" +
-// " \"AddressInfo\":[\n" +
-// " {\n" +
-// " \"Address\":\"100 apache Ln.\",\n" +
-// " \"City\":{\n" +
-// " \"CountryRegion\":\"United States\",\n" +
-// " \"Name\":\"Boise\",\n" +
-// " \"Region\":\"ID\"\n" +
-// " }\n" +
-// " }\n" +
-// " ],\n" +
-// " \"Gender\":\"0\",\n" +
-// " \"Concurrency\":635585295719432047\n" +
-// "}";
-// ContentResponse response = http.POST(baseURL + "/People")
-// .content(content(payload), "application/json")
-// .header("Prefer", "return=minimal")
-// .send();
-// // the below woud be 204, if minimal was not supplied
-// assertEquals(204, response.getStatus());
-// assertEquals("/People('olingodude')",
response.getHeaders().get("Location"));
-// assertEquals("return=minimal",
response.getHeaders().get("Preference-Applied"));
-//
-// String location = baseURL+response.getHeaders().get("Location");
-// response = http.GET(location);
-// assertEquals(200, response.getStatus());
-//
-// response = http.newRequest(location).method(HttpMethod.DELETE).send();
-// assertEquals(204, response.getStatus());
-//
-// response = http.GET(location);
-// assertEquals(404, response.getStatus());
-// }
-//
-//
-// @Test
-// public void testCreateEntityWithLinkToRelatedEntities() throws Exception {
-// String payload = "{\n" +
-// " \"UserName\":\"olingo\",\n" +
-// " \"FirstName\":\"Olingo\",\n" +
-// " \"LastName\":\"Apache\",\n" +
-// " \"Emails\":[\n" +
-// " \"[email protected]\"\n" +
-// " ],\n" +
-// " \"AddressInfo\":[\n" +
-// " {\n" +
-// " \"Address\":\"100 apache Ln.\",\n" +
-// " \"City\":{\n" +
-// " \"CountryRegion\":\"United States\",\n" +
-// " \"Name\":\"Boise\",\n" +
-// " \"Region\":\"ID\"\n" +
-// " }\n" +
-// " }\n" +
-// " ],\n" +
-// " \"Gender\":\"0\",\n" +
-// " \"Concurrency\":635585295719432047,\n" +
-// "\"[email protected]\":[\"" +
-// baseURL+"/People('russellwhyte')\",\""+
-// baseURL+"/People('scottketchum')\""+
-// "]"+
-// "}";
-// ContentResponse response = http.POST(baseURL + "/People")
-// .content(content(payload), "application/json")
-// .header("Prefer", "return=minimal")
-// .send();
-// // the below woud be 204, if minimal was not supplied
-// assertEquals(204, response.getStatus());
-//
-// response = http.GET(baseURL+"/People('olingo')/Friends");
-// assertEquals(200, response.getStatus());
-//
-// JsonNode node = getJSONNode(response);
-// assertEquals("$metadata#People", node.get("@odata.context").asText());
-// assertTrue(node.get("value").isArray());
-// assertEquals("scottketchum",
((ArrayNode)node.get("value")).get(1).get("UserName").asText());
-// }
-//
-// @Test
-// public void testUpdatePrimitiveProperty() throws Exception {
-// String payload = "{"
-// + " \"value\":\"Pilar Ackerman\""
-// + "}";
-//
-// String editUrl = baseURL + "/People('russellwhyte')/FirstName";
-// ContentResponse response = http.newRequest(editUrl)
-// .content(content(payload), "application/json")
-// .method(HttpMethod.PUT)
-// .send();
-// assertEquals(204, response.getStatus());
-//
-// response = http.GET(editUrl);
-// assertEquals(200, response.getStatus());
-// JsonNode node = getJSONNode(response);
-// assertEquals("$metadata#People('russellwhyte')/FirstName",
node.get("@odata.context").asText());
-// assertEquals("Pilar Ackerman", node.get("value").asText());
-// }
-//
-// @Test
-// public void testUpdatePrimitiveArrayProperty() throws Exception {
-// String payload = "{"
-// + " \"value\": [\n" +
-// " \"[email protected]\"\n" +
-// " ]"
-// + "}";
-//
-// String editUrl = baseURL + "/People('russellwhyte')/Emails";
-// ContentResponse response = http.newRequest(editUrl)
-// .content(content(payload), "application/json")
-// .method(HttpMethod.PUT)
-// .send();
-// assertEquals(204, response.getStatus());
-//
-// response = http.GET(editUrl);
-// assertEquals(200, response.getStatus());
-// JsonNode node = getJSONNode(response);
-// assertEquals("$metadata#People('russellwhyte')/Emails",
node.get("@odata.context").asText());
-// assertTrue(node.get("value").isArray());
-// assertEquals("[email protected]",
((ArrayNode)node.get("value")).get(0).asText());
-// }
-//
-// @Test
-// public void testDeleteProperty() throws Exception {
-// String editUrl = baseURL + "/People('russellwhyte')/FirstName";
-// ContentResponse response = http.GET(editUrl);
-// assertEquals(200, response.getStatus());
-// JsonNode node = getJSONNode(response);
-// assertEquals("Russell", node.get("value").asText());
-//
-// response = http.newRequest(editUrl)
-// .method(HttpMethod.DELETE)
-// .send();
-// assertEquals(204, response.getStatus());
-//
-// response = http.GET(editUrl);
-// assertEquals(204, response.getStatus());
-// }
-//
-// @Test
-// public void testReadNavigationPropertyEntityCollection() throws Exception {
-// String editUrl = baseURL + "/People('russellwhyte')/Friends";
-// ContentResponse response = http.GET(editUrl);
-// assertEquals(200, response.getStatus());
-//
-// JsonNode node = getJSONNode(response);
-// assertEquals("$metadata#People", node.get("@odata.context").asText());
-//
-// JsonNode person = ((ArrayNode)node.get("value")).get(0);
-// assertEquals("scottketchum", person.get("UserName").asText());
-// }
-//
-// @Test
-// public void testReadNavigationPropertyEntityCollection2() throws Exception
{
-// String editUrl = baseURL +
"/People('russellwhyte')/Friends('scottketchum')/Trips";
-// ContentResponse response = http.GET(editUrl);
-// assertEquals(200, response.getStatus());
-//
-// JsonNode node = getJSONNode(response);
-//
assertEquals("$metadata#People('russellwhyte')/Friends('scottketchum')/Trips",
-// node.get("@odata.context").asText());
-// assertTrue(node.get("value").isArray());
-// assertEquals("1001",
((ArrayNode)node.get("value")).get(0).get("TripId").asText());
-// }
-//
-// @Test
-// public void testReadNavigationPropertyEntity() throws Exception {
-// String editUrl = baseURL + "/People('russellwhyte')/Trips(1003)";
-// ContentResponse response = http.GET(editUrl);
-// assertEquals(200, response.getStatus());
-//
-// JsonNode node = getJSONNode(response);
-// assertEquals("$metadata#People('russellwhyte')/Trips/$entity",
-// node.get("@odata.context").asText());
-// assertEquals("f94e9116-8bdd-4dac-ab61-08438d0d9a71",
node.get("ShareId").asText());
-// }
-//
-// @Test
-// public void testReadNavigationPropertyEntityNotExisting() throws Exception
{
-// String editUrl = baseURL + "/People('russellwhyte')/Trips(9999)";
-// ContentResponse response = http.GET(editUrl);
-// assertEquals(204, response.getStatus());
-// }
-//
-// @Test
-// public void testReadNavigationPropertyEntitySetNotExisting() throws
Exception {
-// String editUrl = baseURL + "/People('jhondoe')/Trips";
-// ContentResponse response = http.GET(editUrl);
-// assertEquals(200, response.getStatus());
-// JsonNode node = getJSONNode(response);
-// assertEquals("$metadata#People('jhondoe')/Trips",
-// node.get("@odata.context").asText());
-// assertEquals(0, ((ArrayNode)node.get("value")).size());
-// }
-//
-// @Test
-// public void testBadNavigationProperty() throws Exception {
-// String editUrl = baseURL + "/People('russellwhyte')/Unknown";
-// ContentResponse response = http.GET(editUrl);
-// assertEquals(404, response.getStatus());
-// }
-//
-// @Test
-// public void testReadNavigationPropertyEntityProperty() throws Exception {
-// String editUrl = baseURL +
"/People('russellwhyte')/Trips(1003)/PlanItems(5)/ConfirmationCode";
-// ContentResponse response = http.GET(editUrl);
-// assertEquals(200, response.getStatus());
-//
-// JsonNode node = getJSONNode(response);
-//
assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems(5)/ConfirmationCode",
-// node.get("@odata.context").asText());
-//
-// assertEquals("JH58494", node.get("value").asText());
-// }
-//
-// @Test
-// public void testReadNavigationPropertyEntityMultipleDerivedTypes() throws
Exception {
-// String editUrl = baseURL +
"/People('russellwhyte')/Trips(1003)/PlanItems";
-// ContentResponse response = http.GET(editUrl);
-// assertEquals(200, response.getStatus());
-//
-// JsonNode node = getJSONNode(response);
-// assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems",
-// node.get("@odata.context").asText());
-//
-// assertEquals("#Microsoft.OData.SampleService.Models.TripPin.Flight",
-// ((ArrayNode) node.get("value")).get(0).get("@odata.type").asText());
-// }
-//
-// @Test
-// public void testReadNavigationPropertyEntityCoolectionDerivedFilter()
throws Exception {
-// String editUrl = baseURL
-// +
"/People('russellwhyte')/Trips(1003)/PlanItems/Microsoft.OData.SampleService.Models.TripPin.Event";
-// ContentResponse response = http.GET(editUrl);
-// assertEquals(200, response.getStatus());
-//
-// JsonNode node = getJSONNode(response);
-// assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems/"
-// + "Microsoft.OData.SampleService.Models.TripPin.Event",
-// node.get("@odata.context").asText());
-//
-// assertEquals("#Microsoft.OData.SampleService.Models.TripPin.Event",
-// ((ArrayNode) node.get("value")).get(0).get("@odata.type").asText());
-// }
-//
-// @Test
-// public void testReadNavigationPropertyEntityDerivedFilter() throws
Exception {
-// String editUrl = baseURL+
"/People('russellwhyte')/Trips(1003)/PlanItems(56)/"
-// + "Microsoft.OData.SampleService.Models.TripPin.Event";
-// ContentResponse response = http.GET(editUrl);
-// assertEquals(200, response.getStatus());
-// JsonNode node = getJSONNode(response);
-// assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems/"
-// + "Microsoft.OData.SampleService.Models.TripPin.Event/$entity",
-// node.get("@odata.context").asText());
-//
-// assertEquals("#Microsoft.OData.SampleService.Models.TripPin.Event",
node.get("@odata.type").asText());
-// assertEquals("56", node.get("PlanItemId").asText());
-// }
-//
-// @Test
-// public void testUpdateReference() throws Exception {
-// ContentResponse response =
http.GET(baseURL+"/People('ronaldmundy')/Photo/$ref");
-// assertEquals(200, response.getStatus());
-// JsonNode node = getJSONNode(response);
-// assertEquals("/Photos(12)", node.get("@odata.id").asText());
-//
-// String msg = "{\n" +
-// "\"@odata.id\": \"/Photos(11)\"\n" +
-// "}";
-// String editUrl = baseURL + "/People('ronaldmundy')/Photo/$ref";
-// response = http.newRequest(editUrl)
-// .method(HttpMethod.PUT)
-// .content(content(msg))
-// .header("Content-Type", "application/json;odata.metadata=minimal")
-// .send();
-// assertEquals(204, response.getStatus());
-//
-// response = http.GET(baseURL+"/People('ronaldmundy')/Photo/$ref");
-// assertEquals(200, response.getStatus());
-// node = getJSONNode(response);
-// assertEquals("/Photos(11)", node.get("@odata.id").asText());
-// }
-//
-// @Test
-// public void testAddDelete2ReferenceCollection() throws Exception {
-// // add
-// String msg = "{\n" +
-// "\"@odata.id\": \"/People('russellwhyte')\"\n" +
-// "}";
-// String editUrl = baseURL + "/People('vincentcalabrese')/Friends/$ref";
-// ContentResponse response = http.newRequest(editUrl)
-// .method(HttpMethod.POST)
-// .content(content(msg))
-// .header("Content-Type", "application/json;odata.metadata=minimal")
-// .send();
-// assertEquals(204, response.getStatus());
-//
-// // get
-// response = http.GET(editUrl);
-// assertEquals(200, response.getStatus());
-// JsonNode node = getJSONNode(response);
-// assertEquals("/People('russellwhyte')",
-// ((ArrayNode) node.get("value")).get(2).get("@odata.id").asText());
-//
-// //delete
-// response =
http.newRequest(editUrl+"?$id="+baseURL+"/People('russellwhyte')")
-// .method(HttpMethod.DELETE)
-// .content(content(msg))
-// .header("Content-Type", "application/json;odata.metadata=minimal")
-// .send();
-// assertEquals(204, response.getStatus());
-//
-// // get
-// response = http.GET(editUrl);
-// assertEquals(200, response.getStatus());
-// node = getJSONNode(response);
-// assertNull("/People('russellwhyte')", ((ArrayNode)
node.get("value")).get(2));
-// }
-//
-// @Test
-// public void testDeleteReference() throws Exception {
-// String editUrl = baseURL + "/People('russellwhyte')/Photo/$ref";
-// ContentResponse response = http.GET(editUrl);
-// assertEquals(200, response.getStatus());
-//
-// response = http.newRequest(editUrl)
-// .method(HttpMethod.DELETE)
-// .send();
-// assertEquals(204, response.getStatus());
-//
-// response = http.GET(editUrl);
-// assertEquals(204, response.getStatus());
-// }
-//
-// @Test
-// public void testCrossJoin() throws Exception {
-// String editUrl = baseURL + "/$crossjoin(People,Airlines)";
-// ContentResponse response = http.GET(editUrl);
-// assertEquals(200, response.getStatus());
-// }
-//
-// public static ContentProvider content(final String msg) {
-// return new ContentProvider() {
-// boolean hasNext = true;
-//
-// @Override
-// public Iterator<ByteBuffer> iterator() {
-// return new Iterator<ByteBuffer>() {
-// @Override
-// public boolean hasNext() {
-// return hasNext;
-// }
-// @Override
-// public ByteBuffer next() {
-// hasNext = false;
-// return ByteBuffer.wrap(msg.getBytes());
-// }
-// @Override
-// public void remove() {
-// }
-// };
-// }
-// @Override
-// public long getLength() {
-// return msg.length();
-// }
-// };
-// }
+ @Test
+ public void testReadNavigationPropertyEntity() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Trips(1003)";
+ HttpResponse response = httpGET(editUrl, 200);
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Trips/$entity",
+ node.get("@odata.context").asText());
+ assertEquals("f94e9116-8bdd-4dac-ab61-08438d0d9a71",
node.get("ShareId").asText());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityNotExisting() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Trips(9999)";
+ HttpResponse response = httpGET(editUrl, 204);
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntitySetNotExisting() throws
Exception {
+ String editUrl = baseURL + "/People('jhondoe')/Trips";
+ HttpResponse response = httpGET(editUrl, 200);
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('jhondoe')/Trips",
+ node.get("@odata.context").asText());
+ assertEquals(0, ((ArrayNode)node.get("value")).size());
+ }
+
+ @Test
+ public void testBadNavigationProperty() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Unknown";
+ HttpResponse response = httpGET(editUrl, 404);
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityProperty() throws Exception {
+ String editUrl = baseURL +
"/People('russellwhyte')/Trips(1003)/PlanItems(5)/ConfirmationCode";
+ HttpResponse response = httpGET(editUrl, 200);
+ JsonNode node = getJSONNode(response);
+
assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems(5)/ConfirmationCode",
+ node.get("@odata.context").asText());
+ assertEquals("JH58494", node.get("value").asText());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityMultipleDerivedTypes() throws
Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Trips(1003)/PlanItems";
+ HttpResponse response = httpGET(editUrl, 200);
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems",
+ node.get("@odata.context").asText());
+ assertEquals("#Microsoft.OData.SampleService.Models.TripPin.Flight",
+ ((ArrayNode) node.get("value")).get(0).get("@odata.type").asText());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityCoolectionDerivedFilter() throws
Exception {
+ String editUrl = baseURL
+ +
"/People('russellwhyte')/Trips(1003)/PlanItems/Microsoft.OData.SampleService.Models.TripPin.Event";
+ HttpResponse response = httpGET(editUrl, 200);
+
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems/"
+ + "Microsoft.OData.SampleService.Models.TripPin.Event",
+ node.get("@odata.context").asText());
+
+ assertEquals("#Microsoft.OData.SampleService.Models.TripPin.Event",
+ ((ArrayNode) node.get("value")).get(0).get("@odata.type").asText());
+ }
+
+ @Test
+ public void testReadNavigationPropertyEntityDerivedFilter() throws Exception
{
+ String editUrl = baseURL+
"/People('russellwhyte')/Trips(1003)/PlanItems(56)/"
+ + "Microsoft.OData.SampleService.Models.TripPin.Event";
+ HttpResponse response = httpGET(editUrl, 200);
+ JsonNode node = getJSONNode(response);
+ assertEquals("$metadata#People('russellwhyte')/Trips(1003)/PlanItems/"
+ + "Microsoft.OData.SampleService.Models.TripPin.Event/$entity",
+ node.get("@odata.context").asText());
+ assertEquals("#Microsoft.OData.SampleService.Models.TripPin.Event",
node.get("@odata.type").asText());
+ assertEquals("56", node.get("PlanItemId").asText());
+ }
+
+ @Test
+ public void testUpdateReference() throws Exception {
+ HttpResponse response =
httpGET(baseURL+"/People('ronaldmundy')/Photo/$ref", 200);
+ JsonNode node = getJSONNode(response);
+ assertEquals("/Photos(12)", node.get("@odata.id").asText());
+
+ String msg = "{\n" +
+ "\"@odata.id\": \"/Photos(11)\"\n" +
+ "}";
+ String editUrl = baseURL + "/People('ronaldmundy')/Photo/$ref";
+ HttpPut putRequest = new HttpPut(editUrl);
+ putRequest.setEntity(new StringEntity(msg, ContentType.APPLICATION_JSON));
+ putRequest.setHeader("Content-Type",
"application/json;odata.metadata=minimal");
+ response = httpSend(putRequest, 204);
+ EntityUtils.consumeQuietly(response.getEntity());
+
+ response = httpGET(baseURL+"/People('ronaldmundy')/Photo/$ref", 200);
+ node = getJSONNode(response);
+ assertEquals("/Photos(11)", node.get("@odata.id").asText());
+ }
+
+ @Test
+ public void testAddDelete2ReferenceCollection() throws Exception {
+ // add
+ String msg = "{\n" +
+ "\"@odata.id\": \"/People('russellwhyte')\"\n" +
+ "}";
+ String editUrl = baseURL + "/People('vincentcalabrese')/Friends/$ref";
+ HttpPost postRequest = new HttpPost(editUrl);
+ postRequest.setEntity(new StringEntity(msg, ContentType.APPLICATION_JSON));
+ postRequest.addHeader("Content-Type",
"application/json;odata.metadata=minimal");
+ HttpResponse response = httpSend(postRequest, 204);
+ EntityUtils.consumeQuietly(response.getEntity());
+
+ // get
+ response = httpGET(editUrl, 200);
+ JsonNode node = getJSONNode(response);
+ assertEquals("/People('russellwhyte')",
+ ((ArrayNode) node.get("value")).get(2).get("@odata.id").asText());
+
+ //delete
+ HttpDelete deleteRequest = new
HttpDelete(editUrl+"?$id="+baseURL+"/People('russellwhyte')");
+ deleteRequest.addHeader("Content-Type",
"application/json;odata.metadata=minimal");
+ response = httpSend(deleteRequest, 204);
+ EntityUtils.consumeQuietly(response.getEntity());
+
+ // get
+ response = httpGET(editUrl, 200);
+ node = getJSONNode(response);
+ assertNull("/People('russellwhyte')", ((ArrayNode)
node.get("value")).get(2));
+ }
+
+ @Test
+ public void testDeleteReference() throws Exception {
+ String editUrl = baseURL + "/People('russellwhyte')/Photo/$ref";
+ HttpResponse response = httpGET(editUrl, 200);
+ EntityUtils.consumeQuietly(response.getEntity());
+
+ HttpDelete deleteRequest = new HttpDelete(editUrl);
+ response = httpSend(deleteRequest, 204);
+ EntityUtils.consumeQuietly(response.getEntity());
+
+ response = httpGET(editUrl, 204);
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
+
+ @Test
+ public void testCrossJoin() throws Exception {
+ String editUrl = baseURL + "/$crossjoin(People,Airlines)";
+ HttpResponse response = httpGET(editUrl, 200);
+ EntityUtils.consumeQuietly(response.getEntity());
+ }
}