-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test to verify that the application can use Jfr4Jdbc
- Loading branch information
Showing
6 changed files
with
178 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns="http://maven.apache.org/POM/4.0.0" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>dev.jfr4jdbc</groupId> | ||
<artifactId>artifact-test</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.compiler.source>11</maven.compiler.source> | ||
<maven.compiler.target>11</maven.compiler.target> | ||
<maven.install.skip>true</maven.install.skip> | ||
</properties> | ||
|
||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<version>2.22.2</version> | ||
</plugin> | ||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>dev.jfr4jdbc</groupId> | ||
<artifactId>jfr4jdbc-driver</artifactId> | ||
<version>999-SNAPSHOT</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-api</artifactId> | ||
<version>5.9.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>5.9.2</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
86 changes: 86 additions & 0 deletions
86
artifact-test/src/test/java/dev/jfr4jdbc/artifact/MultiReleaseJarTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package dev.jfr4jdbc.artifact; | ||
|
||
import org.junit.jupiter.api.*; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.jar.JarFile; | ||
import java.util.zip.ZipEntry; | ||
|
||
public class MultiReleaseJarTest { | ||
|
||
private JarFile open() throws IOException { | ||
File artifactDir = new File("../jfr4jdbc-driver/target"); | ||
File[] files = artifactDir.listFiles((dir, name) -> name.matches("jfr4jdbc-driver-.+\\.jar") && !(name.endsWith("-javadoc.jar") || name.endsWith("-sources.jar"))); | ||
assertEquals(1, files.length); | ||
return new JarFile(files[0]); | ||
} | ||
|
||
@DisplayName("Multi Release Jar") | ||
@Test | ||
void isMultiRelease() throws Exception { | ||
|
||
JarFile jarFile = open(); | ||
assertTrue(jarFile.isMultiRelease()); | ||
} | ||
|
||
@DisplayName("Service Loader File exists") | ||
@Test | ||
void hasServiceLoaderFile() throws IOException { | ||
JarFile jarFile = open(); | ||
assertNotNull(jarFile.getEntry("META-INF/services/java.sql.Driver")); | ||
} | ||
|
||
@DisplayName("Java 11 Directory exists") | ||
@Test | ||
void hasJava11Directory() throws IOException { | ||
JarFile jarFile = open(); | ||
assertNotNull(jarFile.getEntry("META-INF/versions/11")); | ||
} | ||
|
||
private final int JAVA_8_VERSION = 52; | ||
private final int JAVA_11_VERSION = 55; | ||
|
||
@DisplayName("Classes for JDBC 4.2 exists") | ||
@Test | ||
void hasJdbc42() throws IOException { | ||
JarFile jarFile = open(); | ||
|
||
assertEquals(JAVA_8_VERSION, readMajorVersion(jarFile, "dev/jfr4jdbc/Jfr4JdbcDataSource.class")); | ||
assertEquals(JAVA_8_VERSION, readMajorVersion(jarFile, "dev/jfr4jdbc/Jfr4JdbcDataSource42.class")); | ||
} | ||
|
||
@DisplayName("Classes for JDBC 4.3 exists") | ||
@Test | ||
void hasJdbc43() throws IOException { | ||
JarFile jarFile = open(); | ||
|
||
assertEquals(JAVA_11_VERSION, readMajorVersion(jarFile, "META-INF/versions/11/dev/jfr4jdbc/Jfr4JdbcDataSource.class")); | ||
assertEquals(JAVA_11_VERSION, readMajorVersion(jarFile, "META-INF/versions/11/dev/jfr4jdbc/Jfr4JdbcDataSource43.class")); | ||
} | ||
|
||
|
||
private int readMajorVersion(JarFile jarFile, String path) throws IOException { | ||
|
||
ZipEntry classFileEntry = jarFile.getEntry(path); | ||
InputStream inputStream = jarFile.getInputStream(classFileEntry); | ||
|
||
DataInputStream dataInputStream = new DataInputStream(inputStream); | ||
String cafe = Integer.toHexString(dataInputStream.readUnsignedShort()); | ||
assertEquals("cafe", cafe); | ||
String babe = Integer.toHexString(dataInputStream.readUnsignedShort()); | ||
assertEquals("babe", babe); | ||
|
||
int minorVersion = dataInputStream.readUnsignedShort(); | ||
int majorVersion = dataInputStream.readUnsignedShort(); | ||
|
||
inputStream.close(); | ||
|
||
return majorVersion; | ||
} | ||
|
||
} |
21 changes: 21 additions & 0 deletions
21
artifact-test/src/test/java/dev/jfr4jdbc/artifact/ServiceLoaderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package dev.jfr4jdbc.artifact; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
|
||
import java.sql.Driver; | ||
import java.util.ServiceLoader; | ||
|
||
public class ServiceLoaderTest { | ||
@DisplayName("ServiceLoader loads Jfr4Jdbc") | ||
@Test | ||
void loadedTest() throws Exception { | ||
ServiceLoader<Driver> loader = ServiceLoader.load(Driver.class); | ||
long jfrDriverCount = loader.stream().filter(d -> d.get().getClass().getCanonicalName().equals("dev.jfr4jdbc.Jfr4JdbcDriver")).count(); | ||
|
||
assertEquals(1, jfrDriverCount); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters