-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve log messages when database container test query fails (#3015)
Co-authored-by: Sergei Egorov <bsideup@gmail.com>
- Loading branch information
Showing
3 changed files
with
88 additions
and
16 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
71 changes: 71 additions & 0 deletions
71
modules/jdbc/src/test/java/org/testcontainers/containers/JdbcDatabaseContainerTest.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,71 @@ | ||
package org.testcontainers.containers; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import lombok.NonNull; | ||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
|
||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; | ||
import static org.mockito.Mockito.mock; | ||
|
||
public class JdbcDatabaseContainerTest { | ||
|
||
@Test | ||
public void anExceptionIsThrownIfJdbcIsNotAvailable() { | ||
JdbcDatabaseContainer<?> jdbcContainer = new JdbcDatabaseContainerStub("mysql:latest") | ||
.withStartupTimeoutSeconds(1); | ||
|
||
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(jdbcContainer::waitUntilContainerStarted); | ||
} | ||
|
||
static class JdbcDatabaseContainerStub extends JdbcDatabaseContainer { | ||
|
||
public JdbcDatabaseContainerStub(@NonNull String dockerImageName) { | ||
super(dockerImageName); | ||
} | ||
|
||
@Override | ||
public String getDriverClassName() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getJdbcUrl() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getUsername() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getPassword() { | ||
return null; | ||
} | ||
|
||
@Override | ||
protected String getTestQueryString() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public boolean isRunning() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Connection createConnection(String queryString) throws SQLException, NoDriverFoundException { | ||
throw new SQLException("Could not create new connection"); | ||
} | ||
|
||
@Override | ||
protected Logger logger() { | ||
return mock(Logger.class); | ||
} | ||
|
||
@Override | ||
public void setDockerImageName(@NonNull String dockerImageName) {} | ||
} | ||
} |