Skip to content

Commit c0236eb

Browse files
committed
#280: Extract common JDBC parts to separate Maven module
Task-Url: exasol/virtual-schemas#280
1 parent aa1d229 commit c0236eb

File tree

9 files changed

+228
-0
lines changed

9 files changed

+228
-0
lines changed

.classpath

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" output="target/classes" path="src/main/java">
4+
<attributes>
5+
<attribute name="optional" value="true"/>
6+
<attribute name="maven.pomderived" value="true"/>
7+
</attributes>
8+
</classpathentry>
9+
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
10+
<attributes>
11+
<attribute name="optional" value="true"/>
12+
<attribute name="maven.pomderived" value="true"/>
13+
<attribute name="test" value="true"/>
14+
</attributes>
15+
</classpathentry>
16+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
17+
<attributes>
18+
<attribute name="maven.pomderived" value="true"/>
19+
</attributes>
20+
</classpathentry>
21+
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
22+
<attributes>
23+
<attribute name="maven.pomderived" value="true"/>
24+
</attributes>
25+
</classpathentry>
26+
<classpathentry kind="output" path="target/classes"/>
27+
</classpath>

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target/

.project

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>java-util-logging-testing</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
<buildCommand>
14+
<name>org.eclipse.m2e.core.maven2Builder</name>
15+
<arguments>
16+
</arguments>
17+
</buildCommand>
18+
</buildSpec>
19+
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
21+
<nature>org.eclipse.m2e.core.maven2Nature</nature>
22+
</natures>
23+
</projectDescription>

.settings/org.eclipse.jdt.core.prefs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
3+
org.eclipse.jdt.core.compiler.compliance=1.5
4+
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
5+
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
6+
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
7+
org.eclipse.jdt.core.compiler.release=disabled
8+
org.eclipse.jdt.core.compiler.source=1.5

.settings/org.eclipse.m2e.core.prefs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
activeProfiles=
2+
eclipse.preferences.version=1
3+
resolveWorkspaceProjects=true
4+
version=1

