mirror of https://github.com/apache/nifi.git
- Unit test creates resources in HOME directory This closes #174
Signed-off-by: Matt Gilman <matt.c.gilman@gmail.com>
This commit is contained in:
parent
f53aaed122
commit
9e9182aa63
|
@ -20,7 +20,6 @@ import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
@ -34,11 +33,14 @@ import org.apache.avro.generic.GenericDatumReader;
|
||||||
import org.apache.avro.generic.GenericRecord;
|
import org.apache.avro.generic.GenericRecord;
|
||||||
import org.apache.avro.io.DatumReader;
|
import org.apache.avro.io.DatumReader;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
|
import org.junit.Rule;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.rules.TemporaryFolder;
|
||||||
|
|
||||||
public class TestJdbcTypesH2 {
|
public class TestJdbcTypesH2 {
|
||||||
|
|
||||||
final static String DB_LOCATION = "~/var/test/h2";
|
@Rule
|
||||||
|
public TemporaryFolder folder = new TemporaryFolder();
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setup() {
|
public static void setup() {
|
||||||
|
@ -75,11 +77,7 @@ public class TestJdbcTypesH2 {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSQLTypesMapping() throws ClassNotFoundException, SQLException, IOException {
|
public void testSQLTypesMapping() throws ClassNotFoundException, SQLException, IOException {
|
||||||
// remove previous test database, if any
|
final Connection con = createConnection(folder.getRoot().getAbsolutePath());
|
||||||
final File dbLocation = new File(DB_LOCATION);
|
|
||||||
dbLocation.delete();
|
|
||||||
|
|
||||||
final Connection con = createConnection();
|
|
||||||
final Statement st = con.createStatement();
|
final Statement st = con.createStatement();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -114,8 +112,8 @@ public class TestJdbcTypesH2 {
|
||||||
|
|
||||||
final InputStream instream = new ByteArrayInputStream(serializedBytes);
|
final InputStream instream = new ByteArrayInputStream(serializedBytes);
|
||||||
|
|
||||||
final DatumReader<GenericRecord> datumReader = new GenericDatumReader<GenericRecord>();
|
final DatumReader<GenericRecord> datumReader = new GenericDatumReader<>();
|
||||||
try (final DataFileStream<GenericRecord> dataFileReader = new DataFileStream<GenericRecord>(instream, datumReader)) {
|
try (final DataFileStream<GenericRecord> dataFileReader = new DataFileStream<>(instream, datumReader)) {
|
||||||
GenericRecord record = null;
|
GenericRecord record = null;
|
||||||
while (dataFileReader.hasNext()) {
|
while (dataFileReader.hasNext()) {
|
||||||
// Reuse record object by passing it to next(). This saves us from
|
// Reuse record object by passing it to next(). This saves us from
|
||||||
|
@ -132,18 +130,17 @@ public class TestJdbcTypesH2 {
|
||||||
public void testDriverLoad() throws ClassNotFoundException, SQLException {
|
public void testDriverLoad() throws ClassNotFoundException, SQLException {
|
||||||
// final Class<?> clazz = Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
|
// final Class<?> clazz = Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
|
||||||
|
|
||||||
Connection con = createConnection();
|
Connection con = createConnection(folder.getRoot().getAbsolutePath());
|
||||||
|
|
||||||
assertNotNull(con);
|
assertNotNull(con);
|
||||||
con.close();
|
con.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Connection createConnection() throws ClassNotFoundException, SQLException {
|
private Connection createConnection(String location) throws ClassNotFoundException, SQLException {
|
||||||
|
|
||||||
// Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
|
// Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
|
||||||
String connectionString = "jdbc:h2:file:" + DB_LOCATION + "/testdb7";
|
String connectionString = "jdbc:h2:file:" + location + "/testdb7";
|
||||||
final Connection con = DriverManager.getConnection(connectionString, "SA", "");
|
return DriverManager.getConnection(connectionString, "SA", "");
|
||||||
return con;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue