-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix JENKINS-68826: Exception creating MySQL database dao after upgrad…
…ing pipeline-maven-plugin to v3.11.0 (#464)
- Loading branch information
Showing
6 changed files
with
60 additions
and
55 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
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 |
---|---|---|
|
@@ -24,41 +24,29 @@ | |
|
||
package org.jenkinsci.plugins.pipeline.maven.dao; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.zaxxer.hikari.HikariConfig; | ||
import com.zaxxer.hikari.HikariDataSource; | ||
import javax.sql.DataSource; | ||
|
||
import org.jenkinsci.plugins.pipeline.maven.db.migration.MigrationStep; | ||
import org.junit.ClassRule; | ||
import org.testcontainers.containers.MySQLContainer; | ||
|
||
import javax.sql.DataSource; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Properties; | ||
import com.zaxxer.hikari.HikariConfig; | ||
import com.zaxxer.hikari.HikariDataSource; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Cyrille Le Clerc</a> | ||
*/ | ||
public class PipelineMavenPluginMySqlDaoIT extends PipelineMavenPluginDaoAbstractTest { | ||
|
||
@ClassRule | ||
public static MySQLContainer<?> DB = new MySQLContainer<>(MySQLContainer.NAME); | ||
|
||
@Override | ||
public DataSource before_newDataSource() { | ||
HikariConfig config = new HikariConfig(); | ||
String configurationFilePath = ".mysql_config"; | ||
InputStream propertiesInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(configurationFilePath); | ||
|
||
Properties properties = new Properties(); | ||
if (propertiesInputStream == null) { | ||
throw new IllegalArgumentException("Config file " + configurationFilePath + " not found in classpath"); | ||
} else { | ||
try { | ||
properties.load(propertiesInputStream); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
config.setJdbcUrl(Preconditions.checkNotNull(properties.getProperty("jdbc.url"))); | ||
config.setUsername(Preconditions.checkNotNull(properties.getProperty("jdbc.username"))); | ||
config.setPassword(Preconditions.checkNotNull(properties.getProperty("jdbc.password"))); | ||
config.setDataSourceProperties(properties); | ||
config.setJdbcUrl(DB.getJdbcUrl()); | ||
config.setUsername(DB.getUsername()); | ||
config.setPassword(DB.getPassword()); | ||
return new HikariDataSource(config); | ||
} | ||
|
||
|
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 |
---|---|---|
|
@@ -24,43 +24,32 @@ | |
|
||
package org.jenkinsci.plugins.pipeline.maven.dao; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.zaxxer.hikari.HikariConfig; | ||
import com.zaxxer.hikari.HikariDataSource; | ||
import javax.sql.DataSource; | ||
|
||
import org.jenkinsci.plugins.pipeline.maven.db.migration.MigrationStep; | ||
import org.junit.ClassRule; | ||
import org.testcontainers.containers.PostgreSQLContainer; | ||
|
||
import javax.sql.DataSource; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Properties; | ||
import com.zaxxer.hikari.HikariConfig; | ||
import com.zaxxer.hikari.HikariDataSource; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Cyrille Le Clerc</a> | ||
*/ | ||
public class PipelineMavenPluginPostgreSqlDaoIT extends PipelineMavenPluginDaoAbstractTest { | ||
|
||
@ClassRule | ||
public static PostgreSQLContainer<?> DB = new PostgreSQLContainer<>(PostgreSQLContainer.IMAGE); | ||
|
||
@Override | ||
public DataSource before_newDataSource() throws Exception { | ||
|
||
Class.forName("org.postgresql.Driver"); | ||
|
||
HikariConfig config = new HikariConfig(); | ||
String configurationFilePath = ".postgresql_config"; | ||
InputStream propertiesInputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(configurationFilePath); | ||
|
||
Properties properties = new Properties(); | ||
if (propertiesInputStream == null) { | ||
throw new IllegalArgumentException("Config file " + configurationFilePath + " not found in classpath"); | ||
} else { | ||
try { | ||
properties.load(propertiesInputStream); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
config.setJdbcUrl(Preconditions.checkNotNull(properties.getProperty("jdbc.url"))); | ||
config.setUsername(Preconditions.checkNotNull(properties.getProperty("jdbc.username"))); | ||
config.setPassword(Preconditions.checkNotNull(properties.getProperty("jdbc.password"))); | ||
config.setJdbcUrl(DB.getJdbcUrl()); | ||
config.setUsername(DB.getUsername()); | ||
config.setPassword(DB.getPassword()); | ||
return new HikariDataSource(config); | ||
} | ||
|
||
|