Java Code Examples for com.google.gson.internal.StringMap#get()
The following examples show how to use
com.google.gson.internal.StringMap#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntryJsonCreateInlineTest.java From cloud-odata-java with Apache License 2.0 | 6 votes |
@Test public void createThreeLevelsDeepInsert() throws Exception { String content = "{\"Name\" : \"Room 2\",\"nr_Building\" : {\"Name\" : \"Building 2\",\"nb_Rooms\" : {\"results\" : [{" + "\"nr_Employees\" : {\"__deferred\" : {\"uri\" : \"" + getEndpoint() + "Rooms('1')/nr_Employees\"" + "}},\"nr_Building\" : {\"__deferred\" : {\"uri\" : \"" + getEndpoint() + "/Rooms('1')/nr_Building\"" + "}}}]}}}"; HttpResponse response = postUri("Rooms", content, HttpContentType.APPLICATION_JSON, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED); checkMediaType(response, HttpContentType.APPLICATION_JSON); String body = getBody(response); //Check inline building StringMap<?> map = getStringMap(body); map = (StringMap<?>) map.get("nr_Building"); assertNotNull(map); assertEquals("Building 2", map.get("Name")); //Check inline rooms of the inline building map = (StringMap<?>) map.get("nb_Rooms"); assertNotNull(map); ArrayList<?> results = (ArrayList<?>) map.get("results"); assertNotNull(results); assertEquals(2, results.size()); }
Example 2
Source File: EntryJsonCreateTest.java From cloud-odata-java with Apache License 2.0 | 6 votes |
@Test public void createEntryRoomWithLink() throws Exception { String content = "{\"d\":{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('1')\"," + "\"uri\":\"" + getEndpoint() + "Rooms('1')\",\"type\":\"RefScenario.Room\"," + "\"etag\":\"W/\\\"3\\\"\"}," + "\"Id\":\"1\",\"Name\":\"Room 104\"," + "\"nr_Employees\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('1')/nr_Employees\"}}," + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('1')/nr_Building\"}}}}"; assertNotNull(content); HttpResponse response = postUri("Rooms", content, HttpContentType.APPLICATION_JSON, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED); checkMediaType(response, HttpContentType.APPLICATION_JSON); String body = getBody(response); StringMap<?> map = getStringMap(body); assertEquals("104", map.get("Id")); assertEquals("Room 104", map.get("Name")); @SuppressWarnings("unchecked") StringMap<Object> employeesMap = (StringMap<Object>) map.get("nr_Employees"); assertNotNull(employeesMap); @SuppressWarnings("unchecked") StringMap<String> deferredMap = (StringMap<String>) employeesMap.get("__deferred"); assertNotNull(deferredMap); assertEquals(getEndpoint() + "Rooms('104')/nr_Employees", deferredMap.get("uri")); }
Example 3
Source File: EntryJsonCreateInlineTest.java From cloud-odata-java with Apache License 2.0 | 6 votes |
@Test public void createEntryRoomWithInlineEmptyFeedObject() throws Exception { String content = "{\"d\":{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('1')\"," + "\"uri\":\"" + getEndpoint() + "Rooms('1')\",\"type\":\"RefScenario.Room\"," + "\"etag\":\"W/\\\"3\\\"\"}," + "\"Id\":\"1\",\"Name\":\"Room 104\",\"Seats\":4,\"Version\":2," + "\"nr_Employees\":{\"results\":[]}," + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('1')/nr_Building\"}}}}"; HttpResponse response = postUri("Rooms", content, HttpContentType.APPLICATION_JSON, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED); checkMediaType(response, HttpContentType.APPLICATION_JSON); checkEtag(response, "W/\"2\""); String body = getBody(response); StringMap<?> map = getStringMap(body); assertEquals("104", map.get("Id")); assertEquals("Room 104", map.get("Name")); @SuppressWarnings("unchecked") StringMap<String> metadataMap = (StringMap<String>) map.get("__metadata"); assertNotNull(metadataMap); assertEquals(getEndpoint() + "Rooms('104')", metadataMap.get("id")); assertEquals("RefScenario.Room", metadataMap.get("type")); assertEquals(getEndpoint() + "Rooms('104')", metadataMap.get("uri")); }
Example 4
Source File: EntryJsonCreateInlineTest.java From cloud-odata-java with Apache License 2.0 | 6 votes |
@Test public void createEntryRoomWithInlineEmptyFeedArray() throws Exception { String content = "{\"d\":{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('1')\"," + "\"uri\":\"" + getEndpoint() + "Rooms('1')\",\"type\":\"RefScenario.Room\"," + "\"etag\":\"W/\\\"3\\\"\"}," + "\"Id\":\"1\",\"Name\":\"Room 104\",\"Seats\":4,\"Version\":2," + "\"nr_Employees\":[]," + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('1')/nr_Building\"}}}}"; HttpResponse response = postUri("Rooms", content, HttpContentType.APPLICATION_JSON, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED); checkMediaType(response, HttpContentType.APPLICATION_JSON); checkEtag(response, "W/\"2\""); String body = getBody(response); StringMap<?> map = getStringMap(body); assertEquals("104", map.get("Id")); assertEquals("Room 104", map.get("Name")); @SuppressWarnings("unchecked") StringMap<String> metadataMap = (StringMap<String>) map.get("__metadata"); assertNotNull(metadataMap); assertEquals(getEndpoint() + "Rooms('104')", metadataMap.get("id")); assertEquals("RefScenario.Room", metadataMap.get("type")); assertEquals(getEndpoint() + "Rooms('104')", metadataMap.get("uri")); }
Example 5
Source File: FilterToJsonTest.java From cloud-odata-java with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void testToJsonMember2() throws Exception { FilterExpression expression = UriParser.parseFilter(null, null, "Location/Country/PostalCode"); String jsonString = toJson(expression); Gson gsonConverter = new Gson(); StringMap<Object> jsonMap = gsonConverter.fromJson(jsonString, StringMap.class); checkMember(jsonMap, null); StringMap<Object> source1 = (StringMap<Object>) jsonMap.get(SOURCE); checkMember(source1, null); StringMap<Object> source2 = (StringMap<Object>) source1.get(SOURCE); checkProperty(source2, null, "Location"); StringMap<Object> path1 = (StringMap<Object>) source1.get(PATH); checkProperty(path1, null, "Country"); StringMap<Object> path = (StringMap<Object>) jsonMap.get(PATH); checkProperty(path, null, "PostalCode"); }
Example 6
Source File: FilterToJsonTest.java From cloud-odata-java with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void testToJsonMember() throws Exception { FilterExpression expression = UriParser.parseFilter(null, null, "Location/Country"); String jsonString = toJson(expression); Gson gsonConverter = new Gson(); StringMap<Object> jsonMap = gsonConverter.fromJson(jsonString, StringMap.class); checkMember(jsonMap, null); StringMap<Object> source = (StringMap<Object>) jsonMap.get(SOURCE); checkProperty(source, null, "Location"); StringMap<Object> path = (StringMap<Object>) jsonMap.get(PATH); checkProperty(path, null, "Country"); }
Example 7
Source File: FilterToJsonTest.java From cloud-odata-java with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void testToJsonBinaryLiteral() throws Exception { FilterExpression expression = UriParser.parseFilter(null, null, "'a' eq 'b'"); String jsonString = toJson(expression); Gson gsonConverter = new Gson(); StringMap<Object> jsonMap = gsonConverter.fromJson(jsonString, StringMap.class); checkBinary(jsonMap, "eq", "Edm.Boolean"); StringMap<Object> left = (StringMap<Object>) jsonMap.get(LEFT); checkLiteral(left, "Edm.String", "a"); StringMap<Object> right = (StringMap<Object>) jsonMap.get(RIGHT); checkLiteral(right, "Edm.String", "b"); }
Example 8
Source File: FilterToJsonTest.java From cloud-odata-java with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") @Test public void testToJsonBinaryProperty() throws Exception { FilterExpression expression = UriParser.parseFilter(null, null, "a eq b"); String jsonString = toJson(expression); Gson gsonConverter = new Gson(); StringMap<Object> jsonMap = gsonConverter.fromJson(jsonString, StringMap.class); checkBinary(jsonMap, "eq", null); StringMap<Object> left = (StringMap<Object>) jsonMap.get(LEFT); checkProperty(left, null, "a"); StringMap<Object> right = (StringMap<Object>) jsonMap.get(RIGHT); checkProperty(right, null, "b"); }
Example 9
Source File: FilterToJsonTest.java From cloud-odata-java with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testToJsonUnary() throws Exception { FilterExpression expression = UriParser.parseFilter(null, null, "not 'a'"); String jsonString = toJson(expression); StringMap<Object> jsonMap = new Gson().fromJson(jsonString, StringMap.class); checkUnary(jsonMap, UnaryOperator.NOT, null); StringMap<Object> operand = (StringMap<Object>) jsonMap.get(OPERAND); checkLiteral(operand, "Edm.String", "a"); }
Example 10
Source File: FilterToJsonTest.java From cloud-odata-java with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testToJsonMethod() throws Exception { FilterExpression expression = UriParser.parseFilter(null, null, "concat('aa','b')"); String jsonString = toJson(expression); Gson gsonConverter = new Gson(); StringMap<Object> jsonMap = gsonConverter.fromJson(jsonString, StringMap.class); checkMethod(jsonMap, MethodOperator.CONCAT, "Edm.String"); List<Object> parameter = (List<Object>) jsonMap.get(PARAMETERS); checkLiteral((StringMap<Object>) parameter.get(0), "Edm.String", "aa"); checkLiteral((StringMap<Object>) parameter.get(1), "Edm.String", "b"); }
Example 11
Source File: AbstractRefJsonTest.java From cloud-odata-java with Apache License 2.0 | 5 votes |
public StringMap<?> getStringMap(final String body) { Gson gson = new Gson(); final StringMap<?> map = gson.fromJson(body, new TypeToken<StringMap<?>>() {}.getType()); if (map.get("d") instanceof StringMap<?>) { return (StringMap<?>) map.get("d"); } else { return map; } }
Example 12
Source File: FilterToJsonTest.java From cloud-odata-java with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void testToJsonBinaryAdd() throws Exception { FilterExpression expression = UriParser.parseFilter(null, null, "1d add 2d add 3d add 4d"); String jsonString = toJson(expression); Gson gsonConverter = new Gson(); StringMap<Object> jsonMap = gsonConverter.fromJson(jsonString, StringMap.class); checkBinary(jsonMap, "add", "Edm.Double"); StringMap<Object> left1 = (StringMap<Object>) jsonMap.get(LEFT); checkBinary(left1, "add", "Edm.Double"); StringMap<Object> left2 = (StringMap<Object>) left1.get(LEFT); checkBinary(left2, "add", "Edm.Double"); StringMap<Object> literal1 = (StringMap<Object>) left2.get(LEFT); checkLiteral(literal1, "Edm.Double", "1"); StringMap<Object> literal2 = (StringMap<Object>) left2.get(RIGHT); checkLiteral(literal2, "Edm.Double", "2"); StringMap<Object> literal3 = (StringMap<Object>) left1.get(RIGHT); checkLiteral(literal3, "Edm.Double", "3"); StringMap<Object> right1 = (StringMap<Object>) jsonMap.get(RIGHT); checkLiteral(right1, "Edm.Double", "4"); }
Example 13
Source File: EntryJsonCreateInlineTest.java From cloud-odata-java with Apache License 2.0 | 5 votes |
@Test public void createEntryRoomWithInlineFeedEmployee() throws Exception { String content = "{\"d\":{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('1')\"," + "\"uri\":\"" + getEndpoint() + "Rooms('1')\",\"type\":\"RefScenario.Room\"," + "\"etag\":\"W/\\\"3\\\"\"}," + "\"Id\":\"1\",\"Name\":\"Room 104\",\"Seats\":4,\"Version\":2," + "\"nr_Employees\":{\"results\":[{" + "\"__metadata\":{" + "\"id\":\"" + getEndpoint() + "Employees('1')\"," + "\"type\":\"RefScenario.Employee\"," + "\"content_type\":\"image/jpeg\"," + "\"media_src\":\"" + getEndpoint() + "Employees('1')/$value\"," + "\"edit_media\":\"" + getEndpoint() + "Employees('1')/$value\"}," + " \"EmployeeName\": \"Walter Winter\"," + "\"ManagerId\": \"1\"," + "\"RoomId\": \"1\"," + "\"TeamId\": \"1\"," + "\"Age\": 52," + "\"Location\":{\"City\":{\"PostalCode\":\"69124\",\"CityName\":\"Heidelberg\"}," + " \"Country\":\"Germany\"}," + "\"ImageUrl\": \"" + getEndpoint() + "Employees('1')/$value\"}]}," + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('1')/nr_Building\"}}}}"; HttpResponse response = postUri("Rooms", content, HttpContentType.APPLICATION_JSON, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED); checkMediaType(response, HttpContentType.APPLICATION_JSON); String body = getBody(response); StringMap<?> map = getStringMap(body); assertEquals("104", map.get("Id")); assertEquals("Room 104", map.get("Name")); @SuppressWarnings("unchecked") StringMap<String> metadataMap = (StringMap<String>) map.get("__metadata"); assertNotNull(metadataMap); assertEquals(getEndpoint() + "Rooms('104')", metadataMap.get("id")); assertEquals("RefScenario.Room", metadataMap.get("type")); assertEquals(getEndpoint() + "Rooms('104')", metadataMap.get("uri")); }
Example 14
Source File: EntryJsonCreateTest.java From cloud-odata-java with Apache License 2.0 | 5 votes |
@Test public void createEntryRoom() throws Exception { String content = "{\"d\":{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('1')\"," + "\"uri\":\"" + getEndpoint() + "Rooms('1')\",\"type\":\"RefScenario.Room\"," + "\"etag\":\"W/\\\"3\\\"\"}," + "\"Id\":\"1\",\"Name\":\"Room 104\",\"Seats\":4,\"Version\":2," + "\"nr_Employees\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('1')/nr_Employees\"}}," + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('1')/nr_Building\"}}}}"; assertNotNull(content); HttpResponse response = postUri("Rooms", content, HttpContentType.APPLICATION_JSON, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED); checkMediaType(response, HttpContentType.APPLICATION_JSON); String body = getBody(response); StringMap<?> map = getStringMap(body); assertEquals("104", map.get("Id")); assertEquals("Room 104", map.get("Name")); @SuppressWarnings("unchecked") StringMap<String> metadataMap = (StringMap<String>) map.get("__metadata"); assertNotNull(metadataMap); assertEquals(getEndpoint() + "Rooms('104')", metadataMap.get("id")); assertEquals("RefScenario.Room", metadataMap.get("type")); assertEquals(getEndpoint() + "Rooms('104')", metadataMap.get("uri")); response = callUri("Rooms('104')/Seats/$value"); body = getBody(response); assertEquals("4", body); }
Example 15
Source File: NotebookRestApiTest.java From zeppelin with Apache License 2.0 | 4 votes |
@Test public void testRunParagraphSynchronously() throws IOException { LOG.info("Running testRunParagraphSynchronously"); Note note1 = null; try { note1 = TestUtils.getInstance(Notebook.class).createNote("note1", anonymous); note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); Paragraph p = note1.addNewParagraph(AuthenticationInfo.ANONYMOUS); // run non-blank paragraph String title = "title"; String text = "%sh\n sleep 1"; p.setTitle(title); p.setText(text); PostMethod post = httpPost("/notebook/run/" + note1.getId() + "/" + p.getId(), ""); assertThat(post, isAllowed()); Map<String, Object> resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {}.getType()); assertEquals(resp.get("status"), "OK"); post.releaseConnection(); assertNotEquals(p.getStatus(), Job.Status.READY); // Check if the paragraph is emptied assertEquals(title, p.getTitle()); assertEquals(text, p.getText()); // run invalid code text = "%sh\n invalid_cmd"; p.setTitle(title); p.setText(text); post = httpPost("/notebook/run/" + note1.getId() + "/" + p.getId(), ""); assertEquals(500, post.getStatusCode()); resp = gson.fromJson(post.getResponseBodyAsString(), new TypeToken<Map<String, Object>>() {}.getType()); assertEquals("INTERNAL_SERVER_ERROR", resp.get("status")); StringMap stringMap = (StringMap) resp.get("body"); assertEquals("ERROR", stringMap.get("code")); List<StringMap> interpreterResults = (List<StringMap>) stringMap.get("msg"); assertTrue(interpreterResults.get(0).toString(), interpreterResults.get(0).get("data").toString().contains("invalid_cmd: command not found")); post.releaseConnection(); assertNotEquals(p.getStatus(), Job.Status.READY); // Check if the paragraph is emptied assertEquals(title, p.getTitle()); assertEquals(text, p.getText()); } finally { // cleanup if (null != note1) { TestUtils.getInstance(Notebook.class).removeNote(note1, anonymous); } } }
Example 16
Source File: EntryJsonCreateInlineTest.java From cloud-odata-java with Apache License 2.0 | 4 votes |
@Test public void createEntryRoomWithInlineEntry() throws Exception { String content = "{\"d\":{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('1')\"," + "\"uri\":\"" + getEndpoint() + "Rooms('1')\",\"type\":\"RefScenario.Room\"," + "\"etag\":\"W/\\\"3\\\"\"}," + "\"Id\":\"1\",\"Name\":\"Room 104\",\"Seats\":4,\"Version\":2," + "\"nr_Employees\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('1')/nr_Employees\"}}," + "\"nr_Building\":{\"__metadata\":{\"id\":\"" + getEndpoint() + "Buildings('2')\"," + "\"uri\":\"" + getEndpoint() + "Buildings('2')\",\"type\":\"RefScenario.Building\"}," + "\"Id\":\"2\",\"Name\":\"Building 4\",\"Image\":null," + "\"nb_Rooms\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Buildings('2')/nb_Rooms\"}}}}}"; HttpResponse response = postUri("Rooms", content, HttpContentType.APPLICATION_JSON, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED); checkMediaType(response, HttpContentType.APPLICATION_JSON); checkEtag(response, "W/\"2\""); String body = getBody(response); StringMap<?> map = getStringMap(body); assertEquals("104", map.get("Id")); assertEquals("Room 104", map.get("Name")); @SuppressWarnings("unchecked") StringMap<String> metadataMap = (StringMap<String>) map.get("__metadata"); assertNotNull(metadataMap); assertEquals(getEndpoint() + "Rooms('104')", metadataMap.get("id")); assertEquals("RefScenario.Room", metadataMap.get("type")); assertEquals(getEndpoint() + "Rooms('104')", metadataMap.get("uri")); response = callUri("Rooms('104')/nr_Building/", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON); body = getBody(response); map = getStringMap(body); assertEquals("4", map.get("Id")); assertEquals("Building 4", map.get("Name")); @SuppressWarnings("unchecked") StringMap<String> metadataMap2 = (StringMap<String>) map.get("__metadata"); assertNotNull(metadataMap2); assertEquals(getEndpoint() + "Buildings('4')", metadataMap2.get("id")); assertEquals("RefScenario.Building", metadataMap2.get("type")); assertEquals(getEndpoint() + "Buildings('4')", metadataMap2.get("uri")); }
Example 17
Source File: EntryJsonCreateInlineTest.java From cloud-odata-java with Apache License 2.0 | 4 votes |
@Test public void createEntryRoomWithInlineFeedArray() throws Exception { String content = "{\"d\":{\"__metadata\":{\"id\":\"" + getEndpoint() + "Buildings('2')\"," + "\"uri\":\"" + getEndpoint() + "Buildings('2')\",\"type\":\"RefScenario.Building\"}," + "\"Id\":\"2\",\"Name\":\"Building 2\",\"Image\":null," + "\"nb_Rooms\":[{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('2')\"," + "\"uri\":\"" + getEndpoint() + "Rooms('2')\",\"type\":\"RefScenario.Room\"," + "\"etag\":\"W/\\\"2\\\"\"}," + "\"Id\":\"2\",\"Name\":\"Room 2\",\"Seats\":5,\"Version\":2," + "\"nr_Employees\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('2')/nr_Employees\"}}," + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('2')/nr_Building\"}}}," + "{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('3')\"," + "\"uri\":\"" + getEndpoint() + "Rooms('3')\",\"type\":\"RefScenario.Room\"," + "\"etag\":\"W/\\\"3\\\"\"}," + "\"Id\":\"3\",\"Name\":\"Room 3\",\"Seats\":2,\"Version\":3," + "\"nr_Employees\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('3')/nr_Employees\"}}," + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('3')/nr_Building\"}}}]}}"; HttpResponse response = postUri("Buildings", content, HttpContentType.APPLICATION_JSON, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED); checkMediaType(response, HttpContentType.APPLICATION_JSON); //checkEtag(response, "W/\"2\""); String body = getBody(response); StringMap<?> map = getStringMap(body); assertEquals("4", map.get("Id")); assertEquals("Building 2", map.get("Name")); @SuppressWarnings("unchecked") StringMap<String> metadataMap = (StringMap<String>) map.get("__metadata"); assertNotNull(metadataMap); assertEquals(getEndpoint() + "Buildings('4')", metadataMap.get("id")); assertEquals("RefScenario.Building", metadataMap.get("type")); assertEquals(getEndpoint() + "Buildings('4')", metadataMap.get("uri")); response = callUri("Buildings('4')/nb_Rooms('104')/", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON); body = getBody(response); map = getStringMap(body); assertEquals("104", map.get("Id")); assertEquals("Room 2", map.get("Name")); response = callUri("Buildings('4')/nb_Rooms('104')/Seats/$value", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON); body = getBody(response); assertEquals("5", body); response = callUri("Buildings('4')/nb_Rooms('105')/", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON); body = getBody(response); map = getStringMap(body); assertEquals("105", map.get("Id")); assertEquals("Room 3", map.get("Name")); response = callUri("Buildings('4')/nb_Rooms('105')/Seats/$value", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON); body = getBody(response); assertEquals("2", body); }
Example 18
Source File: EntryJsonCreateInlineTest.java From cloud-odata-java with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Test public void createEntryRoomWithInlineFeedObject() throws Exception { String content = "{\"d\":{\"__metadata\":{\"id\":\"" + getEndpoint() + "Buildings('2')\"," + "\"uri\":\"" + getEndpoint() + "Buildings('2')\",\"type\":\"RefScenario.Building\"}," + "\"Id\":\"2\",\"Name\":\"Building 2\",\"Image\":null," + "\"nb_Rooms\":{\"results\":[{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('2')\"," + "\"uri\":\"" + getEndpoint() + "Rooms('2')\",\"type\":\"RefScenario.Room\"," + "\"etag\":\"W/\\\"2\\\"\"}," + "\"Id\":\"2\",\"Name\":\"Room 2\",\"Seats\":5,\"Version\":2," + "\"nr_Employees\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('2')/nr_Employees\"}}," + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('2')/nr_Building\"}}}," + "{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('3')\"," + "\"uri\":\"" + getEndpoint() + "Rooms('3')\",\"type\":\"RefScenario.Room\"," + "\"etag\":\"W/\\\"3\\\"\"}," + "\"Id\":\"3\",\"Name\":\"Room 3\",\"Seats\":2,\"Version\":3," + "\"nr_Employees\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('3')/nr_Employees\"}}," + "\"nr_Building\":{\"__deferred\":{\"uri\":\"" + getEndpoint() + "Rooms('3')/nr_Building\"}}}]}}}"; HttpResponse response = callUri("Buildings('4')/nb_Rooms('104')/", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.NOT_FOUND); getBody(response); response = callUri("Buildings('4')/nb_Rooms('105')/", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.NOT_FOUND); getBody(response); response = postUri("Buildings", content, HttpContentType.APPLICATION_JSON, HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON, HttpStatusCodes.CREATED); checkMediaType(response, HttpContentType.APPLICATION_JSON); String body = getBody(response); StringMap<?> map = getStringMap(body); assertEquals("4", map.get("Id")); assertEquals("Building 2", map.get("Name")); StringMap<String> metadataMap = (StringMap<String>) map.get("__metadata"); assertNotNull(metadataMap); assertEquals(getEndpoint() + "Buildings('4')", metadataMap.get("id")); assertEquals("RefScenario.Building", metadataMap.get("type")); assertEquals(getEndpoint() + "Buildings('4')", metadataMap.get("uri")); StringMap<Object> navProperty = (StringMap<Object>) map.get("nb_Rooms"); assertNotNull(navProperty); List<StringMap<String>> results = (ArrayList<StringMap<String>>) navProperty.get("results"); assertNotNull(results); for (int i = 0; i < results.size(); i++) { StringMap<String> resultMap = results.get(i); switch (i) { case 0: assertEquals("Room 2", resultMap.get("Name")); assertEquals("104", resultMap.get("Id")); break; case 1: assertEquals("105", resultMap.get("Id")); assertEquals("Room 3", resultMap.get("Name")); } } response = callUri("Buildings('4')/nb_Rooms('104')/Seats/$value", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON); assertEquals("5", getBody(response)); response = callUri("Buildings('4')/nb_Rooms('105')/Seats/$value", HttpHeaders.ACCEPT, HttpContentType.APPLICATION_JSON); assertEquals("2", getBody(response)); }