diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 40135907..956f557d 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -10,7 +10,7 @@ jobs: strategy: fail-fast: false matrix: - versions: [8, 11, 17] + versions: [8, 11] runs-on: ubuntu-latest name: Build Java ${{ matrix.versions }} projects steps: diff --git a/buildGradleJdk8Projects.sh b/buildGradleJdk8Projects.sh deleted file mode 100755 index a1f93814..00000000 --- a/buildGradleJdk8Projects.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -set -e -set -o pipefail - -declare -a arr=("") - -for project in "${arr[@]}" -do - cd $project - - cd .. -done \ No newline at end of file diff --git a/buildJdk17Projects.sh b/buildJdk17Projects.sh deleted file mode 100644 index d15b0787..00000000 --- a/buildJdk17Projects.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -set -e -set -o pipefail - -declare -a arr=( - "serverless-java-aws-examples/java-aws-lambda-custom-image" - "launchdarkly-java-development-testing-hints" - "random-data-in-java-using-java-faker" - "testcontainers-introduction" - "maven-junit-paralellize-tests" -) - -for project in "${arr[@]}" -do - mvn -B -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=warn -f $project/pom.xml verify -done diff --git a/launchdarkly-java-development-testing-hints/pom.xml b/launchdarkly-java-development-testing-hints/pom.xml index 801bad1b..c84f9b6d 100644 --- a/launchdarkly-java-development-testing-hints/pom.xml +++ b/launchdarkly-java-development-testing-hints/pom.xml @@ -3,16 +3,17 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - de.rieckpil.blog + + de.rieckpil.blog + blog-parent + 0.0.1-SNAPSHOT + ../pom.xml + + launchdarkly-java-development-testing-hints 1.0-SNAPSHOT - 17 - 17 - UTF-8 - UTF-8 - 1.17.1 5.7.2 4.5.1 4.2.0 @@ -29,13 +30,6 @@ pom import - - org.testcontainers - testcontainers-bom - ${testcontainers.version} - pom - import - diff --git a/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/FeatureFlagClient.java b/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/FeatureFlagClient.java index c7574462..70bce5b6 100644 --- a/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/FeatureFlagClient.java +++ b/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/FeatureFlagClient.java @@ -3,5 +3,6 @@ public interface FeatureFlagClient { String getCurrentValue(String featureFlagKey, String username); - void registerChangeListener(String featureFlagKey, String username, FeatureFlagValueChangeHandler changeHandler); + void registerChangeListener( + String featureFlagKey, String username, FeatureFlagValueChangeHandler changeHandler); } diff --git a/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/FeatureFlagClientFactory.java b/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/FeatureFlagClientFactory.java index 1b310e98..81db8585 100644 --- a/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/FeatureFlagClientFactory.java +++ b/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/FeatureFlagClientFactory.java @@ -1,13 +1,12 @@ package de.rieckpil.blog; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - import com.launchdarkly.sdk.server.Components; import com.launchdarkly.sdk.server.LDClient; import com.launchdarkly.sdk.server.LDConfig; import com.launchdarkly.sdk.server.integrations.FileData; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; public class FeatureFlagClientFactory { @@ -16,26 +15,30 @@ public static FeatureFlagClient buildOnlineClient(String accessKey) { return new LaunchDarklyFeatureFlagClient(onlineClient); } -public static FeatureFlagClient buildOfflineFileBasedClient(String inMemoryFileLocation) { - Path localFeatureFlagStateFilePath = Paths.get(inMemoryFileLocation); - - if (Files.exists(localFeatureFlagStateFilePath)) { - LDClient fileBaseClient = new LDClient( - "invalid-ignored-access-key", - new LDConfig.Builder() - .dataSource( - FileData.dataSource().filePaths(localFeatureFlagStateFilePath).autoUpdate(true)) - .events(Components.noEvents()) - .build()); - - return new LaunchDarklyFeatureFlagClient(fileBaseClient); - } else { - return buildOfflineClient(); + public static FeatureFlagClient buildOfflineFileBasedClient(String inMemoryFileLocation) { + Path localFeatureFlagStateFilePath = Paths.get(inMemoryFileLocation); + + if (Files.exists(localFeatureFlagStateFilePath)) { + LDClient fileBaseClient = + new LDClient( + "invalid-ignored-access-key", + new LDConfig.Builder() + .dataSource( + FileData.dataSource() + .filePaths(localFeatureFlagStateFilePath) + .autoUpdate(true)) + .events(Components.noEvents()) + .build()); + + return new LaunchDarklyFeatureFlagClient(fileBaseClient); + } else { + return buildOfflineClient(); + } } -} -public static FeatureFlagClient buildOfflineClient() { - LDClient offlineClient = new LDClient("ignored-access-key", new LDConfig.Builder().offline(true).build()); - return new LaunchDarklyFeatureFlagClient(offlineClient); -} + public static FeatureFlagClient buildOfflineClient() { + LDClient offlineClient = + new LDClient("ignored-access-key", new LDConfig.Builder().offline(true).build()); + return new LaunchDarklyFeatureFlagClient(offlineClient); + } } diff --git a/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/LaunchDarklyFeatureFlagClient.java b/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/LaunchDarklyFeatureFlagClient.java index 35a45002..2cec8c01 100644 --- a/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/LaunchDarklyFeatureFlagClient.java +++ b/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/LaunchDarklyFeatureFlagClient.java @@ -13,13 +13,21 @@ public LaunchDarklyFeatureFlagClient(LDClient ldClient) { @Override public String getCurrentValue(String featureFlagKey, String username) { - return ldClient.stringVariation(featureFlagKey, new LDUser.Builder(username).build(), "unknown"); + return ldClient.stringVariation( + featureFlagKey, new LDUser.Builder(username).build(), "unknown"); } @Override - public void registerChangeListener(String featureFlagKey, String username, FeatureFlagValueChangeHandler changeHandler) { + public void registerChangeListener( + String featureFlagKey, String username, FeatureFlagValueChangeHandler changeHandler) { ldClient - .getFlagTracker() - .addFlagValueChangeListener(featureFlagKey, new LDUser.Builder(username).build(), (changeEvent) -> changeHandler.handle(changeEvent.getOldValue().stringValue(), changeEvent.getNewValue().stringValue())); + .getFlagTracker() + .addFlagValueChangeListener( + featureFlagKey, + new LDUser.Builder(username).build(), + (changeEvent) -> + changeHandler.handle( + changeEvent.getOldValue().stringValue(), + changeEvent.getNewValue().stringValue())); } } diff --git a/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/OrderService.java b/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/OrderService.java index f497f555..33921358 100644 --- a/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/OrderService.java +++ b/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/OrderService.java @@ -9,9 +9,9 @@ public OrderService(FeatureFlagClient featureFlagClient) { } public void processOrder(String orderId) { - if("plane".equals(featureFlagClient.getCurrentValue("primary-shipment-method", "duke"))) { + if ("plane".equals(featureFlagClient.getCurrentValue("primary-shipment-method", "duke"))) { // distribute via plane - }else { + } else { // different implementation } } diff --git a/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/RootLogLevelUpdater.java b/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/RootLogLevelUpdater.java index 54e372ff..f867784c 100644 --- a/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/RootLogLevelUpdater.java +++ b/launchdarkly-java-development-testing-hints/src/main/java/de/rieckpil/blog/RootLogLevelUpdater.java @@ -20,13 +20,12 @@ public void registerListener() { LOG.info("Going to register root log level updater"); featureFlagClient.registerChangeListener( - "root-log-level", - "duke", - (oldValue, newValue) -> { + "root-log-level", + "duke", + (oldValue, newValue) -> { + LOG.info("Going to change the root log level from '{}' to '{}'", oldValue, newValue); - LOG.info("Going to change the root log level from '{}' to '{}'", oldValue, newValue); - - Configurator.setRootLevel(Level.valueOf(newValue)); - }); + Configurator.setRootLevel(Level.valueOf(newValue)); + }); } } diff --git a/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/InMemoryFeatureFlagStoreTest.java b/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/InMemoryFeatureFlagStoreTest.java index c07aaedb..079f8b36 100644 --- a/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/InMemoryFeatureFlagStoreTest.java +++ b/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/InMemoryFeatureFlagStoreTest.java @@ -4,7 +4,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; - import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,8 +25,8 @@ public void initializeEmptyState() { try { JSONObject featureFlagState = new JSONObject().put("flagValues", new JSONObject()); Files.write( - featureFlagStateFile.toPath(), - featureFlagState.toString().getBytes(StandardCharsets.UTF_8)); + featureFlagStateFile.toPath(), + featureFlagState.toString().getBytes(StandardCharsets.UTF_8)); } catch (Exception exception) { LOG.error("Failed to initialize empty in-memory feature flag state", exception); } @@ -36,12 +35,12 @@ public void initializeEmptyState() { public void updateFeature(String featureFlagKey, Object featureFlagValue) { try { JSONObject featureFlagState = - new JSONObject() - .put("flagValues", new JSONObject().put(featureFlagKey, featureFlagValue)); + new JSONObject() + .put("flagValues", new JSONObject().put(featureFlagKey, featureFlagValue)); Files.write( - featureFlagStateFile.toPath(), - featureFlagState.toString().getBytes(StandardCharsets.UTF_8)); + featureFlagStateFile.toPath(), + featureFlagState.toString().getBytes(StandardCharsets.UTF_8)); } catch (Exception exception) { LOG.error("Failed to update in-memory feature flag state", exception); } @@ -51,4 +50,3 @@ public Path getPath() { return featureFlagStateFile.toPath(); } } - diff --git a/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/OrderServiceTest.java b/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/OrderServiceTest.java index 3f526110..720f22a5 100644 --- a/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/OrderServiceTest.java +++ b/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/OrderServiceTest.java @@ -1,32 +1,25 @@ package de.rieckpil.blog; +import static org.junit.jupiter.api.Assertions.*; +import static org.mockito.ArgumentMatchers.*; +import static org.mockito.Mockito.when; + import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; -import static org.junit.jupiter.api.Assertions.*; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.when; -import static org.mockito.Mockito.verify; - @ExtendWith(MockitoExtension.class) class OrderServiceTest { - @Mock - private FeatureFlagClient featureFlagClient; + @Mock private FeatureFlagClient featureFlagClient; - @InjectMocks - private OrderService orderService; + @InjectMocks private OrderService orderService; @Test void shouldDeliverViaPlaneWhenConfigured() { - when(featureFlagClient.getCurrentValue(anyString(), anyString())) - .thenReturn("plane"); + when(featureFlagClient.getCurrentValue(anyString(), anyString())).thenReturn("plane"); orderService.processOrder("42"); diff --git a/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/RootLogLevelUpdaterTest.java b/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/RootLogLevelUpdaterTest.java index 0f3af30d..272fb56f 100644 --- a/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/RootLogLevelUpdaterTest.java +++ b/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/RootLogLevelUpdaterTest.java @@ -1,16 +1,15 @@ package de.rieckpil.blog; -import java.util.concurrent.TimeUnit; +import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import java.util.concurrent.TimeUnit; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.awaitility.Awaitility.await; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotEquals; - class RootLogLevelUpdaterTest { private TestDataFeatureFlagClient testDataFeatureFlagClient; @@ -31,7 +30,7 @@ void shouldUpdateRootLogLevel() { testDataFeatureFlagClient.updateFeatureFlag("root-log-level", "TRACE"); await() - .atMost(2, TimeUnit.SECONDS) - .untilAsserted(() -> assertEquals(Level.TRACE, LogManager.getRootLogger().getLevel())); + .atMost(2, TimeUnit.SECONDS) + .untilAsserted(() -> assertEquals(Level.TRACE, LogManager.getRootLogger().getLevel())); } } diff --git a/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/TestDataFeatureFlagClient.java b/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/TestDataFeatureFlagClient.java index 8c79cd6f..363e30ff 100644 --- a/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/TestDataFeatureFlagClient.java +++ b/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/TestDataFeatureFlagClient.java @@ -14,21 +14,30 @@ public class TestDataFeatureFlagClient implements FeatureFlagClient { public TestDataFeatureFlagClient() { this.testData = TestData.dataSource(); - this.ldClient = new LDClient( - "ignored-access-key", - new LDConfig.Builder().dataSource(testData).events(Components.noEvents()).build()); + this.ldClient = + new LDClient( + "ignored-access-key", + new LDConfig.Builder().dataSource(testData).events(Components.noEvents()).build()); } @Override public String getCurrentValue(String featureFlagKey, String username) { - return ldClient.stringVariation(featureFlagKey, new LDUser.Builder(username).build(), "unknown"); + return ldClient.stringVariation( + featureFlagKey, new LDUser.Builder(username).build(), "unknown"); } @Override - public void registerChangeListener(String featureFlagKey, String username, FeatureFlagValueChangeHandler changeHandler) { + public void registerChangeListener( + String featureFlagKey, String username, FeatureFlagValueChangeHandler changeHandler) { ldClient - .getFlagTracker() - .addFlagValueChangeListener(featureFlagKey, new LDUser.Builder(username).build(), (changeEvent) -> changeHandler.handle(changeEvent.getOldValue().stringValue(), changeEvent.getNewValue().stringValue())); + .getFlagTracker() + .addFlagValueChangeListener( + featureFlagKey, + new LDUser.Builder(username).build(), + (changeEvent) -> + changeHandler.handle( + changeEvent.getOldValue().stringValue(), + changeEvent.getNewValue().stringValue())); } public void updateFeatureFlag(String featureFlag, String newValue) { diff --git a/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/TestDataFeatureFlagStoreTest.java b/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/TestDataFeatureFlagStoreTest.java index e7ab3e67..9b33d804 100644 --- a/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/TestDataFeatureFlagStoreTest.java +++ b/launchdarkly-java-development-testing-hints/src/test/java/de/rieckpil/blog/TestDataFeatureFlagStoreTest.java @@ -1,18 +1,17 @@ package de.rieckpil.blog; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; +import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.launchdarkly.sdk.LDValue; import com.launchdarkly.sdk.server.Components; import com.launchdarkly.sdk.server.LDClient; import com.launchdarkly.sdk.server.LDConfig; import com.launchdarkly.sdk.server.integrations.TestData; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.Test; -import static org.awaitility.Awaitility.await; -import static org.junit.jupiter.api.Assertions.assertEquals; - class TestDataFeatureFlagStoreTest { @Test @@ -22,31 +21,25 @@ void shouldUseTestDataFeatureFlagStore() { TestData testData = TestData.dataSource(); - testData.update( - testData - .flag("root-log-level") - .valueForAllUsers(LDValue.of("ERROR"))); + testData.update(testData.flag("root-log-level").valueForAllUsers(LDValue.of("ERROR"))); LaunchDarklyFeatureFlagClient cut = - new LaunchDarklyFeatureFlagClient( - new LDClient( - "ignored-access-key", - new LDConfig.Builder().dataSource(testData).events(Components.noEvents()).build())); + new LaunchDarklyFeatureFlagClient( + new LDClient( + "ignored-access-key", + new LDConfig.Builder().dataSource(testData).events(Components.noEvents()).build())); cut.registerChangeListener( - "root-log-level", - "duke", - (oldValue, newValue) -> { - countDownLatch.countDown(); - }); + "root-log-level", + "duke", + (oldValue, newValue) -> { + countDownLatch.countDown(); + }); - testData.update( - testData - .flag("root-log-level") - .valueForAllUsers(LDValue.of("DEBUG"))); + testData.update(testData.flag("root-log-level").valueForAllUsers(LDValue.of("DEBUG"))); await() - .atMost(5, TimeUnit.SECONDS) - .untilAsserted(() -> assertEquals(0, countDownLatch.getCount())); + .atMost(5, TimeUnit.SECONDS) + .untilAsserted(() -> assertEquals(0, countDownLatch.getCount())); } } diff --git a/maven-junit-paralellize-tests/pom.xml b/maven-junit-paralellize-tests/pom.xml index 2a4ab3a7..94e205a1 100644 --- a/maven-junit-paralellize-tests/pom.xml +++ b/maven-junit-paralellize-tests/pom.xml @@ -3,15 +3,17 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - de.rieckpil.blog + + de.rieckpil.blog + blog-parent + 0.0.1-SNAPSHOT + ../pom.xml + + maven-junit-paralellize-tests 1.0-SNAPSHOT - 17 - 17 - UTF-8 - UTF-8 5.9.0 diff --git a/maven-junit-paralellize-tests/src/test/java/de/rieckpil/blog/StringFormatterIT.java b/maven-junit-paralellize-tests/src/test/java/de/rieckpil/blog/StringFormatterIT.java index edcb1d0b..753cc92a 100644 --- a/maven-junit-paralellize-tests/src/test/java/de/rieckpil/blog/StringFormatterIT.java +++ b/maven-junit-paralellize-tests/src/test/java/de/rieckpil/blog/StringFormatterIT.java @@ -1,10 +1,10 @@ package de.rieckpil.blog; +import static org.junit.jupiter.api.Assertions.assertEquals; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; - class StringFormatterIT { private StringFormatter cut = new StringFormatter(); diff --git a/maven-junit-paralellize-tests/src/test/java/de/rieckpil/blog/StringFormatterTest.java b/maven-junit-paralellize-tests/src/test/java/de/rieckpil/blog/StringFormatterTest.java index a565294f..76ebacae 100644 --- a/maven-junit-paralellize-tests/src/test/java/de/rieckpil/blog/StringFormatterTest.java +++ b/maven-junit-paralellize-tests/src/test/java/de/rieckpil/blog/StringFormatterTest.java @@ -1,10 +1,10 @@ package de.rieckpil.blog; +import static org.junit.jupiter.api.Assertions.assertEquals; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import static org.junit.jupiter.api.Assertions.assertEquals; - class StringFormatterTest { private StringFormatter cut = new StringFormatter(); diff --git a/pom.xml b/pom.xml index f57d4d17..e5555042 100644 --- a/pom.xml +++ b/pom.xml @@ -75,6 +75,11 @@ testing-spring-rest-template azure-blob-storage-azurite-testing testing-libraries-overview + testcontainers-introduction + random-data-in-java-using-java-faker + launchdarkly-java-development-testing-hints + maven-junit-paralellize-tests + serverless-java-aws-examples/java-aws-lambda-custom-image diff --git a/random-data-in-java-using-java-faker/pom.xml b/random-data-in-java-using-java-faker/pom.xml index 2004caff..895e412a 100644 --- a/random-data-in-java-using-java-faker/pom.xml +++ b/random-data-in-java-using-java-faker/pom.xml @@ -4,22 +4,17 @@ 4.0.0 - org.springframework.boot - spring-boot-starter-parent - 2.7.0 - + de.rieckpil.blog + blog-parent + 0.0.1-SNAPSHOT + ../pom.xml - de.rieckpil.blog random-data-java-faker 0.0.1-SNAPSHOT random-data-java-faker Demo project for Spring Boot - - 17 - - org.springframework.boot diff --git a/random-data-in-java-using-java-faker/src/main/java/de/rieckpil/blog/Application.java b/random-data-in-java-using-java-faker/src/main/java/de/rieckpil/blog/Application.java index bd5e4c56..6511f3c1 100644 --- a/random-data-in-java-using-java-faker/src/main/java/de/rieckpil/blog/Application.java +++ b/random-data-in-java-using-java-faker/src/main/java/de/rieckpil/blog/Application.java @@ -9,5 +9,4 @@ public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } - } diff --git a/random-data-in-java-using-java-faker/src/main/java/de/rieckpil/blog/RandomDataEndpoint.java b/random-data-in-java-using-java-faker/src/main/java/de/rieckpil/blog/RandomDataEndpoint.java index 351c3c5a..ea3e3d26 100644 --- a/random-data-in-java-using-java-faker/src/main/java/de/rieckpil/blog/RandomDataEndpoint.java +++ b/random-data-in-java-using-java-faker/src/main/java/de/rieckpil/blog/RandomDataEndpoint.java @@ -3,13 +3,12 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; +import java.util.Locale; import net.datafaker.Faker; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -import java.util.Locale; - @RestController @RequestMapping("/random") public class RandomDataEndpoint { @@ -27,14 +26,16 @@ public JsonNode getRandomPersons() { ArrayNode persons = objectMapper.createArrayNode(); for (int i = 0; i < 10; i++) { - persons.add(objectMapper.createObjectNode() - .put("firstName", faker.name().firstName()) - .put("lastName", faker.name().lastName()) - .put("title", faker.name().title()) - .put("suffix", faker.name().suffix()) - .put("address", faker.address().streetAddress()) - .put("city", faker.address().cityName()) - .put("country", faker.address().country())); + persons.add( + objectMapper + .createObjectNode() + .put("firstName", faker.name().firstName()) + .put("lastName", faker.name().lastName()) + .put("title", faker.name().title()) + .put("suffix", faker.name().suffix()) + .put("address", faker.address().streetAddress()) + .put("city", faker.address().cityName()) + .put("country", faker.address().country())); } return persons; @@ -47,11 +48,13 @@ public JsonNode getRandomBook() { ArrayNode books = objectMapper.createArrayNode(); for (int i = 0; i < 10; i++) { - books.add(objectMapper.createObjectNode() - .put("author", faker.book().author()) - .put("genre", faker.book().genre()) - .put("publisher", faker.book().publisher()) - .put("title", faker.book().title())); + books.add( + objectMapper + .createObjectNode() + .put("author", faker.book().author()) + .put("genre", faker.book().genre()) + .put("publisher", faker.book().publisher()) + .put("title", faker.book().title())); } return books; @@ -64,10 +67,12 @@ public JsonNode getRandomFoods() { ArrayNode foods = objectMapper.createArrayNode(); for (int i = 0; i < 10; i++) { - foods.add(objectMapper.createObjectNode() - .put("ingredients", faker.food().ingredient()) - .put("spices", faker.food().spice()) - .put("measurements", faker.food().measurement())); + foods.add( + objectMapper + .createObjectNode() + .put("ingredients", faker.food().ingredient()) + .put("spices", faker.food().spice()) + .put("measurements", faker.food().measurement())); } return foods; diff --git a/random-data-in-java-using-java-faker/src/test/java/de/rieckpil/blog/ApplicationTest.java b/random-data-in-java-using-java-faker/src/test/java/de/rieckpil/blog/ApplicationTest.java index 0197f736..b277760f 100644 --- a/random-data-in-java-using-java-faker/src/test/java/de/rieckpil/blog/ApplicationTest.java +++ b/random-data-in-java-using-java-faker/src/test/java/de/rieckpil/blog/ApplicationTest.java @@ -8,29 +8,15 @@ @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) class ApplicationTest { - @Autowired - private WebTestClient webTestClient; + @Autowired private WebTestClient webTestClient; @Test void contextLoads() { - this.webTestClient - .get() - .uri("/random/persons") - .exchange() - .expectStatus().is2xxSuccessful(); + this.webTestClient.get().uri("/random/persons").exchange().expectStatus().is2xxSuccessful(); - this.webTestClient - .get() - .uri("/random/foods") - .exchange() - .expectStatus().is2xxSuccessful(); - - this.webTestClient - .get() - .uri("/random/books") - .exchange() - .expectStatus().is2xxSuccessful(); + this.webTestClient.get().uri("/random/foods").exchange().expectStatus().is2xxSuccessful(); + this.webTestClient.get().uri("/random/books").exchange().expectStatus().is2xxSuccessful(); } } diff --git a/serverless-java-aws-examples/java-aws-lambda-custom-image/pom.xml b/serverless-java-aws-examples/java-aws-lambda-custom-image/pom.xml index 9ef6ea7b..f0836e10 100644 --- a/serverless-java-aws-examples/java-aws-lambda-custom-image/pom.xml +++ b/serverless-java-aws-examples/java-aws-lambda-custom-image/pom.xml @@ -2,15 +2,18 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - de.rieckpil.blog + + de.rieckpil.blog + blog-parent + 0.0.1-SNAPSHOT + ../../pom.xml + + java-aws-lambda-custom-image 1.0.0 jar - 15 - 15 - UTF-8 1.0.0 diff --git a/serverless-java-aws-examples/java-aws-lambda-custom-image/src/main/java/de/rieckpil/blog/Java15Lambda.java b/serverless-java-aws-examples/java-aws-lambda-custom-image/src/main/java/de/rieckpil/blog/Java15Lambda.java index 1b1ec232..8340caf7 100644 --- a/serverless-java-aws-examples/java-aws-lambda-custom-image/src/main/java/de/rieckpil/blog/Java15Lambda.java +++ b/serverless-java-aws-examples/java-aws-lambda-custom-image/src/main/java/de/rieckpil/blog/Java15Lambda.java @@ -8,7 +8,8 @@ public class Java15Lambda implements RequestHandler { @Override public String handleRequest(Void input, Context context) { - var message = """ + var message = + """ Hello World! I'm using one of the latest language feature's of Java. @@ -18,7 +19,6 @@ public String handleRequest(Void input, Context context) { Duke """; - return message; } } diff --git a/serverless-java-aws-examples/java-aws-lambda-custom-image/src/test/java/de/rieckpil/blog/Java15LambdaTest.java b/serverless-java-aws-examples/java-aws-lambda-custom-image/src/test/java/de/rieckpil/blog/Java15LambdaTest.java index 7fbab03f..2262e3c5 100644 --- a/serverless-java-aws-examples/java-aws-lambda-custom-image/src/test/java/de/rieckpil/blog/Java15LambdaTest.java +++ b/serverless-java-aws-examples/java-aws-lambda-custom-image/src/test/java/de/rieckpil/blog/Java15LambdaTest.java @@ -1,9 +1,9 @@ package de.rieckpil.blog; -import org.junit.jupiter.api.Test; - import static org.junit.jupiter.api.Assertions.assertTrue; +import org.junit.jupiter.api.Test; + class Java15LambdaTest { private Java15Lambda cut = new Java15Lambda(); diff --git a/spring-boot-supabase/spring-boot-supabase/.mvn/wrapper/maven-wrapper.jar b/spring-boot-supabase/spring-boot-supabase/.mvn/wrapper/maven-wrapper.jar deleted file mode 100644 index bf82ff01..00000000 Binary files a/spring-boot-supabase/spring-boot-supabase/.mvn/wrapper/maven-wrapper.jar and /dev/null differ diff --git a/spring-boot-testing-masterclass/.gitignore b/spring-boot-testing-masterclass/.gitignore deleted file mode 100644 index a2a3040a..00000000 --- a/spring-boot-testing-masterclass/.gitignore +++ /dev/null @@ -1,31 +0,0 @@ -HELP.md -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/** -!**/src/test/** - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ - -### VS Code ### -.vscode/ diff --git a/spring-boot-testing-masterclass/pom.xml b/spring-boot-testing-masterclass/pom.xml deleted file mode 100644 index 22e6879e..00000000 --- a/spring-boot-testing-masterclass/pom.xml +++ /dev/null @@ -1,81 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.2.2.RELEASE - - - - de.rieckpil.blog - spring-boot-testing-masterclass - 0.0.1-SNAPSHOT - spring-boot-testing-masterclass - Demo project for Spring Boot - - - 11 - Hoxton.SR3 - - - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-web - - - org.flywaydb - flyway-core - - - - org.postgresql - postgresql - runtime - - - org.springframework.boot - spring-boot-starter-test - test - - - org.junit.vintage - junit-vintage-engine - - - - - org.springframework.cloud - spring-cloud-starter-contract-stub-runner - test - - - - - - - org.springframework.cloud - spring-cloud-dependencies - ${spring-cloud.version} - pom - import - - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/spring-boot-testing-masterclass/src/main/java/de/rieckpil/blog/SpringBootTestingMasterclassApplication.java b/spring-boot-testing-masterclass/src/main/java/de/rieckpil/blog/SpringBootTestingMasterclassApplication.java deleted file mode 100644 index 3b10e9e1..00000000 --- a/spring-boot-testing-masterclass/src/main/java/de/rieckpil/blog/SpringBootTestingMasterclassApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.rieckpil.blog; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class SpringBootTestingMasterclassApplication { - - public static void main(String[] args) { - SpringApplication.run(SpringBootTestingMasterclassApplication.class, args); - } - -} diff --git a/spring-boot-testing-masterclass/src/main/java/de/rieckpil/blog/pricing/PricingService.java b/spring-boot-testing-masterclass/src/main/java/de/rieckpil/blog/pricing/PricingService.java deleted file mode 100644 index a5d74499..00000000 --- a/spring-boot-testing-masterclass/src/main/java/de/rieckpil/blog/pricing/PricingService.java +++ /dev/null @@ -1,26 +0,0 @@ -package de.rieckpil.blog.pricing; - -import org.springframework.stereotype.Service; - -import java.math.BigDecimal; - -@Service -public class PricingService { - - private final ProductVerifier productVerifier; - private final ProductReporter productReporter; - - public PricingService(ProductVerifier productVerifier, ProductReporter productReporter) { - this.productVerifier = productVerifier; - this.productReporter = productReporter; - } - - public BigDecimal calculatePrice(String productName) { - if (productVerifier.isCurrentlyInStockOfCompetitor(productName)) { - productReporter.notify(productName); - return new BigDecimal("99.99"); - } - - return new BigDecimal("149.99"); - } -} diff --git a/spring-boot-testing-masterclass/src/main/java/de/rieckpil/blog/pricing/ProductReporter.java b/spring-boot-testing-masterclass/src/main/java/de/rieckpil/blog/pricing/ProductReporter.java deleted file mode 100644 index 5bdd30a4..00000000 --- a/spring-boot-testing-masterclass/src/main/java/de/rieckpil/blog/pricing/ProductReporter.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.rieckpil.blog.pricing; - -import org.springframework.stereotype.Service; - -@Service -public class ProductReporter { - - public void notify(String productName) { - System.out.println(productName + " is also in stock of the competitor"); - } -} diff --git a/spring-boot-testing-masterclass/src/main/java/de/rieckpil/blog/pricing/ProductVerifier.java b/spring-boot-testing-masterclass/src/main/java/de/rieckpil/blog/pricing/ProductVerifier.java deleted file mode 100644 index 777ca501..00000000 --- a/spring-boot-testing-masterclass/src/main/java/de/rieckpil/blog/pricing/ProductVerifier.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.rieckpil.blog.pricing; - -import org.springframework.stereotype.Service; - -@Service -public class ProductVerifier { - - public boolean isCurrentlyInStockOfCompetitor(String productName) { - return false; - } -} diff --git a/spring-boot-testing-masterclass/src/main/resources/application.properties b/spring-boot-testing-masterclass/src/main/resources/application.properties deleted file mode 100644 index 8b137891..00000000 --- a/spring-boot-testing-masterclass/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/spring-boot-testing-masterclass/src/test/java/de/rieckpil/blog/SpringBootTestingMasterclassApplicationTests.java b/spring-boot-testing-masterclass/src/test/java/de/rieckpil/blog/SpringBootTestingMasterclassApplicationTests.java deleted file mode 100644 index 63085455..00000000 --- a/spring-boot-testing-masterclass/src/test/java/de/rieckpil/blog/SpringBootTestingMasterclassApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package de.rieckpil.blog; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class SpringBootTestingMasterclassApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/spring-boot-testing-masterclass/src/test/java/de/rieckpil/blog/pricing/PricingServiceTest.java b/spring-boot-testing-masterclass/src/test/java/de/rieckpil/blog/pricing/PricingServiceTest.java deleted file mode 100644 index 90893a34..00000000 --- a/spring-boot-testing-masterclass/src/test/java/de/rieckpil/blog/pricing/PricingServiceTest.java +++ /dev/null @@ -1,30 +0,0 @@ -package de.rieckpil.blog.pricing; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.math.BigDecimal; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.Mockito.when; - -@ExtendWith(MockitoExtension.class) -public class PricingServiceTest { - - @Mock - private ProductVerifier mockedProductVerifier; - - @Mock - private ProductReporter mockedProductReporter; - - @Test - public void shouldReturnCheapPriceWhenProductIsInStockOfCompetitor() { - when(mockedProductVerifier.isCurrentlyInStockOfCompetitor("AirPods")).thenReturn(true); - - PricingService cut = new PricingService(mockedProductVerifier, mockedProductReporter); - - assertEquals(new BigDecimal("99.99"), cut.calculatePrice("AirPods")); - } -} diff --git a/testcontainers-introduction/pom.xml b/testcontainers-introduction/pom.xml index 80bd3fca..fcda893f 100644 --- a/testcontainers-introduction/pom.xml +++ b/testcontainers-introduction/pom.xml @@ -4,20 +4,15 @@ 4.0.0 - org.springframework.boot - spring-boot-starter-parent - 2.7.0 - + de.rieckpil.blog + blog-parent + 0.0.1-SNAPSHOT + ../pom.xml - de.rieckpil testcontainers-introduction 1.0-SNAPSHOT - - 17 - 1.17.3 - @@ -28,13 +23,6 @@ pom import - - org.testcontainers - testcontainers-bom - ${testcontainers.version} - pom - import - @@ -102,7 +90,6 @@ org.testcontainers testcontainers - 1.17.3 test diff --git a/testcontainers-introduction/src/test/java/de/rieckpil/blog/CommandExecutingExampleTest.java b/testcontainers-introduction/src/test/java/de/rieckpil/blog/CommandExecutingExampleTest.java index a57210cb..6c5ccec4 100644 --- a/testcontainers-introduction/src/test/java/de/rieckpil/blog/CommandExecutingExampleTest.java +++ b/testcontainers-introduction/src/test/java/de/rieckpil/blog/CommandExecutingExampleTest.java @@ -1,22 +1,22 @@ package de.rieckpil.blog; +import static org.assertj.core.api.Assertions.assertThat; + import org.junit.jupiter.api.Test; import org.testcontainers.containers.Container.ExecResult; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import static org.assertj.core.api.Assertions.assertThat; - @Testcontainers class CommandExecutingExampleTest { @Container static PostgreSQLContainer database = - new PostgreSQLContainer<>("postgres:14.0") - .withDatabaseName("test") - .withUsername("duke") - .withPassword("s3cret"); + new PostgreSQLContainer<>("postgres:14.0") + .withDatabaseName("test") + .withUsername("duke") + .withPassword("s3cret"); @Test void shouldExecuteCommand() throws Exception { diff --git a/testcontainers-introduction/src/test/java/de/rieckpil/blog/DatabaseExampleTest.java b/testcontainers-introduction/src/test/java/de/rieckpil/blog/DatabaseExampleTest.java index 339b27a0..179d8c88 100644 --- a/testcontainers-introduction/src/test/java/de/rieckpil/blog/DatabaseExampleTest.java +++ b/testcontainers-introduction/src/test/java/de/rieckpil/blog/DatabaseExampleTest.java @@ -1,32 +1,31 @@ package de.rieckpil.blog; +import static org.assertj.core.api.Assertions.assertThat; + import java.sql.Connection; import java.sql.DriverManager; - import org.junit.jupiter.api.Test; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import static org.assertj.core.api.Assertions.assertThat; - @Testcontainers class DatabaseExampleTest { @Container static PostgreSQLContainer database = - new PostgreSQLContainer<>("postgres:14.0") - .withDatabaseName("test") - .withUsername("duke") - .withPassword("s3cret"); + new PostgreSQLContainer<>("postgres:14.0") + .withDatabaseName("test") + .withUsername("duke") + .withPassword("s3cret"); @Test void shouldConnectToDatabase() throws Exception { - try (Connection connection = DriverManager - .getConnection(database.getJdbcUrl(), database.getUsername(), database.getPassword())) { + try (Connection connection = + DriverManager.getConnection( + database.getJdbcUrl(), database.getUsername(), database.getPassword())) { - assertThat(connection.getMetaData().getDatabaseProductName()) - .isEqualTo("PostgreSQL"); + assertThat(connection.getMetaData().getDatabaseProductName()).isEqualTo("PostgreSQL"); } } } diff --git a/testcontainers-introduction/src/test/java/de/rieckpil/blog/FileMountingExampleTest.java b/testcontainers-introduction/src/test/java/de/rieckpil/blog/FileMountingExampleTest.java index 926e5946..73987fbe 100644 --- a/testcontainers-introduction/src/test/java/de/rieckpil/blog/FileMountingExampleTest.java +++ b/testcontainers-introduction/src/test/java/de/rieckpil/blog/FileMountingExampleTest.java @@ -1,40 +1,40 @@ package de.rieckpil.blog; +import static org.assertj.core.api.Assertions.assertThat; + import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.Statement; - import org.junit.jupiter.api.Test; import org.testcontainers.containers.BindMode; import org.testcontainers.containers.PostgreSQLContainer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import static org.assertj.core.api.Assertions.assertThat; - @Testcontainers class FileMountingExampleTest { @Container static PostgreSQLContainer database = - new PostgreSQLContainer<>("postgres:14.0") - .withDatabaseName("test") - .withUsername("duke") - .withPassword("s3cret") - .withClasspathResourceMapping("/database-init", "/docker-entrypoint-initdb.d/", BindMode.READ_ONLY); + new PostgreSQLContainer<>("postgres:14.0") + .withDatabaseName("test") + .withUsername("duke") + .withPassword("s3cret") + .withClasspathResourceMapping( + "/database-init", "/docker-entrypoint-initdb.d/", BindMode.READ_ONLY); @Test void shouldConnectToDatabase() throws Exception { - try (Connection connection = DriverManager - .getConnection(database.getJdbcUrl(), database.getUsername(), database.getPassword())) { + try (Connection connection = + DriverManager.getConnection( + database.getJdbcUrl(), database.getUsername(), database.getPassword())) { Statement stmt = connection.createStatement(); ResultSet resultSet = stmt.executeQuery("SELECT * FROM orders"); while (resultSet.next()) { - assertThat(resultSet.getString(2)) - .isEqualTo("XYZ123"); + assertThat(resultSet.getString(2)).isEqualTo("XYZ123"); } } } diff --git a/testcontainers-introduction/src/test/java/de/rieckpil/blog/GenericContainerExampleTest.java b/testcontainers-introduction/src/test/java/de/rieckpil/blog/GenericContainerExampleTest.java index 9676546b..2d698701 100644 --- a/testcontainers-introduction/src/test/java/de/rieckpil/blog/GenericContainerExampleTest.java +++ b/testcontainers-introduction/src/test/java/de/rieckpil/blog/GenericContainerExampleTest.java @@ -1,24 +1,21 @@ package de.rieckpil.blog; +import static org.assertj.core.api.Assertions.assertThat; import org.junit.jupiter.api.Test; import org.testcontainers.containers.GenericContainer; import org.testcontainers.utility.DockerImageName; -import static org.assertj.core.api.Assertions.assertThat; - class GenericContainerExampleTest { - static GenericContainer nginx = - new GenericContainer<>(DockerImageName.parse("nginx:1.23.1")); + static GenericContainer nginx = new GenericContainer<>(DockerImageName.parse("nginx:1.23.1")); @Test void shouldStartContainer() { nginx.start(); // container is running - assertThat(nginx.isRunning()) - .isTrue(); + assertThat(nginx.isRunning()).isTrue(); nginx.stop(); } diff --git a/testcontainers-introduction/src/test/java/de/rieckpil/blog/GenericContainerInitializedExampleTest.java b/testcontainers-introduction/src/test/java/de/rieckpil/blog/GenericContainerInitializedExampleTest.java index 4a55c743..37278946 100644 --- a/testcontainers-introduction/src/test/java/de/rieckpil/blog/GenericContainerInitializedExampleTest.java +++ b/testcontainers-introduction/src/test/java/de/rieckpil/blog/GenericContainerInitializedExampleTest.java @@ -1,8 +1,9 @@ package de.rieckpil.blog; +import static org.assertj.core.api.Assertions.assertThat; + import java.sql.Connection; import java.sql.DriverManager; - import org.junit.jupiter.api.Test; import org.testcontainers.containers.GenericContainer; import org.testcontainers.containers.wait.strategy.Wait; @@ -10,30 +11,27 @@ import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.utility.DockerImageName; -import static org.assertj.core.api.Assertions.assertThat; - - @Testcontainers - class GenericContainerInitializedExampleTest { +@Testcontainers +class GenericContainerInitializedExampleTest { - @Container - static GenericContainer database = + @Container + static GenericContainer database = new GenericContainer<>(DockerImageName.parse("postgres:14.0")) - .withEnv("POSTGRES_PASSWORD", "secret") - .withEnv("POSTGRES_USER", "duke") - .withEnv("POSTGRES_DB", "test") - .withExposedPorts(5432) - .waitingFor(Wait.forListeningPort()); - - @Test - void shouldConnectToDatabase() throws Exception { - try (Connection connection = DriverManager - .getConnection("jdbc:postgresql://localhost:" + - database.getMappedPort(5432) + "/test", "duke", "secret")) { - - assertThat(connection.getMetaData().getDatabaseProductName()) - .isEqualTo("PostgreSQL"); - } + .withEnv("POSTGRES_PASSWORD", "secret") + .withEnv("POSTGRES_USER", "duke") + .withEnv("POSTGRES_DB", "test") + .withExposedPorts(5432) + .waitingFor(Wait.forListeningPort()); + + @Test + void shouldConnectToDatabase() throws Exception { + try (Connection connection = + DriverManager.getConnection( + "jdbc:postgresql://localhost:" + database.getMappedPort(5432) + "/test", + "duke", + "secret")) { + + assertThat(connection.getMetaData().getDatabaseProductName()).isEqualTo("PostgreSQL"); } } - - +} diff --git a/testcontainers-introduction/src/test/java/de/rieckpil/blog/ManualLifecycleExampleTest.java b/testcontainers-introduction/src/test/java/de/rieckpil/blog/ManualLifecycleExampleTest.java index ace7fd77..1bcbf0a2 100644 --- a/testcontainers-introduction/src/test/java/de/rieckpil/blog/ManualLifecycleExampleTest.java +++ b/testcontainers-introduction/src/test/java/de/rieckpil/blog/ManualLifecycleExampleTest.java @@ -1,31 +1,30 @@ package de.rieckpil.blog; +import static org.assertj.core.api.Assertions.assertThat; + import java.sql.Connection; import java.sql.DriverManager; - import org.junit.jupiter.api.Test; import org.testcontainers.containers.PostgreSQLContainer; -import org.testcontainers.junit.jupiter.Container; - -import static org.assertj.core.api.Assertions.assertThat; class ManualLifecycleExampleTest { - static PostgreSQLContainer database = new PostgreSQLContainer<>("postgres:14.0") - .withDatabaseName("test") - .withUsername("duke") - .withPassword("s3cret"); + static PostgreSQLContainer database = + new PostgreSQLContainer<>("postgres:14.0") + .withDatabaseName("test") + .withUsername("duke") + .withPassword("s3cret"); @Test void shouldConnectToDatabase() throws Exception { database.start(); - try (Connection connection = DriverManager - .getConnection(database.getJdbcUrl(), database.getUsername(), database.getPassword())) { + try (Connection connection = + DriverManager.getConnection( + database.getJdbcUrl(), database.getUsername(), database.getPassword())) { - assertThat(connection.getMetaData().getDatabaseProductName()) - .isEqualTo("PostgreSQL"); + assertThat(connection.getMetaData().getDatabaseProductName()).isEqualTo("PostgreSQL"); } database.stop(); diff --git a/testcontainers-introduction/src/test/java/de/rieckpil/blog/MockServerExampleTest.java b/testcontainers-introduction/src/test/java/de/rieckpil/blog/MockServerExampleTest.java index 1cfe93cf..f21aa210 100644 --- a/testcontainers-introduction/src/test/java/de/rieckpil/blog/MockServerExampleTest.java +++ b/testcontainers-introduction/src/test/java/de/rieckpil/blog/MockServerExampleTest.java @@ -1,13 +1,15 @@ package de.rieckpil.blog; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockserver.model.HttpRequest.request; +import static org.mockserver.model.HttpResponse.response; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; -import java.time.Duration; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; import org.junit.jupiter.api.Test; import org.mockserver.client.MockServerClient; import org.mockserver.model.MediaType; @@ -16,46 +18,42 @@ import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.utility.DockerImageName; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockserver.model.HttpRequest.request; -import static org.mockserver.model.HttpResponse.response; - @Testcontainers class MockServerExampleTest { @Container static MockServerContainer mockServer = - new MockServerContainer(DockerImageName.parse("mockserver/mockserver:5.14.0")); + new MockServerContainer(DockerImageName.parse("mockserver/mockserver:5.14.0")); - static final HttpClient httpClient = HttpClient.newBuilder() - .version(HttpClient.Version.HTTP_2) - .build(); + static final HttpClient httpClient = + HttpClient.newBuilder().version(HttpClient.Version.HTTP_2).build(); @Test void shouldStubHttpCall() throws Exception { new MockServerClient(mockServer.getHost(), mockServer.getServerPort()) - .when(request() - .withPath("/orders")) - .respond(response() - .withBody(""" + .when(request().withPath("/orders")) + .respond( + response() + .withBody( + """ [{ "orderId": 42, "customerId": "XYZ1445" }] - """, MediaType.APPLICATION_JSON_UTF_8)); + """, + MediaType.APPLICATION_JSON_UTF_8)); - HttpRequest request = HttpRequest.newBuilder() - .GET() - .uri(URI.create(mockServer.getEndpoint() + "/orders")) - .setHeader("Accept", "application/json") - .build(); + HttpRequest request = + HttpRequest.newBuilder() + .GET() + .uri(URI.create(mockServer.getEndpoint() + "/orders")) + .setHeader("Accept", "application/json") + .build(); - HttpResponse response = httpClient - .send(request, HttpResponse.BodyHandlers.ofString()); + HttpResponse response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); System.out.println("Response: " + response.body()); - assertThat(new ObjectMapper().readValue(response.body(), ArrayNode.class)) - .hasSize(1); + assertThat(new ObjectMapper().readValue(response.body(), ArrayNode.class)).hasSize(1); } } diff --git a/testcontainers-introduction/src/test/java/de/rieckpil/blog/PubSubExampleTest.java b/testcontainers-introduction/src/test/java/de/rieckpil/blog/PubSubExampleTest.java index 61f2c79c..6c290b8d 100644 --- a/testcontainers-introduction/src/test/java/de/rieckpil/blog/PubSubExampleTest.java +++ b/testcontainers-introduction/src/test/java/de/rieckpil/blog/PubSubExampleTest.java @@ -1,7 +1,7 @@ package de.rieckpil.blog; -import java.io.IOException; -import java.time.Duration; +import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await; import com.google.api.gax.core.NoCredentialsProvider; import com.google.api.gax.grpc.GrpcTransportChannel; @@ -25,6 +25,8 @@ import com.google.pubsub.v1.TopicName; import io.grpc.ManagedChannel; import io.grpc.ManagedChannelBuilder; +import java.io.IOException; +import java.time.Duration; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.testcontainers.containers.PubSubEmulatorContainer; @@ -32,16 +34,13 @@ import org.testcontainers.junit.jupiter.Testcontainers; import org.testcontainers.utility.DockerImageName; -import static org.assertj.core.api.Assertions.assertThat; -import static org.awaitility.Awaitility.await; - @Testcontainers class PubSubExampleTest { @Container static PubSubEmulatorContainer emulator = - new PubSubEmulatorContainer( - DockerImageName.parse("gcr.io/google.com/cloudsdktool/cloud-sdk:372.0.0-emulators")); + new PubSubEmulatorContainer( + DockerImageName.parse("gcr.io/google.com/cloudsdktool/cloud-sdk:372.0.0-emulators")); static final String PROJECT_ID = "test-project"; static final String TOPIC_ID = "sample-topic"; @@ -49,67 +48,81 @@ class PubSubExampleTest { @BeforeAll static void setupEmulator() throws Exception { - ManagedChannel channel = ManagedChannelBuilder.forTarget(emulator.getEmulatorEndpoint()).usePlaintext().build(); + ManagedChannel channel = + ManagedChannelBuilder.forTarget(emulator.getEmulatorEndpoint()).usePlaintext().build(); TransportChannelProvider channelProvider = - FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel)); + FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel)); NoCredentialsProvider credentialsProvider = NoCredentialsProvider.create(); createTopic(TOPIC_ID, channelProvider, credentialsProvider); createSubscription(SUBSCRIPTION_ID, TOPIC_ID, channelProvider, credentialsProvider); - } @Test void shouldPublishAndConsumeMessage() throws Exception { Publisher publisher = - Publisher.newBuilder(TopicName.of(PROJECT_ID, TOPIC_ID)) - .setChannelProvider(FixedTransportChannelProvider.create(GrpcTransportChannel.create(ManagedChannelBuilder.forTarget(emulator.getEmulatorEndpoint()).usePlaintext().build()))) - .setCredentialsProvider(NoCredentialsProvider.create()) - .build(); - - publisher - .publish(PubsubMessage.newBuilder().setData(ByteString.copyFromUtf8("Hello World!")) - .build()); + Publisher.newBuilder(TopicName.of(PROJECT_ID, TOPIC_ID)) + .setChannelProvider( + FixedTransportChannelProvider.create( + GrpcTransportChannel.create( + ManagedChannelBuilder.forTarget(emulator.getEmulatorEndpoint()) + .usePlaintext() + .build()))) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + + publisher.publish( + PubsubMessage.newBuilder().setData(ByteString.copyFromUtf8("Hello World!")).build()); SubscriberStubSettings subscriberStubSettings = - SubscriberStubSettings.newBuilder() - .setTransportChannelProvider(FixedTransportChannelProvider.create(GrpcTransportChannel.create(ManagedChannelBuilder.forTarget(emulator.getEmulatorEndpoint()).usePlaintext().build()))) - .setCredentialsProvider(NoCredentialsProvider.create()) - .build(); - - SubscriberStub subscriber = GrpcSubscriberStub - .create(subscriberStubSettings); + SubscriberStubSettings.newBuilder() + .setTransportChannelProvider( + FixedTransportChannelProvider.create( + GrpcTransportChannel.create( + ManagedChannelBuilder.forTarget(emulator.getEmulatorEndpoint()) + .usePlaintext() + .build()))) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + + SubscriberStub subscriber = GrpcSubscriberStub.create(subscriberStubSettings); PullRequest pullRequest = - PullRequest.newBuilder() - .setMaxMessages(1) - .setSubscription(ProjectSubscriptionName.format(PROJECT_ID, SUBSCRIPTION_ID)) - .build(); + PullRequest.newBuilder() + .setMaxMessages(1) + .setSubscription(ProjectSubscriptionName.format(PROJECT_ID, SUBSCRIPTION_ID)) + .build(); await() - .atMost(Duration.ofSeconds(3)) - .untilAsserted(() -> { - PullResponse pullResponse = subscriber.pullCallable().call(pullRequest); - - assertThat(pullResponse.getReceivedMessagesList()) - .hasSize(1); - - assertThat(pullResponse.getReceivedMessagesList().get(0).getMessage().getData().toStringUtf8()) - .isEqualTo("Hello World!"); - }); + .atMost(Duration.ofSeconds(3)) + .untilAsserted( + () -> { + PullResponse pullResponse = subscriber.pullCallable().call(pullRequest); + + assertThat(pullResponse.getReceivedMessagesList()).hasSize(1); + + assertThat( + pullResponse + .getReceivedMessagesList() + .get(0) + .getMessage() + .getData() + .toStringUtf8()) + .isEqualTo("Hello World!"); + }); } private static void createTopic( - String topicId, - TransportChannelProvider channelProvider, - NoCredentialsProvider credentialsProvider) - throws IOException { + String topicId, + TransportChannelProvider channelProvider, + NoCredentialsProvider credentialsProvider) + throws IOException { TopicAdminSettings topicAdminSettings = - TopicAdminSettings.newBuilder() - .setTransportChannelProvider(channelProvider) - .setCredentialsProvider(credentialsProvider) - .build(); + TopicAdminSettings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(credentialsProvider) + .build(); try (TopicAdminClient topicAdminClient = TopicAdminClient.create(topicAdminSettings)) { TopicName topicName = TopicName.of(PROJECT_ID, topicId); topicAdminClient.createTopic(topicName); @@ -119,28 +132,27 @@ private static void createTopic( } private static void createSubscription( - String subscriptionId, - String topicId, - TransportChannelProvider channelProvider, - NoCredentialsProvider credentialsProvider) - throws IOException { + String subscriptionId, + String topicId, + TransportChannelProvider channelProvider, + NoCredentialsProvider credentialsProvider) + throws IOException { SubscriptionAdminSettings subscriptionAdminSettings = - SubscriptionAdminSettings.newBuilder() - .setTransportChannelProvider(channelProvider) - .setCredentialsProvider(credentialsProvider) - .build(); + SubscriptionAdminSettings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(credentialsProvider) + .build(); SubscriptionAdminClient subscriptionAdminClient = - SubscriptionAdminClient.create(subscriptionAdminSettings); + SubscriptionAdminClient.create(subscriptionAdminSettings); ProjectSubscriptionName subscriptionName = - ProjectSubscriptionName.of(PROJECT_ID, subscriptionId); + ProjectSubscriptionName.of(PROJECT_ID, subscriptionId); try { subscriptionAdminClient.createSubscription( - subscriptionName, TopicName.of(PROJECT_ID, topicId), PushConfig.getDefaultInstance(), 10); + subscriptionName, TopicName.of(PROJECT_ID, topicId), PushConfig.getDefaultInstance(), 10); } catch (AlreadyExistsException e) { // The subscription already exists -- OK } } - } diff --git a/testcontainers-introduction/src/test/java/de/rieckpil/blog/SeleniumExampleTest.java b/testcontainers-introduction/src/test/java/de/rieckpil/blog/SeleniumExampleTest.java index 1817b364..056789b2 100644 --- a/testcontainers-introduction/src/test/java/de/rieckpil/blog/SeleniumExampleTest.java +++ b/testcontainers-introduction/src/test/java/de/rieckpil/blog/SeleniumExampleTest.java @@ -1,9 +1,13 @@ package de.rieckpil.blog; -import java.io.File; +import static com.codeborne.selenide.Selenide.$; +import static com.codeborne.selenide.Selenide.open; +import static com.codeborne.selenide.Selenide.screenshot; +import static org.assertj.core.api.Assertions.assertThat; import com.codeborne.selenide.Configuration; import com.codeborne.selenide.WebDriverRunner; +import java.io.File; import org.junit.jupiter.api.Test; import org.openqa.selenium.By; import org.openqa.selenium.chrome.ChromeOptions; @@ -12,21 +16,18 @@ import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import static com.codeborne.selenide.Selenide.$; -import static com.codeborne.selenide.Selenide.open; -import static com.codeborne.selenide.Selenide.screenshot; -import static org.assertj.core.api.Assertions.assertThat; - @Testcontainers class SeleniumExampleTest { @Container static BrowserWebDriverContainer webDriverContainer = - new BrowserWebDriverContainer<>() - .withRecordingMode(BrowserWebDriverContainer.VncRecordingMode.RECORD_ALL, new File("./target")) - .withCapabilities(new ChromeOptions() - .addArguments("--no-sandbox") - .addArguments("--disable-dev-shm-usage")); + new BrowserWebDriverContainer<>() + .withRecordingMode( + BrowserWebDriverContainer.VncRecordingMode.RECORD_ALL, new File("./target")) + .withCapabilities( + new ChromeOptions() + .addArguments("--no-sandbox") + .addArguments("--disable-dev-shm-usage")); @Test void shouldAccessHomePage() { @@ -43,7 +44,6 @@ void shouldAccessHomePage() { String h1Text = $(By.tagName("h1")).text(); - assertThat(h1Text) - .isNotNull(); + assertThat(h1Text).isNotNull(); } } diff --git a/whats-new-in-spring-boot-2.2/pom.xml b/whats-new-in-spring-boot-2.2/pom.xml index 2bcccdfd..fb0c0880 100644 --- a/whats-new-in-spring-boot-2.2/pom.xml +++ b/whats-new-in-spring-boot-2.2/pom.xml @@ -11,7 +11,7 @@ ../pom.xml - whats-new-in-spring-boot.2.2 + whats-new-in-spring-boot-2.2 0.0.1-SNAPSHOT whats-new-in-spring-boot-2.2 What's new in Spring Boot 2.2 diff --git a/whats-new-in-spring-boot-2.3/pom.xml b/whats-new-in-spring-boot-2.3/pom.xml index e75afed9..a99dd76e 100644 --- a/whats-new-in-spring-boot-2.3/pom.xml +++ b/whats-new-in-spring-boot-2.3/pom.xml @@ -10,7 +10,7 @@ ../pom.xml - whats-new-in-spring-boot-2-3 + whats-new-in-spring-boot-2.3 0.0.1-SNAPSHOT whats-new-in-spring-boot-2-3 Updates with Spring Boot 2.3