Search in sources :

Example 56 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest in project siesta by cadenzauk.

the class InProjectionExpectingCommaTest method testComma.

@ParameterizedTest
@MethodSource("argsForComma")
void testComma(BiFunction<InProjectionExpectingComma1<String>, Alias<SalespersonRow>, Select<?>> method, String expectedSql, Object[] expectedArgs) {
    MockitoAnnotations.initMocks(this);
    Database database = testDatabase(new AnsiDialect());
    Alias<SalespersonRow> alias = database.table(SalespersonRow.class).as("s");
    InProjectionExpectingComma1<String> sut = database.from(alias).select(SalespersonRow::firstName, "name");
    method.apply(sut, alias).list(transaction);
    verify(transaction).query(sql.capture(), args.capture(), rowMapper.capture());
    Pattern pattern = Pattern.compile("select s.FIRST_NAME as name, " + expectedSql + " from SIESTA.SALESPERSON s");
    assertThat(pattern.matcher(sql.getValue()).matches(), is(true));
    assertThat(args.getValue(), is(expectedArgs));
}
Also used : Pattern(java.util.regex.Pattern) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Database(com.cadenzauk.siesta.Database) SalespersonRow(com.cadenzauk.siesta.model.SalespersonRow) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 57 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest in project siesta by cadenzauk.

the class BooleanExpressionTest method testAnd.

@ParameterizedTest
@MethodSource("argsForAnd")
void testAnd(BiFunction<Alias<SalespersonRow>, BooleanExpression, BooleanExpression> method, String expectedSql) {
    MockitoAnnotations.initMocks(this);
    Database database = testDatabase(new AnsiDialect());
    Alias<SalespersonRow> alias = database.table(SalespersonRow.class).as("s");
    Scope scope = new Scope(database, alias);
    when(sut.precedence()).thenReturn(Precedence.UNARY);
    method.apply(alias, sut);
    verify(sut).appendAnd(appendArg.capture());
    assertThat(appendArg.getValue().sql(scope), is(expectedSql));
}
Also used : AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) Scope(com.cadenzauk.siesta.Scope) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Database(com.cadenzauk.siesta.Database) SalespersonRow(com.cadenzauk.siesta.model.SalespersonRow) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 58 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest in project siesta by cadenzauk.

the class BooleanExpressionTest method testOr.

@ParameterizedTest
@MethodSource("argsForOr")
void testOr(BiFunction<Alias<SalespersonRow>, BooleanExpression, BooleanExpression> method, String expectedSql) {
    MockitoAnnotations.initMocks(this);
    Database database = testDatabase(new AnsiDialect());
    Alias<SalespersonRow> alias = database.table(SalespersonRow.class).as("s");
    Scope scope = new Scope(database, alias);
    when(sut.precedence()).thenReturn(Precedence.UNARY);
    method.apply(alias, sut);
    verify(sut).appendOr(appendArg.capture());
    assertThat(appendArg.getValue().sql(scope), is(expectedSql));
}
Also used : AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) Scope(com.cadenzauk.siesta.Scope) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Database(com.cadenzauk.siesta.Database) SalespersonRow(com.cadenzauk.siesta.model.SalespersonRow) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 59 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest in project siesta by cadenzauk.

the class CaseExpressionTest method initialWhen.

@ParameterizedTest
@MethodSource("parametersForInitialWhen")
void initialWhen(String expected, Function<Alias<WidgetRow>, CaseExpression<String>> f, Object[] expectedArgs) {
    Database database = testDatabase(new AnsiDialect());
    Alias<WidgetRow> w = database.table(WidgetRow.class).as("w");
    database.from(w).select(f.apply(w).orElse(literal("DEFAULT")), "name").list(transaction);
    verify(transaction).query(sql.capture(), args.capture(), any());
    assertThat(sql.getValue(), is("select case " + expected + " else 'DEFAULT' end as name " + "from SIESTA.WIDGET w"));
    assertThat(args.getValue(), is(expectedArgs));
}
Also used : WidgetRow(com.cadenzauk.siesta.model.WidgetRow) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Database(com.cadenzauk.siesta.Database) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 60 with ParameterizedTest

use of org.junit.jupiter.params.ParameterizedTest in project siesta by cadenzauk.

the class CoalesceFunctionTest method coalesceTest.

@ParameterizedTest
@MethodSource("parametersForCoalesce")
void coalesceTest(String name, Function<Alias<WidgetRow>, CoalesceFunction<String>> f, String expected) {
    Database database = testDatabase(new AnsiDialect());
    Alias<WidgetRow> w = database.table(WidgetRow.class).as("w");
    String sql = database.from(w).select(f.apply(w), "name").where(WidgetRow::manufacturerId).isEqualTo(2L).sql();
    assertThat(sql, is("select " + expected + " as name " + "from SIESTA.WIDGET w " + "where w.MANUFACTURER_ID = ?"));
}
Also used : WidgetRow(com.cadenzauk.siesta.model.WidgetRow) AnsiDialect(com.cadenzauk.siesta.dialect.AnsiDialect) TestDatabase.testDatabase(com.cadenzauk.siesta.model.TestDatabase.testDatabase) Database(com.cadenzauk.siesta.Database) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2045 MethodSource (org.junit.jupiter.params.provider.MethodSource)1116 EnumSource (org.junit.jupiter.params.provider.EnumSource)325 ValueSource (org.junit.jupiter.params.provider.ValueSource)302 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)181 Transaction (org.neo4j.graphdb.Transaction)117 CsvSource (org.junit.jupiter.params.provider.CsvSource)113 ArrayList (java.util.ArrayList)112 ByteBuffer (java.nio.ByteBuffer)81 List (java.util.List)81 Path (java.nio.file.Path)75 Test (org.junit.jupiter.api.Test)74 InterruptAfter (io.aeron.test.InterruptAfter)72 IOException (java.io.IOException)72 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)67 TimeUnit (java.util.concurrent.TimeUnit)65 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)62 CountDownLatch (java.util.concurrent.CountDownLatch)61 SelfSignedCertificate (io.netty.handler.ssl.util.SelfSignedCertificate)60 Stream (java.util.stream.Stream)59