Java Code Examples for com.google.gson.internal.LinkedTreeMap#get()
The following examples show how to use
com.google.gson.internal.LinkedTreeMap#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: FeeProvider.java From bisq-core with GNU Affero General Public License v3.0 | 6 votes |
public Tuple2<Map<String, Long>, Map<String, Long>> getFees() throws IOException { String json = httpClient.requestWithGET("getFees", "User-Agent", "bisq/" + Version.VERSION + ", uid:" + httpClient.getUid()); LinkedTreeMap<String, Object> linkedTreeMap = new Gson().<LinkedTreeMap<String, Object>>fromJson(json, LinkedTreeMap.class); Map<String, Long> tsMap = new HashMap<>(); tsMap.put("bitcoinFeesTs", ((Double) linkedTreeMap.get("bitcoinFeesTs")).longValue()); Map<String, Long> map = new HashMap<>(); try { //noinspection unchecked LinkedTreeMap<String, Double> dataMap = (LinkedTreeMap<String, Double>) linkedTreeMap.get("dataMap"); Long btcTxFee = dataMap.get("btcTxFee").longValue(); Long ltcTxFee = dataMap.get("ltcTxFee").longValue(); Long dashTxFee = dataMap.get("dashTxFee").longValue(); map.put("BTC", btcTxFee); map.put("LTC", ltcTxFee); map.put("DASH", dashTxFee); } catch (Throwable t) { log.error(t.toString()); t.printStackTrace(); } return new Tuple2<>(tsMap, map); }
Example 2
Source File: EntryJsonCreateInlineTest.java From olingo-odata2 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); LinkedTreeMap<?, ?> map = getLinkedTreeMap(body); assertEquals("104", map.get("Id")); assertEquals("Room 104", map.get("Name")); @SuppressWarnings("unchecked") LinkedTreeMap<String, String> metadataMap = (LinkedTreeMap<String, 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 3
Source File: MarketoBaseRESTClient.java From components with Apache License 2.0 | 6 votes |
private MarketoRecordResult fillMarketoRecordResultFromReader(InputStreamReader reader, Schema schema) { Gson gson = new Gson(); MarketoRecordResult mkr = new MarketoRecordResult(); LinkedTreeMap ltm = (LinkedTreeMap) gson.fromJson(reader, Object.class); mkr.setRequestId(REST + "::" + ltm.get("requestId")); mkr.setSuccess(Boolean.parseBoolean(ltm.get("success").toString())); mkr.setStreamPosition((String) ltm.get(FIELD_NEXT_PAGE_TOKEN)); if (!mkr.isSuccess() && ltm.get(FIELD_ERRORS) != null) { List<LinkedTreeMap> errors = (List<LinkedTreeMap>) ltm.get(FIELD_ERRORS); for (LinkedTreeMap err : errors) { MarketoError error = new MarketoError(REST, (String) err.get("code"), (String) err.get("message")); mkr.setErrors(Arrays.asList(error)); } } if (mkr.isSuccess()) { List<LinkedTreeMap> tmp = (List<LinkedTreeMap>) ltm.get("result"); if (tmp != null) { mkr.setRecordCount(tmp.size()); mkr.setRecords(parseRecords(tmp, schema)); } if (mkr.getStreamPosition() != null) { mkr.setRemainCount(mkr.getRecordCount()); } } return mkr; }
Example 4
Source File: FilterToJsonTest.java From olingo-odata2 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(); LinkedTreeMap<String, Object> jsonMap = gsonConverter.fromJson(jsonString, LinkedTreeMap.class); checkBinary(jsonMap, "eq", "Edm.Boolean"); LinkedTreeMap<String, Object> left = (LinkedTreeMap<String, Object>) jsonMap.get(LEFT); checkLiteral(left, "Edm.String", "a"); LinkedTreeMap<String, Object> right = (LinkedTreeMap<String, Object>) jsonMap.get(RIGHT); checkLiteral(right, "Edm.String", "b"); }
Example 5
Source File: FilterToJsonTest.java From olingo-odata2 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(); LinkedTreeMap<String, Object> jsonMap = gsonConverter.fromJson(jsonString, LinkedTreeMap.class); checkBinary(jsonMap, "eq", null); LinkedTreeMap<String, Object> left = (LinkedTreeMap<String, Object>) jsonMap.get(LEFT); checkProperty(left, null, "a"); LinkedTreeMap<String, Object> right = (LinkedTreeMap<String, Object>) jsonMap.get(RIGHT); checkProperty(right, null, "b"); }
Example 6
Source File: LawnAndGardenScheduleController.java From arcusandroid with Apache License 2.0 | 5 votes |
public ArrayList<LinkedTreeMap<String, Object>> filterDeletedEvents(ArrayList<LinkedTreeMap<String, Object>> events) { ArrayList<LinkedTreeMap<String, Object>> returnList = new ArrayList<>(); for(LinkedTreeMap<String, Object> event : events) { if(event.get("status") != null) { String status = (String)event.get("status"); if(!status.equals("DELETING") && !status.equals("DELETED")) { returnList.add(event); } } } return returnList; }
Example 7
Source File: LawnAndGardenScheduleController.java From arcusandroid with Apache License 2.0 | 5 votes |
public double getNextEventTime(String deviceAddress) { Map<String, Object> schedule = getLawnNGardenSubsystem().getScheduleStatus().get(deviceAddress); LinkedTreeMap<String, Object> nextEvent = (LinkedTreeMap<String, Object>) schedule.get("nextEvent"); if(nextEvent != null) { if(nextEvent.get("startTime") != null) { return (double)nextEvent.get("startTime"); } } return -1; }
Example 8
Source File: FilterToJsonTest.java From olingo-odata2 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(); LinkedTreeMap<String, Object> jsonMap = gsonConverter.fromJson(jsonString, LinkedTreeMap.class); checkMethod(jsonMap, MethodOperator.CONCAT, "Edm.String"); List<Object> parameter = (List<Object>) jsonMap.get(PARAMETERS); checkLiteral((LinkedTreeMap<String, Object>) parameter.get(0), "Edm.String", "aa"); checkLiteral((LinkedTreeMap<String, Object>) parameter.get(1), "Edm.String", "b"); }
Example 9
Source File: EntryJsonCreateInlineTest.java From olingo-odata2 with Apache License 2.0 | 5 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 LinkedTreeMap<?, ?> map = getLinkedTreeMap(body); map = (LinkedTreeMap<?, ?>) map.get("nr_Building"); assertNotNull(map); assertEquals("Building 2", map.get("Name")); // Check inline rooms of the inline building map = (LinkedTreeMap<?, ?>) map.get("nb_Rooms"); assertNotNull(map); ArrayList<?> results = (ArrayList<?>) map.get("results"); assertNotNull(results); assertEquals(2, results.size()); }
Example 10
Source File: IrrigationScheduleCommandEditorFragment.java From arcusandroid with Apache License 2.0 | 5 votes |
private void parseEventDays(LinkedTreeMap<String, Object> item) { EnumSet<DayOfWeek> repetitions = EnumSet.of(DayOfWeek.FRIDAY); repetitions.remove(DayOfWeek.FRIDAY); ArrayList<String> eventDays = (ArrayList<String>) item.get("days"); if(eventDays.contains("MON")) { repetitions.add(DayOfWeek.MONDAY); } if(eventDays.contains("TUE")) { repetitions.add(DayOfWeek.TUESDAY); } if(eventDays.contains("WED")) { repetitions.add(DayOfWeek.WEDNESDAY); } if(eventDays.contains("THU")) { repetitions.add(DayOfWeek.THURSDAY); } if(eventDays.contains("FRI")) { repetitions.add(DayOfWeek.FRIDAY); } if(eventDays.contains("SAT")) { repetitions.add(DayOfWeek.SATURDAY); } if(eventDays.contains("SUN")) { repetitions.add(DayOfWeek.SUNDAY); } setSelectedDays(repetitions); }
Example 11
Source File: EntryJsonCreateTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@Test public void createEntryRoom() throws Exception { String id = UUID.randomUUID().toString(); String content = "{\"d\":{\"__metadata\":{\"id\":\"" + getEndpoint() + "Rooms('1')\"," + "\"uri\":\"" + getEndpoint() + "Rooms('1')\",\"type\":\"RefScenario.Room\"," + "\"etag\":\"W/\\\"3\\\"\"}," + "\"Id\":\"" + id + "\",\"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); LinkedTreeMap<?,?> map = getStringMap(body); assertEquals(id, map.get("Id")); assertEquals("Room 104", map.get("Name")); @SuppressWarnings("unchecked") LinkedTreeMap<String, String> metadataMap = (LinkedTreeMap<String, String>) map.get("__metadata"); assertNotNull(metadataMap); String expectedRoomId = getEndpoint() + "Rooms('" + id + "')"; assertEquals(expectedRoomId, metadataMap.get("id")); assertEquals("RefScenario.Room", metadataMap.get("type")); assertEquals(expectedRoomId, metadataMap.get("uri")); response = callUri("Rooms('" + id + "')/Seats/$value"); body = getBody(response); assertEquals("4", body); }
Example 12
Source File: FilterToJsonTest.java From olingo-odata2 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); LinkedTreeMap<String, Object> jsonMap = new Gson().fromJson(jsonString, LinkedTreeMap.class); checkUnary(jsonMap, UnaryOperator.NOT, null); LinkedTreeMap<String, Object> operand = (LinkedTreeMap<String, Object>) jsonMap.get(OPERAND); checkLiteral(operand, "Edm.String", "a"); }
Example 13
Source File: JsonEntryEntitySerializerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void serializeWithCustomSrcAttributeOnRoom() throws Exception { Entity roomData = new Entity(); roomData.addProperty("Id", "1"); roomData.addProperty("Name", "Neu Schwanstein"); roomData.addProperty("Seats", new Integer(20)); roomData.addProperty("Version", new Integer(3)); String mediaResourceSourceKey = "~src"; roomData.addProperty(mediaResourceSourceKey, "http://localhost:8080/images/image1"); roomData.setWriteProperties(EntitySerializerProperties.serviceRoot(URI.create(BASE_URI)). includeMetadata(true).build()); EdmEntitySet roomsSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"); EdmEntityType roomType = roomsSet.getEntityType(); EdmMapping mapping = mock(EdmMapping.class); when(roomType.getMapping()).thenReturn(mapping); when(mapping.getMediaResourceSourceKey()).thenReturn(mediaResourceSourceKey); ODataResponse response = new JsonSerializerDeserializer().writeEntry(roomsSet, roomData); String jsonString = verifyResponse(response); Gson gson = new Gson(); LinkedTreeMap<String, Object> jsonMap = gson.fromJson(jsonString, LinkedTreeMap.class); jsonMap = (LinkedTreeMap<String, Object>) jsonMap.get("__metadata"); assertNull(jsonMap.get("media_src")); assertNull(jsonMap.get("content_type")); assertNull(jsonMap.get("edit_media")); }
Example 14
Source File: JsonEntryEntityProducerTest.java From olingo-odata2 with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Test public void serializeWithCustomSrcAndTypeAttributeOnRoom() throws Exception { Map<String, Object> roomData = new HashMap<String, Object>(); roomData.put("Id", "1"); roomData.put("Name", "Neu Schwanstein"); roomData.put("Seats", new Integer(20)); roomData.put("Version", new Integer(3)); String mediaResourceSourceKey = "~src"; roomData.put(mediaResourceSourceKey, "http://localhost:8080/images/image1"); String mediaResourceMimeTypeKey = "~type"; roomData.put(mediaResourceMimeTypeKey, "image/jpeg"); EdmEntitySet roomsSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Rooms"); EdmEntityType roomType = roomsSet.getEntityType(); EdmMapping mapping = mock(EdmMapping.class); when(roomType.getMapping()).thenReturn(mapping); when(mapping.getMediaResourceSourceKey()).thenReturn(mediaResourceSourceKey); when(mapping.getMediaResourceMimeTypeKey()).thenReturn(mediaResourceMimeTypeKey); ODataResponse response = new JsonEntityProvider().writeEntry(roomsSet, roomData, DEFAULT_PROPERTIES); String jsonString = verifyResponse(response); Gson gson = new Gson(); LinkedTreeMap<String, Object> jsonMap = gson.fromJson(jsonString, LinkedTreeMap.class); jsonMap = (LinkedTreeMap<String, Object>) jsonMap.get("d"); jsonMap = (LinkedTreeMap<String, Object>) jsonMap.get("__metadata"); assertNull(jsonMap.get("media_src")); assertNull(jsonMap.get("content_type")); assertNull(jsonMap.get("edit_media")); }
Example 15
Source File: PriceProvider.java From bisq with GNU Affero General Public License v3.0 | 5 votes |
public Tuple2<Map<String, Long>, Map<String, MarketPrice>> getAll() throws IOException { Map<String, MarketPrice> marketPriceMap = new HashMap<>(); String hsVersion = ""; if (P2PService.getMyNodeAddress() != null) hsVersion = P2PService.getMyNodeAddress().getHostName().length() > 22 ? ", HSv3" : ", HSv2"; String json = httpClient.requestWithGET("getAllMarketPrices", "User-Agent", "bisq/" + Version.VERSION + hsVersion); LinkedTreeMap<?, ?> map = new Gson().fromJson(json, LinkedTreeMap.class); Map<String, Long> tsMap = new HashMap<>(); tsMap.put("btcAverageTs", ((Double) map.get("btcAverageTs")).longValue()); tsMap.put("poloniexTs", ((Double) map.get("poloniexTs")).longValue()); tsMap.put("coinmarketcapTs", ((Double) map.get("coinmarketcapTs")).longValue()); List<?> list = (ArrayList<?>) map.get("data"); list.forEach(obj -> { try { LinkedTreeMap<?, ?> treeMap = (LinkedTreeMap<?, ?>) obj; final String currencyCode = (String) treeMap.get("currencyCode"); final double price = (Double) treeMap.get("price"); // json uses double for our timestampSec long value... final long timestampSec = MathUtils.doubleToLong((Double) treeMap.get("timestampSec")); marketPriceMap.put(currencyCode, new MarketPrice(currencyCode, price, timestampSec, true)); } catch (Throwable t) { log.error(t.toString()); t.printStackTrace(); } }); return new Tuple2<>(tsMap, marketPriceMap); }
Example 16
Source File: JsonEntryEntityProducerTest.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Test public void serializeWithCustomSrcAndTypeAttributeOnEmployee() throws Exception { Map<String, Object> employeeData = new HashMap<String, Object>(); Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT")); date.clear(); date.set(1999, 0, 1); employeeData.put("EmployeeId", "1"); employeeData.put("ImmageUrl", null); employeeData.put("ManagerId", "1"); employeeData.put("Age", new Integer(52)); employeeData.put("RoomId", "1"); employeeData.put("EntryDate", date); employeeData.put("TeamId", "42"); employeeData.put("EmployeeName", "Walter Winter"); Map<String, Object> locationData = new HashMap<String, Object>(); Map<String, Object> cityData = new HashMap<String, Object>(); cityData.put("PostalCode", "33470"); cityData.put("CityName", "Duckburg"); locationData.put("City", cityData); locationData.put("Country", "Calisota"); employeeData.put("Location", locationData); String mediaResourceSourceKey = "~src"; employeeData.put(mediaResourceSourceKey, "http://localhost:8080/images/image1"); String mediaResourceMimeTypeKey = "~type"; employeeData.put(mediaResourceMimeTypeKey, "image/jpeg"); EdmEntitySet employeesSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"); EdmMapping mapping = employeesSet.getEntityType().getMapping(); when(mapping.getMediaResourceSourceKey()).thenReturn(mediaResourceSourceKey); when(mapping.getMediaResourceMimeTypeKey()).thenReturn(mediaResourceMimeTypeKey); ODataResponse response = new JsonEntityProvider().writeEntry(employeesSet, employeeData, DEFAULT_PROPERTIES); String jsonString = verifyResponse(response); Gson gson = new Gson(); LinkedTreeMap<String, Object> jsonMap = gson.fromJson(jsonString, LinkedTreeMap.class); jsonMap = (LinkedTreeMap<String, Object>) jsonMap.get("d"); jsonMap = (LinkedTreeMap<String, Object>) jsonMap.get("__metadata"); assertEquals("http://localhost:8080/images/image1", jsonMap.get("media_src")); assertEquals("image/jpeg", jsonMap.get("content_type")); assertEquals("http://host:80/service/Employees('1')/$value", jsonMap.get("edit_media")); }
Example 17
Source File: EntryJsonCreateInlineTest.java From olingo-odata2 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); LinkedTreeMap<?, ?> map = getLinkedTreeMap(body); assertEquals("4", map.get("Id")); assertEquals("Building 2", map.get("Name")); LinkedTreeMap<String, String> metadataMap = (LinkedTreeMap<String, 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")); LinkedTreeMap<String, Object> navProperty = (LinkedTreeMap<String, Object>) map.get("nb_Rooms"); assertNotNull(navProperty); List<LinkedTreeMap<String, String>> results = (ArrayList<LinkedTreeMap<String, String>>) navProperty.get("results"); assertNotNull(results); for (int i = 0; i < results.size(); i++) { LinkedTreeMap<String, 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)); }
Example 18
Source File: JsonEntryEntitySerializerTest.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Test public void serializeWithCustomSrcAttributeOnEmployee() throws Exception { Entity employeeData = new Entity(); Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT")); date.clear(); date.set(1999, 0, 1); employeeData.addProperty("EmployeeId", "1"); employeeData.addProperty("ImmageUrl", null); employeeData.addProperty("ManagerId", "1"); employeeData.addProperty("Age", new Integer(52)); employeeData.addProperty("RoomId", "1"); employeeData.addProperty("EntryDate", date); employeeData.addProperty("TeamId", "42"); employeeData.addProperty("EmployeeName", "Walter Winter"); Map<String, Object> locationData = new HashMap<String, Object>(); Map<String, Object> cityData = new HashMap<String, Object>(); cityData.put("PostalCode", "33470"); cityData.put("CityName", "Duckburg"); locationData.put("City", cityData); locationData.put("Country", "Calisota"); employeeData.addProperty("Location", locationData); String mediaResourceSourceKey = "~src"; employeeData.addProperty(mediaResourceSourceKey, "http://localhost:8080/images/image1"); employeeData.setWriteProperties(EntitySerializerProperties.serviceRoot(URI.create(BASE_URI)). includeMetadata(true).build()); EdmEntitySet employeesSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"); EdmMapping mapping = employeesSet.getEntityType().getMapping(); when(mapping.getMediaResourceSourceKey()).thenReturn(mediaResourceSourceKey); ODataResponse response = new JsonSerializerDeserializer().writeEntry(employeesSet, employeeData); String jsonString = verifyResponse(response); Gson gson = new Gson(); LinkedTreeMap<String, Object> jsonMap = gson.fromJson(jsonString, LinkedTreeMap.class); jsonMap = (LinkedTreeMap<String, Object>) jsonMap.get("__metadata"); assertEquals("http://localhost:8080/images/image1", jsonMap.get("media_src")); assertEquals("application/octet-stream", jsonMap.get("content_type")); assertEquals("http://host:80/service/Employees('1')/$value", jsonMap.get("edit_media")); }
Example 19
Source File: JsonEntryEntityProducerTest.java From olingo-odata2 with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") @Test public void serializeWithCustomSrcAttributeOnEmployee() throws Exception { Map<String, Object> employeeData = new HashMap<String, Object>(); Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT")); date.clear(); date.set(1999, 0, 1); employeeData.put("EmployeeId", "1"); employeeData.put("ImmageUrl", null); employeeData.put("ManagerId", "1"); employeeData.put("Age", new Integer(52)); employeeData.put("RoomId", "1"); employeeData.put("EntryDate", date); employeeData.put("TeamId", "42"); employeeData.put("EmployeeName", "Walter Winter"); Map<String, Object> locationData = new HashMap<String, Object>(); Map<String, Object> cityData = new HashMap<String, Object>(); cityData.put("PostalCode", "33470"); cityData.put("CityName", "Duckburg"); locationData.put("City", cityData); locationData.put("Country", "Calisota"); employeeData.put("Location", locationData); String mediaResourceSourceKey = "~src"; employeeData.put(mediaResourceSourceKey, "http://localhost:8080/images/image1"); EdmEntitySet employeesSet = MockFacade.getMockEdm().getDefaultEntityContainer().getEntitySet("Employees"); EdmMapping mapping = employeesSet.getEntityType().getMapping(); when(mapping.getMediaResourceSourceKey()).thenReturn(mediaResourceSourceKey); ODataResponse response = new JsonEntityProvider().writeEntry(employeesSet, employeeData, DEFAULT_PROPERTIES); String jsonString = verifyResponse(response); Gson gson = new Gson(); LinkedTreeMap<String, Object> jsonMap = gson.fromJson(jsonString, LinkedTreeMap.class); jsonMap = (LinkedTreeMap<String, Object>) jsonMap.get("d"); jsonMap = (LinkedTreeMap<String, Object>) jsonMap.get("__metadata"); assertEquals("http://localhost:8080/images/image1", jsonMap.get("media_src")); assertEquals("application/octet-stream", jsonMap.get("content_type")); assertEquals("http://host:80/service/Employees('1')/$value", jsonMap.get("edit_media")); }
Example 20
Source File: TestReconWithOzoneManager.java From hadoop-ozone with Apache License 2.0 | 4 votes |
private long getReconContainerCount(String containerResponse) { Map map = new Gson().fromJson(containerResponse, HashMap.class); LinkedTreeMap linkedTreeMap = (LinkedTreeMap) map.get("data"); return (long)(double) linkedTreeMap.get("totalCount"); }