-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor extract method ensuring we close resources
- Loading branch information
Showing
3 changed files
with
105 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.ebean.migration; | ||
|
||
import jdk.nashorn.internal.ir.annotations.Ignore; | ||
import org.testng.annotations.Test; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class DbNameUtilTest { | ||
|
||
/** | ||
* Run manually against Postgres database. | ||
*/ | ||
@Ignore | ||
@Test | ||
public void normalise_when_realPostgres() throws SQLException { | ||
|
||
MigrationConfig config = createConfig(); | ||
// assumes DB unit exists on our local postgres database | ||
config.setDbUrl("jdbc:postgresql://127.0.0.1:5432/unit"); | ||
|
||
try (Connection connection = config.createConnection()) { | ||
String platformName = DbNameUtil.normalise(connection); | ||
|
||
assertThat(platformName).isEqualTo("postgres"); | ||
} catch (SQLException e) { | ||
throw e; | ||
} | ||
} | ||
|
||
/** | ||
* Run manually against cockroach database. | ||
*/ | ||
@Ignore | ||
@Test | ||
public void normalise_when_cockroach() throws SQLException { | ||
|
||
MigrationConfig config = createConfig(); | ||
// assumes DB unit exists on our local cockroach database | ||
config.setDbUrl("jdbc:postgresql://127.0.0.1:26257/unit"); | ||
|
||
try (Connection connection = config.createConnection()) { | ||
String platformName = DbNameUtil.normalise(connection); | ||
assertThat(platformName).isEqualTo("cockroach"); | ||
} catch (SQLException e) { | ||
throw e; | ||
} | ||
} | ||
|
||
/** | ||
* Assumes a DB user unit exists on the databases. | ||
*/ | ||
private MigrationConfig createConfig() { | ||
MigrationConfig config = new MigrationConfig(); | ||
config.setDbUsername("unit"); | ||
config.setDbPassword("unit"); | ||
config.setDbDriver("org.postgresql.Driver"); | ||
return config; | ||
} | ||
} |