Skip to content

TestRunnerStatement with dynamic Parameter-list #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
de3311c
Add some more unit-tests
pesse Jul 19, 2019
7f52a33
completely filled TestRunnerOptions for testing purposes
pesse Jul 19, 2019
156f2d9
Start exploring possibilities for a dynamic TestRunner-Statement
pesse Jul 19, 2019
a10b8b7
Merge branch 'develop' into feature/testRunnerStatement_as_dynamic_pa…
pesse Jul 22, 2019
166720b
Make getSql public for better testability
pesse Jul 22, 2019
2ce1e79
Test against interface
pesse Jul 22, 2019
6100f3c
Slow approach towards new DynamicTestRunner-Statement
pesse Jul 22, 2019
4f591ef
Add failing test for Boolean support of DynamicParameterList
pesse Jul 22, 2019
4aba265
Some more params of TestRunner handeled
pesse Jul 22, 2019
b3d5779
We can add booleans now
pesse Oct 20, 2019
f2e1e01
Two more parameters in the new DynamicStatement
pesse Oct 20, 2019
5ff0ee2
FileMappings are more complicated to pass around
pesse Oct 20, 2019
a7b8266
Adding TestFileMappings
pesse Oct 21, 2019
e1b7dd3
Implement remaining dynamic parameters
pesse Oct 21, 2019
c0ca8cd
Remove helper comments
pesse Oct 21, 2019
4afca5f
Add version Bugfix-numbers
pesse Oct 21, 2019
32b7d56
Version isGreaterThanOrEqual and isLessOrEqual treat NULL in base ver…
pesse Oct 21, 2019
1b9e0b2
Add tests for all utPLSQL versions
pesse Oct 21, 2019
2a3d9df
Added "end case" part
pesse Oct 21, 2019
19a9037
Replace old TestRunnerStatements with the new DynamicTestRunnerStatement
pesse Oct 21, 2019
1751d68
Switch to OpenJDK 8
pesse Oct 21, 2019
02114ae
Add utPLSQL 3.1.8 version
pesse Oct 21, 2019
6a0723a
Fix Version-String
pesse Oct 22, 2019
3799867
Merge branch 'develop' into feature/testRunnerStatement_as_dynamic_pa…
pesse Oct 22, 2019
6ffa576
Test JDK13 also with version 3.1.8
pesse Oct 22, 2019
97be74d
We don't need Maven CFG anymore
pesse Oct 22, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tests for all utPLSQL versions
  • Loading branch information
pesse committed Oct 21, 2019
commit 1b9e0b2fb72558d91156a0753a2c89fc08f52998
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

