Skip to content
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

Merged
merged 9 commits into from
Jan 24, 2019

Conversation

artjomka
Copy link
Contributor

Spring boot example update
issue #1137 (#1137)

serialization:
WRITE_DATES_AS_TIMESTAMPS: false
datasource:
driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver
Copy link
Member

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

@@ -0,0 +1,19 @@
spring:
Copy link
Member

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:
Copy link
Member

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.

@bsideup bsideup added this to the next milestone Jan 24, 2019
@bsideup bsideup mentioned this pull request Jan 24, 2019
4 tasks
@bsideup bsideup merged commit d1c0292 into testcontainers:master Jan 24, 2019
@bsideup
Copy link
Member

bsideup commented Jan 24, 2019

@artjomka thanks for your contribution! 👍

@bsideup bsideup changed the title Spring example updates modernize Spring boot example Jan 24, 2019
@bsideup bsideup changed the title modernize Spring boot example Modernize Spring boot example Jan 24, 2019
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;
Copy link
Contributor

@bmuschko bmuschko Jan 30, 2019

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.

Copy link
Contributor Author

@artjomka artjomka Jan 31, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was done for consistency - another test in same module is using that assertion library, so separate issue need to be created and reviewed if assertions should be from JUnit library.
@bsideup @rnorth @kiview what's your opinion on this matter is?

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 = {
Copy link
Contributor

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.

philsttr added a commit to philsttr/testcontainers-java that referenced this pull request Sep 7, 2019
…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.
@artjomka artjomka deleted the spring-example-updates branch February 28, 2020 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants