@Test public void assert_maps_can_be_read() { assertThat(reader.read("$.store.book[0]", Map.class)) .containsEntry("category", "reference") .containsEntry("author", "Nigel Rees") .containsEntry("title", "Sayings of the Century") .containsEntry("display-price", 8.95D); }
@Test public void when_deep_scanning_leaf_multi_props_work() { Object result = JsonPath.parse("[{\"a\": \"a-val\", \"b\": \"b-val\", \"c\": \"c-val\"}, [1, 5], {\"a\": \"a-val\"}]").read( "$..['a', 'c']"); // This is current deep scan semantics: only objects containing all properties specified in multiprops token are // considered. assertThat(result).asList().hasSize(1); result = ((List)result).get(0); assertThat(result).isInstanceOf(Map.class); assertThat((Map)result).hasSize(2).containsEntry("a", "a-val").containsEntry("c", "c-val"); // But this semantics changes when DEFAULT_PATH_LEAF_TO_NULL comes into play. Configuration conf = Configuration.defaultConfiguration().addOptions(Option.DEFAULT_PATH_LEAF_TO_NULL); result = using(conf).parse("[{\"a\": \"a-val\", \"b\": \"b-val\", \"c\": \"c-val\"}, [1, 5], {\"a\": \"a-val\"}]").read( "$..['a', 'c']"); // todo: deep equality test, but not tied to any json provider assertThat(result).asList().hasSize(2); for (final Object node : (List)result) { assertThat(node).isInstanceOf(Map.class); assertThat((Map)node).hasSize(2).containsEntry("a", "a-val"); } }
@Test public void multi_prop_can_be_read_from_root() { Map<String, Object> model = new HashMap<String, Object>(){{ put("a", "a-val"); put("b", "b-val"); put("c", "c-val"); }}; Configuration conf = Configuration.defaultConfiguration(); assertThat(using(conf).parse(model).read("$['a', 'b']", Map.class)) .containsEntry("a", "a-val") .containsEntry("b", "b-val"); // current semantics: absent props are skipped assertThat(using(conf).parse(model).read("$['a', 'd']", Map.class)) .hasSize(1).containsEntry("a", "a-val"); }
@Test public void multi_props_can_be_defaulted_to_null() { Map<String, Object> model = new HashMap<String, Object>(){{ put("a", "a-val"); put("b", "b-val"); put("c", "c-val"); }}; Configuration conf = Configuration.defaultConfiguration().addOptions(Option.DEFAULT_PATH_LEAF_TO_NULL); assertThat(using(conf).parse(model).read("$['a', 'd']", Map.class)) .containsEntry("a", "a-val") .containsEntry("d", null); }
@Test(groups = "short") public void should_handle_contains_on_map_with_index() { PreparedStatement byFeatures = session() .prepare( select("id", "description", "features_values") .from("products") .where(contains("features_values", bindMarker("feature")))); ResultSet results = session().execute(byFeatures.bind().setString("feature", "LED")); Row row = results.one(); assertThat(row).isNotNull(); assertThat(row.getInt("id")).isEqualTo(29412); assertThat(row.getMap("features_values", String.class, String.class)) .containsEntry("techno", "LED"); }
@Test(groups = "short") public void should_handle_contains_key_on_map_with_index() { PreparedStatement byFeatures = session() .prepare( select("id", "description", "features_keys") .from("products") .where(containsKey("features_keys", bindMarker("feature")))); ResultSet results = session().execute(byFeatures.bind().setString("feature", "refresh-rate")); Row row = results.one(); assertThat(row).isNotNull(); assertThat(row.getInt("id")).isEqualTo(34134); assertThat(row.getMap("features_keys", String.class, String.class)) .containsEntry("refresh-rate", "400hz"); } }
assertThat(function.getSimpleName()).isEqualTo("plus"); assertThat(function.getReturnType()).isEqualTo(cint()); assertThat(function.getArguments()).containsEntry("s", cint()).containsEntry("v", cint()); assertThat(function.getLanguage()).isEqualTo("java"); assertThat(function.getBody()).isEqualTo("return s+v;");
assertThat(function.getSimpleName()).isEqualTo("complex"); assertThat(function.getReturnType()).isEqualTo(cint()); assertThat(function.getArguments()).containsEntry("x", argumentType); assertThat(function.getLanguage()).isEqualTo("java"); assertThat(function.getBody()).isEqualTo("return 42;");
@Test public void createWithoutDeviceIdCollection() { context = AnalyticsContext.create(RuntimeEnvironment.application, traits, false); assertThat(context.getValueMap("device")) // .containsEntry("id", traits.anonymousId()) .containsEntry("manufacturer", "unknown") .containsEntry("model", "unknown") .containsEntry("name", "unknown"); }
@Test public void device() { AnalyticsContext.Device device = new AnalyticsContext.Device(); device.putAdvertisingInfo("adId", true); assertThat(device).containsEntry("advertisingId", "adId"); assertThat(device).containsEntry("adTrackingEnabled", true); }
@Test public void alias() { String anonymousId = traits.anonymousId(); analytics.alias("foo"); ArgumentCaptor<AliasPayload> payloadArgumentCaptor = ArgumentCaptor.forClass(AliasPayload.class); verify(integration).alias(payloadArgumentCaptor.capture()); assertThat(payloadArgumentCaptor.getValue()) .containsEntry("previousId", anonymousId) .containsEntry("userId", "foo"); }
@Test public void groupId() { GroupPayload payload = builder.groupId("group_id").build(); assertThat(payload.groupId()).isEqualTo("group_id"); assertThat(payload).containsEntry(GroupPayload.GROUP_ID_KEY, "group_id"); }
@Test public void category() { ScreenPayload payload = builder.category("category").build(); assertThat(payload.category()).isEqualTo("category"); assertThat(payload).containsEntry(ScreenPayload.CATEGORY_KEY, "category"); }
@Test public void extractAllCookies() { ArrayMap<String, String> cookies = CookieHelper.extractAll(headers); assertThat(cookies).hasSize(2) .containsEntry("pwg_id", "asdfghjklqwertyuiop") .containsEntry("something", "else") .doesNotContainEntry("Not-Cookie", "aValue") .doesNotContainEntry("Also-Not-Cookie", "anotherValue"); }
@Test public void previousId() { AliasPayload payload = builder.previousId("previous_id").build(); assertThat(payload.previousId()).isEqualTo("previous_id"); assertThat(payload).containsEntry(AliasPayload.PREVIOUS_ID_KEY, "previous_id"); }
@Test public void traits() { GroupPayload payload = builder.groupId("group_id").traits(ImmutableMap.of("foo", "bar")).build(); assertThat(payload.traits()).isEqualTo(ImmutableMap.of("foo", "bar")); assertThat(payload).containsEntry(GroupPayload.TRAITS_KEY, ImmutableMap.of("foo", "bar")); } }
@Test public void traits() { IdentifyPayload payload = new IdentifyPayload.Builder() .userId("user_id") .traits(ImmutableMap.of("foo", "bar")) .build(); assertThat(payload.traits()).isEqualTo(ImmutableMap.of("foo", "bar")); assertThat(payload).containsEntry(IdentifyPayload.TRAITS_KEY, ImmutableMap.of("foo", "bar")); }
@Test public void messageId() { for (Builder builder : builders) { BasePayload payload = builder.userId("user_id").messageId("message_id").build(); assertThat(payload.messageId()).isEqualTo("message_id"); assertThat(payload).containsEntry(BasePayload.MESSAGE_ID, "message_id"); } }
@Test public void context() { for (Builder builder : builders) { BasePayload payload = builder.userId("user_id").context(ImmutableMap.of("foo", "bar")).build(); assertThat(payload.context()).containsExactly(MapEntry.entry("foo", "bar")); assertThat(payload).containsEntry(BasePayload.CONTEXT_KEY, ImmutableMap.of("foo", "bar")); } }
@Test public void integrations() { for (Builder builder : builders) { BasePayload payload = builder.userId("user_id").integrations(ImmutableMap.of("foo", "bar")).build(); assertThat(payload.integrations()).containsExactly(MapEntry.entry("foo", "bar")); assertThat(payload) .containsEntry(BasePayload.INTEGRATIONS_KEY, ImmutableMap.of("foo", "bar")); } }