.compareTo(ProtocolVersion.V5) >= 0) { assertThat(e.getFailuresMap()).hasSize(1).containsValue(0); } else { assertThat(e.getFailuresMap()).isEmpty();
@Test(groups = "short") public void should_fail_if_host_fails_query() { String query = "mock"; sCluster .node(1) .primingClient() .prime( PrimingRequest.queryBuilder() .withQuery(query) .withThen(then().withResult(Result.unavailable)) .build()); // given a statement with a host configured to fail the given query. Host host1 = TestUtils.findHost(cluster, 1); Statement statement = new SimpleStatement(query).setHost(host1); try { // when statement is executed an error should be raised. session.execute(statement); fail("Query should have failed"); } catch (NoHostAvailableException e) { // then the request should fail with a NHAE and no host was tried. assertThat(e.getErrors()).hasSize(1); assertThat(e.getErrors().values().iterator().next()).isInstanceOf(UnavailableException.class); } finally { verifyNoLbpInteractions(); } }
.compareTo(ProtocolVersion.V5) >= 0) { assertThat(e.getFailuresMap()).hasSize(1).containsValue(1); } else { assertThat(e.getFailuresMap()).isEmpty();
assertThat(snapshot.getAllStats()).hasSize(1); LatencyAwarePolicy.Snapshot.Stats stats = snapshot.getStats(retrieveSingleHost(cluster)); assertThat(stats).isNotNull();
assertThat(snapshot.getAllStats()).hasSize(1); LatencyAwarePolicy.Snapshot.Stats stats = snapshot.getStats(retrieveSingleHost(cluster)); assertThat(stats).isNotNull();
@Test public void emptyMap() throws Exception { assertThat(valueMap).hasSize(0).isEmpty(); }
@Test public void publicConstructorGivesEmptyTraits() throws Exception { assertThat(new Traits()).hasSize(0); }
@Test public void performIntegrationOperation() throws IOException { stats.performIntegrationOperation(new Pair<>("foo", 43L)); assertThat(stats.integrationOperationCount).isEqualTo(1); assertThat(stats.integrationOperationDuration).isEqualTo(43L); assertThat(stats.integrationOperationDurationByIntegration) // .containsExactly(MapEntry.entry("foo", 43L)); stats.performIntegrationOperation(new Pair<>("bar", 2L)); assertThat(stats.integrationOperationCount).isEqualTo(2); assertThat(stats.integrationOperationDuration).isEqualTo(45L); assertThat(stats.integrationOperationDurationByIntegration) .hasSize(2) .contains(MapEntry.entry("bar", 2L)); stats.performIntegrationOperation(new Pair<>("bar", 19L)); assertThat(stats.integrationOperationCount).isEqualTo(3); assertThat(stats.integrationOperationDuration).isEqualTo(64L); assertThat(stats.integrationOperationDurationByIntegration) .hasSize(2) .contains(MapEntry.entry("bar", 21L)); }
@Test public void canChangeKeyValueSplitStrategy() throws Exception { // given TypeParser parser = TypeParser.newBuilder() .setKeyValueSplitStrategy(new SplitStrategy() { @Override public List<String> split(String input, SplitStrategyHelper helper) { return Arrays.asList(input.split("#")); } }) .build(); // when Map<String, String> map = parser.parse("aaa#AAA,bbb#BBB", new GenericType<Map<String, String>>() {}); // then assertThat(map).hasSize(2); assertThat(map.get("aaa")).isEqualTo("AAA"); assertThat(map.get("bbb")).isEqualTo("BBB"); }
@Test public void testExplodeTestMethodsUseDataProviderShouldReturnFrameworkMethodInjectedToUseDataProviderMethodIfExists() throws Throwable { // Given: final Method method = getMethod("dataProviderMethod"); doReturn(method).when(dataProviderMethod).getMethod(); List<Object[]> dataConverterResult = listOfArrays(new Object[] { null }); doReturn(dataConverterResult).when(dataConverter).convert(any(), anyBoolean(), any(Class[].class), any(DataProvider.class)); doReturn(dataProvider).when(dataProviderMethod).getAnnotation(DataProvider.class); doReturn(DataProvider.DEFAULT_FORMAT).when(dataProvider).format(); doReturn(true).when(dataProvider).cache(); // When: List<FrameworkMethod> result = underTest.explodeTestMethod(testMethod, dataProviderMethod); // Then: assertThat(TestGenerator.dataProviderDataCache).hasSize(1).containsKey(dataProviderMethod); assertThat(result).hasSize(1); verify(dataProviderMethod).invokeExplosively(null, testMethod); }
@Test public void nestedMaps() throws Exception { ValueMap nested = new ValueMap(); nested.put("value", "box"); valueMap.put("nested", nested); assertThat(valueMap).hasSize(1).contains(MapEntry.entry("nested", nested)); assertThat(cartographer.toJson(valueMap)).isEqualTo("{\"nested\":{\"value\":\"box\"}}"); valueMap = new ValueMap(cartographer.fromJson("{\"nested\":{\"value\":\"box\"}}")); assertThat(valueMap).hasSize(1).contains(MapEntry.entry("nested", nested)); }
@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"); }
public void testDeleteSinglePartObjectWithMultiPartDelete() throws Exception { String objectName = "testDeleteSinglePartObjectWithMultiPartDelete"; for (String regionId : regions) { getApi().getObjectApi(regionId, defaultContainerName).put(objectName, newByteSourcePayload(ByteSource.wrap("swifty".getBytes()))); DeleteStaticLargeObjectResponse resp = getApi().getStaticLargeObjectApi(regionId, defaultContainerName).delete(objectName); assertThat(resp.status()).isEqualTo("400 Bad Request"); assertThat(resp.deleted()).isZero(); assertThat(resp.notFound()).isZero(); assertThat(resp.errors()).hasSize(1); getApi().getObjectApi(regionId, defaultContainerName).delete(objectName); } }
final public void toLinkedHashMap(GenericType<Map<T, T>> type) throws Exception { assertThat(parser.parse(stringToParse, type)) .hasSameClassAs(new LinkedHashMap<T, T>()) .contains(MapEntry.entry(key(0), value(0))) .contains(MapEntry.entry(key(1), value(1))) .hasSize(2); }
@Test public void traitsAreMergedCorrectly() throws Exception { Traits traits1 = new Traits() // .putAge(20) .putAvatar("f2prateek") .putDescription("the first one") .putLastName("Srivastava") .putEmail("f2prateek@gmail.com") .putEmployees(50); assertThat(traits1).hasSize(6); Traits traits2 = new Traits() .putAvatar("f2prateek") .putFirstName("Prateek") .putDescription("the second one"); assertThat(traits2).hasSize(3); traits1.putAll(traits2); assertThat(traits1) .hasSize(7) .contains(MapEntry.entry("avatar", "f2prateek")) .contains(MapEntry.entry("description", "the second one")) .contains(MapEntry.entry("email", "f2prateek@gmail.com")); assertThat(traits1.name()).isEqualTo("Prateek Srivastava"); }
@Test public void logoutClearsTraitsAndUpdatesContext() { analyticsContext.setTraits(new Traits().putAge(20).putAvatar("bar")); analytics.logout(); verify(traitsCache).delete(); verify(traitsCache) .set( argThat( new TypeSafeMatcher<Traits>() { @Override protected boolean matchesSafely(Traits traits) { return !isNullOrEmpty(traits.anonymousId()); } @Override public void describeTo(Description description) {} })); assertThat(analyticsContext.traits()).hasSize(1).containsKey("anonymousId"); }
@Test(groups = "short") public void should_fail_if_host_fails_query() { String query = "mock"; sCluster .node(1) .primingClient() .prime( PrimingRequest.queryBuilder() .withQuery(query) .withThen(then().withResult(Result.unavailable)) .build()); // given a statement with a host configured to fail the given query. Host host1 = TestUtils.findHost(cluster, 1); Statement statement = new SimpleStatement(query).setHost(host1); try { // when statement is executed an error should be raised. session.execute(statement); fail("Query should have failed"); } catch (NoHostAvailableException e) { // then the request should fail with a NHAE and no host was tried. assertThat(e.getErrors()).hasSize(1); assertThat(e.getErrors().values().iterator().next()).isInstanceOf(UnavailableException.class); } finally { verifyNoLbpInteractions(); } }
@Test public void projectSettings() throws Exception { @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") ValueMap valueMap = new ValueMap(cartographer.fromJson(PROJECT_SETTINGS_JSON_SAMPLE)); assertThat(valueMap.getValueMap("Amplitude")) .isNotNull() .hasSize(4) .contains(MapEntry.entry("apiKey", "ad3c426eb736d7442a65da8174bc1b1b")) .contains(MapEntry.entry("trackNamedPages", true)) .contains(MapEntry.entry("trackCategorizedPages", true)) .contains(MapEntry.entry("trackAllPages", false)); assertThat(valueMap.getValueMap("Flurry")) .isNotNull() .hasSize(4) .contains(MapEntry.entry("apiKey", "8DY3D6S7CCWH54RBJ9ZM")) .contains(MapEntry.entry("captureUncaughtExceptions", false)) .contains(MapEntry.entry("useHttps", true)) .contains(MapEntry.entry("sessionContinueSeconds", 10.0)); }
@Test public void customJsonMapDeserialization() throws Exception { Settings settings = new Settings(cartographer.fromJson(PROJECT_SETTINGS_JSON_SAMPLE)); assertThat(settings) .hasSize(4) .containsKey("Amplitude") .containsKey("Segment") .containsKey("Flurry") .containsKey("Mixpanel"); // Map Constructor MixpanelSettings mixpanelSettings = settings.getMixpanelSettings(); assertThat(mixpanelSettings) // .contains(MapEntry.entry("token", "f7afe0cb436685f61a2b203254779e02")) .contains(MapEntry.entry("people", true)) .contains(MapEntry.entry("trackNamedPages", true)) .contains(MapEntry.entry("trackCategorizedPages", true)) .contains(MapEntry.entry("trackAllPages", false)); try { settings.getAmplitudeSettings(); } catch (AssertionError exception) { assertThat(exception) // .hasMessage( "Could not create instance of com.segment.analytics.ValueMapTest.AmplitudeSettings.\n" + "java.lang.NoSuchMethodException: " + "com.segment.analytics.ValueMapTest$AmplitudeSettings.<init>(java.util.Map)"); } }
@Test public void decodesPrimitives() throws IOException { String json = "{\n" + " \"byte\": 32,\n" + " \"boolean\": true,\n" + " \"short\": 100,\n" + " \"int\": 1,\n" + " \"long\": 43,\n" + " \"float\": 23.0,\n" + " \"double\": 3.141592653589793,\n" + " \"char\": \"a\",\n" + " \"String\": \"string\"\n" + "}"; Map<String, Object> map = cartographer.fromJson(json); assertThat(map) .hasSize(9) .contains(MapEntry.entry("byte", 32.0)) .contains(MapEntry.entry("boolean", true)) .contains(MapEntry.entry("short", 100.0)) .contains(MapEntry.entry("int", 1.0)) .contains(MapEntry.entry("long", 43.0)) .contains(MapEntry.entry("float", 23.0)) .contains(MapEntry.entry("double", Math.PI)) .contains(MapEntry.entry("char", "a")) .contains(MapEntry.entry("String", "string")); }