public static void verifyMinimumMigrationNumber(DbVersion underTest, int minimumMigrationNumber) { TestMigrationStepRegistry registry = new TestMigrationStepRegistry() { @Override public <T extends MigrationStep> MigrationStepRegistry add(long migrationNumber, String description, Class<T> stepClass) { super.add(migrationNumber, description, MigrationStep.class); assertThat(migrationNumber).isGreaterThanOrEqualTo(minimumMigrationNumber); return this; } }; underTest.addSteps(registry); assertThat(registry.migrationNumbers).describedAs("No migration added to registry").isNotEmpty(); assertThat(registry.migrationNumbers.stream().sorted().findFirst().get()).isEqualTo(minimumMigrationNumber); }
@Override public ConstraintViolationSetAssert describedAs(String description, Object... args) { return (ConstraintViolationSetAssert) super.describedAs( description, args ); }
@Test public void shouldDoNotOverrideAttachmentsForGroups() throws IOException { Set<TestResult> testResults = process( "allure2/other-testcase.json", generateTestResultName(), "allure2/other-testcase.json", generateTestResultName(), "allure2/second-testgroup.json", generateTestResultContainerName(), "allure2/after-sample-attachment.txt", "after-sample-attachment.txt" ).getResults(); assertThat(testResults) .describedAs("Test cases is not found") .hasSize(2); testResults.forEach(testResult -> assertThat(testResult.getAfterStages()) .hasSize(1) .flatExtracting(StageResult::getAttachments) .hasSize(1) .extracting(Attachment::getName) .containsExactly("String attachment in after")); }
/** * Asserts that the given violation list has no violations (is empty). * * @param violations The violation list to verify. */ public static void assertNoViolations(Set<? extends ConstraintViolation<?>> violations, String message) { Assertions.assertThat( violations ).describedAs( message ).isEmpty(); }
@Test public void shouldPickUpAttachmentsForTestCase() throws IOException { Set<TestResult> testResults = process( "allure2/simple-testcase.json", generateTestResultName(), "allure2/first-testgroup.json", generateTestResultContainerName(), "allure2/second-testgroup.json", generateTestResultContainerName(), "allure2/test-sample-attachment.txt", "test-sample-attachment.txt" ).getResults(); assertThat(testResults) .describedAs("Test case is not found") .hasSize(1) .extracting(TestResult::getTestStage) .flatExtracting(StageResult::getSteps) .describedAs("Test case should have one step") .hasSize(1) .flatExtracting(Step::getAttachments) .describedAs("Step should have an attachment") .hasSize(1) .extracting(Attachment::getName) .containsExactly("String attachment in test"); }
@Test public void shouldPickUpAttachmentsForAfters() throws IOException { Set<TestResult> testResults = process( "allure2/simple-testcase.json", generateTestResultName(), "allure2/first-testgroup.json", generateTestResultContainerName(), "allure2/second-testgroup.json", generateTestResultContainerName(), "allure2/after-sample-attachment.txt", "after-sample-attachment.txt" ).getResults(); assertThat(testResults) .describedAs("Test case is not found") .hasSize(1) .flatExtracting(TestResult::getAfterStages) .describedAs("Test case should have afters") .hasSize(2) .flatExtracting(StageResult::getAttachments) .describedAs("Second after method should have an attachment") .hasSize(1) .extracting(Attachment::getName) .describedAs("Attachment's name is unexpected") .containsExactly("String attachment in after"); }
public void assertFiltersMutationAtNLocations(int n, Sample s, GregorMutater mutator) { final List<MutationDetails> mutations = mutator.findMutations(s.className); final Collection<MutationDetails> actual = filter(s.clazz, mutations, mutator); final Set<Loc> originalLocations = new LinkedHashSet<>(); FCollection.mapTo(mutations, toLocation(s.clazz), originalLocations); final Set<Loc> filteredLocations = new LinkedHashSet<>(); FCollection.mapTo(actual, toLocation(s.clazz), filteredLocations); assertThat(filteredLocations) .describedAs("Expected to filter %d locations from the %d in %s", n, originalLocations.size(), s.clazz.toString()) .hasSize(originalLocations.size() - n); }
@Override public void tearDown() throws Exception { try { Optional<Span> finishedSpan = Tracer.completeSpan(); SpanObserver observer = Tracer.unsubscribe(TEST_OBSERVER_NAME); assertThat(observer).isInstanceOf(TestSpanObserver.class); List<Span> spans = ((TestSpanObserver) observer).spans(); log.warn("{} spans: {}", spans.size(), spans.stream().map(Span::getOperation).collect(Collectors.toList())); if (Tracer.isTraceObservable()) { assertThat(finishedSpan.isPresent()).isTrue(); assertThat(finishedSpan.get().getOperation()).isEqualTo("test"); String traceId = finishedSpan.get().getTraceId(); assertThat(traceId).isNotNull(); assertThat(traceId).isNotEmpty(); assertThat(spans).isNotEmpty(); assertThat(spans.size()) .describedAs("Should include root test span and additional KVS method spans %s", spans) .isGreaterThanOrEqualTo(1); assertThat(spans.stream() .filter(span -> !Objects.equals(traceId, span.getTraceId())) .map(Span::getTraceId) .collect(Collectors.toSet())) .describedAs("All spans should have same trace ID %s, spans %s", traceId, spans) .isEmpty(); } } finally { super.tearDown(); } }
@Override public ConstraintViolationSetAssert describedAs(String description, Object... args) { return (ConstraintViolationSetAssert) super.describedAs( description, args ); }
/** * Asserts that the given violation list has no violations (is empty). * * @param violations The violation list to verify. */ public static void assertNoViolations(Set<? extends ConstraintViolation<?>> violations, String message) { Assertions.assertThat( violations ).describedAs( message ).isEmpty(); }
@Test @SpecAssertion(section = Sections.CONSTRAINTMETADATA_BEANDESCRIPTOR, id = "h") public void testGetConstrainedConstructors() { BeanDescriptor beanDescriptor = getValidator().getConstraintsForClass( CustomerService.class ); Set<ConstructorDescriptor> constructorDescriptors = beanDescriptor.getConstrainedConstructors(); Set<List<Class<?>>> actualParameterTypes = getParameterTypes( constructorDescriptors ); assertThat( actualParameterTypes ).describedAs( "Wrong constructors" ).containsExactlyInAnyOrder( Collections.<Class<?>>emptyList(), Arrays.<Class<?>>asList( String.class, String.class ), Arrays.<Class<?>>asList( Customer.class ), Arrays.<Class<?>>asList( Account.class ), Arrays.<Class<?>>asList( int.class, Account.class ), Arrays.<Class<?>>asList( long.class ), Arrays.<Class<?>>asList( long.class, int.class ), Arrays.<Class<?>>asList( Map.class ) ); }
@Test void kind_inheritance_related_to_UNCONDITIONAL_JUMP() { List<UastNode.Kind> controlKinds = Arrays.asList(UastNode.Kind.RETURN, UastNode.Kind.GOTO, UastNode.Kind.BREAK, UastNode.Kind.CONTINUE, UastNode.Kind.THROW); controlKinds.forEach(kind -> assertThat(kind.extendedKinds()).describedAs(kind.name()) .containsExactlyInAnyOrder(UastNode.Kind.UNCONDITIONAL_JUMP)); controlKinds.forEach(kind -> assertThat(uast("{ kinds: ['" + kind.name() + "'] }").kinds).describedAs(kind.name()) .containsExactlyInAnyOrder(kind, UastNode.Kind.UNCONDITIONAL_JUMP)); }
@Test void kind_inheritance_related_to_CONDITIONAL_JUMP() { List<UastNode.Kind> controlKinds = Arrays.asList(UastNode.Kind.IF, UastNode.Kind.SWITCH, UastNode.Kind.FOR); controlKinds.forEach(kind -> assertThat(kind.extendedKinds()).describedAs(kind.name()) .contains(UastNode.Kind.CONDITIONAL_JUMP)); controlKinds.forEach(kind -> assertThat(uast("{ kinds: ['" + kind.name() + "'] }").kinds).describedAs(kind.name()) .contains(kind, UastNode.Kind.CONDITIONAL_JUMP)); }
@Test public void testStoreAndRetrieveWildCardAddressMapping() throws ErrorMappingException, RecipientRewriteTableException { String user = "test"; String user2 = "test2"; Domain domain = Domain.LOCALHOST; String address = "test@localhost2"; String address2 = "test@james"; MappingSource source = MappingSource.fromUser(user, domain); assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping") .isEqualTo(MappingsImpl.empty()); virtualUserTable.addMapping(MappingSource.fromDomain(domain), Mapping.address(address)); virtualUserTable.addMapping(source, Mapping.address(address2)); assertThat(virtualUserTable.getMappings(user, domain)).describedAs("One mappings").hasSize(1); assertThat(virtualUserTable.getMappings(user2, domain)).describedAs("One mappings").hasSize(1); virtualUserTable.removeMapping(source, Mapping.address(address2)); virtualUserTable.removeMapping(MappingSource.fromDomain(domain), Mapping.address(address)); assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping") .isEqualTo(MappingsImpl.empty()); assertThat(virtualUserTable.getMappings(user2, domain)).describedAs("No mapping") .isEqualTo(MappingsImpl.empty()); }
@Test public void testStoreAndRetrieveErrorMapping() throws ErrorMappingException, RecipientRewriteTableException { String user = "test"; Domain domain = Domain.LOCALHOST; MappingSource source = MappingSource.fromUser(user, domain); String error = "bounce!"; assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping") .isEqualTo(MappingsImpl.empty()); virtualUserTable.addMapping(source, Mapping.error(error)); assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1); assertThatThrownBy(() -> virtualUserTable.getMappings(user, domain)) .describedAs("Exception thrown on to many mappings") .isInstanceOf(ErrorMappingException.class); virtualUserTable.removeMapping(source, Mapping.error(error)); assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping") .isEqualTo(MappingsImpl.empty()); assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isEmpty(); }
@Test public void testStoreAndRetrieveAddressMapping() throws ErrorMappingException, RecipientRewriteTableException { String user = "test"; Domain domain = Domain.LOCALHOST; MappingSource source = MappingSource.fromUser(user, domain); String address = "test@localhost2"; String address2 = "test@james"; assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping") .isEqualTo(MappingsImpl.empty()); virtualUserTable.addMapping(source, Mapping.address(address)); virtualUserTable.addMapping(source, Mapping.address(address2)); assertThat(virtualUserTable.getMappings(user, domain)).describedAs("Two mappings").hasSize(2); assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1); virtualUserTable.removeMapping(source, Mapping.address(address)); virtualUserTable.removeMapping(source, Mapping.address(address2)); assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping") .isEqualTo(MappingsImpl.empty()); assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isEmpty(); }
@Test public void testStoreAndRetrieveRegexMapping() throws ErrorMappingException, RecipientRewriteTableException { String user = "test"; Domain domain = Domain.LOCALHOST; MappingSource source = MappingSource.fromUser(user, domain); // String regex = "(.*):{$1}@localhost"; // String regex2 = "(.+):{$1}@test"; String regex = "(.*)@localhost"; String regex2 = "(.+)@test"; String invalidRegex = ".*):"; assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping") .isEqualTo(MappingsImpl.empty()); virtualUserTable.addMapping(source, Mapping.regex(regex)); virtualUserTable.addMapping(source, Mapping.regex(regex2)); assertThat(virtualUserTable.getMappings(user, domain)).describedAs("Two mappings").hasSize(2); assertThat(virtualUserTable.getAllMappings()).describedAs("One mappingline").hasSize(1); virtualUserTable.removeMapping(source, Mapping.regex(regex)); assertThatThrownBy(() -> virtualUserTable.addRegexMapping(source, invalidRegex)) .describedAs("Invalid Mapping throw exception") .isInstanceOf(RecipientRewriteTableException.class); virtualUserTable.removeMapping(source, Mapping.regex(regex2)); assertThat(virtualUserTable.getMappings(user, domain)).describedAs("No mapping") .isEqualTo(MappingsImpl.empty()); assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isEmpty(); }
@Test public void testRecursiveMapping() throws ErrorMappingException, RecipientRewriteTableException { String user1 = "user1"; String user2 = "user2"; String user3 = "user3"; Domain domain1 = Domain.of("domain1"); Domain domain2 = Domain.of("domain2"); Domain domain3 = Domain.of("domain3"); MappingSource source1 = MappingSource.fromUser(user1, domain1); MappingSource source2 = MappingSource.fromUser(user2, domain2); MappingSource source3 = MappingSource.fromUser(user3, domain3); virtualUserTable.setRecursiveMapping(true); assertThat(virtualUserTable.getAllMappings()).describedAs("No mapping").isEmpty(); virtualUserTable.addMapping(source1, Mapping.address(user2 + "@" + domain2.asString())); virtualUserTable.addMapping(source2, Mapping.address(user3 + "@" + domain3.asString())); assertThat(virtualUserTable.getMappings(user1, domain1)).containsOnly(Mapping.address(user3 + "@" + domain3.asString())); virtualUserTable.addMapping(source3, Mapping.address(user1 + "@" + domain1.asString())); assertThatThrownBy(() -> virtualUserTable.getMappings(user1, domain1)) .describedAs("Exception thrown on to many mappings") .isInstanceOf(ErrorMappingException.class); // disable recursive mapping virtualUserTable.setRecursiveMapping(false); assertThat(virtualUserTable.getMappings(user1, domain1)).describedAs("Not recursive mapped").containsExactly(Mapping.address(user2 + "@" + domain2.asString())); }
.describedAs( "internalDescription should be ignored" ) .extracting( t -> t.field() ) .doesNotContain( "internalDescription" );
@Test public void testAliasDomainMapping() throws ErrorMappingException, RecipientRewriteTableException { String domain = "realdomain"; Domain aliasDomain = Domain.of("aliasdomain"); String user = "user"; String user2 = "user2"; assertThat(virtualUserTable.getAllMappings()).describedAs("No mappings").isEmpty(); virtualUserTable.addMapping(MappingSource.fromDomain(aliasDomain), Mapping.address(user2 + "@" + domain)); virtualUserTable.addMapping(MappingSource.fromDomain(aliasDomain), Mapping.domain(Domain.of(domain))); assertThat(virtualUserTable.getMappings(user, aliasDomain)) .describedAs("Domain mapped as first, Address mapped as second") .isEqualTo(MappingsImpl.builder() .add(Mapping.address(user + "@" + domain)) .add(Mapping.address(user2 + "@" + domain)) .build()); virtualUserTable.removeMapping(MappingSource.fromDomain(aliasDomain), Mapping.address(user2 + "@" + domain)); virtualUserTable.removeMapping(MappingSource.fromDomain(aliasDomain), Mapping.domain(Domain.of(domain))); }