import oracle.jdbc.OracleConnection;
import org.utplsql.api.CustomTypes;
import org.utplsql.api.FileMapping;
import org.utplsql.api.TestRunnerOptions;
import org.utplsql.api.Version;
import org.utplsql.api.compatibility.OptionalFeatures;
import org.utplsql.api.db.DynamicParameterList;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class DynamicTestRunnerStatement implements TestRunnerStatement {

Expand Down Expand Up @@ -40,21 +38,31 @@ private DynamicParameterList initParameterList() throws SQLException {
?FileMapper.buildFileMappingList(oracleConnection, options.testMappingOptions).toArray()
:null;

return DynamicParameterList.builder()
DynamicParameterList.DynamicParameterListBuilder builder = DynamicParameterList.builder()
.addIfNotEmpty("a_paths", options.pathList.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection)
.addIfNotEmpty("a_reporters", options.reporterList.toArray(), CustomTypes.UT_REPORTERS, oracleConnection)
.addIfNotEmpty("a_color_console", options.colorConsole)
.addIfNotEmpty("a_coverage_schemes", options.coverageSchemes.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection)
.addIfNotEmpty("a_source_file_mappings", sourceMappings, CustomTypes.UT_FILE_MAPPINGS, oracleConnection)
.addIfNotEmpty("a_test_file_mappings", testMappings, CustomTypes.UT_FILE_MAPPINGS, oracleConnection)
.addIfNotEmpty("a_include_objects", options.includeObjects.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection)
.addIfNotEmpty("a_exclude_objects", options.excludeObjects.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection)
.addIfNotEmpty("a_fail_on_errors", options.failOnErrors)
.addIfNotEmpty("a_client_character_set", options.clientCharacterSet)
.addIfNotEmpty("a_random_test_order", options.randomTestOrder)
.addIfNotEmpty("a_random_test_order_seed", options.randomTestOrderSeed)
.addIfNotEmpty("a_tags", options.getTagsAsString())
.build();
.addIfNotEmpty("a_exclude_objects", options.excludeObjects.toArray(), CustomTypes.UT_VARCHAR2_LIST, oracleConnection);

if (OptionalFeatures.FAIL_ON_ERROR.isAvailableFor(utPlSQlVersion)) {
builder.addIfNotEmpty("a_fail_on_errors", options.failOnErrors);
}
if (OptionalFeatures.CLIENT_CHARACTER_SET.isAvailableFor(utPlSQlVersion)) {
builder.addIfNotEmpty("a_client_character_set", options.clientCharacterSet);
}
if (OptionalFeatures.RANDOM_EXECUTION_ORDER.isAvailableFor(utPlSQlVersion)) {
builder.addIfNotEmpty("a_random_test_order", options.randomTestOrder)
.addIfNotEmpty("a_random_test_order_seed", options.randomTestOrderSeed);
}
if (OptionalFeatures.TAGS.isAvailableFor(utPlSQlVersion)) {
builder.addIfNotEmpty("a_tags", options.getTagsAsString());
}

return builder.build();
}

private void prepareStatement() throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.utplsql.api.testRunner;

import oracle.jdbc.OracleConnection;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.verification.VerificationMode;
import org.utplsql.api.CustomTypes;
import org.utplsql.api.FileMapping;
import org.utplsql.api.TestRunnerOptions;
Expand All @@ -13,41 +16,58 @@

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.not;
import static org.mockito.Mockito.*;

public class DynamicTestRunnerStatementTest {

@Test
void explore() throws SQLException {
// Expectation objects
Object[] expectedFileMapping = new Object[]{new FileMapping("someFile", "owner", "object", "PACKAGE")};
private DynamicTestRunnerStatement testRunnerStatement;
private CallableStatement callableStatement;
private OracleConnection oracleConnection;
private TestRunnerOptions options;
private Object[] expectedFileMapping;

// Mock some internals. This is not pretty, but a first step
private OracleConnection getMockedOracleConnection( Object[] expectedFileMapping ) throws SQLException {
OracleConnection oracleConnection = mock(OracleConnection.class);
when(oracleConnection.unwrap(OracleConnection.class))
.thenReturn(oracleConnection);
CallableStatement callableStatement = mock(CallableStatement.class);
mockFileMapper(oracleConnection, expectedFileMapping);
return oracleConnection;
}

// FileMapper mocks
private void mockFileMapper( OracleConnection mockedOracleConnection, Object[] expectedFileMapping ) throws SQLException {
Array fileMapperArray = mock(Array.class);
CallableStatement fileMapperStatement = mock(CallableStatement.class);

when(fileMapperArray.getArray())
.thenReturn(expectedFileMapping);
when(fileMapperStatement.getArray(1))
.thenReturn(fileMapperArray);
when(
oracleConnection.prepareCall(argThat(
mockedOracleConnection.prepareCall(argThat(
a -> a.startsWith("BEGIN ? := ut_file_mapper.build_file_mappings("))
))
.thenReturn(fileMapperStatement);
Array fileMapperArray = mock(Array.class);
when(fileMapperStatement.getArray(1))
.thenReturn(fileMapperArray);
when(fileMapperArray.getArray())
.thenReturn(expectedFileMapping);
}

// Act
TestRunnerOptions options = TestRunnerStatementProviderIT.getCompletelyFilledOptions();
private Matcher<String> doesOrDoesNotContainString( String string, boolean shouldBeThere ) {
return (shouldBeThere)
? containsString(string)
: not(containsString(string));
}

DynamicTestRunnerStatement testRunnerStatement = DynamicTestRunnerStatement
.forVersion(Version.V3_1_7, oracleConnection, options, callableStatement);
private VerificationMode doesOrDoesNotGetCalled( boolean shouldBeThere ) {
return (shouldBeThere)
? times(1)
: never();
}

// Assert all parameters are set appropriately
private void initTestRunnerStatementForVersion( Version version ) throws SQLException {
testRunnerStatement = DynamicTestRunnerStatement
.forVersion(version, oracleConnection, options, callableStatement);
}

private void checkBaseParameters() throws SQLException {
assertThat(testRunnerStatement.getSql(), containsString("a_paths => ?"));
verify(callableStatement).setArray(1, null);
verify(oracleConnection).createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.pathList.toArray());
Expand Down Expand Up @@ -77,20 +97,160 @@ void explore() throws SQLException {
assertThat(testRunnerStatement.getSql(), containsString("a_exclude_objects => ?"));
verify(callableStatement).setArray(8, null);
verify(oracleConnection).createOracleArray(CustomTypes.UT_VARCHAR2_LIST, options.includeObjects.toArray());
}

private void checkFailOnError( boolean shouldBeThere ) throws SQLException {
assertThat(testRunnerStatement.getSql(), doesOrDoesNotContainString("a_fail_on_errors => (case ? when 1 then true else false)", shouldBeThere));
verify(callableStatement, doesOrDoesNotGetCalled(shouldBeThere)).setInt(9, 1);
}

private void checkClientCharacterSet( boolean shouldBeThere ) throws SQLException {
assertThat(testRunnerStatement.getSql(), doesOrDoesNotContainString("a_client_character_set => ?", shouldBeThere));
verify(callableStatement, doesOrDoesNotGetCalled(shouldBeThere)).setString(10, "UTF8");
}

private void checkRandomTestOrder( boolean shouldBeThere ) throws SQLException {
assertThat(testRunnerStatement.getSql(), doesOrDoesNotContainString("a_random_test_order => (case ? when 1 then true else false)", shouldBeThere));
verify(callableStatement, doesOrDoesNotGetCalled(shouldBeThere)).setInt(11, 1);
assertThat(testRunnerStatement.getSql(), doesOrDoesNotContainString("a_random_test_order_seed => ?", shouldBeThere));
verify(callableStatement, doesOrDoesNotGetCalled(shouldBeThere)).setInt(12, 123);
}

private void checkTags( boolean shouldBeThere ) throws SQLException {
assertThat(testRunnerStatement.getSql(), doesOrDoesNotContainString("a_tags => ?", shouldBeThere));
verify(callableStatement, doesOrDoesNotGetCalled(shouldBeThere)).setString(13, "WIP,long_running");
}

assertThat(testRunnerStatement.getSql(), containsString("a_fail_on_errors => (case ? when 1 then true else false)"));
verify(callableStatement).setInt(9, 1);
@BeforeEach
void initParameters() throws SQLException {
expectedFileMapping = new Object[]{new FileMapping("someFile", "owner", "object", "PACKAGE")};

assertThat(testRunnerStatement.getSql(), containsString("a_client_character_set => ?"));
verify(callableStatement).setString(10, "UTF8");
// Mock some internals. This is not pretty, but a first step
oracleConnection = getMockedOracleConnection(expectedFileMapping);
callableStatement = mock(CallableStatement.class);

assertThat(testRunnerStatement.getSql(), containsString("a_random_test_order => (case ? when 1 then true else false)"));
verify(callableStatement).setInt(11, 1);
// Act
options = TestRunnerStatementProviderIT.getCompletelyFilledOptions();
}

assertThat(testRunnerStatement.getSql(), containsString("a_random_test_order_seed => ?"));
verify(callableStatement).setInt(12, 123);
@Test
void version_3_0_2_parameters() throws SQLException {
initTestRunnerStatementForVersion(Version.V3_0_2);

checkBaseParameters();
checkFailOnError(false);
checkClientCharacterSet(false);
checkRandomTestOrder(false);
checkTags(false);
}

@Test
void version_3_0_3_parameters() throws SQLException {
initTestRunnerStatementForVersion(Version.V3_0_3);

checkBaseParameters();
checkFailOnError(true);
checkClientCharacterSet(false);
checkRandomTestOrder(false);
checkTags(false);
}

@Test
void version_3_0_4_parameters() throws SQLException {
initTestRunnerStatementForVersion(Version.V3_0_4);

checkBaseParameters();
checkFailOnError(true);
checkClientCharacterSet(false);
checkRandomTestOrder(false);
checkTags(false);
}

@Test
void version_3_1_0_parameters() throws SQLException {
initTestRunnerStatementForVersion(Version.V3_1_0);

checkBaseParameters();
checkFailOnError(true);
checkClientCharacterSet(false);
checkRandomTestOrder(false);
checkTags(false);
}

@Test
void version_3_1_1_parameters() throws SQLException {
initTestRunnerStatementForVersion(Version.V3_1_1);

checkBaseParameters();
checkFailOnError(true);
checkClientCharacterSet(false);
checkRandomTestOrder(false);
checkTags(false);
}

@Test
void version_3_1_2_parameters() throws SQLException {
initTestRunnerStatementForVersion(Version.V3_1_2);

checkBaseParameters();
checkFailOnError(true);
checkClientCharacterSet(true);
checkRandomTestOrder(false);
checkTags(false);
}

@Test
void version_3_1_3_parameters() throws SQLException {
initTestRunnerStatementForVersion(Version.V3_1_3);

checkBaseParameters();
checkFailOnError(true);
checkClientCharacterSet(true);
checkRandomTestOrder(false);
checkTags(false);
}

@Test
void version_3_1_4_parameters() throws SQLException {
initTestRunnerStatementForVersion(Version.V3_1_4);

checkBaseParameters();
checkFailOnError(true);
checkClientCharacterSet(true);
checkRandomTestOrder(false);
checkTags(false);
}

@Test
void version_3_1_5_parameters() throws SQLException {
initTestRunnerStatementForVersion(Version.V3_1_5);

checkBaseParameters();
checkFailOnError(true);
checkClientCharacterSet(true);
checkRandomTestOrder(false);
checkTags(false);
}

@Test
void version_3_1_6_parameters() throws SQLException {
initTestRunnerStatementForVersion(Version.V3_1_6);

checkBaseParameters();
checkFailOnError(true);
checkClientCharacterSet(true);
checkRandomTestOrder(false);
checkTags(false);
}

@Test
void version_3_1_7_parameters() throws SQLException {
initTestRunnerStatementForVersion(Version.V3_1_7);

assertThat(testRunnerStatement.getSql(), containsString("a_tags => ?"));
verify(callableStatement).setString(13, "WIP,long_running");
checkBaseParameters();
checkFailOnError(true);
checkClientCharacterSet(true);
checkRandomTestOrder(true);
checkTags(true);
}
}