Search in sources :

Example 16 with TestFactory

use of org.junit.jupiter.api.TestFactory in project acceptance-testing by Abhigulve.

the class EventHandler method TestInitiator.

@TestFactory
public Collection<DynamicTest> TestInitiator() {
    domManipulation.open(jr.getManupulatorBean().getUrl());
    String testName = jr.getManupulatorBean().getTestName();
    List<List<Map<String, String>>> list = jr.getManupulatorBean().getList();
    Collection<DynamicTest> dynamicTests = new ArrayList<>();
    for (int j = 0; j < list.size(); j++) {
        domManipulation.open(jr.getManupulatorBean().getUrl());
        List<Map<String, String>> testCase = list.get(j);
        int i = 0;
        for (int values = 1; values < testCase.size(); values++) {
            Map<String, String> map = testCase.get(values);
            domManipulation.action(map.get("id").toString(), map.get("value"), map.get("event").toUpperCase());
            i++;
            if (i == (testCase.size())) {
                DynamicTest dTest = DynamicTest.dynamicTest(testName, () -> domManipulation.testCaseAnalyser(map.get("id").toString(), map.get("condition").toUpperCase()));
                dynamicTests.add(dTest);
            }
        }
    }
    return dynamicTests;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) DynamicTest(org.junit.jupiter.api.DynamicTest) TestFactory(org.junit.jupiter.api.TestFactory)

Example 17 with TestFactory

use of org.junit.jupiter.api.TestFactory in project kafka-connect-cdc-mssql by jcustenborder.

the class QueryServiceIT method queryTable.

@TestFactory
public Stream<DynamicTest> queryTable() throws SQLException {
    List<ChangeKey> changeCaptureTables = new ArrayList<>();
    PooledConnection pooledConnection = null;
    try {
        pooledConnection = JdbcUtils.openPooledConnection(this.config, new ChangeKey(MsSqlTestConstants.DATABASE_NAME, null, null));
        MsSqlQueryBuilder queryBuilder = new MsSqlQueryBuilder(pooledConnection.getConnection());
        try (PreparedStatement statement = queryBuilder.listChangeTrackingTablesStatement()) {
            try (ResultSet resultSet = statement.executeQuery()) {
                while (resultSet.next()) {
                    String databaseName = resultSet.getString("databaseName");
                    String schemaName = resultSet.getString("schemaName");
                    String tableName = resultSet.getString("tableName");
                    ChangeKey changeKey = new ChangeKey(databaseName, schemaName, tableName);
                    changeCaptureTables.add(changeKey);
                    log.trace("Found Change Tracking Enabled Table {}", changeKey);
                }
            }
        }
    } finally {
        JdbcUtils.closeConnection(pooledConnection);
    }
    return changeCaptureTables.stream().map(data -> dynamicTest(data.tableName, () -> queryTable(data)));
}
Also used : ChangeKey(com.github.jcustenborder.kafka.connect.cdc.ChangeKey) PooledConnection(javax.sql.PooledConnection) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) TestFactory(org.junit.jupiter.api.TestFactory)

Example 18 with TestFactory

use of org.junit.jupiter.api.TestFactory in project mssql-jdbc by Microsoft.

the class lobsTest method executeDynamicTests.

@TestFactory
public Collection<DynamicTest> executeDynamicTests() {
    List<Class> classes = new ArrayList<Class>(Arrays.asList(Blob.class, Clob.class, DBBinaryStream.class, DBCharacterStream.class));
    List<Boolean> isResultSetTypes = new ArrayList<>(Arrays.asList(true, false));
    Collection<DynamicTest> dynamicTests = new ArrayList<>();
    for (Class aClass : classes) {
        for (Boolean isResultSetType : isResultSetTypes) {
            final Class lobClass = aClass;
            final boolean isResultSet = isResultSetType;
            Executable exec = new Executable() {

                @Override
                public void execute() throws Throwable {
                    testInvalidLobs(lobClass, isResultSet);
                }
            };
            // create a test display name
            String testName = " Test: " + lobClass + (isResultSet ? " isResultSet" : " isPreparedStatement");
            // create dynamic test
            DynamicTest dTest = DynamicTest.dynamicTest(testName, exec);
            // add the dynamic test to collection
            dynamicTests.add(dTest);
        }
    }
    return dynamicTests;
}
Also used : DBCharacterStream(com.microsoft.sqlserver.testframework.Utils.DBCharacterStream) Blob(java.sql.Blob) DBBinaryStream(com.microsoft.sqlserver.testframework.Utils.DBBinaryStream) ArrayList(java.util.ArrayList) DynamicTest(org.junit.jupiter.api.DynamicTest) NClob(java.sql.NClob) Clob(java.sql.Clob) Executable(org.junit.jupiter.api.function.Executable) TestFactory(org.junit.jupiter.api.TestFactory)

Example 19 with TestFactory

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

the class DynamicTestsExample method dynamicTestsForEmployeeWorkflows.

@TestFactory
Stream<DynamicTest> dynamicTestsForEmployeeWorkflows() {
    List<Employee> inputList = Arrays.asList(new Employee(1, "Fred"), new Employee(2), new Employee(3, "John"));
    EmployeeDao dao = new EmployeeDao();
    Stream<DynamicTest> saveEmployeeStream = inputList.stream().map(emp -> DynamicTest.dynamicTest("saveEmployee: " + emp.toString(), () -> {
        Employee returned = dao.save(emp.getId());
        assertEquals(returned.getId(), emp.getId());
    }));
    Stream<DynamicTest> saveEmployeeWithFirstNameStream = inputList.stream().filter(emp -> !emp.getFirstName().isEmpty()).map(emp -> DynamicTest.dynamicTest("saveEmployeeWithName" + emp.toString(), () -> {
        Employee returned = dao.save(emp.getId(), emp.getFirstName());
        assertEquals(returned.getId(), emp.getId());
        assertEquals(returned.getFirstName(), emp.getFirstName());
    }));
    return Stream.concat(saveEmployeeStream, saveEmployeeWithFirstNameStream);
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) TestFactory(org.junit.jupiter.api.TestFactory) Iterator(java.util.Iterator) Collection(java.util.Collection) HashMap(java.util.HashMap) Function(java.util.function.Function) List(java.util.List) Employee(com.baeldung.helpers.Employee) Stream(java.util.stream.Stream) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Map(java.util.Map) DynamicTest(org.junit.jupiter.api.DynamicTest) EmployeeDao(com.baeldung.helpers.EmployeeDao) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ThrowingConsumer(org.junit.jupiter.api.function.ThrowingConsumer) EmployeeDao(com.baeldung.helpers.EmployeeDao) Employee(com.baeldung.helpers.Employee) DynamicTest(org.junit.jupiter.api.DynamicTest) 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