Skip to content

Commit

Permalink
feat: add testcontainers
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Oct 5, 2023
1 parent 6d831f6 commit d498005
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions jpa/boot-hibernate2ndlevelcache-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.example.hibernatecache;

import com.example.hibernatecache.common.TestContainersConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.context.ImportTestcontainers;

@TestConfiguration(proxyBeanMethods = false)
@ImportTestcontainers(TestContainersConfig.class)
class TestApplication {

public static void main(String[] args) {
SpringApplication.from(Application::main).with(TestApplication.class).run(args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.hibernatecache.common;

import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.testcontainers.containers.PostgreSQLContainer;

public interface TestContainersConfig {

@ServiceConnection
PostgreSQLContainer<?> postgreSQLContainer = new PostgreSQLContainer<>("postgres:16.0-alpine");
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ void shouldReturn400WhenCreateNewOrderWithoutName() throws Exception {
.andExpect(jsonPath("$.violations[0].field", is("name")))
.andExpect(jsonPath("$.violations[0].message", is("Name cannot be blank")))
.andExpect(jsonPath("$.violations[1].field", is("price")))
.andExpect(jsonPath("$.violations[1].message", is("Value must be greater than or equal to 0.01")))
.andExpect(
jsonPath(
"$.violations[1].message",
is("Value must be greater than or equal to 0.01")))
.andReturn();
}

Expand Down

0 comments on commit d498005

Please sign in to comment.