Open dhanyn10 opened 1 year ago
blog from url: https://rieckpil.de/mongodb-testcontainers-setup-for-datamongotest/
im trying to make simple insert database testing, below is my test code
@Testcontainers @SpringBootTest @DisplayName("users testing") @DataMongoTest(excludeAutoConfiguration = EmbeddedMongoAutoConfiguration.class) class OrderApplicationUsersTests { @Container static MongoDBContainer mongoDBContainer = new MongoDBContainer(DockerImageName.parse("mongo:6.0.3")); @DynamicPropertySource static void setProperties(DynamicPropertyRegistry registry) { registry.add("spring.data.mongodb.uri", mongoDBContainer::getReplicaSetUrl); } private UserRepository userRepo; private String uriContainer = mongoDBContainer.getIpAddress(); @Test @DisplayName("add admin") void isertAdmin() throws IOException { userRepo.deleteAll(); URL url = new URL(uriContainer + "/users/admin"); URLConnection conn = url.openConnection(); InputStream in = conn.getInputStream(); String encoding = conn.getContentEncoding(); encoding = encoding == null ? "UTF-8" : encoding; String body = IOUtils.toString(in, encoding); MatcherAssert.assertThat(body, CoreMatchers.containsString("admin generated")); } @Test @DisplayName("add admin failed") void isertAdminTwice() throws IOException { URL url = new URL(uriContainer + "/users/admin"); URLConnection conn = url.openConnection(); InputStream in = conn.getInputStream(); String encoding = conn.getContentEncoding(); encoding = encoding == null ? "UTF-8" : encoding; String body = IOUtils.toString(in, encoding); MatcherAssert.assertThat(body, CoreMatchers.containsString("admin only generated once")); }
also already post question to stackoverflow https://stackoverflow.com/questions/75198138/how-to-keep-data-when-testing-insert-to-mongodb-collection-with-spring-inside-do
dna@dna:~$ java --version openjdk 17.0.5 2022-10-18 OpenJDK Runtime Environment (build 17.0.5+8-Ubuntu-2ubuntu122.04) OpenJDK 64-Bit Server VM (build 17.0.5+8-Ubuntu-2ubuntu122.04, mixed mode, sharing)
dna@dna:~$ mvn --version Apache Maven 3.6.3 Maven home: /usr/share/maven Java version: 17.0.5, vendor: Private Build, runtime: /usr/lib/jvm/java-17-openjdk-amd64 Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "5.15.0-41-generic", arch: "amd64", family: "unix"
my pom.xml https://github.com/dhanyn10/tes-jejakin-be/blob/main/order/pom.xml im using Linux Mint 21 Cinnamon my error log: https://github.com/dhanyn10/tes-jejakin-be/actions/runs/3980299926/jobs/6823284040
pom.xml
What is the error you get? @dhanyn10
Blog post you are referring to
blog from url: https://rieckpil.de/mongodb-testcontainers-setup-for-datamongotest/
Your Question
im trying to make simple insert database testing, below is my test code
also already post question to stackoverflow https://stackoverflow.com/questions/75198138/how-to-keep-data-when-testing-insert-to-mongodb-collection-with-spring-inside-do
Context (Environment, Dependency Versions, Framework)
my
pom.xml
https://github.com/dhanyn10/tes-jejakin-be/blob/main/order/pom.xml im using Linux Mint 21 Cinnamon my error log: https://github.com/dhanyn10/tes-jejakin-be/actions/runs/3980299926/jobs/6823284040