Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions components/camel-sql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
</properties>

<dependencies>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-support</artifactId>
Expand Down Expand Up @@ -70,17 +69,10 @@
<version>${hamcrest-version}</version>
<scope>test</scope>
</dependency>
<!-- derby used for stored procedure tests -->
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>${derby-version}</version>
<scope>test</scope>
</dependency>
<dependency>
Comment thread
apupier marked this conversation as resolved.
<groupId>org.apache.derby</groupId>
<artifactId>derbytools</artifactId>
<version>${derby-version}</version>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2-version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -89,17 +81,25 @@
<version>${hsqldb-version}</version>
<scope>test</scope>
</dependency>
<!-- MariaDB4j only used for SQL stored function tests -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>2.4.240</version>
<groupId>ch.vorburger.mariaDB4j</groupId>
<artifactId>mariaDB4j</artifactId>
<version>${mariadb4j-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<version>${mariadb-version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<!-- This is necessary when debugging tests to enable HSQLDB to find
the classes in the classpath. -->
<plugins>

<!-- generate source code from grammar for the stored procedure component -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand All @@ -120,7 +120,16 @@
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<!-- This is necessary when debugging tests to enable HSQLDB to find
the classes in the classpath. -->
<hsqldb.method_class_names>org.apache.camel.component.sql.stored.*</hsqldb.method_class_names>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class SqlConsumerMaxMessagesPerPollTest extends CamelTestSupport {
public void doPreSetup() throws Exception {
db = new EmbeddedDatabaseBuilder()
.setName(getClass().getSimpleName())
.setType(EmbeddedDatabaseType.DERBY)
.setType(EmbeddedDatabaseType.HSQL)
.addScript("sql/createAndPopulateDatabase4.sql")
.build();

Expand All @@ -60,19 +60,19 @@ public void maxMessagesPerPoll() throws Exception {
MockEndpoint.assertIsSatisfied(context);

List<Exchange> exchanges = mock.getReceivedExchanges();
assertBodyMapValue(1, "ID", exchanges.get(0));
assertBodyMapValue(0, "ID", exchanges.get(0));
assertBodyMapValue("Camel", "PROJECT", exchanges.get(0));
assertProperty(0, "CamelBatchIndex", exchanges.get(0));
assertProperty(2, "CamelBatchSize", exchanges.get(0));
assertProperty(Boolean.FALSE, "CamelBatchComplete", exchanges.get(0));

assertBodyMapValue(2, "ID", exchanges.get(1));
assertBodyMapValue(1, "ID", exchanges.get(1));
assertBodyMapValue("AMQ", "PROJECT", exchanges.get(1));
assertProperty(1, "CamelBatchIndex", exchanges.get(1));
assertProperty(2, "CamelBatchSize", exchanges.get(1));
assertProperty(Boolean.TRUE, "CamelBatchComplete", exchanges.get(1)); // end of the first batch

assertBodyMapValue(3, "ID", exchanges.get(2));
assertBodyMapValue(2, "ID", exchanges.get(2));
assertBodyMapValue("Linux", "PROJECT", exchanges.get(2));
assertProperty(0, "CamelBatchIndex", exchanges.get(2)); // the second batch
assertProperty(1, "CamelBatchSize", exchanges.get(2)); // only one entry in this batch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ public void testRetrieveGeneratedKeysForBatch() {
List<Map<String, Object>> generatedKeys = out.getMessage().getHeader(SqlConstants.SQL_GENERATED_KEYS_DATA, List.class);
assertNotNull(generatedKeys, "out body could not be converted to a List - was: " + out.getMessage().getBody());

// it seems not to work with Derby...
assertEquals(4, generatedKeys.size());

int id = 3;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,28 @@

public class CallableStatementWrapperTest extends CamelTestSupport {

/* This is necessary when debugging tests to enable HSQLDB to find
the classes in the classpath. */
/*
static {
if (System.getProperty("hsqldb.method_class_names") == null) {
System.setProperty(
"hsqldb.method_class_names",
"org.apache.camel.component.sql.stored.*");
}
}
*/

private TemplateParser templateParser;
private EmbeddedDatabase db;
private JdbcTemplate jdbcTemplate;
private CallableStatementWrapperFactory factory;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commented-out static {} block is unnecessary since the hsqldb.method_class_names property is already set via the surefire plugin configuration in pom.xml. Please remove this dead code (also applies to ProducerInOutTest and ProducerTest).


@Override

public void doPreSetup() throws Exception {
db = new EmbeddedDatabaseBuilder()
.setName(getClass().getSimpleName())
.setType(EmbeddedDatabaseType.DERBY)
.setType(EmbeddedDatabaseType.HSQL)
.addScript("sql/storedProcedureTest.sql").build();
jdbcTemplate = new JdbcTemplate(db);

Expand All @@ -60,32 +71,7 @@ void setupTest() {
@Test
public void shouldExecuteStoredProcedure() throws Exception {
CallableStatementWrapper wrapper = new CallableStatementWrapper(
"SUBNUMBERS"
+ "(INTEGER ${header.v1},INTEGER ${header.v2},OUT INTEGER resultofsub)",
factory);

final Exchange exchange = createExchangeWithBody(null);
exchange.getIn().setHeader("v1", 1);
exchange.getIn().setHeader("v2", 2);

wrapper.call(new WrapperExecuteCallback() {
@Override
public void execute(StatementWrapper statementWrapper) throws SQLException, DataAccessException {
statementWrapper.populateStatement(null, exchange);

Map resultOfQuery = (Map) statementWrapper.executeStatement();
assertEquals(-1, resultOfQuery.get("resultofsub"));
}
});
}

@Test
public void shouldExecuteStoredFunction() throws Exception {
CallableStatementWrapperFactory factory = new CallableStatementWrapperFactory(jdbcTemplate, templateParser, true);

CallableStatementWrapper wrapper = new CallableStatementWrapper(
"SUBNUMBERS_FUNCTION"
+ "(OUT INTEGER resultofsub, INTEGER ${header.v1},INTEGER ${header.v2})",
"SUBNUMBERS(INTEGER ${header.v1},INTEGER ${header.v2},OUT INTEGER resultofsub)",
factory);

final Exchange exchange = createExchangeWithBody(null);
Expand Down Expand Up @@ -116,7 +102,6 @@ public void execute(StatementWrapper statementWrapper) throws SQLException, Data
//no output parameter in stored procedure NILADIC()
//Spring sets #update-count-1
assertNotNull(result.get("#update-count-1"));

}
});
}
Expand All @@ -127,5 +112,4 @@ public void doPostTearDown() throws Exception {
db.shutdown();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ProducerBatchInvalidTest extends CamelTestSupport {
public void doPreSetup() throws Exception {
db = new EmbeddedDatabaseBuilder()
.setName(getClass().getSimpleName())
.setType(EmbeddedDatabaseType.DERBY)
.setType(EmbeddedDatabaseType.HSQL)
.addScript("sql/storedProcedureTest.sql").build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class ProducerBatchTest extends CamelTestSupport {
public void doPreSetup() throws Exception {
db = new EmbeddedDatabaseBuilder()
.setName(getClass().getSimpleName())
.setType(EmbeddedDatabaseType.DERBY)
.setType(EmbeddedDatabaseType.HSQL)
.addScript("sql/storedProcedureTest.sql").build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ProducerBodyArrayTest extends CamelTestSupport {
public void doPreSetup() throws Exception {
db = new EmbeddedDatabaseBuilder()
.setName(getClass().getSimpleName())
.setType(EmbeddedDatabaseType.DERBY)
.setType(EmbeddedDatabaseType.HSQL)
.addScript("sql/storedProcedureTest.sql").build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,26 @@

public class ProducerInOutTest extends CamelTestSupport {

/* This is necessary when debugging tests to enable HSQLDB to find
the classes in the classpath. */
/*
static {
if (System.getProperty("hsqldb.method_class_names") == null) {
System.setProperty(
"hsqldb.method_class_names",
"org.apache.camel.component.sql.stored.*");
}
}
*/

EmbeddedDatabase db;

@Override

public void doPreSetup() throws Exception {
db = new EmbeddedDatabaseBuilder()
.setName(getClass().getSimpleName())
.setType(EmbeddedDatabaseType.DERBY)
.setType(EmbeddedDatabaseType.HSQL)
.addScript("sql/storedProcedureTest.sql").build();

}
Expand Down Expand Up @@ -81,7 +93,7 @@ public void configure() {
getContext().getComponent("sql-stored", SqlStoredComponent.class).setDataSource(db);

from("direct:query")
.to("sql-stored:INOUTDEMO(INTEGER ${headers.in1},INOUT INTEGER ${headers.in2} out1,OUT INTEGER out2)")
.to("sql-stored:INOUTDEMO(INTEGER ${headers.in1}, INOUT INTEGER ${headers.in2} out1, OUT INTEGER out2)")
.to("mock:query");
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ProducerNamedParameterTest extends CamelTestSupport {
public void doPreSetup() throws Exception {
db = new EmbeddedDatabaseBuilder()
.setName(getClass().getSimpleName())
.setType(EmbeddedDatabaseType.DERBY)
.setType(EmbeddedDatabaseType.HSQL)
.addScript("sql/storedProcedureTest.sql").build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,26 @@

public class ProducerTest extends CamelTestSupport {

/* This is necessary when debugging tests to enable HSQLDB to find
the classes in the classpath. */
/*
static {
if (System.getProperty("hsqldb.method_class_names") == null) {
System.setProperty(
"hsqldb.method_class_names",
"org.apache.camel.component.sql.stored.*");
}
}
*/

EmbeddedDatabase db;

@Override

public void doPreSetup() throws Exception {
db = new EmbeddedDatabaseBuilder()
.setName(getClass().getSimpleName())
.setType(EmbeddedDatabaseType.DERBY)
.setType(EmbeddedDatabaseType.HSQL)
.addScript("sql/storedProcedureTest.sql").build();

}

@Override
Expand Down Expand Up @@ -78,8 +88,9 @@ public void configure() {
// required for the sql component
getContext().getComponent("sql-stored", SqlStoredComponent.class).setDataSource(db);

from("direct:query").to("sql-stored:SUBNUMBERS(INTEGER ${headers.num1},INTEGER ${headers"
+ ".num2},OUT INTEGER resultofsub)")
from("direct:query")
.to("sql-stored:SUBNUMBERS(INTEGER ${headers.num1},INTEGER ${headers"
+ ".num2},OUT INTEGER resultofsub)")
.to("mock:query");
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class ProducerUseMessageBodyForTemplateTest extends CamelTestSupport {
public void doPreSetup() throws Exception {
db = new EmbeddedDatabaseBuilder()
.setName(getClass().getSimpleName())
.setType(EmbeddedDatabaseType.DERBY)
.setType(EmbeddedDatabaseType.HSQL)
.addScript("sql/storedProcedureTest.sql").build();

}
Expand Down
Loading