/** * Factory method for constructing an empty JSON Object ("struct") node */ public ObjectNode objectNode() { return new ObjectNode(this); }
/** * Factory method for constructing an empty JSON Object ("struct") node */ public ObjectNode objectNode() { return new ObjectNode(this); }
/** * Factory method for constructing an empty JSON Object ("struct") node */ public ObjectNode objectNode() { return new ObjectNode(this); }
/** * Factory method for constructing an empty JSON Object ("struct") node */ public ObjectNode objectNode() { return new ObjectNode(this); }
/** * Factory method for constructing an empty JSON Object ("struct") node */ public ObjectNode objectNode() { return new ObjectNode(this); }
public LinkRepresentation() { this(new ObjectNode(JsonNodeFactory.instance)); withMethod(HttpMethod.GET); }
public LinkRepresentation() { this(new ObjectNode(JsonNodeFactory.instance)); withMethod(RestfulHttpMethod.GET); }
public static JsonRepresentation newMap(final String... keyValuePairs) { final JsonRepresentation repr = new JsonRepresentation(new ObjectNode(JsonNodeFactory.instance)); String key = null; for (final String keyOrValue : keyValuePairs) { if (key != null) { repr.mapPut(key, keyOrValue); key = null; } else { key = keyOrValue; } } if (key != null) { throw new IllegalArgumentException("must provide an even number of keys and values"); } return repr; }
public static JsonRepresentation newMap(final String... keyValuePairs) { final JsonRepresentation repr = new JsonRepresentation(new ObjectNode(JsonNodeFactory.instance)); String key = null; for (final String keyOrValue : keyValuePairs) { if (key != null) { repr.mapPut(key, keyOrValue); key = null; } else { key = keyOrValue; } } if (key != null) { throw new IllegalArgumentException("must provide an even number of keys and values"); } return repr; }
JsonNode jsonNode = node.get(key); if (jsonNode == null) { jsonNode = new ObjectNode(JsonNodeFactory.instance); node.put(key, jsonNode); } else {
JsonNode jsonNode = node.get(key); if (jsonNode == null) { jsonNode = new ObjectNode(JsonNodeFactory.instance); node.put(key, jsonNode); } else {
@Test public void testIDAssignment() throws JsonProcessingException, IOException { ObjectNode beacon = new ObjectNode(JsonNodeFactory.instance); beacon.put("sessionID", "" + Long.toString(Beacon.REQUEST_NEW_SESSION_ID_MARKER, 16)); beacon.put("tabID", "" + Long.toString(Beacon.REQUEST_NEW_TAB_ID_MARKER, 16)); beacon.put("activeAgentModules", MODULES_DEMOVALUE); ArrayNode data = beacon.arrayNode(); beacon.put("data", data); String beaconJson = beacon.toString(); String responseJson = dataHandler.insertBeacon(beaconJson); Mockito.verify(coreService, Mockito.times(0)).addDefaultData(any(DefaultData.class)); JsonNode response = (new ObjectMapper()).readTree(responseJson); assertThat(response, instanceOf(ObjectNode.class)); assertThat(response.get("sessionID").asText(), notNullValue()); assertThat(response.get("tabID").asText(), notNullValue()); }
@Test public void testSessionInfoSending() { ObjectNode beacon = new ObjectNode(JsonNodeFactory.instance); ObjectNode sessInfo = new ObjectNode(JsonNodeFactory.instance); sessInfo.put("type", "metaInfo"); sessInfo.put("browser", "Firefox"); sessInfo.put("device", "iOS"); sessInfo.put("language", "de"); beacon.put("sessionID", "" + Long.toString(SESSID_DEMOVALUE, 16)); beacon.put("tabID", "" + Long.toString(TABID_DEMOVALUE, 16)); beacon.put("activeAgentModules", MODULES_DEMOVALUE); ArrayNode data = beacon.arrayNode(); beacon.put("data", data); data.add(sessInfo); String beaconJson = beacon.toString(); dataHandler.insertBeacon(beaconJson); Mockito.verify(coreService, Mockito.times(1)).addDefaultData(any(DefaultData.class)); List<DefaultData> sent = sentElements.getAllValues(); assertThat(sent.size(), equalTo(1)); assertThat(sent.get(0), instanceOf(UserSessionInfo.class)); UserSessionInfo sentInfo = (UserSessionInfo) sent.get(0); assertThat(sentInfo.getBrowser(), equalTo("Firefox")); assertThat(sentInfo.getDevice(), equalTo("iOS")); assertThat(sentInfo.getLanguage(), equalTo("de")); assertThat(sentInfo.getSessionId(), equalTo(SESSID_DEMOVALUE)); }
@Test public void testInvalidBeaconContent() { ObjectNode beacon = new ObjectNode(JsonNodeFactory.instance); ObjectNode sessInfo = new ObjectNode(JsonNodeFactory.instance); sessInfo.put("type", "unkownType"); sessInfo.put("browser", "Firefox"); sessInfo.put("device", "iOS"); sessInfo.put("language", "de"); beacon.put("sessionID", "" + Long.toString(SESSID_DEMOVALUE, 16)); beacon.put("tabID", "" + Long.toString(TABID_DEMOVALUE, 16)); beacon.put("activeAgentModules", MODULES_DEMOVALUE); ArrayNode data = beacon.arrayNode(); beacon.put("data", data); data.add(sessInfo); String beaconJson = beacon.toString(); dataHandler.insertBeacon(beaconJson); Mockito.verify(coreService, Mockito.times(0)).addDefaultData(any(DefaultData.class)); } }