-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
191 additions
and
81 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
82 changes: 82 additions & 0 deletions
82
...s/e2e-tests/src/test/java/org/eclipse/tractusx/edc/helpers/TxPostgresqlLocalInstance.java
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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.tractusx.edc.helpers; | ||
|
||
import org.postgresql.ds.PGSimpleDataSource; | ||
|
||
import java.sql.Connection; | ||
import java.sql.DriverManager; | ||
import java.sql.SQLException; | ||
import javax.sql.DataSource; | ||
|
||
import static java.lang.String.format; | ||
|
||
@Deprecated(forRemoval = true) | ||
public final class TxPostgresqlLocalInstance { | ||
private final String password; | ||
private final String jdbcUrlPrefix; | ||
private final String username; | ||
private final String databaseName; | ||
|
||
public TxPostgresqlLocalInstance(String user, String password, String jdbcUrlPrefix, String db) { | ||
username = user; | ||
this.password = password; | ||
this.jdbcUrlPrefix = jdbcUrlPrefix; | ||
databaseName = db; | ||
} | ||
|
||
public void createDatabase() { | ||
createDatabase(databaseName); | ||
} | ||
|
||
public void createDatabase(String name) { | ||
try (var connection = DriverManager.getConnection(jdbcUrlPrefix + username, username, password)) { | ||
connection.createStatement().execute(format("create database %s;", name)); | ||
} catch (SQLException e) { | ||
e.printStackTrace(); | ||
// database could already exist | ||
} | ||
} | ||
|
||
public Connection getTestConnection(String hostName, int port, String dbName) { | ||
try { | ||
return createTestDataSource(hostName, port, dbName).getConnection(); | ||
} catch (SQLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public Connection getConnection() { | ||
try { | ||
return DriverManager.getConnection(jdbcUrlPrefix, username, password); | ||
} catch (SQLException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
public String getJdbcUrlPrefix() { | ||
return jdbcUrlPrefix; | ||
} | ||
|
||
private DataSource createTestDataSource(String hostName, int port, String dbName) { | ||
var dataSource = new PGSimpleDataSource(); | ||
dataSource.setServerNames(new String[]{ hostName }); | ||
dataSource.setPortNumbers(new int[]{ port }); | ||
dataSource.setUser(username); | ||
dataSource.setPassword(password); | ||
dataSource.setDatabaseName(dbName); | ||
return dataSource; | ||
} | ||
} |
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
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
Oops, something went wrong.