Search in sources :

Example 11 with TestFactory

use of org.junit.jupiter.api.TestFactory in project tutorials by eugenp.

the class DynamicTests method dynamicUserTestCollection.

@TestFactory
public Stream<DynamicTest> dynamicUserTestCollection() {
    List<User> inputList = Arrays.asList(new User("john@yahoo.com", "John"), new User("ana@yahoo.com", "Ana"));
    Function<User, String> displayNameGenerator = (input) -> "Saving user: " + input;
    UserDAO userDAO = new UserDAO();
    ThrowingConsumer<User> testExecutor = (input) -> {
        userDAO.add(input);
        assertNotNull(userDAO.findOne(input.getEmail()));
    };
    return DynamicTest.stream(inputList.iterator(), displayNameGenerator, testExecutor);
}
Also used : Arrays(java.util.Arrays) List(java.util.List) Stream(java.util.stream.Stream) TestFactory(org.junit.jupiter.api.TestFactory) Collection(java.util.Collection) UserDAO(com.stackify.daos.UserDAO) Assertions(org.junit.jupiter.api.Assertions) DynamicTest(org.junit.jupiter.api.DynamicTest) User(com.stackify.models.User) Function(java.util.function.Function) ThrowingConsumer(org.junit.jupiter.api.function.ThrowingConsumer) User(com.stackify.models.User) UserDAO(com.stackify.daos.UserDAO) TestFactory(org.junit.jupiter.api.TestFactory)

Example 12 with TestFactory

use of org.junit.jupiter.api.TestFactory in project robozonky by RoboZonky.

the class EmailingListenerTest method listeners.

