◐ Shell
reader mode source ↗
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
10 changes: 10 additions & 0 deletions .idea/codeStyles/Project.xml
5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml
7 changes: 7 additions & 0 deletions .idea/dictionaries/utPLSQL.xml
3 changes: 2 additions & 1 deletion src/main/java/org/utplsql/api/CustomTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public final class CustomTypes {
public static final String UT_KEY_VALUE_PAIR = "UT_KEY_VALUE_PAIR";
public static final String UT_KEY_VALUE_PAIRS = "UT_KEY_VALUE_PAIRS";

private CustomTypes() {}

}
16 changes: 11 additions & 5 deletions src/main/java/org/utplsql/api/DBHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
*/
public final class DBHelper {

private DBHelper() {}

/**
* Return a new sys_guid from database.
* @param conn the connection
* @return the new id string
* @throws SQLException any database error
Expand Down Expand Up @@ -47,35 +49,38 @@ public static String getCurrentSchema(Connection conn) throws SQLException {
}
}

/** Returns the Frameworks version string of the given connection
* Deprecated. Use DatabaseInformation-Interface instead.
*
* @param conn Active db connection
* @return Version-string of the utPLSQL framework
* @throws SQLException any database error
*/
@Deprecated
public static Version getDatabaseFrameworkVersion( Connection conn ) throws SQLException {
DatabaseInformation databaseInformation = new DefaultDatabaseInformation();
return databaseInformation.getUtPlsqlFrameworkVersion(conn);

}

/** Returns the Oracle database Version from a given connection object
* Deprecated. Use DatabaseInformation-Interface instead.
*
* @param conn Connection-Object
* @return Returns version-string of the Oracle Database product component
* @throws SQLException any database error
*/
@Deprecated
public static String getOracleDatabaseVersion( Connection conn ) throws SQLException {
DatabaseInformation databaseInformation = new DefaultDatabaseInformation();
return databaseInformation.getOracleVersion(conn);
}

/**
* Enable the dbms_output buffer with unlimited size.
* @param conn the connection
*/
public static void enableDBMSOutput(Connection conn) {
Expand All @@ -88,6 +93,7 @@ public static void enableDBMSOutput(Connection conn) {

/**
* Disable the dbms_output buffer.
* @param conn the connection
*/
public static void disableDBMSOutput(Connection conn) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/utplsql/api/EnvironmentVariableUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
*/
public class EnvironmentVariableUtil {

private EnvironmentVariableUtil() {}

/**
* Returns the value for a given key from environment (see class description)
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/utplsql/api/FileMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

public final class FileMapper {

private FileMapper() {}

/**
* Call the database api to build the custom file mappings.
Expand All @@ -27,15 +28,15 @@ public static Array buildFileMappingArray(

CallableStatement callableStatement = conn.prepareCall(
"BEGIN " +
"? := ut_file_mapper.build_file_mappings(" +
"a_object_owner => ?, " +
"a_file_paths => ?, " +
"a_file_to_object_type_mapping => ?, " +
"a_regex_pattern => ?, " +
"a_object_owner_subexpression => ?, " +
"a_object_name_subexpression => ?, " +
"a_object_type_subexpression => ?); " +
"END;");

int paramIdx = 0;
callableStatement.registerOutParameter(++paramIdx, OracleTypes.ARRAY, CustomTypes.UT_FILE_MAPPINGS);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/utplsql/api/FileMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class FileMapping implements SQLData {
private String objectName;
private String objectType;

public FileMapping() {}

public FileMapping(String fileName, String objectOwner, String objectName, String objectType) {
this.fileName = fileName;
Expand Down
25 changes: 15 additions & 10 deletions src/main/java/org/utplsql/api/JavaApiVersionInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,38 @@
import java.io.InputStream;
import java.io.InputStreamReader;

/** This class is getting updated automatically by the build process.
* Please do not update its constants manually cause they will be overwritten.
*
* @author pesse
*/
public class JavaApiVersionInfo {

private JavaApiVersionInfo() { }


private static final String MAVEN_PROJECT_NAME = "utPLSQL-java-api";
private static String MAVEN_PROJECT_VERSION = "unknown";

static {
try {

try ( InputStream in = JavaApiVersionInfo.class.getClassLoader().getResourceAsStream("utplsql-api.version");
BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {
MAVEN_PROJECT_VERSION = reader.readLine();
}
}
catch ( IOException e ) {
System.out.println("WARNING: Could not get Version information!");
}
}

public static String getVersion() { return MAVEN_PROJECT_VERSION; }
public static String getInfo() { return MAVEN_PROJECT_NAME + " " + getVersion(); }

}
6 changes: 4 additions & 2 deletions src/main/java/org/utplsql/api/ResourceUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
*/
public class ResourceUtil {

private ResourceUtil() {}

/**
* Returns the Path to a resource so it is walkable no matter if it's inside a jar or on the file system
Expand Down Expand Up @@ -68,8 +69,9 @@ public static List<Path> getListOfChildren(Path resourceAsPath, boolean filesOnl
// Get entry-path with root element so we can compare it
Path entryPath = resourcePath.getRoot().resolve(resourcePath.getFileSystem().getPath(entry.toString()));

if (entryPath.startsWith(resourcePath) && (!filesOnly || !entry.isDirectory()))
result.add(entryPath.subpath(relativeStartIndex, entryPath.getNameCount()));
}
}
resourcePath.getFileSystem().close();
Expand Down
49 changes: 27 additions & 22 deletions src/main/java/org/utplsql/api/TestRunner.java
Original file line number Diff line number Diff line change
@@ -28,9 +28,9 @@ public class TestRunner {
private static final Logger logger = LoggerFactory.getLogger(TestRunner.class);

private final TestRunnerOptions options = new TestRunnerOptions();
private CompatibilityProxy compatibilityProxy;
private ReporterFactory reporterFactory;
private final List<String> reporterNames = new ArrayList<>();

public TestRunner addPath(String path) {
options.pathList.add(path);
Expand All @@ -47,11 +47,12 @@ public TestRunner addReporter(Reporter reporter) {
return this;
}

public TestRunner addReporter( String reporterName ) {
if ( reporterFactory != null )
options.reporterList.add(reporterFactory.createReporter(reporterName));
else
reporterNames.add(reporterName);
return this;
}

Expand Down Expand Up @@ -105,22 +106,22 @@ public TestRunner failOnErrors(boolean failOnErrors) {
return this;
}

public TestRunner skipCompatibilityCheck( boolean skipCompatibilityCheck )
{
options.skipCompatibilityCheck = skipCompatibilityCheck;
return this;
}

public TestRunner setReporterFactory( ReporterFactory reporterFactory ) {
this.reporterFactory = reporterFactory;
return this;
}

private void delayedAddReporters() {
if ( reporterFactory != null )
reporterNames.forEach( this::addReporter );
else
throw new IllegalStateException("ReporterFactory must be set to add delayed Reporters!");
}

public void run(Connection conn) throws SQLException {
Expand All @@ -132,17 +133,19 @@ public void run(Connection conn) throws SQLException {
compatibilityProxy = new CompatibilityProxy(conn, options.skipCompatibilityCheck, databaseInformation);
logger.info("Running on utPLSQL {}", compatibilityProxy.getDatabaseVersion());

if ( reporterFactory == null )
reporterFactory = ReporterFactory.createDefault(compatibilityProxy);

delayedAddReporters();

// First of all check version compatibility
compatibilityProxy.failOnNotCompatible();

logger.info("Initializing reporters");
for (Reporter r : options.reporterList)
validateReporter(conn, r);

if (options.pathList.isEmpty()) {
options.pathList.add(databaseInformation.getCurrentSchema(conn));
Expand All @@ -153,43 +156,45 @@ public void run(Connection conn) throws SQLException {
options.reporterList.add(new DocumentationReporter().init(conn));
}

try(TestRunnerStatement testRunnerStatement = compatibilityProxy.getTestRunnerStatement(options, conn)) {
logger.info("Running tests");
testRunnerStatement.execute();
logger.info("Running tests finished.");
} catch (SQLException e) {
if (e.getErrorCode() == SomeTestsFailedException.ERROR_CODE) {
throw new SomeTestsFailedException(e.getMessage(), e);
}
else if (e.getErrorCode() == UtPLSQLNotInstalledException.ERROR_CODE) {
throw new UtPLSQLNotInstalledException(e);
}
else {
throw e;
}
}
}

/**
* Check if the reporter was initialized, if not call reporter.init.
* @param conn the database connection
* @param reporter the reporter
* @throws SQLException any sql exception
*/
private void validateReporter(Connection conn, Reporter reporter) throws SQLException {
if (!reporter.isInit() || reporter.getId() == null || reporter.getId().isEmpty())
reporter.init(conn, compatibilityProxy, reporterFactory);
}

/** Returns the databaseVersion the TestRunner was run against
*
* @return Version of the database the TestRunner was run against
*/
public Version getUsedDatabaseVersion() {
if ( compatibilityProxy != null )
return compatibilityProxy.getDatabaseVersion();
else
return null;
}

}
5 changes: 3 additions & 2 deletions src/main/java/org/utplsql/api/TestRunnerOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,20 @@
import java.util.ArrayList;
import java.util.List;

/** Holds the various possible options of TestRunner
*
* @author pesse
*/
public class TestRunnerOptions {
public final List<String> pathList = new ArrayList<>();
public final List<Reporter> reporterList = new ArrayList<>();
public boolean colorConsole = false;
public final List<String> coverageSchemes = new ArrayList<>();
public final List<String> sourceFiles = new ArrayList<>();
public final List<String> testFiles = new ArrayList<>();
public final List<String> includeObjects = new ArrayList<>();
public final List<String> excludeObjects = new ArrayList<>();
public FileMapperOptions sourceMappingOptions;
public FileMapperOptions testMappingOptions;
public boolean failOnErrors = false;
Expand Down
Loading
Toggle all file notes Toggle all file annotations