README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Test Utilities for `java.util.logging`
2+
3+
[![Build Status](https://travis-ci.org/exasol/virtual-schemas.svg?branch=master)](https://travis-ci.org/exasol/virtual-schemas)
4+
5+
SonarCloud results:
6+
7+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=com.exasol%3Ajava-util-logging-testing&metric=alert_status)](https://sonarcloud.io/dashboard?id=com.exasol%3Ajava-util-logging-testing)
8+
9+
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=com.exasol%3Ajava-util-logging-testing&metric=security_rating)](https://sonarcloud.io/dashboard?id=com.exasol%3Ajava-util-logging-testing)
10+
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=com.exasol%3Ajava-util-logging-testing&metric=reliability_rating)](https://sonarcloud.io/dashboard?id=com.exasol%3Ajava-util-logging-testing)
11+
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=com.exasol%3Ajava-util-logging-testing&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=com.exasol%3Ajava-util-logging-testing)
12+
[![Technical Debt](https://sonarcloud.io/api/project_badges/measure?project=com.exasol%3Ajava-util-logging-testing&metric=sqale_index)](https://sonarcloud.io/dashboard?id=com.exasol%3Ajava-util-logging-testing)
13+
14+
[![Code Smells](https://sonarcloud.io/api/project_badges/measure?project=com.exasol%3Ajava-util-logging-testing&metric=code_smells)](https://sonarcloud.io/dashboard?id=com.exasol%3Ajava-util-logging-testing)
15+
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=com.exasol%3Ajava-util-logging-testing&metric=coverage)](https://sonarcloud.io/dashboard?id=com.exasol%3Ajava-util-logging-testing)
16+
[![Duplicated Lines (%)](https://sonarcloud.io/api/project_badges/measure?project=com.exasol%3Ajava-util-logging-testing&metric=duplicated_lines_density)](https://sonarcloud.io/dashboard?id=com.exasol%3Ajava-util-logging-testing)
17+
[![Lines of Code](https://sonarcloud.io/api/project_badges/measure?project=com.exasol%3Ajava-util-logging-testing&metric=ncloc)](https://sonarcloud.io/dashboard?id=com.exasol%3Ajava-util-logging-testing)
18+
19+
# Overview
20+
21+
The Exasol's testing utilities for `java.util.logging` allow testing log message creation in software that uses the `java.util.logging` framework.
22+
23+
## Utilities
24+
25+
## `CapturingLogHandler`
26+
27+
Add this log handler if you want to record log messages created by your software and check the contents as part of unit tests.
28+
29+
## Customer Support
30+
31+
This is an open source project which is officially supported by Exasol. For any question, you can contact our support team.
32+
33+
## Dependencies
34+
35+
### Run Time Dependencies
36+
37+
Running the Virtual Schema requires a Java Runtime version 9 or later.
38+
39+
### Build Time Dependencies
40+
41+
| Dependency | Purpose | License |
42+
|-------------------------------------------------------------------------------------|--------------------------------------------------------|-------------------------------|
43+
| [Java Hamcrest](http://hamcrest.org/JavaHamcrest/) | Checking for conditions in code via matchers | BSD License |
44+
| [J5SE](https://github.com/itsallcode/junit5-system-extensions) | JUnit5 extensions to test Java System.x functions | Eclipse Public License 2.0 |
45+
46+
# License
47+
48+
This software is licensed under the [MIT license](LICENSE)

pom.xml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>com.exasol</groupId>
6+
<artifactId>java-util-logging-testing</artifactId>
7+
<version>${product.version}</version>
8+
<name>Test utilities for `java.util.logging`</name>
9+
<description>This project provides utilities that help testing software that uses `java.util.logging` as its logging framework.</description>
10+
<properties>
11+
<product.version>2.2.0</product.version>
12+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
14+
<java.version>9</java.version>
15+
<junit.version>5.4.2</junit.version>
16+
<junit.platform.version>1.4.2</junit.platform.version>
17+
<maven.surefire.version>2.22.1</maven.surefire.version>
18+
<vscommon.version>7.3.0</vscommon.version>
19+
<vsjdbc.version>1.0.0</vsjdbc.version>
20+
</properties>
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.junit.jupiter</groupId>
24+
<artifactId>junit-jupiter-engine</artifactId>
25+
<version>${junit.version}</version>
26+
<scope>test</scope>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.junit.platform</groupId>
30+
<artifactId>junit-platform-runner</artifactId>
31+
<version>${junit.platform.version}</version>
32+
<scope>test</scope>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.junit.jupiter</groupId>
36+
<artifactId>junit-jupiter-params</artifactId>
37+
<version>${junit.version}</version>
38+
<scope>test</scope>
39+
</dependency>
40+
<dependency>
41+
<groupId>org.hamcrest</groupId>
42+
<artifactId>hamcrest</artifactId>
43+
<version>2.1</version>
44+
<scope>test</scope>
45+
</dependency>
46+
</dependencies>
47+
</project>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.exasol.logging;
2+
3+
import java.util.logging.Handler;
4+
import java.util.logging.LogRecord;
5+
6+
/**
7+
* This class implements a dummy log handler that allows capturing the log messages.
8+
* <p>
9+
* This allows checking the contents of the log messages in unit tests.
10+
*/
11+
public class CapturingLogHandler extends Handler {
12+
private final StringBuilder buffer = new StringBuilder();
13+
14+
@Override
15+
public void publish(final LogRecord record) {
16+
this.buffer.append(record.getMessage());
17+
}
18+
19+
@Override
20+
public void flush() {
21+
// intentionally blank
22+
}
23+
24+
@Override
25+
public void close() {
26+
reset();
27+
}
28+
29+
/**
30+
* Get the captured data from the messages
31+
*
32+
* @return messages as string
33+
*/
34+
public String getCapturedData() {
35+
return this.buffer.toString();
36+
}
37+
38+
/**
39+
* Reset the capture buffer
40+
*/
41+
public void reset() {
42+
this.buffer.setLength(0);
43+
}
44+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.exasol.logging;
2+
3+
import static org.hamcrest.MatcherAssert.assertThat;
4+
import static org.hamcrest.Matchers.equalTo;
5+
6+
import java.util.logging.Logger;
7+
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.junit.jupiter.api.Test;
10+
11+
class CapturingLogHandlerTest {
12+
private final CapturingLogHandler capturingLogHandler = new CapturingLogHandler();
13+
14+
@BeforeEach
15+
void beforeEach() {
16+
Logger.getLogger("com.exasol").addHandler(this.capturingLogHandler);
17+
this.capturingLogHandler.reset();
18+
}
19+
20+
@Test
21+
void testCapturingLogMessage() {
22+
final String messageToBeCaptured = "Capture this!";
23+
Logger.getLogger("com.exasol").info(messageToBeCaptured);
24+
assertThat(this.capturingLogHandler.getCapturedData(), equalTo(messageToBeCaptured));
25+
}
26+
}

0 commit comments

Comments
 (0)