Skip to content

Commit

Permalink
NIFI-5579: Incorporated review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mattyb149 committed Feb 11, 2025
1 parent 41f9f37 commit 0eca2c7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,6 @@
<artifactId>nifi-record</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-dbcp-service</artifactId>
<version>2.3.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.nifi</groupId>
<artifactId>nifi-mock-record-utils</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import groovy.json.JsonSlurper;
import org.apache.commons.io.FileUtils;
import org.apache.nifi.controller.AbstractControllerService;
import org.apache.nifi.dbcp.DBCPConnectionPoolLookup;
import org.apache.nifi.dbcp.DBCPService;
import org.apache.nifi.processor.exception.ProcessException;
import org.apache.nifi.serialization.RecordSetWriterFactory;
Expand Down Expand Up @@ -70,7 +69,6 @@ public class ExecuteGroovyScriptTest {

protected TestRunner runner;
protected static DBCPService dbcp = null; //to make single initialization
protected static MockDBCPConnectionPoolLookup dbcpServiceLookup = new MockDBCPConnectionPoolLookup();
protected MockRecordParser recordParser = null;
protected RecordSetWriterFactory recordWriter = null;
protected ExecuteGroovyScript proc;
Expand Down Expand Up @@ -135,10 +133,6 @@ public void setup() throws Exception {
runner.addControllerService("dbcp", dbcp, new HashMap<>());
runner.enableControllerService(dbcp);

runner.addControllerService("dbcpLookup", dbcpServiceLookup, new HashMap<>());
runner.setProperty(dbcpServiceLookup, "testDB", "dbcp");
runner.enableControllerService(dbcpServiceLookup);

List<RecordField> recordFields = Arrays.asList(
new RecordField("id", RecordFieldType.INT.getDataType()),
new RecordField("name", RecordFieldType.STRING.getDataType()),
Expand Down Expand Up @@ -554,12 +548,11 @@ public void test_onUnscheduled() {
public void test_attribute_passed_to_SQL() {
runner.setProperty(ExecuteGroovyScript.SCRIPT_FILE, TEST_RESOURCE_LOCATION + "test_attributes_passed_to_SQL.groovy");
runner.setProperty("database.name", "testDB");
runner.setProperty("SQL.mydb", "dbcpLookup");

runner.setProperty("SQL.mydb", "dbcp");
runner.assertValid();

runner.run();
assertEquals("testDB", dbcpServiceLookup.getDatabaseName());
assertEquals("testDB", ((DBCPServiceSimpleImpl) dbcp).getDatabaseName());
}


Expand All @@ -571,6 +564,8 @@ private HashMap<String, String> map(String key, String value) {

private static class DBCPServiceSimpleImpl extends AbstractControllerService implements DBCPService {

private String dbName;

@Override
public String getIdentifier() {
return "dbcp";
Expand All @@ -585,19 +580,10 @@ public Connection getConnection() throws ProcessException {
throw new ProcessException("getConnection failed: " + e);
}
}
}

private static class MockDBCPConnectionPoolLookup extends DBCPConnectionPoolLookup {
private String dbName;

@Override
public String getIdentifier() {
return "dbcpLookup";
}

@Override
public Connection getConnection(Map<String, String> attributes) throws ProcessException {
dbName = attributes.get(DBCPConnectionPoolLookup.DATABASE_NAME_ATTRIBUTE);
dbName = attributes.get("database.name");
try {
Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
return DriverManager.getConnection("jdbc:derby:" + DB_LOCATION + ";create=true");
Expand Down

0 comments on commit 0eca2c7

Please sign in to comment.