-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add demo app with Testcontainers URL
- Loading branch information
Showing
10 changed files
with
165 additions
and
4 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
21 changes: 21 additions & 0 deletions
21
spring-boot-integration/postgres-tc-url-demo-app/build.gradle.kts
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,21 @@ | ||
plugins { | ||
id("pg-index-health.java-application") | ||
alias(libs.plugins.spring.boot.gradlePlugin) | ||
alias(libs.plugins.spring.dependency.management) | ||
} | ||
|
||
ext["commons-lang3.version"] = libs.versions.commons.lang3.get() | ||
ext["assertj.version"] = libs.versions.assertj.get() | ||
// ext["mockito.version"] = libs.versions.mockito.get() | ||
ext["junit-jupiter.version"] = libs.versions.junit.get() | ||
|
||
dependencies { | ||
implementation(platform(libs.testcontainers.bom)) | ||
implementation("org.testcontainers:postgresql") | ||
implementation(libs.spring.boot.starter.data.jdbc) | ||
|
||
runtimeOnly(libs.postgresql) | ||
|
||
testImplementation(libs.spring.boot.starter.test) | ||
testImplementation(project(":spring-boot-integration:pg-index-health-test-starter")) | ||
} |
25 changes: 25 additions & 0 deletions
25
...io/github/mfvanek/pg/spring/postgres/tc/url/PostgresTestcontainersUrlDemoApplication.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,25 @@ | ||
/* | ||
* Copyright (c) 2019-2024. Ivan Vakhrushev and others. | ||
* https://github.com/mfvanek/pg-index-health | ||
* | ||
* This file is a part of "pg-index-health" - a Java library for | ||
* analyzing and maintaining indexes health in PostgreSQL databases. | ||
* | ||
* Licensed under the Apache License 2.0 | ||
*/ | ||
|
||
package io.github.mfvanek.pg.spring.postgres.tc.url; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class PostgresTestcontainersUrlDemoApplication { | ||
|
||
/** | ||
* Demo application with PostgreSQL datasource. | ||
*/ | ||
public static void main(final String[] args) { | ||
SpringApplication.run(PostgresTestcontainersUrlDemoApplication.class, args); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
spring-boot-integration/postgres-tc-url-demo-app/src/main/resources/application.yaml
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,8 @@ | ||
debug: false | ||
|
||
spring: | ||
main: | ||
banner-mode: off | ||
datasource: | ||
url: jdbc:tc:postgresql:17.2:///demo_for_pg_index_health_starter | ||
driverClassName: org.testcontainers.jdbc.ContainerDatabaseDriver |
33 changes: 33 additions & 0 deletions
33
...ub/mfvanek/pg/spring/postgres/tc/url/PostgresTestcontainersUrlDemoApplicationRunTest.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,33 @@ | ||
/* | ||
* Copyright (c) 2019-2024. Ivan Vakhrushev and others. | ||
* https://github.com/mfvanek/pg-index-health | ||
* | ||
* This file is a part of "pg-index-health" - a Java library for | ||
* analyzing and maintaining indexes health in PostgreSQL databases. | ||
* | ||
* Licensed under the Apache License 2.0 | ||
*/ | ||
|
||
package io.github.mfvanek.pg.spring.postgres.tc.url; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.springframework.boot.test.system.CapturedOutput; | ||
import org.springframework.boot.test.system.OutputCaptureExtension; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatCode; | ||
|
||
@ExtendWith(OutputCaptureExtension.class) | ||
class PostgresTestcontainersUrlDemoApplicationRunTest { | ||
|
||
@Test | ||
void applicationShouldRun(final CapturedOutput output) { | ||
assertThatCode(() -> PostgresTestcontainersUrlDemoApplication.main(new String[]{})) | ||
.doesNotThrowAnyException(); | ||
assertThat(output.getAll()) | ||
.contains("Starting PostgresTestcontainersUrlDemoApplication using Java") | ||
.contains("Container is started (JDBC URL: jdbc:postgresql://localhost:") | ||
.contains("Started PostgresTestcontainersUrlDemoApplication in"); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...ithub/mfvanek/pg/spring/postgres/tc/url/PostgresTestcontainersUrlDemoApplicationTest.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,72 @@ | ||
/* | ||
* Copyright (c) 2019-2024. Ivan Vakhrushev and others. | ||
* https://github.com/mfvanek/pg-index-health | ||
* | ||
* This file is a part of "pg-index-health" - a Java library for | ||
* analyzing and maintaining indexes health in PostgreSQL databases. | ||
* | ||
* Licensed under the Apache License 2.0 | ||
*/ | ||
|
||
package io.github.mfvanek.pg.spring.postgres.tc.url; | ||
|
||
import com.zaxxer.hikari.HikariDataSource; | ||
import io.github.mfvanek.pg.connection.PgConnection; | ||
import io.github.mfvanek.pg.core.checks.common.DatabaseCheckOnHost; | ||
import io.github.mfvanek.pg.core.checks.common.Diagnostic; | ||
import io.github.mfvanek.pg.model.dbobject.DbObject; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import java.util.List; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@ActiveProfiles("test") | ||
@SpringBootTest | ||
class PostgresTestcontainersUrlDemoApplicationTest { | ||
|
||
@Autowired | ||
private ApplicationContext applicationContext; | ||
|
||
@Autowired | ||
private Environment environment; | ||
|
||
@Autowired | ||
private List<DatabaseCheckOnHost<? extends DbObject>> checks; | ||
|
||
@Test | ||
void contextLoadsAndDoesNotContainPgIndexHealthBeans() { | ||
assertThat(applicationContext.getBean("dataSource")) | ||
.isInstanceOf(HikariDataSource.class); | ||
|
||
assertThat(applicationContext.getBean("pgConnection")) | ||
.isInstanceOf(PgConnection.class); | ||
|
||
assertThat(environment.getProperty("spring.datasource.url")) | ||
.isNotBlank() | ||
.isEqualTo("jdbc:tc:postgresql:17.2:///demo_for_pg_index_health_starter"); | ||
} | ||
|
||
@Test | ||
void checksShouldWork() { | ||
assertThat(checks) | ||
.hasSameSizeAs(Diagnostic.values()); | ||
|
||
checks.stream() | ||
.filter(DatabaseCheckOnHost::isStatic) | ||
.forEach(c -> { | ||
assertThat(c.check()) | ||
.as(c.getDiagnostic().name()) | ||
.isEmpty(); | ||
|
||
assertThat(c.getHost().getPgUrl()) | ||
.startsWith("jdbc:postgresql://localhost:") | ||
.endsWith("/test?loggerLevel=OFF"); | ||
}); | ||
} | ||
} |