@Override protected <ELEMENT2> AbstractListAssert<?, List<? extends ELEMENT2>, ELEMENT2, ObjectAssert<ELEMENT2>> newListAssertInstance(List<? extends ELEMENT2> newActual) { return new ProxyableListAssert<>(newActual); }
@Override public ProxyableListAssert<ELEMENT> startsWith(@SuppressWarnings("unchecked") ELEMENT... sequence) { if (!(actual instanceof ProxyableListAssert.ListFromStream)) { return super.startsWith(sequence); } objects.assertNotNull(info, actual); checkIsNotNull(sequence); // NO SUPPORT FOR infinite streams as it prevents chaining other assertions afterward, it requires to consume the // Stream partially, if you chain another assertion, the stream is already consumed. Iterator<? extends ELEMENT> iterator = asListFromStream().stream().iterator(); if (sequence.length == 0 && iterator.hasNext()) throw new AssertionError("actual is not empty"); int i = 0; while (iterator.hasNext()) { if (i >= sequence.length) break; if (iterables.getComparisonStrategy().areEqual(iterator.next(), sequence[i++])) continue; throw actualDoesNotStartWithSequence(info, sequence); } if (sequence.length > i) { // sequence has more elements than actual throw actualDoesNotStartWithSequence(info, sequence); } return myself; }
private void validateList(List<String> actualList, List<String> expectedList, String message) { if (CollectionUtils.isNotEmpty(expectedList)) { softAssertions.assertThat(actualList).as(message).isNotEmpty(); if (CollectionUtils.isNotEmpty(actualList)) { softAssertions.assertThat(actualList).as(message).hasSameElementsAs(expectedList); } } else { softAssertions.assertThat(actualList).as(message).isNullOrEmpty(); } }
private void validateParameters(List<Parameter> actualOperationParameters, List<Parameter> expectedOperationParameters, String httpMethod, String path) { String message = String.format("Checking parameters of '%s' operation of path '%s'", httpMethod, path); if (CollectionUtils.isNotEmpty(expectedOperationParameters)) { softAssertions.assertThat(actualOperationParameters).as(message).isNotEmpty(); if (CollectionUtils.isNotEmpty(actualOperationParameters)) { softAssertions.assertThat(actualOperationParameters).as(message).hasSameSizeAs(expectedOperationParameters); softAssertions.assertThat(actualOperationParameters).as(message).usingElementComparatorOnFields("in", "name", "required").hasSameElementsAs(expectedOperationParameters); Map<String, Parameter> expectedParametersAsMap = new HashMap<>(); for (Parameter expectedParameter : expectedOperationParameters) { expectedParametersAsMap.put(expectedParameter.getName(), expectedParameter); } for (Parameter actualParameter : actualOperationParameters) { String parameterName = actualParameter.getName(); Parameter expectedParameter = expectedParametersAsMap.get(parameterName); validateParameter(actualParameter, expectedParameter, parameterName, httpMethod, path); } } } else { softAssertions.assertThat(actualOperationParameters).as(message).isNullOrEmpty(); } }
private void validateList(List<String> actualList, List<String> expectedList, String message) { if (CollectionUtils.isNotEmpty(expectedList)) { softAssertions.assertThat(actualList).as(message).isNotEmpty(); if (CollectionUtils.isNotEmpty(actualList)) { softAssertions.assertThat(actualList).as(message).containsAll(expectedList); } } else { softAssertions.assertThat(actualList).as(message).isNullOrEmpty(); } }
List<String> expectedEnums = expectedPathParameter.getEnum(); if (CollectionUtils.isNotEmpty(expectedEnums)) { softAssertions.assertThat(actualPathParameter.getEnum()).as(message).hasSameElementsAs(expectedEnums); } else { softAssertions.assertThat(actualPathParameter.getEnum()).as(message).isNullOrEmpty(); List<String> expectedEnums = expectedQueryParameter.getEnum(); if (CollectionUtils.isNotEmpty(expectedEnums)) { softAssertions.assertThat(actualQueryParameter.getEnum()).as(message).hasSameElementsAs(expectedEnums); } else { softAssertions.assertThat(actualQueryParameter.getEnum()).as(message).isNullOrEmpty(); List<String> expectedEnums = expectedHeaderParameter.getEnum(); if (CollectionUtils.isNotEmpty(expectedEnums)) { softAssertions.assertThat(actualHeaderParameter.getEnum()).as(message).hasSameElementsAs(expectedEnums); } else { softAssertions.assertThat(actualHeaderParameter.getEnum()).as(message).isNullOrEmpty(); List<String> expectedEnums = expectedFormParameter.getEnum(); if (CollectionUtils.isNotEmpty(expectedEnums)) { softAssertions.assertThat(actualFormParameter.getEnum()).as(message).hasSameElementsAs(expectedEnums); } else { softAssertions.assertThat(actualFormParameter.getEnum()).as(message).isNullOrEmpty(); List<String> expectedEnums = expectedCookieParameter.getEnum(); if (CollectionUtils.isNotEmpty(expectedEnums)) { softAssertions.assertThat(actualCookieParameter.getEnum()).as(message).hasSameElementsAs(expectedEnums); } else { softAssertions.assertThat(actualCookieParameter.getEnum()).as(message).isNullOrEmpty();
@Test default void retriesBackOffShouldDelayByExponentialGrowth() throws Exception { ThrowingListener throwingListener = throwingListener(); eventBus().register(throwingListener, GROUP_A); eventBus().dispatch(EVENT, NO_KEYS).block(); TimeUnit.SECONDS.sleep(5); SoftAssertions.assertSoftly(softly -> { List<Instant> timeElapsed = throwingListener.timeElapsed; softly.assertThat(timeElapsed).hasSize(4); long minFirstDelayAfter = 100; // first backOff long minSecondDelayAfter = 100; // 200 * jitter factor (200 * 0.5) long minThirdDelayAfter = 200; // 400 * jitter factor (400 * 0.5) softly.assertThat(timeElapsed.get(1)) .isAfterOrEqualTo(timeElapsed.get(0).plusMillis(minFirstDelayAfter)); softly.assertThat(timeElapsed.get(2)) .isAfterOrEqualTo(timeElapsed.get(1).plusMillis(minSecondDelayAfter)); softly.assertThat(timeElapsed.get(3)) .isAfterOrEqualTo(timeElapsed.get(2).plusMillis(minThirdDelayAfter)); }); }
@Test public void automaticallyMigratesTimestampsAndFailsOnRestart() throws Exception { TimestampService timestampClient = createEteClientFor(TimestampService.class); TodoResource todoClient = createEteClientFor(TodoResource.class); todoClient.addTodo(TODO); softAssertions.assertThat(todoClient.getTodoList()) .as("contains one todo pre-migration") .contains(TODO); long embeddedTimestamp = timestampClient.getFreshTimestamp(); softAssertions.assertThat(embeddedTimestamp) .as("can get a timestamp before migration") .isNotNull(); upgradeAtlasClientToTimelock(); assertTimeLockGivesHigherTimestampThan(embeddedTimestamp); softAssertions.assertThat(todoClient.getTodoList()) .as("can still read todo after migration to TimeLock") .contains(TODO); todoClient.addTodo(TODO_2); softAssertions.assertThat(todoClient.getTodoList()) .as("can add a new todo using TimeLock") .contains(TODO, TODO_2); assertNoLongerExposesEmbeddedTimestampService(); downgradeAtlasClientFromTimelockWithoutMigration(); assertCanNeitherReadNorWrite(); }
@Override public ProxyableListAssert<ELEMENT> isEqualTo(Object expected) { if (actual instanceof ProxyableListAssert.ListFromStream && asListFromStream().stream == expected) { return myself; } return super.isEqualTo(expected); }
@Test default void deadLettersIsNotAppliedForKeyRegistrations() throws Exception { EventCollector eventCollector = eventCollector(); doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doThrow(new RuntimeException()) .doCallRealMethod() .when(eventCollector).event(EVENT); eventBus().register(eventCollector, KEY_1); eventBus().dispatch(EVENT, ImmutableSet.of(KEY_1)).block(); TimeUnit.SECONDS.sleep(1); SoftAssertions.assertSoftly(softly -> { softly.assertThat(eventCollector.getEvents()).isEmpty(); softly.assertThat(deadLetter().groupsWithFailedEvents().toIterable()) .isEmpty(); }); }
@Test public void testSpanWithSlotFeatures() throws Exception { TypeSystemDescription tsd = createTypeSystemDescription("tsd/spanWithSlotFeatures"); TypeSystemAnalysis analysis = TypeSystemAnalysis.of(tsd); AnnotationLayer slotSpanLayer = new AnnotationLayer(); slotSpanLayer.setName("webanno.custom.SlotSpan"); slotSpanLayer.setUiName("SlotSpan"); slotSpanLayer.setType(WebAnnoConst.SPAN_TYPE); slotSpanLayer.setAnchoringMode(AnchoringMode.CHARACTERS); slotSpanLayer.setAllowStacking(true); slotSpanLayer.setCrossSentence(true); AnnotationFeature freeSlot = new AnnotationFeature( "freeSlot", CAS.TYPE_NAME_ANNOTATION); AnnotationFeature boundSlot = new AnnotationFeature( "boundSlot", "webanno.custom.SlotSpan"); SoftAssertions softly = new SoftAssertions(); softly.assertThat(analysis.getLayers()) .containsExactly(slotSpanLayer) .usingFieldByFieldElementComparator(); softly.assertThat(analysis.getFeatures(slotSpanLayer.getName())) .containsExactlyInAnyOrder(freeSlot, boundSlot) .usingFieldByFieldElementComparator(); softly.assertAll(); }
private void validatePath(String pathName, Path actualPath, Path expectedPath) { if (expectedPath != null) { softAssertions.assertThat(actualPath.getOperations()).as("Checking number of operations of path '%s'", pathName).hasSameSizeAs(actualPath.getOperations()); validateOperation(actualPath.getGet(), expectedPath.getGet(), pathName, "GET"); validateOperation(actualPath.getDelete(), expectedPath.getDelete(), pathName, "DELETE"); validateOperation(actualPath.getPost(), expectedPath.getPost(), pathName, "POST"); validateOperation(actualPath.getPut(), expectedPath.getPut(), pathName, "PUT"); validateOperation(actualPath.getPatch(), expectedPath.getPatch(), pathName, "PATCH"); validateOperation(actualPath.getOptions(), expectedPath.getOptions(), pathName, "OPTIONS"); } }
private void validateDefinitionRequiredProperties(List<String> actualRequiredProperties, List<String> expectedRequiredProperties, String definitionName) { if (CollectionUtils.isNotEmpty(expectedRequiredProperties)) { softAssertions.assertThat(actualRequiredProperties).as("Checking required properties of definition '%s'", definitionName).isNotEmpty(); if (CollectionUtils.isNotEmpty(actualRequiredProperties)) { final Set<String> filteredExpectedProperties = filterWhitelistedPropertyNames(definitionName, new HashSet<>(expectedRequiredProperties)); softAssertions.assertThat(actualRequiredProperties).as("Checking required properties of definition '%s'", definitionName).hasSameElementsAs(filteredExpectedProperties); } } else { softAssertions.assertThat(actualRequiredProperties).as("Checking required properties of definition '%s'", definitionName).isNullOrEmpty(); } }
List<String> expectedEnums = expectedPathParameter.getEnum(); if (CollectionUtils.isNotEmpty(expectedEnums)) { softAssertions.assertThat(actualPathParameter.getEnum()).as(message).hasSameElementsAs(expectedEnums); } else { softAssertions.assertThat(actualPathParameter.getEnum()).as(message).isNullOrEmpty(); List<String> expectedEnums = expectedQueryParameter.getEnum(); if (CollectionUtils.isNotEmpty(expectedEnums)) { softAssertions.assertThat(actualQueryParameter.getEnum()).as(message).hasSameElementsAs(expectedEnums); } else { softAssertions.assertThat(actualQueryParameter.getEnum()).as(message).isNullOrEmpty(); List<String> expectedEnums = expectedHeaderParameter.getEnum(); if (CollectionUtils.isNotEmpty(expectedEnums)) { softAssertions.assertThat(actualHeaderParameter.getEnum()).as(message).hasSameElementsAs(expectedEnums); } else { softAssertions.assertThat(actualHeaderParameter.getEnum()).as(message).isNullOrEmpty(); List<String> expectedEnums = expectedFormParameter.getEnum(); if (CollectionUtils.isNotEmpty(expectedEnums)) { softAssertions.assertThat(actualFormParameter.getEnum()).as(message).hasSameElementsAs(expectedEnums); } else { softAssertions.assertThat(actualFormParameter.getEnum()).as(message).isNullOrEmpty(); List<String> expectedEnums = expectedCookieParameter.getEnum(); if (CollectionUtils.isNotEmpty(expectedEnums)) { softAssertions.assertThat(actualCookieParameter.getEnum()).as(message).hasSameElementsAs(expectedEnums); } else { softAssertions.assertThat(actualCookieParameter.getEnum()).as(message).isNullOrEmpty();
softly.assertThat(list).hasSize(4); softly.assertThat(entryWithId(list, failedId)) .isEqualTo(TaskManager.Status.FAILED);
@Override public ProxyableListAssert<ELEMENT> isEqualTo(Object expected) { if (actual instanceof ProxyableListAssert.ListFromStream && asListFromStream().stream == expected) { return myself; } return super.isEqualTo(expected); }