@TestFactory
Stream<DynamicNode> listeners() throws MalformedURLException {
    // prepare data
    final Loan loan = Loan.custom().setId(66666).setAmount(100_000).setInterestRate(BigDecimal.TEN).setDatePublished(OffsetDateTime.now().minusMonths(2)).setName("Úvěr").setRegion(Region.JIHOCESKY).setPurpose(Purpose.AUTO_MOTO).setMainIncomeType(MainIncomeType.EMPLOYMENT).setRemainingInvestment(2000).setRating(Rating.AAAAA).setTermInMonths(25).setUrl(new URL("http://www.robozonky.cz")).build();
    final LoanDescriptor loanDescriptor = new LoanDescriptor(loan);
    final RecommendedLoan recommendation = loanDescriptor.recommend(1200, false).get();
    final Investment i = Investment.fresh((MarketplaceLoan) loan, 1000).build();
    // create events for listeners
    return Stream.of(forListener(SupportedListener.INVESTMENT_DELEGATED, new InvestmentDelegatedEvent(recommendation, "random")), forListener(SupportedListener.INVESTMENT_MADE, new InvestmentMadeEvent(i, loan, MAX_PORTFOLIO)), forListener(SupportedListener.INVESTMENT_SOLD, new InvestmentSoldEvent(i, loan, MAX_PORTFOLIO)), forListener(SupportedListener.INVESTMENT_SKIPPED, new InvestmentSkippedEvent(recommendation)), forListener(SupportedListener.INVESTMENT_REJECTED, new InvestmentRejectedEvent(recommendation, "random")), forListener(SupportedListener.LOAN_NO_LONGER_DELINQUENT, new LoanNoLongerDelinquentEvent(i, loan, LocalDate.now(), Collections.singletonList(mockCollectionNoEndDate()))), forListener(SupportedListener.LOAN_DEFAULTED, new LoanDefaultedEvent(i, loan, LocalDate.now(), Collections.singletonList(mockCollectionNoNote()))), forListener(SupportedListener.LOAN_NOW_DELINQUENT, new LoanNowDelinquentEvent(i, loan, LocalDate.now(), Collections.emptyList())), forListener(SupportedListener.LOAN_DELINQUENT_10_PLUS, new LoanDelinquent10DaysOrMoreEvent(i, loan, LocalDate.now().minusDays(11), Collections.emptyList())), forListener(SupportedListener.LOAN_DELINQUENT_30_PLUS, new LoanDelinquent30DaysOrMoreEvent(i, loan, LocalDate.now().minusDays(31), Collections.emptyList())), forListener(SupportedListener.LOAN_DELINQUENT_60_PLUS, new LoanDelinquent60DaysOrMoreEvent(i, loan, LocalDate.now().minusDays(61), Collections.emptyList())), forListener(SupportedListener.LOAN_DELINQUENT_90_PLUS, new LoanDelinquent90DaysOrMoreEvent(i, loan, LocalDate.now().minusDays(91), Collections.emptyList())), forListener(SupportedListener.LOAN_REPAID, new LoanRepaidEvent(i, loan, MAX_PORTFOLIO)), forListener(SupportedListener.BALANCE_ON_TARGET, new ExecutionStartedEvent(Collections.emptyList(), MAX_PORTFOLIO)), forListener(SupportedListener.BALANCE_UNDER_MINIMUM, new ExecutionStartedEvent(Collections.emptyList(), mockPortfolio(0))), forListener(SupportedListener.CRASHED, new RoboZonkyCrashedEvent(ReturnCode.ERROR_UNEXPECTED, new RuntimeException())), forListener(SupportedListener.REMOTE_OPERATION_FAILED, new RemoteOperationFailedEvent(new RuntimeException())), forListener(SupportedListener.DAEMON_FAILED, new RoboZonkyDaemonFailedEvent(new RuntimeException())), forListener(SupportedListener.INITIALIZED, new RoboZonkyInitializedEvent()), forListener(SupportedListener.ENDING, new RoboZonkyEndingEvent()), forListener(SupportedListener.TESTING, new RoboZonkyTestingEvent()), forListener(SupportedListener.UPDATE_DETECTED, new RoboZonkyUpdateDetectedEvent("1.2.3")), forListener(SupportedListener.EXPERIMENTAL_UPDATE_DETECTED, new RoboZonkyExperimentalUpdateDetectedEvent("1.3.0-beta-1")), forListener(SupportedListener.INVESTMENT_PURCHASED, new InvestmentPurchasedEvent(i, loan, MAX_PORTFOLIO)), forListener(SupportedListener.SALE_OFFERED, new SaleOfferedEvent(i, loan)));
}
Also used : RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) InvestmentSoldEvent(com.github.robozonky.api.notifications.InvestmentSoldEvent) ExecutionStartedEvent(com.github.robozonky.api.notifications.ExecutionStartedEvent) InvestmentDelegatedEvent(com.github.robozonky.api.notifications.InvestmentDelegatedEvent) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) LoanDefaultedEvent(com.github.robozonky.api.notifications.LoanDefaultedEvent) URL(java.net.URL) SaleOfferedEvent(com.github.robozonky.api.notifications.SaleOfferedEvent) RoboZonkyEndingEvent(com.github.robozonky.api.notifications.RoboZonkyEndingEvent) RemoteOperationFailedEvent(com.github.robozonky.api.notifications.RemoteOperationFailedEvent) LoanDelinquent10DaysOrMoreEvent(com.github.robozonky.api.notifications.LoanDelinquent10DaysOrMoreEvent) LoanNoLongerDelinquentEvent(com.github.robozonky.api.notifications.LoanNoLongerDelinquentEvent) RoboZonkyDaemonFailedEvent(com.github.robozonky.api.notifications.RoboZonkyDaemonFailedEvent) InvestmentSkippedEvent(com.github.robozonky.api.notifications.InvestmentSkippedEvent) RoboZonkyInitializedEvent(com.github.robozonky.api.notifications.RoboZonkyInitializedEvent) RoboZonkyTestingEvent(com.github.robozonky.api.notifications.RoboZonkyTestingEvent) InvestmentMadeEvent(com.github.robozonky.api.notifications.InvestmentMadeEvent) LoanDelinquent30DaysOrMoreEvent(com.github.robozonky.api.notifications.LoanDelinquent30DaysOrMoreEvent) LoanDelinquent60DaysOrMoreEvent(com.github.robozonky.api.notifications.LoanDelinquent60DaysOrMoreEvent) RoboZonkyUpdateDetectedEvent(com.github.robozonky.api.notifications.RoboZonkyUpdateDetectedEvent) LoanDescriptor(com.github.robozonky.api.strategies.LoanDescriptor) LoanDelinquent90DaysOrMoreEvent(com.github.robozonky.api.notifications.LoanDelinquent90DaysOrMoreEvent) InvestmentPurchasedEvent(com.github.robozonky.api.notifications.InvestmentPurchasedEvent) LoanNowDelinquentEvent(com.github.robozonky.api.notifications.LoanNowDelinquentEvent) MarketplaceLoan(com.github.robozonky.api.remote.entities.sanitized.MarketplaceLoan) RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) Loan(com.github.robozonky.api.remote.entities.sanitized.Loan) RoboZonkyCrashedEvent(com.github.robozonky.api.notifications.RoboZonkyCrashedEvent) LoanRepaidEvent(com.github.robozonky.api.notifications.LoanRepaidEvent) RoboZonkyExperimentalUpdateDetectedEvent(com.github.robozonky.api.notifications.RoboZonkyExperimentalUpdateDetectedEvent) InvestmentRejectedEvent(com.github.robozonky.api.notifications.InvestmentRejectedEvent) Investment(com.github.robozonky.api.remote.entities.sanitized.Investment) TestFactory(org.junit.jupiter.api.TestFactory)

Example 13 with TestFactory

use of org.junit.jupiter.api.TestFactory in project robozonky by RoboZonky.

the class IncompleteStrategyTest method removeLine.

@TestFactory
Stream<DynamicTest> removeLine() throws IOException {
    final File f = IoTestUtil.streamToFile(IncompleteStrategyTest.PROPER);
    final List<String> lines = Files.lines(f.toPath()).collect(Collectors.toList());
    return IntStream.range(0, lines.size()).mapToObj(lineId -> {
        final List<String> newLines = new ArrayList<>(lines);
        final String line = newLines.remove(lineId);
        final File tmp = writeToNewTempFile(newLines);
        return dynamicTest("' " + line + "'", () -> propertyIsMissing(tmp));
    });
}
Also used : ArrayList(java.util.ArrayList) File(java.io.File) TestFactory(org.junit.jupiter.api.TestFactory)

Example 14 with TestFactory

use of org.junit.jupiter.api.TestFactory in project connect-utils by jcustenborder.

the class BaseDocumentationTest method transformations.

@TestFactory
public Stream<DynamicTest> transformations() {
    final File parentDirectory = new File(outputDirectory, "transformations");
    final String templateName = "rst/transformation.rst.ftl";
    return this.pluginTemplate.getTransformations().stream().map(connectorTemplate -> transformRstTest(connectorTemplate, templateName, parentDirectory));
}
Also used : File(java.io.File) TestFactory(org.junit.jupiter.api.TestFactory)

Example 15 with TestFactory

use of org.junit.jupiter.api.TestFactory in project connect-utils by jcustenborder.

the class BaseDocumentationTest method sinks.

@TestFactory
public Stream<DynamicTest> sinks() {
    final File parentDirectory = new File(outputDirectory, "sinks");
    final String templateName = "rst/sink.rst.ftl";
    return this.pluginTemplate.getSinkConnectors().stream().map(connectorTemplate -> connectorRstTest(connectorTemplate, templateName, parentDirectory));
}
Also used : File(java.io.File) TestFactory(org.junit.jupiter.api.TestFactory)

Aggregations

TestFactory (org.junit.jupiter.api.TestFactory)19 ArrayList (java.util.ArrayList)9 DynamicTest (org.junit.jupiter.api.DynamicTest)8 File (java.io.File)5 List (java.util.List)5 Arrays (java.util.Arrays)4 Stream (java.util.stream.Stream)4 Schema (org.apache.kafka.connect.data.Schema)4 BigDecimal (java.math.BigDecimal)3 Collection (java.util.Collection)3 Function (java.util.function.Function)3 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)3 ThrowingConsumer (org.junit.jupiter.api.function.ThrowingConsumer)3 Map (java.util.Map)2 Struct (org.apache.kafka.connect.data.Struct)2 Test (org.junit.jupiter.api.Test)2 Employee (com.baeldung.helpers.Employee)1 EmployeeDao (com.baeldung.helpers.EmployeeDao)1 ChangeKey (com.github.jcustenborder.kafka.connect.cdc.ChangeKey)1 AssertStruct.assertStruct (com.github.jcustenborder.kafka.connect.utils.AssertStruct.assertStruct)1