-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modernize Spring boot example #1175
Modernize Spring boot example #1175
Conversation
serialization: | ||
WRITE_DATES_AS_TIMESTAMPS: false | ||
datasource: | ||
driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should not be in the main config
examples/spring-boot/src/test/java/com/example/AbstractIntegrationTest.java
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,19 @@ | |||
spring: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this file is not needed, simply put spring.datasource.driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver
next to spring.datasource.url
in AbstractIntegrationTest
jackson: | ||
serialization: | ||
WRITE_DATES_AS_TIMESTAMPS: false | ||
datasource: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is a good practice to not put default JDBC parameters into the app, to avoid a mix of two.
@artjomka thanks for your contribution! 👍 |
import org.junit.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
|
||
import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For a general purpose example, I'd avoid using assertion methods from a third-party library. Those imports should come from JUnit e.g. org.junit.Assert.assertEquals
. Users will likely ask themselves which of the dependencies brings in the import. The info
method could probably be replaced by something else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import org.testcontainers.containers.GenericContainer; | ||
|
||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@SpringBootTest(classes = DemoApplication.class,webEnvironment = WebEnvironment.RANDOM_PORT) | ||
@ContextConfiguration(initializers = AbstractIntegrationTest.Initializer.class) | ||
@SpringBootTest(classes = DemoApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT, properties = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I am wrong but most Spring developers would probably write a test annotated with @DataJpaTest
here.
…ntainer. Introduce a new RabbitMQContainer.declare(...) method to declare objects such as exchanges, queues, etc in RabbitMQ. The objects passed to the declare method are constructed via static factory methods from the DeclareCommands class. Those objects provide a fluent methods for method chaining. Existing with* methods are kept for backwards compatibility. New functionality provided by the new fluent declarable objects: 1. Allow objects to be declared inside a vhost. Previously impossible with old with* methods. 2. Only need to specify the minimum number of optional args. Previously had to specify all optional args if only one optional arg was needed. 3. Better defaults provided in the declarable objects, to minimize args needed to be specified. 4. Type-safe convenience methods are provided for common usages. Examples: * exchange("myexchange").direct() instead of withExchange("myexchange", "direct") * queue("myqueue").maxLength(1000).autoDelete() instead of withQueue("myqueue", true, false, Map.of("x-max-length", 1000)) Also added documentation for the RabbitMQ module.
Spring boot example update
issue #1137 (#1137)