Skip to content

Commit

Permalink
Added metadata resouce-config.json for org.apache.commons:commons-dbc…
Browse files Browse the repository at this point in the history
…p2:2.12.0 (#520)
  • Loading branch information
radovanradic authored Aug 5, 2024
1 parent ea95723 commit a64c861
Show file tree
Hide file tree
Showing 10 changed files with 143 additions and 0 deletions.
4 changes: 4 additions & 0 deletions metadata/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@
"allowed-packages" : [ "org.apache.commons" ],
"directory" : "org.apache.commons/commons-compress",
"module" : "org.apache.commons:commons-compress"
}, {
"allowed-packages" : [ "org.apache.commons" ],
"directory" : "org.apache.commons/commons-dbcp2",
"module" : "org.apache.commons:commons-dbcp2"
}, {
"allowed-packages" : [ "org.apache.commons" ],
"directory" : "org.apache.commons/commons-pool2",
Expand Down
3 changes: 3 additions & 0 deletions metadata/org.apache.commons/commons-dbcp2/2.12.0/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"resource-config.json"
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"bundles": [
{"name": "org.apache.commons.dbcp2.LocalStrings"}
]
}
10 changes: 10 additions & 0 deletions metadata/org.apache.commons/commons-dbcp2/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[
{
"latest": true,
"metadata-version": "2.12.0",
"module": "org.apache.commons:commons-dbcp2",
"tested-versions": [
"2.12.0"
]
}
]
6 changes: 6 additions & 0 deletions tests/src/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,12 @@
"name" : "org.apache.commons:commons-compress",
"versions" : [ "1.23.0" ]
} ]
}, {
"test-project-path" : "org.apache.commons/commons-dbcp2/2.12.0",
"libraries" : [ {
"name" : "org.apache.commons:commons-dbcp2",
"versions" : [ "2.12.0" ]
} ]
}, {
"test-project-path" : "org.apache.commons/commons-pool2/2.11.1",
"libraries" : [ {
Expand Down
4 changes: 4 additions & 0 deletions tests/src/org.apache.commons/commons-dbcp2/2.12.0/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
gradlew.bat
gradlew
gradle/
build/
18 changes: 18 additions & 0 deletions tests/src/org.apache.commons/commons-dbcp2/2.12.0/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/

plugins {
id "org.graalvm.internal.tck"
}

String libraryVersion = tck.testedLibraryVersion.get()

dependencies {
testImplementation "org.apache.commons:commons-dbcp2:$libraryVersion"
testImplementation 'org.assertj:assertj-core:3.22.0'
testImplementation 'com.h2database:h2:2.3.230'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
library.version = 2.12.0
metadata.dir = org.apache.commons/commons-dbcp2/2.12.0/
13 changes: 13 additions & 0 deletions tests/src/org.apache.commons/commons-dbcp2/2.12.0/settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pluginManagement {
def tckPath = Objects.requireNonNullElse(
System.getenv("GVM_TCK_TCKDIR"),
"../../../../tck-build-logic"
)
includeBuild(tckPath)
}

plugins {
id "org.graalvm.internal.tck-settings" version "1.0.0-SNAPSHOT"
}

rootProject.name = 'org.apache.commons.commons-dbcp2_tests'
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright and related rights waived via CC0
*
* You should have received a copy of the CC0 legalcode along with this
* work. If not, see <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
package org_apache_commons.commons_dbcp2;

import org.apache.commons.dbcp2.BasicDataSource;
import org.apache.commons.dbcp2.BasicDataSourceFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import static org.assertj.core.api.Assertions.assertThat;

class CommonsDbcp2Test {
private BasicDataSource dataSource;
private Connection connection;

@BeforeEach
public void setUp() throws SQLException {
Properties properties = new Properties();
properties.setProperty("driverClassName", "org.h2.Driver");
properties.setProperty("url", "jdbc:h2:mem:default;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
properties.setProperty("username", "fred");
properties.setProperty("password", "secret");
properties.setProperty("initialSize", "2");
properties.setProperty("minIdle", "1");
properties.setProperty("testOnBorrow", "true");
properties.setProperty("testOnConnect", "true");
properties.setProperty("validationQuery", "select 1");
BasicDataSourceFactory dataSourceFactory = new BasicDataSourceFactory();
dataSource = dataSourceFactory.createDataSource(properties);
connection = dataSource.getConnection();
}

@AfterEach
public void tearDown() throws Exception {
dataSource.close();
if (connection != null) {
connection.close();
connection = null;
}
}

@Test
void testPreparedStatement() throws SQLException {
try (Statement statement = connection.createStatement()) {
statement.executeUpdate("CREATE TABLE person (id INT NOT NULL, name VARCHAR(255), PRIMARY KEY (id))");
}

try (PreparedStatement preparedStatement = connection.prepareStatement("INSERT INTO person(id, name) VALUES( ?, ?)")) {
preparedStatement.setInt(1, 1);
preparedStatement.setString(2, "Elly");
int count = preparedStatement.executeUpdate();
assertThat(count).isEqualTo(1);
}

try (PreparedStatement preparedStatement = connection.prepareStatement("SELECT id, name FROM person WHERE name = ?")) {
preparedStatement.setString(1, "Elly");
try (ResultSet rs = preparedStatement.executeQuery()) {
assertThat(rs.next()).isEqualTo(true);
assertThat(rs.getInt(1)).isEqualTo(1);
assertThat(rs.getString(2)).isEqualTo("Elly");
// No more records
assertThat(rs.next()).isEqualTo(false);
}
}
}
}

0 comments on commit a64c861

Please sign in to comment.