diff --git a/.github/ISSUE_TEMPLATE/issue_report.md b/.github/ISSUE_TEMPLATE/issue_report.md new file mode 100644 index 0000000000..4bc8c8121c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/issue_report.md @@ -0,0 +1,32 @@ +--- +name: Issue Report +about: Report an issue to help us improve +title: '[ISSUE] ' +--- + +**Article and Module Links** +A link to the affected article and the affected module. You can find the link to the module in the Conclusion section in the "on Github" standard phase. + +**Describe the Issue** +A clear and concise description of what the issue is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected Behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Environment (please complete the following information):** +- OS: [e.g. Windows] +- Browser [e.g. chrome, safari] +- Version [e.g. 22] + +**Additional Context** +Add any other context about the issue here. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000000..642f4c6707 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,11 @@ +# Contributing to Baeldung Tutorials +First off, thank you for considering contributing to Baeldung Tutorials. + +## Reporting Issues +Before you submit an issue, please review the guidelines below: + +1. **No Custom Modifications:** If your issue arises from any custom modifications you've made to the code in the repository, we won't be able to assist. We can only help if the issue is reproducible with the untouched codebase from this repo. If you're working with a modified version, consider asking for help on StackOverflow or other relevant forums. +2. **Use a clear and descriptive title** for the issue to identify the problem. +3. **Include a link to the article** you're having issues with. +4. **Describe the exact steps which reproduce the problem** in as many details as possible. +5. **Additional Details:** Offer any other context or descriptions that could be useful. Screenshots, error messages, copy/pasteable snippets, or logs can be immensely helpful. \ No newline at end of file diff --git a/apache-poi-3/README.md b/apache-poi-3/README.md new file mode 100644 index 0000000000..9e9d6a94eb --- /dev/null +++ b/apache-poi-3/README.md @@ -0,0 +1,3 @@ +## Relevant Articles +- [How To Convert Excel Data Into List Of Java Objects](https://www.baeldung.com/java-convert-excel-data-into-list) +- [Expand Columns with Apache POI](https://www.baeldung.com/java-apache-poi-expand-columns) diff --git a/apache-poi-3/pom.xml b/apache-poi-3/pom.xml index 5031e1c5c7..905db3d58c 100644 --- a/apache-poi-3/pom.xml +++ b/apache-poi-3/pom.xml @@ -24,10 +24,74 @@ poi-scratchpad ${poi.version} + + + com.github.ozlerhakan + poiji + ${poiji.version} + + + + + org.apache.poi + poi + ${poi.version} + + + + org.apache.poi + poi-ooxml-schemas + 4.1.2 + + + + org.apache.xmlbeans + xmlbeans + 5.1.1 + + + + org.apache.commons + commons-collections4 + 4.4 + + + + org.dhatim + fastexcel + ${fastexcel.version} + + + + org.dhatim + fastexcel-reader + ${fastexcel.version} + + + + net.sourceforge.jexcelapi + jxl + ${jxl.version} + + + + org.apache.logging.log4j + log4j-api + 2.17.1 + + + + org.apache.logging.log4j + log4j-core + 2.17.1 + 5.2.3 + 4.1.1 + 0.15.7 + 2.6.12 \ No newline at end of file diff --git a/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/FoodInfo.java b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/FoodInfo.java new file mode 100644 index 0000000000..b8fe4522de --- /dev/null +++ b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/FoodInfo.java @@ -0,0 +1,54 @@ +package com.baeldung.convert.exceldatatolist; + +import com.poiji.annotation.ExcelCellName; + +public class FoodInfo { + + @ExcelCellName("Category") + private String category; //food category + @ExcelCellName("Name") + private String name; // food name + @ExcelCellName("Measure") + private String measure; + @ExcelCellName("Calories") + private double calories; //amount of calories in kcal/measure + + @Override + public String toString() { + return "FoodInfo{" + "category='" + category + '\'' + ", name='" + name + '\'' + ", measure='" + measure + '\'' + ", calories=" + calories + "} \n"; + } + + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getMeasure() { + return measure; + } + + public void setMeasure(String measure) { + this.measure = measure; + } + + public double getCalories() { + return calories; + } + + public void setCalories(double calories) { + this.calories = calories; + } + +} diff --git a/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/fastexcel/ExcelDataToListOfObjectsFastExcel.java b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/fastexcel/ExcelDataToListOfObjectsFastExcel.java new file mode 100644 index 0000000000..87d31520e6 --- /dev/null +++ b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/fastexcel/ExcelDataToListOfObjectsFastExcel.java @@ -0,0 +1,42 @@ +package com.baeldung.convert.exceldatatolist.fastexcel; + +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.stream.Stream; + +import org.dhatim.fastexcel.reader.ReadableWorkbook; +import org.dhatim.fastexcel.reader.Row; +import org.dhatim.fastexcel.reader.Sheet; + +import com.baeldung.convert.exceldatatolist.FoodInfo; + +public class ExcelDataToListOfObjectsFastExcel { + public static List excelDataToListOfObjets_withFastExcel(String fileLocation)throws IOException, NumberFormatException { + List foodData = new ArrayList(); + + try (FileInputStream file = new FileInputStream(fileLocation); + ReadableWorkbook wb = new ReadableWorkbook(file)) { + Sheet sheet = wb.getFirstSheet(); + for (Row row: + sheet.read() + ) { + if(row.getRowNum() == 1) { + continue; + } + FoodInfo food = new FoodInfo(); + food.setCategory(row.getCellText(0)); + food.setName(row.getCellText(1)); + food.setMeasure(row.getCellText(2)); + food.setCalories(Double.parseDouble(row.getCellText(3))); + + foodData.add(food); + + } + } + + return foodData; + } +} diff --git a/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/jexcelapi/ExcelDataToListOfObjectsJxl.java b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/jexcelapi/ExcelDataToListOfObjectsJxl.java new file mode 100644 index 0000000000..61ba5e4700 --- /dev/null +++ b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/jexcelapi/ExcelDataToListOfObjectsJxl.java @@ -0,0 +1,37 @@ +package com.baeldung.convert.exceldatatolist.jexcelapi; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import com.baeldung.convert.exceldatatolist.FoodInfo; + +import jxl.Sheet; +import jxl.Workbook; +import jxl.read.biff.BiffException; + +public class ExcelDataToListOfObjectsJxl { + public static List excelDataToListOfObjets_withJxl(String fileLocation) throws IOException, BiffException { + + List foodData = new ArrayList(); + + Workbook workbook = Workbook.getWorkbook(new File(fileLocation)); + Sheet sheet = workbook.getSheet(0); + + int rows = sheet.getRows(); + + for (int i = 1; i < rows; i++) { + FoodInfo foodInfo = new FoodInfo(); + + foodInfo.setCategory(sheet.getCell(0, i).getContents()); + foodInfo.setName(sheet.getCell(1, i).getContents()); + foodInfo.setMeasure(sheet.getCell(2, i).getContents()); + foodInfo.setCalories(Double.parseDouble(sheet.getCell(3, i).getContents())); + + foodData.add(foodInfo); + + } + return foodData; + } +} diff --git a/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poi/ExcelDataToListApachePOI.java b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poi/ExcelDataToListApachePOI.java new file mode 100644 index 0000000000..8b568b889a --- /dev/null +++ b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poi/ExcelDataToListApachePOI.java @@ -0,0 +1,39 @@ +package com.baeldung.convert.exceldatatolist.poi; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.apache.poi.ss.usermodel.DataFormatter; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +import com.baeldung.convert.exceldatatolist.FoodInfo; + +public class ExcelDataToListApachePOI { + public static List excelDataToListOfObjets_withApachePOI(String fileLocation) throws IOException { + FileInputStream file = new FileInputStream(new File(fileLocation)); + Workbook workbook = new XSSFWorkbook(file); + Sheet sheet = workbook.getSheetAt(0); + List foodData = new ArrayList(); + DataFormatter dataFormatter = new DataFormatter(); + for (int n = 1; n < sheet.getPhysicalNumberOfRows(); n++) { + Row row = sheet.getRow(n); + FoodInfo foodInfo = new FoodInfo(); + int i = row.getFirstCellNum(); + + foodInfo.setCategory(dataFormatter.formatCellValue(row.getCell(i))); + foodInfo.setName(dataFormatter.formatCellValue(row.getCell(++i))); + foodInfo.setMeasure(dataFormatter.formatCellValue(row.getCell(++i))); + foodInfo.setCalories(Double.parseDouble(dataFormatter.formatCellValue(row.getCell(++i)))); + + foodData.add(foodInfo); + + } + return foodData; + } +} diff --git a/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poiji/ExcelDataToListOfObjectsPOIJI.java b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poiji/ExcelDataToListOfObjectsPOIJI.java new file mode 100644 index 0000000000..be190d38f7 --- /dev/null +++ b/apache-poi-3/src/main/java/com/baeldung/convert/exceldatatolist/poiji/ExcelDataToListOfObjectsPOIJI.java @@ -0,0 +1,13 @@ +package com.baeldung.convert.exceldatatolist.poiji; + +import java.io.File; +import java.util.List; + +import com.baeldung.convert.exceldatatolist.FoodInfo; +import com.poiji.bind.Poiji; + +public class ExcelDataToListOfObjectsPOIJI { + public static List excelDataToListOfObjets_withPOIJI(String fileLocation){ + return Poiji.fromExcel(new File(fileLocation), FoodInfo.class); + } +} diff --git a/apache-poi-3/src/main/resources/food_info.xls b/apache-poi-3/src/main/resources/food_info.xls new file mode 100644 index 0000000000..1377d8e18d Binary files /dev/null and b/apache-poi-3/src/main/resources/food_info.xls differ diff --git a/apache-poi-3/src/main/resources/food_info.xlsx b/apache-poi-3/src/main/resources/food_info.xlsx new file mode 100644 index 0000000000..c604ff367d Binary files /dev/null and b/apache-poi-3/src/main/resources/food_info.xlsx differ diff --git a/apache-poi-3/src/test/java/com/baeldung/convert/exceldatatolist/ExcelDataToListOfObjectsUnitTest.java b/apache-poi-3/src/test/java/com/baeldung/convert/exceldatatolist/ExcelDataToListOfObjectsUnitTest.java new file mode 100644 index 0000000000..5d65c04b31 --- /dev/null +++ b/apache-poi-3/src/test/java/com/baeldung/convert/exceldatatolist/ExcelDataToListOfObjectsUnitTest.java @@ -0,0 +1,53 @@ +package com.baeldung.convert.exceldatatolist; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.util.List; + +// import org.junit.jupiter.api.Test; +// import static org.junit.jupiter.api.Assertions.*; +import org.junit.Test; + +import com.baeldung.convert.exceldatatolist.fastexcel.ExcelDataToListOfObjectsFastExcel; +import com.baeldung.convert.exceldatatolist.jexcelapi.ExcelDataToListOfObjectsJxl; +import com.baeldung.convert.exceldatatolist.poi.ExcelDataToListApachePOI; +import com.baeldung.convert.exceldatatolist.poiji.ExcelDataToListOfObjectsPOIJI; + +import jxl.read.biff.BiffException; + +public class ExcelDataToListOfObjectsUnitTest { + + @Test + public void whenParsingExcelFileWithPOIJI_thenConvertsToList() throws IOException { + List foodInfoList = ExcelDataToListOfObjectsPOIJI.excelDataToListOfObjets_withPOIJI("src/main/resources/food_info.xlsx"); + + assertEquals("Beverages", foodInfoList.get(0).getCategory()); + assertEquals("Dairy", foodInfoList.get(3).getCategory()); + } + + @Test + public void whenParsingExcelFileWithApachePOI_thenConvertsToList() throws IOException { + List foodInfoList = ExcelDataToListApachePOI.excelDataToListOfObjets_withApachePOI("src/main/resources/food_info.xlsx"); + + assertEquals("Beverages", foodInfoList.get(0).getCategory()); + assertEquals("Dairy", foodInfoList.get(3).getCategory()); + } + + @Test + public void whenParsingExcelFileWithFastExcel_thenConvertsToList() throws IOException { + List foodInfoList = ExcelDataToListOfObjectsFastExcel.excelDataToListOfObjets_withFastExcel("src/main/resources/food_info.xlsx"); + + assertEquals("Beverages", foodInfoList.get(0).getCategory()); + assertEquals("Dairy", foodInfoList.get(3).getCategory()); + } + + @Test + public void whenParsingExcelFileWithJxl_thenConvertsToList() throws IOException, BiffException { + List foodInfoList = ExcelDataToListOfObjectsJxl.excelDataToListOfObjets_withJxl("src/main/resources/food_info.xls"); + + assertEquals("Beverages", foodInfoList.get(0).getCategory()); + assertEquals("Dairy", foodInfoList.get(3).getCategory()); + } + +} diff --git a/core-java-modules/core-java-16/README.md b/core-java-modules/core-java-16/README.md index b2740d194c..11b0fba8d3 100644 --- a/core-java-modules/core-java-16/README.md +++ b/core-java-modules/core-java-16/README.md @@ -5,3 +5,4 @@ - [Collecting Stream Elements into a List in Java](https://www.baeldung.com/java-stream-to-list-collecting) - [New Features in Java 16](https://www.baeldung.com/java-16-new-features) - [Guide to Java 8 groupingBy Collector](https://www.baeldung.com/java-groupingby-collector) +- [Value-Based Classes in Java](https://www.baeldung.com/java-value-based-classes) diff --git a/core-java-modules/core-java-21/README.md b/core-java-modules/core-java-21/README.md index 2e7130c906..2c51db275a 100644 --- a/core-java-modules/core-java-21/README.md +++ b/core-java-modules/core-java-21/README.md @@ -1,2 +1,3 @@ ## Relevant Articles - [Sequenced Collections in Java 21](https://www.baeldung.com/java-21-sequenced-collections) +- [String Templates in Java 21](https://www.baeldung.com/java-21-string-templates) diff --git a/core-java-modules/core-java-21/pom.xml b/core-java-modules/core-java-21/pom.xml index 83b2b1c858..7b8fa9063f 100644 --- a/core-java-modules/core-java-21/pom.xml +++ b/core-java-modules/core-java-21/pom.xml @@ -12,23 +12,36 @@ 0.0.1-SNAPSHOT - - - - - - - - - - - - + + 21 + 21 + UTF-8 + - - - - - + + + + org.apache.maven.plugins + maven-compiler-plugin + + 21 + 21 + + false + + --enable-preview + + + + + org.apache.maven.plugins + maven-surefire-plugin + + --enable-preview + + + + + \ No newline at end of file diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringCompositionTechniques.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringCompositionTechniques.java new file mode 100644 index 0000000000..7e66144f1c --- /dev/null +++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringCompositionTechniques.java @@ -0,0 +1,37 @@ +package com.baeldung.stringtemplates; + +import java.text.MessageFormat; + +public class StringCompositionTechniques { + String composeUsingPlus(String feelsLike, String temperature, String unit) { + return "Today's weather is " + feelsLike + ", with a temperature of " + temperature + " degrees " + unit; + } + + String composeUsingStringBuffer(String feelsLike, String temperature, String unit) { + return new StringBuffer().append("Today's weather is ") + .append(feelsLike) + .append(", with a temperature of ") + .append(temperature) + .append(" degrees ") + .append(unit) + .toString(); + } + + String composeUsingStringBuilder(String feelsLike, String temperature, String unit) { + return new StringBuilder().append("Today's weather is ") + .append(feelsLike) + .append(", with a temperature of ") + .append(temperature) + .append(" degrees ") + .append(unit) + .toString(); + } + + String composeUsingFormatters(String feelsLike, String temperature, String unit) { + return String.format("Today's weather is %s, with a temperature of %s degrees %s", feelsLike, temperature, unit); + } + + String composeUsingMessageFormatter(String feelsLike, String temperature, String unit) { + return MessageFormat.format("Today''s weather is {0}, with a temperature of {1} degrees {2}", feelsLike, temperature, unit); + } +} diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringTemplateExamples.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringTemplateExamples.java new file mode 100644 index 0000000000..0fb18a84e9 --- /dev/null +++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/stringtemplates/StringTemplateExamples.java @@ -0,0 +1,56 @@ +package com.baeldung.stringtemplates; + +import static java.lang.StringTemplate.RAW; +import static java.util.FormatProcessor.FMT; + +public class StringTemplateExamples { + String interpolationUsingSTRProcessor(String feelsLike, String temperature, String unit) { + return STR + . "Today's weather is \{ feelsLike }, with a temperature of \{ temperature } degrees \{ unit }" ; + } + + String interpolationOfJSONBlock(String feelsLike, String temperature, String unit) { + return STR + . """ + { + "feelsLike": "\{ feelsLike }", + "temperature": "\{ temperature }", + "unit": "\{ unit }" + } + """ ; + } + + String interpolationWithExpressions() { + return STR + . "Today's weather is \{ getFeelsLike() }, with a temperature of \{ getTemperature() } degrees \{ getUnit() }" ; + } + + String interpolationWithTemplates() { + StringTemplate str = RAW + . "Today's weather is \{ getFeelsLike() }, with a temperature of \{ getTemperature() } degrees \{ getUnit() }" ; + return STR.process(str); + } + + String interpolationOfJSONBlockWithFMT(String feelsLike, float temperature, String unit) { + return FMT + . """ + { + "feelsLike": "%1s\{ feelsLike }", + "temperature": "%2.2f\{ temperature }", + "unit": "%1s\{ unit }" + } + """ ; + } + + private String getFeelsLike() { + return "pleasant"; + } + + private String getTemperature() { + return "25"; + } + + private String getUnit() { + return "Celsius"; + } +} diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/Car.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/Car.java new file mode 100644 index 0000000000..8f51c03539 --- /dev/null +++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/Car.java @@ -0,0 +1,11 @@ +package com.baeldung.unnamed.variables; + +public record Car(String name, String color, T engine) { } + +abstract class Engine { } + +class GasEngine extends Engine { } + +class ElectricEngine extends Engine { } + +class HybridEngine extends Engine { } \ No newline at end of file diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedPatterns.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedPatterns.java new file mode 100644 index 0000000000..310ce621f9 --- /dev/null +++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedPatterns.java @@ -0,0 +1,50 @@ +package com.baeldung.unnamed.variables; + +public class UnnamedPatterns { + + static String getObjectsColorWithNamedPattern(Object object) { + if (object instanceof Car(String name, String color, Engine engine)) { + return color; + } + return "No color!"; + } + + static String getObjectsColorWithUnnamedPattern(Object object) { + if (object instanceof Car(_, String color, _)) { + return color; + } + return "No color!"; + } + + static String getObjectsColorWithSwitchAndNamedPattern(Object object) { + return switch (object) { + case Car(String name, String color, Engine engine) -> color; + default -> "No color!"; + }; + } + + static String getObjectsColorWithSwitchAndUnnamedPattern(Object object) { + return switch (object) { + case Car(_, String color, _) -> color; + default -> "No color!"; + }; + } + + static String getEngineTypeWithNamedPattern(Car car) { + return switch (car) { + case Car(String name, String color, GasEngine engine) -> "gas"; + case Car(String name, String color, ElectricEngine engine) -> "electric"; + case Car(String name, String color, HybridEngine engine) -> "hybrid"; + default -> "none"; + }; + } + + static String getEngineTypeWithUnnamedPattern(Car car) { + return switch (car) { + case Car(_, _, GasEngine _) -> "gas"; + case Car(_, _, ElectricEngine _) -> "electric"; + case Car(_, _, HybridEngine _) -> "hybrid"; + default -> "none"; + }; + } +} diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedVariables.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedVariables.java new file mode 100644 index 0000000000..82e76b40a4 --- /dev/null +++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamed/variables/UnnamedVariables.java @@ -0,0 +1,134 @@ +package com.baeldung.unnamed.variables; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Queue; + +class Transaction implements AutoCloseable { + + @Override + public void close() { + System.out.println("Closed!"); + } +} + +public class UnnamedVariables { + + static int countCarsOverLimitWithNamedVariable(Collection> cars, int limit) { + var total = 0; + var totalOverLimit = 0; + for (var car : cars) { + total++; + if (total > limit) { + totalOverLimit++; + // side effect + } + } + return totalOverLimit; + } + + static int countCarsOverLimitWithUnnamedVariable(Collection> cars, int limit) { + var total = 0; + var totalOverLimit = 0; + for (var _ : cars) { + total++; + if (total > limit) { + totalOverLimit++; + // side effect + } + } + return totalOverLimit; + } + + static void sendNotificationToCarsWithNamedVariable(Collection> cars) { + sendOneTimeNotification(); + for (int i = 0; i < cars.size(); i++) { + // Notify car + } + } + + static void sendNotificationToCarsWithUnnamedVariable(Collection> cars) { + for (int i = 0, _ = sendOneTimeNotification(); i < cars.size(); i++) { + // Notify car + } + } + + private static int sendOneTimeNotification() { + System.out.println("Sending one time notification!"); + return 1; + } + + static Car removeThreeCarsAndReturnFirstRemovedWithNamedVariables(Queue> cars) { + var x = cars.poll(); + var y = cars.poll(); + var z = cars.poll(); + return x; + } + + static Car removeThreeCarsAndReturnFirstRemovedWithUnnamedVariables(Queue> cars) { + var car = cars.poll(); + var _ = cars.poll(); + var _ = cars.poll(); + return car; + } + + static void handleCarExceptionWithNamedVariables(Car car) { + try { + someOperationThatFails(car); + } catch (IllegalStateException ex) { + System.out.println("Got an illegal state exception for: " + car.name()); + } catch (RuntimeException ex) { + System.out.println("Got a runtime exception!"); + } + } + + static void handleCarExceptionWithUnnamedVariables(Car car) { + try { + someOperationThatFails(car); + } catch (IllegalStateException | NumberFormatException _) { + System.out.println("Got an illegal state exception for: " + car.name()); + } catch (RuntimeException _) { + System.out.println("Got a runtime exception!"); + } + } + + static void obtainTransactionAndUpdateCarWithNamedVariables(Car car) { + try (var transaction = new Transaction()) { + updateCar(car); + } + } + + static void obtainTransactionAndUpdateCarWithUnnamedVariables(Car car) { + try (var _ = new Transaction()) { + updateCar(car); + } + } + + static void updateCar(Car car) { + // Some update logic + System.out.println("Car updated!"); + } + + static Map>> getCarsByFirstLetterWithNamedVariables(List> cars) { + Map>> carMap = new HashMap<>(); + cars.forEach(car -> + carMap.computeIfAbsent(car.name().substring(0, 1), firstLetter -> new ArrayList<>()).add(car) + ); + return carMap; + } + + static Map>> getCarsByFirstLetterWithUnnamedVariables(List> cars) { + Map>> carMap = new HashMap<>(); + cars.forEach(car -> + carMap.computeIfAbsent(car.name().substring(0, 1), _ -> new ArrayList<>()).add(car) + ); + return carMap; + } + + private static void someOperationThatFails(Car car) { + throw new IllegalStateException("Triggered exception for: " + car.name()); + } +} diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorld.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorld.java new file mode 100644 index 0000000000..bf0e2c96c2 --- /dev/null +++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorld.java @@ -0,0 +1,3 @@ +void main() { + System.out.println("Hello, World!"); +} diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldChild.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldChild.java new file mode 100644 index 0000000000..827be7c788 --- /dev/null +++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldChild.java @@ -0,0 +1,7 @@ +package com.baeldung.unnamedclasses; + +public class HelloWorldChild extends HelloWorldSuper { + void main() { + System.out.println("Hello, World!"); + } +} diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldSuper.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldSuper.java new file mode 100644 index 0000000000..59c88716a4 --- /dev/null +++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldSuper.java @@ -0,0 +1,7 @@ +package com.baeldung.unnamedclasses; + +public class HelloWorldSuper { + public static void main(String[] args) { + System.out.println("Hello from the superclass"); + } +} diff --git a/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldWithMethod.java b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldWithMethod.java new file mode 100644 index 0000000000..698516544e --- /dev/null +++ b/core-java-modules/core-java-21/src/main/java/com/baeldung/unnamedclasses/HelloWorldWithMethod.java @@ -0,0 +1,6 @@ +private String getMessage() { + return "Hello, World!"; +} +void main() { + System.out.println(getMessage()); +} diff --git a/core-java-modules/core-java-21/src/test/java/com.baeldung.stringtemplates/StringTemplatesUnitTest.java b/core-java-modules/core-java-21/src/test/java/com.baeldung.stringtemplates/StringTemplatesUnitTest.java new file mode 100644 index 0000000000..b9917cab18 --- /dev/null +++ b/core-java-modules/core-java-21/src/test/java/com.baeldung.stringtemplates/StringTemplatesUnitTest.java @@ -0,0 +1,67 @@ +package com.baeldung.stringtemplates; + +import org.junit.Assert; +import org.junit.Test; + +public class StringTemplatesUnitTest { + + @Test + public void whenStringConcat_thenReturnComposedString() { + StringCompositionTechniques stringCompositionTechniques = new StringCompositionTechniques(); + Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", stringCompositionTechniques.composeUsingPlus("pleasant", "25", "Celsius")); + } + + @Test + public void whenStringBuffer_thenReturnComposedString() { + StringCompositionTechniques stringCompositionTechniques = new StringCompositionTechniques(); + Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", stringCompositionTechniques.composeUsingStringBuffer("pleasant", "25", "Celsius")); + } + + @Test + public void whenStringBuilder_thenReturnComposedString() { + StringCompositionTechniques stringCompositionTechniques = new StringCompositionTechniques(); + Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", stringCompositionTechniques.composeUsingStringBuilder("pleasant", "25", "Celsius")); + } + + @Test + public void whenStringFormatter_thenReturnComposedFormattedString() { + StringCompositionTechniques stringCompositionTechniques = new StringCompositionTechniques(); + Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", stringCompositionTechniques.composeUsingFormatters("pleasant", "25", "Celsius")); + } + + @Test + public void whenMessageFormatter_thenReturnComposedFormattedString() { + StringCompositionTechniques stringCompositionTechniques = new StringCompositionTechniques(); + Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", stringCompositionTechniques.composeUsingMessageFormatter("pleasant", "25", "Celsius")); + } + + @Test + public void whenUsingStringTemplateSTR_thenReturnInterpolatedString() { + StringTemplateExamples templateExamples = new StringTemplateExamples(); + Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", templateExamples.interpolationUsingSTRProcessor("pleasant", "25", "Celsius")); + } + + @Test + public void whenUsingMultilineStringTemplateSTR_thenReturnInterpolatedString() { + StringTemplateExamples templateExamples = new StringTemplateExamples(); + Assert.assertEquals("{\n" + " \"feelsLike\": \"pleasant\",\n" + " \"temperature\": \"25\",\n" + " \"unit\": \"Celsius\"\n" + "}\n", templateExamples.interpolationOfJSONBlock("pleasant", "25", "Celsius")); + } + + @Test + public void whenUsingExpressionSTR_thenReturnInterpolatedString() { + StringTemplateExamples templateExamples = new StringTemplateExamples(); + Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", templateExamples.interpolationWithExpressions()); + } + + @Test + public void whenUsingExpressionRAW_thenReturnInterpolatedString() { + StringTemplateExamples templateExamples = new StringTemplateExamples(); + Assert.assertEquals("Today's weather is pleasant, with a temperature of 25 degrees Celsius", templateExamples.interpolationWithTemplates()); + } + + @Test + public void whenUsingExpressionFMT_thenReturnInterpolatedString() { + StringTemplateExamples templateExamples = new StringTemplateExamples(); + Assert.assertEquals("{\n" + " \"feelsLike\": \"pleasant\",\n" + " \"temperature\": \"25.86\",\n" + " \"unit\": \"Celsius\"\n" + "}\n", templateExamples.interpolationOfJSONBlockWithFMT("pleasant", 25.8636F, "Celsius")); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/CarScenario.java b/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/CarScenario.java new file mode 100644 index 0000000000..2acb83cdef --- /dev/null +++ b/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/CarScenario.java @@ -0,0 +1,13 @@ +package com.baeldung.unnamed.variables; + +import java.util.List; + +class CarScenario { + + protected final List> cars = List.of( + new Car<>("Mitsubishi", "blue", new GasEngine()), + new Car<>("Toyota", "red", new ElectricEngine()), + new Car<>("Jaguar", "white", new HybridEngine()) + ); + +} diff --git a/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedPatternsUnitTest.java b/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedPatternsUnitTest.java new file mode 100644 index 0000000000..9d860a201a --- /dev/null +++ b/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedPatternsUnitTest.java @@ -0,0 +1,44 @@ +package com.baeldung.unnamed.variables; + +import static com.baeldung.unnamed.variables.UnnamedPatterns.getEngineTypeWithNamedPattern; +import static com.baeldung.unnamed.variables.UnnamedPatterns.getEngineTypeWithUnnamedPattern; +import static com.baeldung.unnamed.variables.UnnamedPatterns.getObjectsColorWithNamedPattern; +import static com.baeldung.unnamed.variables.UnnamedPatterns.getObjectsColorWithSwitchAndNamedPattern; +import static com.baeldung.unnamed.variables.UnnamedPatterns.getObjectsColorWithSwitchAndUnnamedPattern; +import static com.baeldung.unnamed.variables.UnnamedPatterns.getObjectsColorWithUnnamedPattern; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +public class UnnamedPatternsUnitTest extends CarScenario { + + @Test + public void whenExtractingColorWithNamedPatterns_thenReturnBlue() { + assertEquals("blue", getObjectsColorWithNamedPattern(cars.get(0))); + } + + @Test + public void whenExtractingColorWithUnnamedPatterns_thenReturnBlue() { + assertEquals("blue", getObjectsColorWithUnnamedPattern(cars.get(0))); + } + + @Test + public void whenExtractingColorWithSwitchAndNamedPatterns_thenReturnBlue() { + assertEquals("blue", getObjectsColorWithSwitchAndNamedPattern(cars.get(0))); + } + + @Test + public void whenExtractingColorWithSwitchAndUnnamedPatterns_thenReturnBlue() { + assertEquals("blue", getObjectsColorWithSwitchAndUnnamedPattern(cars.get(0))); + } + + @Test + public void whenExtractingEngineTypeWithNamedPatterns_thenReturnGas() { + assertEquals("gas", getEngineTypeWithNamedPattern(cars.get(0))); + } + + @Test + public void whenExtractingEngineTypeWithUnnamedPatterns_thenReturnGas() { + assertEquals("gas", getEngineTypeWithUnnamedPattern(cars.get(0))); + } +} diff --git a/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedVariablesUnitTest.java b/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedVariablesUnitTest.java new file mode 100644 index 0000000000..094879c277 --- /dev/null +++ b/core-java-modules/core-java-21/src/test/java/com/baeldung/unnamed/variables/UnnamedVariablesUnitTest.java @@ -0,0 +1,93 @@ +package com.baeldung.unnamed.variables; + +import static com.baeldung.unnamed.variables.UnnamedVariables.countCarsOverLimitWithNamedVariable; +import static com.baeldung.unnamed.variables.UnnamedVariables.countCarsOverLimitWithUnnamedVariable; +import static com.baeldung.unnamed.variables.UnnamedVariables.getCarsByFirstLetterWithNamedVariables; +import static com.baeldung.unnamed.variables.UnnamedVariables.getCarsByFirstLetterWithUnnamedVariables; +import static com.baeldung.unnamed.variables.UnnamedVariables.handleCarExceptionWithNamedVariables; +import static com.baeldung.unnamed.variables.UnnamedVariables.handleCarExceptionWithUnnamedVariables; +import static com.baeldung.unnamed.variables.UnnamedVariables.obtainTransactionAndUpdateCarWithNamedVariables; +import static com.baeldung.unnamed.variables.UnnamedVariables.obtainTransactionAndUpdateCarWithUnnamedVariables; +import static com.baeldung.unnamed.variables.UnnamedVariables.removeThreeCarsAndReturnFirstRemovedWithNamedVariables; +import static com.baeldung.unnamed.variables.UnnamedVariables.removeThreeCarsAndReturnFirstRemovedWithUnnamedVariables; +import static com.baeldung.unnamed.variables.UnnamedVariables.sendNotificationToCarsWithNamedVariable; +import static com.baeldung.unnamed.variables.UnnamedVariables.sendNotificationToCarsWithUnnamedVariable; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.LinkedList; + +import org.junit.jupiter.api.Test; + +public class UnnamedVariablesUnitTest extends CarScenario { + + @Test + public void whenCountingCarsOverLimitWithNamedVariables_thenShouldReturnOne() { + assertEquals(1, countCarsOverLimitWithNamedVariable(cars, 2)); + } + + @Test + public void whenCountingCarsOverLimitWithUnnamedVariables_thenShouldReturnOne() { + assertEquals(1, countCarsOverLimitWithUnnamedVariable(cars, 2)); + } + + @Test + public void whenNotifyingCarsWithNamedVariables_thenShouldNotFail() { + assertDoesNotThrow(() -> sendNotificationToCarsWithNamedVariable(cars)); + } + + @Test + public void whenNotifyingCarsWithUnnamedVariables_thenShouldNotFail() { + assertDoesNotThrow(() -> sendNotificationToCarsWithUnnamedVariable(cars)); + } + + @Test + public void whenPollingCarsWithNamedVariables_thenReturnFirstOneAndEmptyQueue() { + var carQueue = new LinkedList<>(cars); + assertEquals("Mitsubishi", removeThreeCarsAndReturnFirstRemovedWithNamedVariables(carQueue).name()); + assertEquals(0, carQueue.size()); + } + + @Test + public void whenPollingCarsWithUnnamedVariables_thenReturnFirstOneAndEmptyQueue() { + var carQueue = new LinkedList<>(cars); + assertEquals("Mitsubishi", removeThreeCarsAndReturnFirstRemovedWithUnnamedVariables(carQueue).name()); + assertEquals(0, carQueue.size()); + } + + @Test + public void whenHandlingExceptionWithNamedVariables_thenNoExceptionIsThrown() { + assertDoesNotThrow(() -> handleCarExceptionWithNamedVariables(cars.get(0))); + } + + @Test + public void whenHandlingExceptionWithUnnamedVariables_thenNoExceptionIsThrown() { + assertDoesNotThrow(() -> handleCarExceptionWithUnnamedVariables(cars.get(0))); + } + + @Test + public void whenHandlingTransactionUpdateWithNamedVariables_thenNoExceptionIsThrown() { + assertDoesNotThrow(() -> obtainTransactionAndUpdateCarWithNamedVariables(cars.get(0))); + } + + @Test + public void whenHandlingTransactionUpdateWithUnnamedVariables_thenNoExceptionIsThrown() { + assertDoesNotThrow(() -> obtainTransactionAndUpdateCarWithUnnamedVariables(cars.get(0))); + } + + @Test + public void whenGettingCarsByFirstLetterWithNamedVariables_thenHaveThreeKeys() { + var carsByLetter = getCarsByFirstLetterWithNamedVariables(cars); + assertEquals(1, carsByLetter.get("M").size()); + assertEquals(1, carsByLetter.get("T").size()); + assertEquals(1, carsByLetter.get("J").size()); + } + + @Test + public void whenGettingCarsByFirstLetterWithUnnamedVariables_thenHaveThreeKeys() { + var carsByLetter = getCarsByFirstLetterWithUnnamedVariables(cars); + assertEquals(1, carsByLetter.get("M").size()); + assertEquals(1, carsByLetter.get("T").size()); + assertEquals(1, carsByLetter.get("J").size()); + } +} diff --git a/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/dateapi/JavaDurationUnitTest.java b/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/dateapi/JavaDurationUnitTest.java index be43fb609a..d1bd77776a 100644 --- a/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/dateapi/JavaDurationUnitTest.java +++ b/core-java-modules/core-java-8-datetime/src/test/java/com/baeldung/dateapi/JavaDurationUnitTest.java @@ -3,9 +3,11 @@ package com.baeldung.dateapi; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.Duration; import java.time.Instant; +import java.time.LocalDateTime; import java.time.LocalTime; import java.time.temporal.ChronoUnit; @@ -19,7 +21,7 @@ public class JavaDurationUnitTest { LocalTime finalTime = initialTime.plus(Duration.ofSeconds(30)); long seconds = Duration.between(initialTime, finalTime) - .getSeconds(); + .getSeconds(); assertThat(seconds).isEqualTo(30); } @@ -34,6 +36,22 @@ public class JavaDurationUnitTest { assertThat(seconds).isEqualTo(30); } + @Test + public void givenADuration_whenCallingisZeroAndisNegative_thenGetExpectedResult() { + LocalDateTime start = LocalDateTime.parse("2020-01-01T08:00:00"); + LocalDateTime end = LocalDateTime.parse("2020-01-01T12:00:00"); + assertFalse(Duration.between(start, end) + .isNegative()); + assertTrue(Duration.between(end, start) + .isNegative()); + + LocalDateTime theTime = LocalDateTime.parse("2023-09-09T08:00:00"); + assertTrue(Duration.between(theTime, theTime) + .isZero()); + assertFalse(Duration.between(theTime, theTime) + .isNegative()); + } + @Test public void test2() { Instant start = Instant.parse("2017-10-03T10:15:30.00Z"); @@ -53,17 +71,17 @@ public class JavaDurationUnitTest { assertEquals(1, fromMinutes.toHours()); assertEquals(120, duration.plusSeconds(60) - .getSeconds()); + .getSeconds()); assertEquals(30, duration.minusSeconds(30) - .getSeconds()); + .getSeconds()); assertEquals(120, duration.plus(60, ChronoUnit.SECONDS) - .getSeconds()); + .getSeconds()); assertEquals(30, duration.minus(30, ChronoUnit.SECONDS) - .getSeconds()); + .getSeconds()); Duration fromChar1 = Duration.parse("P1DT1H10M10.5S"); Duration fromChar2 = Duration.parse("PT10M"); } -} +} \ No newline at end of file diff --git a/core-java-modules/core-java-9-streams/README.md b/core-java-modules/core-java-9-streams/README.md index 0ad8500689..d9663e0858 100644 --- a/core-java-modules/core-java-9-streams/README.md +++ b/core-java-modules/core-java-9-streams/README.md @@ -4,3 +4,4 @@ This module contains articles about Java 9 streams ### Relevant Articles: - [How to Break from Java Stream forEach](https://www.baeldung.com/java-break-stream-foreach) +- [Creating Stream of Regex Matches](https://www.baeldung.com/java-stream-regex-matches) diff --git a/core-java-modules/core-java-arrays-guides/README.md b/core-java-modules/core-java-arrays-guides/README.md index 0af77980af..d8b0d126a1 100644 --- a/core-java-modules/core-java-arrays-guides/README.md +++ b/core-java-modules/core-java-arrays-guides/README.md @@ -9,3 +9,4 @@ This module contains complete guides about arrays in Java - [Guide to ArrayStoreException](https://www.baeldung.com/java-arraystoreexception) - [Creating a Generic Array in Java](https://www.baeldung.com/java-generic-array) - [Maximum Size of Java Arrays](https://www.baeldung.com/java-arrays-max-size) +- [Merge Two Arrays and Remove Duplicates in Java](https://www.baeldung.com/java-merge-two-arrays-delete-duplicates) diff --git a/core-java-modules/core-java-arrays-operations-advanced-2/README.md b/core-java-modules/core-java-arrays-operations-advanced-2/README.md new file mode 100644 index 0000000000..17ffa2562d --- /dev/null +++ b/core-java-modules/core-java-arrays-operations-advanced-2/README.md @@ -0,0 +1,2 @@ +## Relevant Articles +- [Find the Middle Element of an Array in Java](https://www.baeldung.com/java-array-middle-item) diff --git a/core-java-modules/core-java-arrays-operations-advanced/README.md b/core-java-modules/core-java-arrays-operations-advanced/README.md index 0647d89d16..b379958f37 100644 --- a/core-java-modules/core-java-arrays-operations-advanced/README.md +++ b/core-java-modules/core-java-arrays-operations-advanced/README.md @@ -14,4 +14,3 @@ This module contains articles about advanced operations on arrays in Java. They - [Slicing Arrays in Java](https://www.baeldung.com/java-slicing-arrays) - [Combining Two or More Byte Arrays](https://www.baeldung.com/java-concatenate-byte-arrays) - [Calculating the Sum of Two Arrays in Java](https://www.baeldung.com/java-sum-arrays-element-wise) -- [Find the Middle Element of an Array in Java](https://www.baeldung.com/java-array-middle-item) diff --git a/core-java-modules/core-java-char/src/test/java/com/baeldung/incrementchar/IncrementCharUnitTest.java b/core-java-modules/core-java-char/src/test/java/com/baeldung/incrementchar/IncrementCharUnitTest.java new file mode 100644 index 0000000000..7621e85762 --- /dev/null +++ b/core-java-modules/core-java-char/src/test/java/com/baeldung/incrementchar/IncrementCharUnitTest.java @@ -0,0 +1,29 @@ +package com.baeldung.incrementchar; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +class IncrementCharUnitTest { + @Test + void whenUsingForLoop_thenGenerateCharacters(){ + final List allCapitalCharacters = Arrays.asList('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); + List characters = new ArrayList<>(); + for (char character = 'A'; character <= 'Z'; character++) { + characters.add(character); + } + Assertions.assertEquals(characters, allCapitalCharacters); + } + + @Test + void whenUsingStreams_thenGenerateCharacters() { + final List allCapitalCharacters = Arrays.asList('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'); + final List characters = IntStream.rangeClosed('A', 'Z').mapToObj(c -> (char) c).collect(Collectors.toList()); + Assertions.assertEquals(characters, allCapitalCharacters); + } +} diff --git a/core-java-modules/core-java-collections-5/src/main/java/com/baeldung/skippingfirstelement/SkipFirstElementExample.java b/core-java-modules/core-java-collections-5/src/main/java/com/baeldung/skippingfirstelement/SkipFirstElementExample.java new file mode 100644 index 0000000000..86982486fa --- /dev/null +++ b/core-java-modules/core-java-collections-5/src/main/java/com/baeldung/skippingfirstelement/SkipFirstElementExample.java @@ -0,0 +1,126 @@ +package com.baeldung.skippingfirstelement; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +public class SkipFirstElementExample { + + private final List stringList = new ArrayList<>(); + private final Set stringSet = new HashSet<>(); + private final Map stringMap = new HashMap<>(); + + public SkipFirstElementExample() { + // Initializing a List + stringList.add("Monday"); + stringList.add("Tuesday"); + stringList.add("Wednesday"); + stringList.add("Thursday"); + stringList.add("Friday"); + stringList.add("Saturday"); + stringList.add("Sunday"); + // Initializing a Set + stringSet.add("Monday"); + stringSet.add("Tuesday"); + stringSet.add("Wednesday"); + stringSet.add("Thursday"); + stringSet.add("Friday"); + stringSet.add("Saturday"); + stringSet.add("Sunday"); + // Initializing a Map + stringMap.put("Monday", "The day when coffee is a life support system."); + stringMap.put("Tuesday", "The day you realize that Monday's optimism was a lie."); + stringMap.put("Wednesday", "Hump Day, or as it's known, the 'Is it Friday yet?' day."); + stringMap.put("Thursday", "The day that says, 'Hold my beer, Friday is coming!'"); + stringMap.put("Friday", "The golden child of the weekdays. The superhero of the workweek."); + stringMap.put("Saturday", "The day of rest? More like the day of 'What can I binge-watch next?'"); + stringMap.put("Sunday", "The day before you have to adult again."); + } + + void skippingFirstElementInListWithForLoop(List stringList) { + for (int i = 1; i < stringList.size(); i++) { + process(stringList.get(i)); + } + } + + void skippingFirstElementInListWithWhileLoop(List stringList) { + final Iterator iterator = stringList.iterator(); + if (iterator.hasNext()) { + iterator.next(); + } + while (iterator.hasNext()) { + process(iterator.next()); + } + } + + void skippingFirstElementInSetWithWhileLoop(Set stringSet) { + final Iterator iterator = stringSet.iterator(); + if (iterator.hasNext()) { + iterator.next(); + } + while (iterator.hasNext()) { + process(iterator.next()); + } + } + + void skippingFirstElementInListWithWhileLoopStoringFirstElement(List stringList) { + final Iterator iterator = stringList.iterator(); + String firstElement = null; + if (iterator.hasNext()) { + firstElement = iterator.next(); + } + while (iterator.hasNext()) { + process(iterator.next()); + // additional logic using fistElement + } + } + + void skippingFirstElementInMapWithStreamSkip(Map stringMap) { + stringMap.entrySet().stream().skip(1).forEach(this::process); + } + + void skippingFirstElementInListWithSubList(List stringList) { + for (final String element : stringList.subList(1, stringList.size())) { + process(element); + } + } + + void skippingFirstElementInListWithForLoopWithAdditionalCheck(List stringList) { + for (int i = 0; i < stringList.size(); i++) { + if (i == 0) { + // do something else + } else { + process(stringList.get(i)); + } + } + } + + void skippingFirstElementInListWithWhileLoopWithCounter(List stringList) { + int counter = 0; + while (counter < stringList.size()) { + if (counter != 0) { + process(stringList.get(counter)); + } + ++counter; + } + } + + void skippingFirstElementInListWithReduce(List stringList) { + stringList.stream().reduce((skip, element) -> { + process(element); + return element; + }); + } + + protected void process(String string) { + System.out.println(string); + } + protected void process(Entry mapEntry) { + System.out.println(mapEntry); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/SkipFirstElementExampleUnitTest.java b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/SkipFirstElementExampleUnitTest.java new file mode 100644 index 0000000000..9821b22ac7 --- /dev/null +++ b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/SkipFirstElementExampleUnitTest.java @@ -0,0 +1,122 @@ +package com.baeldung.skippingfirstelement; + +import static org.junit.jupiter.api.Assertions.*; + +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Stream; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.condition.EnabledForJreRange; +import org.junit.jupiter.api.condition.JRE; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; + +@EnabledForJreRange(min = JRE.JAVA_9) +class SkipFirstElementExampleUnitTest { + + private static TestableSkipFirstElement testableSkip = new TestableSkipFirstElement(); + + @BeforeEach + void setup() { + testableSkip.reset(); + } + + private static Stream listProvider() { + return Stream.of( + Arguments.of( + List.of("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"), + List.of("Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")) + ); + } + + private static Stream mapProvider() { + return Stream.of( + Arguments.of( + Map.of( + "Monday", "The day when coffee is a life support system.", + "Tuesday", "The day you realize that Monday's optimism was a lie.", + "Wednesday", "Hump Day, or as it's known, the 'Is it Friday yet?' day.", + "Thursday", "The day that says, 'Hold my beer, Friday is coming!'", + "Friday", "The golden child of the weekdays. The superhero of the workweek.", + "Saturday", "The day of rest? More like the day of 'What can I binge-watch next?'", + "Sunday", "The day before you have to adult again." + ) + ) + ); + } + + @ParameterizedTest + @MethodSource("listProvider") + void skippingFirstElementInListWithForLoop(List input, List expected) { + testableSkip.skippingFirstElementInListWithForLoop(input); + List actual = testableSkip.getResult(); + assertEquals(actual, expected); + } + + @ParameterizedTest + @MethodSource("listProvider") + void skippingFirstElementInListWithWhileLoop(List input, List expected) { + testableSkip.skippingFirstElementInListWithWhileLoop(input); + List actual = testableSkip.getResult(); + assertEquals(actual, expected); + } + + @ParameterizedTest + @MethodSource("listProvider") + void skippingFirstElementInSetWithWhileLoop(List input) { + testableSkip.skippingFirstElementInSetWithWhileLoop(new HashSet<>(input)); + Set actual = new HashSet<>(testableSkip.getResult()); + assertEquals(actual.size(), input.size() - 1); + } + + @ParameterizedTest + @MethodSource("listProvider") + void skippingFirstElementInListWithWhileLoopStoringFirstElement(List input, List expected) { + testableSkip.skippingFirstElementInListWithWhileLoopStoringFirstElement(input); + List actual = testableSkip.getResult(); + assertEquals(actual, expected); + } + + @ParameterizedTest + @MethodSource("mapProvider") + void skippingFirstElementInMapWithStreamSkip(Map input) { + testableSkip.skippingFirstElementInMapWithStreamSkip(input); + List actual = testableSkip.getResult(); + assertEquals(actual.size(), input.size() - 1); + } + + @ParameterizedTest + @MethodSource("listProvider") + void skippingFirstElementInListWithSubList(List input, List expected) { + testableSkip.skippingFirstElementInListWithSubList(input); + List actual = testableSkip.getResult(); + assertEquals(actual, expected); + } + + @ParameterizedTest + @MethodSource("listProvider") + void skippingFirstElementInListWithForLoopWithAdditionalCheck(List input, List expected) { + testableSkip.skippingFirstElementInListWithForLoopWithAdditionalCheck(input); + List actual = testableSkip.getResult(); + assertEquals(actual, expected); + } + + @ParameterizedTest + @MethodSource("listProvider") + void skippingFirstElementInListWithWhileLoopWithCounter(List input, List expected) { + testableSkip.skippingFirstElementInListWithWhileLoopWithCounter(input); + List actual = testableSkip.getResult(); + assertEquals(actual, expected); + } + + @ParameterizedTest + @MethodSource("listProvider") + void skippingFirstElementInListWithReduce(List input, List expected) { + testableSkip.skippingFirstElementInListWithReduce(input); + List actual = testableSkip.getResult(); + assertEquals(actual, expected); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkip.java b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkip.java new file mode 100644 index 0000000000..0e2f340485 --- /dev/null +++ b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkip.java @@ -0,0 +1,10 @@ +package com.baeldung.skippingfirstelement; + +import java.util.List; + +public interface TestableSkip { + + void reset(); + + List getResult(); +} diff --git a/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkipFirstElement.java b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkipFirstElement.java new file mode 100644 index 0000000000..99facb73ad --- /dev/null +++ b/core-java-modules/core-java-collections-5/src/test/java/com/baeldung/skippingfirstelement/TestableSkipFirstElement.java @@ -0,0 +1,37 @@ +package com.baeldung.skippingfirstelement; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map.Entry; + +public class TestableSkipFirstElement extends SkipFirstElementExample implements TestableSkip { + + + private List processedList = new ArrayList<>(); + private List> processedEntryList = new ArrayList<>(); + + @Override + public void process(String string) { + processedList.add(string); + } + + @Override + public void process(Entry stringEntry) { + processedEntryList.add(stringEntry); + } + + @Override + public void reset() { + processedList.clear(); + processedEntryList.clear(); + } + + @Override + public List getResult() { + if (!processedList.isEmpty()) + return processedList; + return processedEntryList; + } + + +} diff --git a/core-java-modules/core-java-collections-array-list-2/README.md b/core-java-modules/core-java-collections-array-list-2/README.md new file mode 100644 index 0000000000..dbf5c47edb --- /dev/null +++ b/core-java-modules/core-java-collections-array-list-2/README.md @@ -0,0 +1,6 @@ +## Core Java Collections ArrayList + +This module contains articles about the Java ArrayList collection + +### Relevant Articles: +- [Create an ArrayList with Multiple Object Types](https://www.baeldung.com/arraylist-with-multiple-object-types) diff --git a/core-java-modules/core-java-collections-array-list-2/pom.xml b/core-java-modules/core-java-collections-array-list-2/pom.xml new file mode 100644 index 0000000000..042f6e5bb5 --- /dev/null +++ b/core-java-modules/core-java-collections-array-list-2/pom.xml @@ -0,0 +1,32 @@ + + 4.0.0 + core-java-collections-array-list-2 + core-java-collections-array-list-2 + jar + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${maven-compiler-plugin.source} + ${maven-compiler-plugin.target} + + + + + + + 17 + 17 + + diff --git a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/AlternativeMultipeTypeList.java b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/AlternativeMultipeTypeList.java new file mode 100644 index 0000000000..5315147dff --- /dev/null +++ b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/AlternativeMultipeTypeList.java @@ -0,0 +1,51 @@ +package com.baeldung.list.multipleobjecttypes; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +import java.util.function.Predicate; + +public class AlternativeMultipeTypeList { + + public static void main(String[] args) { + // List of Parent Class + ArrayList myList = new ArrayList<>(); + myList.add(1.2); + myList.add(2); + myList.add(-3.5); + + // List of Interface type + ArrayList diffMapList = new ArrayList<>(); + diffMapList.add(new HashMap<>()); + diffMapList.add(new TreeMap<>()); + diffMapList.add(new LinkedHashMap<>()); + + // List of Custom Object + ArrayList objList = new ArrayList<>(); + objList.add(new CustomObject("String")); + objList.add(new CustomObject(2)); + + // List via Functional Interface + List dataList = new ArrayList<>(); + + Predicate myPredicate = inputData -> (inputData instanceof String || inputData instanceof Integer); + + UserFunctionalInterface myInterface = (listObj, data) -> { + if (myPredicate.test(data)) + listObj.add(data); + else + System.out.println("Skipping input as data not allowed for class: " + data.getClass() + .getSimpleName()); + return listObj; + }; + + myInterface.addToList(dataList, Integer.valueOf(2)); + myInterface.addToList(dataList, Double.valueOf(3.33)); + myInterface.addToList(dataList, "String Value"); + myInterface.printList(dataList); + } + +} diff --git a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/CustomObject.java b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/CustomObject.java new file mode 100644 index 0000000000..b3ac4ffddb --- /dev/null +++ b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/CustomObject.java @@ -0,0 +1,22 @@ +package com.baeldung.list.multipleobjecttypes; + +public class CustomObject { + String classData; + Integer intData; + + CustomObject(String classData) { + this.classData = classData; + } + + CustomObject(Integer intData) { + this.intData = intData; + } + + public String getClassData() { + return this.classData; + } + + public Integer getIntData() { + return this.intData; + } +} diff --git a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/MultipleObjectTypeArrayList.java b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/MultipleObjectTypeArrayList.java new file mode 100644 index 0000000000..c5740c5cf8 --- /dev/null +++ b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/MultipleObjectTypeArrayList.java @@ -0,0 +1,40 @@ +package com.baeldung.list.multipleobjecttypes; + +import java.math.BigInteger; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class MultipleObjectTypeArrayList { + + public static void main(String[] args) { + + ArrayList multiTypeList = new ArrayList<>(); + + multiTypeList.add(Integer.valueOf(10)); + multiTypeList.add(Double.valueOf(11.5)); + multiTypeList.add("String Data"); + multiTypeList.add(Arrays.asList(1, 2, 3)); + multiTypeList.add(new CustomObject("Class Data")); + multiTypeList.add(BigInteger.valueOf(123456789)); + multiTypeList.add(LocalDate.of(2023, 9, 19)); + + for (Object dataObj : multiTypeList) { + if (dataObj instanceof Integer intData) + System.out.println("Integer Data : " + intData); + else if (dataObj instanceof Double doubleData) + System.out.println("Double Data : " + doubleData); + else if (dataObj instanceof String stringData) + System.out.println("String Data : " + stringData); + else if (dataObj instanceof List intList) + System.out.println("List Data : " + intList); + else if (dataObj instanceof CustomObject customObj) + System.out.println("CustomObject Data : " + customObj.getClassData()); + else if (dataObj instanceof BigInteger bigIntData) + System.out.println("BigInteger Data : " + bigIntData); + else if (dataObj instanceof LocalDate localDate) + System.out.println("LocalDate Data : " + localDate.toString()); + } + } +} diff --git a/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/UserFunctionalInterface.java b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/UserFunctionalInterface.java new file mode 100644 index 0000000000..6c0f8451da --- /dev/null +++ b/core-java-modules/core-java-collections-array-list-2/src/main/java/com/baeldung/list/multipleobjecttypes/UserFunctionalInterface.java @@ -0,0 +1,18 @@ +package com.baeldung.list.multipleobjecttypes; + +import java.util.List; + +@FunctionalInterface +public interface UserFunctionalInterface { + + List addToList(List list, Object data); + + default void printList(List dataList) { + for (Object data : dataList) { + if (data instanceof String stringData) + System.out.println("String Data: " + stringData); + if (data instanceof Integer intData) + System.out.println("Integer Data: " + intData); + } + } +} diff --git a/core-java-modules/core-java-collections-conversions-3/README.md b/core-java-modules/core-java-collections-conversions-3/README.md new file mode 100644 index 0000000000..f89cd199ff --- /dev/null +++ b/core-java-modules/core-java-collections-conversions-3/README.md @@ -0,0 +1,5 @@ +## Java Collections Cookbooks and Examples + +This module contains articles about conversions among Collection types in Java. + +### Relevant Articles: diff --git a/core-java-modules/core-java-collections-conversions-3/pom.xml b/core-java-modules/core-java-collections-conversions-3/pom.xml new file mode 100644 index 0000000000..4813d33713 --- /dev/null +++ b/core-java-modules/core-java-collections-conversions-3/pom.xml @@ -0,0 +1,26 @@ + + + 4.0.0 + core-java-collections-conversions-3 + core-java-collections-conversions-3 + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + + + + core-java-collections-conversions-3 + + + src/main/resources + true + + + + + \ No newline at end of file diff --git a/core-java-modules/core-java-collections-conversions-3/src/main/java/com/baeldung/hashmaptoarraylist/HashMapToArrayListConverterUtils.java b/core-java-modules/core-java-collections-conversions-3/src/main/java/com/baeldung/hashmaptoarraylist/HashMapToArrayListConverterUtils.java new file mode 100644 index 0000000000..dd5cc1fe47 --- /dev/null +++ b/core-java-modules/core-java-collections-conversions-3/src/main/java/com/baeldung/hashmaptoarraylist/HashMapToArrayListConverterUtils.java @@ -0,0 +1,66 @@ +package com.baeldung.hashmaptoarraylist; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Maps.EntryTransformer; + +public class HashMapToArrayListConverterUtils { + + static ArrayList convertUsingConstructor(HashMap hashMap) { + if (hashMap == null) { + return null; + } + return new ArrayList(hashMap.values()); + } + + static ArrayList convertUsingAddAllMethod(HashMap hashMap) { + if (hashMap == null) { + return null; + } + + ArrayList arrayList = new ArrayList(hashMap.size()); + arrayList.addAll(hashMap.values()); + + return arrayList; + } + + static ArrayList convertUsingStreamApi(HashMap hashMap) { + if (hashMap == null) { + return null; + } + + return hashMap.values() + .stream() + .collect(Collectors.toCollection(ArrayList::new)); + } + + static ArrayList convertUsingForLoop(HashMap hashMap) { + if (hashMap == null) { + return null; + } + + ArrayList arrayList = new ArrayList(hashMap.size()); + for (Map.Entry entry : hashMap.entrySet()) { + arrayList.add(entry.getValue()); + } + + return arrayList; + } + + static public ArrayList convertUsingGuava(HashMap hashMap) { + if (hashMap == null) { + return null; + } + + EntryTransformer entryMapTransformer = (key, value) -> value; + + return Lists.newArrayList(Maps.transformEntries(hashMap, entryMapTransformer) + .values()); + } + +} diff --git a/core-java-modules/core-java-collections-conversions-3/src/test/java/com/baeldung/hashmaptoarraylist/HashMapToArrayListConverterUtilsUnitTest.java b/core-java-modules/core-java-collections-conversions-3/src/test/java/com/baeldung/hashmaptoarraylist/HashMapToArrayListConverterUtilsUnitTest.java new file mode 100644 index 0000000000..26a42e77c0 --- /dev/null +++ b/core-java-modules/core-java-collections-conversions-3/src/test/java/com/baeldung/hashmaptoarraylist/HashMapToArrayListConverterUtilsUnitTest.java @@ -0,0 +1,60 @@ +package com.baeldung.hashmaptoarraylist; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; + +import java.util.ArrayList; +import java.util.HashMap; + +import org.junit.Before; +import org.junit.Test; + +public class HashMapToArrayListConverterUtilsUnitTest { + + private HashMap hashMap; + + @Before + public void beforeEach() { + hashMap = new HashMap<>(); + hashMap.put(1, "AAA"); + hashMap.put(2, "BBB"); + hashMap.put(3, "CCC"); + hashMap.put(4, "DDD"); + } + + @Test + public void givenAHashMap_whenConvertUsingConstructor_thenReturnArrayList() { + ArrayList myList = HashMapToArrayListConverterUtils.convertUsingConstructor(hashMap); + + assertThat(hashMap.values(), containsInAnyOrder(myList.toArray())); + } + + @Test + public void givenAHashMap_whenConvertUsingAddAllMethod_thenReturnArrayList() { + ArrayList myList = HashMapToArrayListConverterUtils.convertUsingAddAllMethod(hashMap); + + assertThat(hashMap.values(), containsInAnyOrder(myList.toArray())); + } + + @Test + public void givenAHashMap_whenConvertUsingForLoop_thenReturnArrayList() { + ArrayList myList = HashMapToArrayListConverterUtils.convertUsingForLoop(hashMap); + + assertThat(hashMap.values(), containsInAnyOrder(myList.toArray())); + } + + @Test + public void givenAHashMap_whenConvertUsingStreamApi_thenReturnArrayList() { + ArrayList myList = HashMapToArrayListConverterUtils.convertUsingStreamApi(hashMap); + + assertThat(hashMap.values(), containsInAnyOrder(myList.toArray())); + } + + @Test + public void givenAHashMap_whenConvertUsingGuava_thenReturnArrayList() { + ArrayList myList = HashMapToArrayListConverterUtils.convertUsingGuava(hashMap); + + assertThat(hashMap.values(), containsInAnyOrder(myList.toArray())); + } + +} diff --git a/core-java-modules/core-java-collections-list-6/README.md b/core-java-modules/core-java-collections-list-6/README.md new file mode 100644 index 0000000000..fd162743dc --- /dev/null +++ b/core-java-modules/core-java-collections-list-6/README.md @@ -0,0 +1,2 @@ +## Relevant Articles +- [Check if a List Contains a String Element While Ignoring Case](https://www.baeldung.com/java-list-search-case-insensitive) diff --git a/core-java-modules/core-java-collections-list-6/pom.xml b/core-java-modules/core-java-collections-list-6/pom.xml new file mode 100644 index 0000000000..9bea6358c4 --- /dev/null +++ b/core-java-modules/core-java-collections-list-6/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + core-java-collections-list-6 + core-java-collections-list-6 + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + + \ No newline at end of file diff --git a/core-java-modules/core-java-collections-list-6/src/test/java/com/baeldung/lists/StringListCaseInsensitiveContainsUnitTest.java b/core-java-modules/core-java-collections-list-6/src/test/java/com/baeldung/lists/StringListCaseInsensitiveContainsUnitTest.java new file mode 100644 index 0000000000..51fafcca6b --- /dev/null +++ b/core-java-modules/core-java-collections-list-6/src/test/java/com/baeldung/lists/StringListCaseInsensitiveContainsUnitTest.java @@ -0,0 +1,44 @@ +package com.baeldung.lists; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import java.util.List; + +import org.junit.jupiter.api.Test; + +public class StringListCaseInsensitiveContainsUnitTest { + private final static List THE_LIST = List.of("Game of Thrones", "Forrest Gump", "American Beauty", "Pretty Woman", "Catch Me If You Can"); + + @Test + void whenUsingContains_thenGetExpectedResult() { + assertFalse(THE_LIST.contains("catch me if you can")); + } + + boolean ignoreCaseContainsForLoop(List list, String value) { + for (String e : list) { + if (value.equalsIgnoreCase(e)) + return true; + } + return false; + } + + @Test + void whenUsingIgnoreCaseContainsForLoop_thenGetExpectedResult() { + assertTrue(ignoreCaseContainsForLoop(THE_LIST, "CATCH me if you CAN")); + assertTrue(ignoreCaseContainsForLoop(THE_LIST, "game of thrones")); + assertFalse(ignoreCaseContainsForLoop(THE_LIST, "The Godfather")); + } + + @Test + void whenUsingIgnoreCaseContainsStream_thenGetExpectedResult() { + assertTrue(THE_LIST.stream() + .anyMatch(e -> e.equalsIgnoreCase("CATCH me if you CAN"))); + + assertTrue(THE_LIST.stream() + .anyMatch("game of thrones"::equalsIgnoreCase)); + + assertFalse(THE_LIST.stream() + .anyMatch("The Godfather"::equalsIgnoreCase)); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-collections-maps-6/src/test/com/baeldung/objecttomap/ObjectToMapUnitTest.java b/core-java-modules/core-java-collections-maps-6/src/test/com/baeldung/objecttomap/ObjectToMapUnitTest.java deleted file mode 100644 index 52c2fb2bea..0000000000 --- a/core-java-modules/core-java-collections-maps-6/src/test/com/baeldung/objecttomap/ObjectToMapUnitTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package java.com.baeldung.objecttomap; -import com.google.gson.Gson; -import org.junit.Assert; -import org.junit.Test; -import wiremock.com.fasterxml.jackson.core.type.TypeReference; -import wiremock.com.fasterxml.jackson.databind.ObjectMapper; -import wiremock.com.google.common.reflect.TypeToken; -import java.lang.reflect.Field; -import java.util.HashMap; -import java.util.Map; - -public class ObjectToMapUnitTest { - Employee employee = new Employee("John", 3000.0); - - @Test - public void givenJavaObject_whenUsingReflection_thenConvertToMap() throws IllegalAccessException { - Map map = convertUsingReflection(employee); - Assert.assertEquals(employee.getName(), map.get("name")); - Assert.assertEquals(employee.getSalary(), map.get("salary")); - } - - private Map convertUsingReflection(Object object) throws IllegalAccessException { - Map map = new HashMap<>(); - Field[] fields = object.getClass().getDeclaredFields(); - - for (Field field : fields) { - field.setAccessible(true); - map.put(field.getName(), field.get(object)); - } - - return map; - } - - @Test - public void givenJavaObject_whenUsingJackson_thenConvertToMap() { - ObjectMapper objectMapper = new ObjectMapper(); - Map map = objectMapper.convertValue(employee, new TypeReference>() {}); - Assert.assertEquals(employee.getName(), map.get("name")); - Assert.assertEquals(employee.getSalary(), map.get("salary")); - } - - @Test - public void givenJavaObject_whenUsingGson_thenConvertToMap() { - Gson gson = new Gson(); - String json = gson.toJson(employee); - Map map = gson.fromJson(json, new TypeToken>() {}.getType()); - Assert.assertEquals(employee.getName(), map.get("name")); - Assert.assertEquals(employee.getSalary(), map.get("salary")); - } - - private static class Employee { - private String name; - private Double salary; - - public Employee(String name, Double salary) { - this.name = name; - this.salary = salary; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public Double getSalary() { - return salary; - } - - public void setSalary(Double age) { - this.salary = salary; - } - } -} diff --git a/core-java-modules/core-java-collections-maps-6/src/test/java/com/baeldung/objecttomap/ObjectToMapUnitTest.java b/core-java-modules/core-java-collections-maps-6/src/test/java/com/baeldung/objecttomap/ObjectToMapUnitTest.java new file mode 100644 index 0000000000..e232121048 --- /dev/null +++ b/core-java-modules/core-java-collections-maps-6/src/test/java/com/baeldung/objecttomap/ObjectToMapUnitTest.java @@ -0,0 +1,128 @@ +package com.baeldung.objecttomap; + +import static org.junit.Assert.assertEquals; + +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.common.reflect.TypeToken; +import com.google.gson.Gson; +import org.junit.Test; +import java.lang.reflect.Field; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.SortedMap; +import java.util.TreeMap; +import java.util.stream.Collectors; + +public class ObjectToMapUnitTest { + Employee employee = new Employee("John", 3000.0); + + @Test + public void givenJavaObject_whenUsingReflection_thenConvertToMap() throws IllegalAccessException { + Map map = convertUsingReflection(employee); + assertEquals(employee.getName(), map.get("name")); + assertEquals(employee.getSalary(), map.get("salary")); + } + + private Map convertUsingReflection(Object object) throws IllegalAccessException { + Map map = new HashMap<>(); + Field[] fields = object.getClass().getDeclaredFields(); + + for (Field field : fields) { + field.setAccessible(true); + map.put(field.getName(), field.get(object)); + } + + return map; + } + + @Test + public void givenJavaObject_whenUsingJackson_thenConvertToMap() { + ObjectMapper objectMapper = new ObjectMapper(); + Map map = objectMapper.convertValue(employee, new TypeReference>() {}); + assertEquals(employee.getName(), map.get("name")); + assertEquals(employee.getSalary(), map.get("salary")); + } + + @Test + public void givenJavaObject_whenUsingGson_thenConvertToMap() { + Gson gson = new Gson(); + String json = gson.toJson(employee); + Map map = gson.fromJson(json, new TypeToken>() {}.getType()); + assertEquals(employee.getName(), map.get("name")); + assertEquals(employee.getSalary(), map.get("salary")); + } + + @Test + public void given_UnsortedMap_whenSortingByValueDescending_thenValuesAreInDescendingOrder() { + Map unsortedMap = new HashMap<>(); + unsortedMap.put("one", 1); + unsortedMap.put("three", 3); + unsortedMap.put("five", 5); + unsortedMap.put("two", 2); + unsortedMap.put("four", 4); + + Map sortedMap = sortMapByValueDescending(unsortedMap); + + assertEquals(5, sortedMap.size()); + final Iterator iterator = sortedMap.values().iterator(); + assertEquals(5, (int) iterator.next()); + assertEquals(4, (int) iterator.next()); + assertEquals(3, (int) iterator.next()); + assertEquals(2, (int) iterator.next()); + assertEquals(1, (int) iterator.next()); + } + + @Test + public void given_UnsortedMap_whenUsingTreeMap_thenKeysAreInDescendingOrder() { + SortedMap treeMap = new TreeMap<>(Comparator.reverseOrder()); + treeMap.put("one", 1); + treeMap.put("three", 3); + treeMap.put("five", 5); + treeMap.put("two", 2); + treeMap.put("four", 4); + + assertEquals(5, treeMap.size()); + final Iterator iterator = treeMap.keySet().iterator(); + assertEquals("two", iterator.next()); + assertEquals("three", iterator.next()); + assertEquals("one", iterator.next()); + assertEquals("four", iterator.next()); + assertEquals("five", iterator.next()); + } + + private static class Employee { + private String name; + private Double salary; + + public Employee(String name, Double salary) { + this.name = name; + this.salary = salary; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Double getSalary() { + return salary; + } + + public void setSalary(Double age) { + this.salary = salary; + } + } + + public static > Map sortMapByValueDescending(Map map) { + return map.entrySet().stream() + .sorted(Map.Entry.comparingByValue().reversed()) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new)); + } +} diff --git a/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/datetime/DateTimeFormatterUnitTest.java b/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/datetime/DateTimeFormatterUnitTest.java index 172882af2c..d5128c522e 100644 --- a/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/datetime/DateTimeFormatterUnitTest.java +++ b/core-java-modules/core-java-datetime-string/src/test/java/com/baeldung/datetime/DateTimeFormatterUnitTest.java @@ -96,7 +96,8 @@ public class DateTimeFormatterUnitTest { String newYorkDateTimePattern = "dd.MM.yyyy HH:mm z"; DateTimeFormatter newYorkDateFormatter = DateTimeFormatter.ofPattern(newYorkDateTimePattern); LocalDateTime summerDay = LocalDateTime.of(2016, 7, 31, 14, 15); - Assert.assertEquals("31.07.2016 14:15 EDT", newYorkDateFormatter.format(ZonedDateTime.of(summerDay, ZoneId.of("America/New_York")))); + Assert.assertEquals("31.07.2016 14:15 EDT", + newYorkDateFormatter.format(ZonedDateTime.of(summerDay, ZoneId.of("America/New_York")))); } @Test @@ -121,8 +122,10 @@ public class DateTimeFormatterUnitTest { @Test public void shouldPrintFormattedDateTimeWithPredefined() { Assert.assertEquals("2018-03-09", DateTimeFormatter.ISO_LOCAL_DATE.format(LocalDate.of(2018, 3, 9))); - Assert.assertEquals("2018-03-09-03:00", DateTimeFormatter.ISO_OFFSET_DATE.format(LocalDate.of(2018, 3, 9).atStartOfDay(ZoneId.of("UTC-3")))); - Assert.assertEquals("Fri, 9 Mar 2018 00:00:00 -0300", DateTimeFormatter.RFC_1123_DATE_TIME.format(LocalDate.of(2018, 3, 9).atStartOfDay(ZoneId.of("UTC-3")))); + Assert.assertEquals("2018-03-09-03:00", + DateTimeFormatter.ISO_OFFSET_DATE.format(LocalDate.of(2018, 3, 9).atStartOfDay(ZoneId.of("UTC-3")))); + Assert.assertEquals("Fri, 9 Mar 2018 00:00:00 -0300", + DateTimeFormatter.RFC_1123_DATE_TIME.format(LocalDate.of(2018, 3, 9).atStartOfDay(ZoneId.of("UTC-3")))); } @Test @@ -165,30 +168,62 @@ public class DateTimeFormatterUnitTest { public void shouldPrintFormattedZonedDateTime() { ZonedDateTime zonedDateTime = ZonedDateTime.of(2021, 02, 15, 0, 0, 0, 0, ZoneId.of("Europe/Paris")); String formattedZonedDateTime = DateTimeFormatter.ISO_INSTANT.format(zonedDateTime); - + Assert.assertEquals("2021-02-14T23:00:00Z", formattedZonedDateTime); } - + @Test(expected = UnsupportedTemporalTypeException.class) public void shouldExpectAnExceptionIfInputIsLocalDateTime() { DateTimeFormatter.ISO_INSTANT.format(LocalDate.now()); } - + @Test public void shouldParseZonedDateTime() { DateTimeFormatter formatter = DateTimeFormatter.ISO_INSTANT.withZone(ZoneId.systemDefault()); ZonedDateTime zonedDateTime = ZonedDateTime.parse("2021-10-01T05:06:20Z", formatter); - + Assert.assertEquals("2021-10-01T05:06:20Z", DateTimeFormatter.ISO_INSTANT.format(zonedDateTime)); } - + @Test(expected = DateTimeParseException.class) public void shouldExpectAnExceptionIfTimeZoneIsMissing() { ZonedDateTime zonedDateTime = ZonedDateTime.parse("2021-11-01T05:06:20Z", DateTimeFormatter.ISO_INSTANT); } - + @Test(expected = DateTimeParseException.class) public void shouldExpectAnExceptionIfSecondIsMissing() { ZonedDateTime zonedDateTime = ZonedDateTime.parse("2021-12-02T08:06Z", DateTimeFormatter.ISO_INSTANT); } + + @Test + public void testUSShortFormatting() { + LocalDate date = LocalDate.of(2023, 9, 18); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd, yy: EEE").withLocale(Locale.US); + String formattedDate = date.format(formatter); + Assert.assertEquals("Sep 18, 23: Mon", formattedDate); + } + + @Test + public void testUSFullFormatting() { + LocalDate date = LocalDate.of(2023, 9, 18); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM dd, yyyy: EEEE").withLocale(Locale.US); + String formattedDate = date.format(formatter); + Assert.assertEquals("September 18, 2023: Monday", formattedDate); + } + + @Test + public void testKoreanShortFormatting() { + LocalDate date = LocalDate.of(2023, 9, 18); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMM dd, yy: EEE").withLocale(Locale.KOREA); + String formattedDate = date.format(formatter); + Assert.assertEquals("9월 18, 23: 월", formattedDate); + } + + @Test + public void testKoreanFullFormatting() { + LocalDate date = LocalDate.of(2023, 9, 18); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM dd, yyyy: EEEE").withLocale(Locale.KOREA); + String formattedDate = date.format(formatter); + Assert.assertEquals("9월 18, 2023: 월요일", formattedDate); + } } diff --git a/core-java-modules/core-java-documentation/README.md b/core-java-modules/core-java-documentation/README.md index b66b9e8c05..972e76c165 100644 --- a/core-java-modules/core-java-documentation/README.md +++ b/core-java-modules/core-java-documentation/README.md @@ -3,4 +3,4 @@ ### Relevant Articles: - [Introduction to Javadoc](http://www.baeldung.com/javadoc) - +- [Code Snippets in Java API Documentation](https://www.baeldung.com/java-doc-code-snippets) diff --git a/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsExternalSnippet.java b/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsExternalSnippet.java new file mode 100644 index 0000000000..6cf27b7acc --- /dev/null +++ b/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsExternalSnippet.java @@ -0,0 +1,18 @@ +package com.baeldung.snippettag; + +/** + * + * External code snippet showing the loop process in binary search method. + * {@snippet class="BinarySearch" region="binary"} + * + * Time Zone + * {@snippet file="application.properties" region="zone"} + * + */ + +public class GreetingsExternalSnippet { + public void helloBinarySearch() { + System.out.println("Hi, it's great knowing that binary search uses a loop under the hood"); + } + +} diff --git a/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsHighlightTag.java b/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsHighlightTag.java new file mode 100644 index 0000000000..03f30e1ad2 --- /dev/null +++ b/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsHighlightTag.java @@ -0,0 +1,35 @@ +package com.baeldung.snippettag; + + +/** + * The code below shows a full highlighted line + * {@snippet : + * public void helloBaeldung() { + * System.out.println("Hello From Team Baeldung"); // @highlight + * } + * } + * + * highlighting a substring + * {@snippet : + * public void helloBaeldung() { + * System.out.println("Hello From Team Baeldung"); // @highlight substring="println" + * } + * } + * + * highlighting texts on multiple lines + * {@snippet : + * public void helloBaeldung() { + * System.out.println("Hello From Team Baeldung"); // @highlight region substring="println" + * String country = "USA"; + * System.out.println("Hello From Team " + country); // @end + * } + * } + * + */ + +public class GreetingsHighlightTag { + public void helloBaeldung() { + System.out.println("Hello From Team Baeldung"); + } + +} diff --git a/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsInlineSnippet.java b/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsInlineSnippet.java new file mode 100644 index 0000000000..71876eecf6 --- /dev/null +++ b/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsInlineSnippet.java @@ -0,0 +1,17 @@ +package com.baeldung.snippettag; + +/** + * The code below shows the content of {@code helloBaeldung()} method + * {@snippet : + * public void helloBaeldung() { + * System.out.println("Hello From Team Baeldung"); + * } + * } + */ + +public class GreetingsInlineSnippet { + public void helloBaeldung() { + System.out.println("Hello From Team Baeldung"); + } + +} diff --git a/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsReplaceAndLinkTag.java b/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsReplaceAndLinkTag.java new file mode 100644 index 0000000000..7f6f1b72f7 --- /dev/null +++ b/core-java-modules/core-java-documentation/src/main/java/com/baeldung/snippettag/GreetingsReplaceAndLinkTag.java @@ -0,0 +1,24 @@ +package com.baeldung.snippettag; + +/** + * + * Using the replace tag + * {@snippet : + * public void helloBaeldung() { + * System.out.println("Hello From Team Baeldung"); // @replace regex='".*"' replacement="..." + * } + * } + * Using the link tag + * {@snippet : + * public void helloBaeldung() { + * System.out.println("Hello From Team Baeldung"); // @link substring="System.out" target="System#out" + * } + * } + * + */ + +public class GreetingsReplaceAndLinkTag { + public void helloBaeldung() { + System.out.println("Hello From Team Baeldung"); + } +} diff --git a/core-java-modules/core-java-documentation/src/main/java/snippet-files/BinarySearch.java b/core-java-modules/core-java-documentation/src/main/java/snippet-files/BinarySearch.java new file mode 100644 index 0000000000..a5f6e565ac --- /dev/null +++ b/core-java-modules/core-java-documentation/src/main/java/snippet-files/BinarySearch.java @@ -0,0 +1,27 @@ + +public class BinarySearch { + + public int search(int[] list, int item) { + int index = Integer.MAX_VALUE; + int low = 0; + int high = list.length - 1; + // @start region="binary" + while (low <= high) { + int mid = high - low; + int guess = list[mid]; + if (guess == item) { + index = mid; + break; + } else if (guess > item) { + low = mid - 1; + } else { + low = mid + 1; + } + low++; + } + // @end region="binary" + + return index; + } + +} diff --git a/core-java-modules/core-java-documentation/src/main/java/snippet-files/application.properties b/core-java-modules/core-java-documentation/src/main/java/snippet-files/application.properties new file mode 100644 index 0000000000..a2aeefdb89 --- /dev/null +++ b/core-java-modules/core-java-documentation/src/main/java/snippet-files/application.properties @@ -0,0 +1,4 @@ +# @start region="zone" +local.timezone = GMT+1 +local.zip = 94123 +# @end region="zone" \ No newline at end of file diff --git a/core-java-modules/core-java-io-5/.gitignore b/core-java-modules/core-java-io-5/.gitignore new file mode 100644 index 0000000000..0c0cd871c5 --- /dev/null +++ b/core-java-modules/core-java-io-5/.gitignore @@ -0,0 +1,2 @@ +test-link* +0.* \ No newline at end of file diff --git a/core-java-modules/core-java-io-5/README.md b/core-java-modules/core-java-io-5/README.md new file mode 100644 index 0000000000..6072e0b6d9 --- /dev/null +++ b/core-java-modules/core-java-io-5/README.md @@ -0,0 +1,8 @@ +## Core Java IO + +This module contains articles about core Java input and output (IO) + +### Relevant Articles: + +- [[<-- Prev]](/core-java-modules/core-java-io-4) + diff --git a/core-java-modules/core-java-io-5/pom.xml b/core-java-modules/core-java-io-5/pom.xml new file mode 100644 index 0000000000..11116b071c --- /dev/null +++ b/core-java-modules/core-java-io-5/pom.xml @@ -0,0 +1,66 @@ + + + 4.0.0 + core-java-io-5 + core-java-io-5 + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + + + + + + org.apache.tika + tika-core + ${tika.version} + + + net.sf.jmimemagic + jmimemagic + ${jmime-magic.version} + + + org.jodd + jodd-util + ${jodd-util.version} + + + com.j256.simplemagic + simplemagic + ${simplemagic.version} + + + + + core-java-io-5 + + + src/main/resources + true + + + + + maven-compiler-plugin + + 11 + 11 + + + + + + + + 2.8.0 + 0.1.5 + 6.2.1 + 1.17 + + \ No newline at end of file diff --git a/core-java-modules/core-java-io/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java b/core-java-modules/core-java-io-5/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java similarity index 94% rename from core-java-modules/core-java-io/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java rename to core-java-modules/core-java-io-5/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java index 2238cfcafa..6b1fd490a8 100644 --- a/core-java-modules/core-java-io/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java +++ b/core-java-modules/core-java-io-5/src/test/java/com/baeldung/extension/ExtensionFromMimeTypeUnitTest.java @@ -11,10 +11,8 @@ import java.util.Map; import java.util.Set; import org.apache.tika.mime.MimeTypeException; - -import org.junit.Test; - import com.j256.simplemagic.ContentType; +import org.junit.Test; public class ExtensionFromMimeTypeUnitTest { private static final String IMAGE_JPEG_MIME_TYPE = "image/jpeg"; @@ -37,14 +35,14 @@ public class ExtensionFromMimeTypeUnitTest { } @Test - public void whenUsingMimetypesFileTypeMap_thenGetFileExtension() { + public void whenUsingSimpleMagic_thenGetFileExtension() { List expectedExtensions = Arrays.asList("jpeg", "jpg", "jpe"); String[] detectedExtensions = ContentType.fromMimeType(IMAGE_JPEG_MIME_TYPE).getFileExtensions(); assertThat(detectedExtensions).containsExactlyElementsOf(expectedExtensions); } @Test - public void whenUsingCustomLogic_thenGetFileExtension() { + public void whenUsingCustomMap_thenGetFileExtension() { Map> mimeExtensionsMap = new HashMap<>(); List expectedExtensions = Arrays.asList(".jpg", ".jpe", ".jpeg"); addMimeExtensions(mimeExtensionsMap, "image/jpeg", ".jpg"); diff --git a/core-java-modules/core-java-io-apis-2/README.md b/core-java-modules/core-java-io-apis-2/README.md index cc3c351afc..3ec3220424 100644 --- a/core-java-modules/core-java-io-apis-2/README.md +++ b/core-java-modules/core-java-io-apis-2/README.md @@ -7,3 +7,4 @@ This module contains articles about core Java input/output(IO) APIs. - [Get the Desktop Path in Java](https://www.baeldung.com/java-desktop-path) - [Check if a File Is Empty in Java](https://www.baeldung.com/java-check-file-empty) - [Converting Relative to Absolute Paths in Java](https://www.baeldung.com/java-from-relative-to-absolute-paths) +- [Detect EOF in Java](https://www.baeldung.com/java-file-detect-end-of-file) diff --git a/core-java-modules/core-java-io/pom.xml b/core-java-modules/core-java-io/pom.xml index 12e957a3ba..faeddafd81 100644 --- a/core-java-modules/core-java-io/pom.xml +++ b/core-java-modules/core-java-io/pom.xml @@ -43,17 +43,6 @@ ${angus-activation.version} test - - org.jodd - jodd-util - ${jodd-util.version} - - - com.j256.simplemagic - simplemagic - ${simplemagic.version} - - @@ -153,8 +142,6 @@ 4.4.2 2.1.2 2.0.1 - 6.2.1 - 1.17 \ No newline at end of file diff --git a/core-java-modules/core-java-lang-6/pom.xml b/core-java-modules/core-java-lang-6/pom.xml index 53ef36a898..6561c4fdcc 100644 --- a/core-java-modules/core-java-lang-6/pom.xml +++ b/core-java-modules/core-java-lang-6/pom.xml @@ -18,7 +18,11 @@ mapstruct ${mapstruct.version} - + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + diff --git a/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/Address.java b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/Address.java new file mode 100644 index 0000000000..e82a1018ce --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/Address.java @@ -0,0 +1,47 @@ +package com.baeldung.compareobjects; + +import java.util.Objects; + +public class Address { + private String streetAddress; + private String city; + private String postalCode; + + public Address(String streetAddress, String city, String postalCode) { + this.streetAddress = streetAddress; + this.city = city; + this.postalCode = postalCode; + } + + public String getStreetAddress() { + return streetAddress; + } + + public String getCity() { + return city; + } + + public String getPostalCode() { + return postalCode; + } + + @Override + public String toString() { + return "Address{" + "streetAddress='" + streetAddress + '\'' + ", city='" + city + '\'' + ", postalCode='" + postalCode + '\'' + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Address address = (Address) o; + return Objects.equals(streetAddress, address.streetAddress) && Objects.equals(city, address.city) && Objects.equals(postalCode, address.postalCode); + } + + @Override + public int hashCode() { + return Objects.hash(streetAddress, city, postalCode); + } +} diff --git a/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/Person.java b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/Person.java new file mode 100644 index 0000000000..6ba244ff17 --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/Person.java @@ -0,0 +1,58 @@ +package com.baeldung.compareobjects; + +import java.util.List; +import java.util.Objects; + +import org.apache.commons.lang3.builder.DiffExclude; + +public class Person { + private String firstName; + private String lastName; + private int age; + private List phoneNumbers; + @DiffExclude + private Address address; + + public Person(String firstName, String lastName, int age, List phoneNumbers, Address address) { + this.firstName = firstName; + this.lastName = lastName; + this.age = age; + this.phoneNumbers = phoneNumbers; + this.address = address; + } + + public String getFirstName() { + return firstName; + } + + public String getLastName() { + return lastName; + } + + public int getAge() { + return age; + } + + public List getPhoneNumbers() { + return phoneNumbers; + } + + public Address getAddress() { + return address; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + Person person = (Person) o; + return age == person.age && Objects.equals(firstName, person.firstName) && Objects.equals(lastName, person.lastName) && Objects.equals(phoneNumbers, person.phoneNumbers) && Objects.equals(address, person.address); + } + + @Override + public int hashCode() { + return Objects.hash(firstName, lastName, age, phoneNumbers, address); + } +} diff --git a/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PersonDiffBuilder.java b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PersonDiffBuilder.java new file mode 100644 index 0000000000..9e21f5d7c3 --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PersonDiffBuilder.java @@ -0,0 +1,32 @@ +package com.baeldung.compareobjects; + +import org.apache.commons.lang3.builder.DiffBuilder; +import org.apache.commons.lang3.builder.DiffResult; +import org.apache.commons.lang3.builder.ToStringStyle; + +public class PersonDiffBuilder { + public static DiffResult compare(Person first, Person second) { + DiffBuilder diffBuilder = new DiffBuilder(first, second, ToStringStyle.DEFAULT_STYLE).append("person", first.getFirstName(), second.getFirstName()) + .append("lastName", first.getLastName(), second.getLastName()) + .append("streetAddress", first.getAddress() + .getStreetAddress(), second.getAddress() + .getStreetAddress()) + .append("city", first.getAddress() + .getCity(), second.getAddress() + .getCity()) + .append("postalCode", first.getAddress() + .getPostalCode(), second.getAddress() + .getPostalCode()) + .append("age", first.getAge(), second.getAge()); + + for (int i = 0; i < first.getPhoneNumbers() + .size(); i++) { + diffBuilder.append("phoneNumbers[" + i + "].number", first.getPhoneNumbers() + .get(i) + .getNumber(), second.getPhoneNumbers() + .get(i) + .getNumber()); + } + return diffBuilder.build(); + } +} diff --git a/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PersonReflectionDiffBuilder.java b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PersonReflectionDiffBuilder.java new file mode 100644 index 0000000000..82081e7282 --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PersonReflectionDiffBuilder.java @@ -0,0 +1,11 @@ +package com.baeldung.compareobjects; + +import org.apache.commons.lang3.builder.DiffResult; +import org.apache.commons.lang3.builder.ReflectionDiffBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +public class PersonReflectionDiffBuilder { + public static DiffResult compare(Person first, Person second) { + return new ReflectionDiffBuilder<>(first, second, ToStringStyle.SHORT_PREFIX_STYLE).build(); + } +} diff --git a/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PhoneNumber.java b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PhoneNumber.java new file mode 100644 index 0000000000..4ab2b4a4bd --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/main/java/com/baeldung/compareobjects/PhoneNumber.java @@ -0,0 +1,43 @@ +package com.baeldung.compareobjects; + +import java.util.Objects; + +import org.apache.commons.lang3.builder.DiffExclude; + +public class PhoneNumber { + private String type; + private String number; + + public PhoneNumber(String type, String number) { + this.type = type; + this.number = number; + } + + public String getType() { + return type; + } + + public String getNumber() { + return number; + } + + @Override + public String toString() { + return "PhoneNumber{" + "type='" + type + '\'' + ", number='" + number + '\'' + '}'; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (o == null || getClass() != o.getClass()) + return false; + PhoneNumber that = (PhoneNumber) o; + return Objects.equals(number, that.number); + } + + @Override + public int hashCode() { + return Objects.hash(number); + } +} diff --git a/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/compareobjects/PersonDiffBuilderUnitTest.java b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/compareobjects/PersonDiffBuilderUnitTest.java new file mode 100644 index 0000000000..417e9da0ea --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/compareobjects/PersonDiffBuilderUnitTest.java @@ -0,0 +1,38 @@ +package com.baeldung.compareobjects; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.builder.Diff; +import org.apache.commons.lang3.builder.DiffResult; +import org.junit.jupiter.api.Test; + +public class PersonDiffBuilderUnitTest { + + @Test + void givenTwoPeopleDifferent_whenComparingWithDiffBuilder_thenDifferencesFound() { + List phoneNumbers1 = new ArrayList<>(); + phoneNumbers1.add(new PhoneNumber("home", "123-456-7890")); + phoneNumbers1.add(new PhoneNumber("work", "987-654-3210")); + + List phoneNumbers2 = new ArrayList<>(); + phoneNumbers2.add(new PhoneNumber("mobile1", "123-456-7890")); + phoneNumbers2.add(new PhoneNumber("mobile2", "987-654-3210")); + + Address address1 = new Address("123 Main St", "London", "12345"); + Address address2 = new Address("123 Main St", "Paris", "54321"); + + Person person1 = new Person("John", "Doe", 30, phoneNumbers1, address1); + Person person2 = new Person("Jane", "Smith", 28, phoneNumbers2, address2); + + DiffResult diff = PersonDiffBuilder.compare(person1, person2); + for (Diff d : diff.getDiffs()) { + System.out.println(d.getFieldName() + ": " + d.getLeft() + " != " + d.getRight()); + } + + assertFalse(diff.getDiffs() + .isEmpty()); + } +} diff --git a/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/compareobjects/PersonReflectionDiffBuilderUnitTest.java b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/compareobjects/PersonReflectionDiffBuilderUnitTest.java new file mode 100644 index 0000000000..fffa56dccc --- /dev/null +++ b/core-java-modules/core-java-lang-6/src/test/java/com/baeldung/compareobjects/PersonReflectionDiffBuilderUnitTest.java @@ -0,0 +1,37 @@ +package com.baeldung.compareobjects; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang3.builder.Diff; +import org.apache.commons.lang3.builder.DiffResult; +import org.junit.jupiter.api.Test; + +public class PersonReflectionDiffBuilderUnitTest { + @Test + void givenTwoPeopleDifferent_whenComparingWithReflectionDiffBuilder_thenDifferencesFound() { + List phoneNumbers1 = new ArrayList<>(); + phoneNumbers1.add(new PhoneNumber("home", "123-456-7890")); + phoneNumbers1.add(new PhoneNumber("work", "987-654-3210")); + + List phoneNumbers2 = new ArrayList<>(); + phoneNumbers2.add(new PhoneNumber("mobile1", "123-456-7890")); + phoneNumbers2.add(new PhoneNumber("mobile2", "987-654-3210")); + + Address address1 = new Address("123 Main St", "London", "12345"); + Address address2 = new Address("123 Main St", "Paris", "54321"); + + Person person1 = new Person("John", "Doe", 30, phoneNumbers1, address1); + Person person2 = new Person("Jane", "Smith", 28, phoneNumbers2, address2); + + DiffResult diff = PersonReflectionDiffBuilder.compare(person1, person2); + for (Diff d : diff.getDiffs()) { + System.out.println(d.getFieldName() + ": " + d.getLeft() + " != " + d.getRight()); + } + + assertFalse(diff.getDiffs() + .isEmpty()); + } +} diff --git a/core-java-modules/core-java-numbers-6/README.md b/core-java-modules/core-java-numbers-6/README.md index 254b2b58d7..3bd9fe6ddb 100644 --- a/core-java-modules/core-java-numbers-6/README.md +++ b/core-java-modules/core-java-numbers-6/README.md @@ -4,4 +4,5 @@ - [Integer.class vs Integer.TYPE vs int.class](https://www.baeldung.com/java-integer-class-vs-type-vs-int) - [Does Java Read Integers in Little Endian or Big Endian?](https://www.baeldung.com/java-integers-little-big-endian) - [How to Split an Integer Number Into Digits in Java](https://www.baeldung.com/java-integer-individual-digits) +- [Java Double vs. BigDecimal](https://www.baeldung.com/java-double-vs-bigdecimal) - More articles: [[<-- prev]](../core-java-numbers-5) diff --git a/core-java-modules/core-java-numbers-conversions/pom.xml b/core-java-modules/core-java-numbers-conversions/pom.xml index f745b83f8a..d014675ead 100644 --- a/core-java-modules/core-java-numbers-conversions/pom.xml +++ b/core-java-modules/core-java-numbers-conversions/pom.xml @@ -18,6 +18,18 @@ commons-lang3 ${commons-lang3.version} + + org.testng + testng + RELEASE + test + + + junit + junit + 4.13.2 + test + diff --git a/core-java-modules/core-java-numbers-conversions/src/main/java/com/baeldung/floatdoubleconversions/FloatAndDoubleConversions.java b/core-java-modules/core-java-numbers-conversions/src/main/java/com/baeldung/floatdoubleconversions/FloatAndDoubleConversions.java new file mode 100644 index 0000000000..f4fd68550c --- /dev/null +++ b/core-java-modules/core-java-numbers-conversions/src/main/java/com/baeldung/floatdoubleconversions/FloatAndDoubleConversions.java @@ -0,0 +1,15 @@ +package com.baeldung.floatdoubleconversions; + +public class FloatAndDoubleConversions { + public static void main(String args[]){ + float vatRate = 14.432511f; + System.out.println("vatRate:"+vatRate); + Float localTaxRate = 20.12434f; + System.out.println("localTaxRate:"+localTaxRate); + + double shootingAverage = 56.00000000000001; + System.out.println("shootingAverage:"+shootingAverage); + Double assistAverage = 81.123000000045; + System.out.println("assistAverage:"+assistAverage); + } +} diff --git a/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floatdoubleconversions/FloatDoubleConversionsTest.java b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floatdoubleconversions/FloatDoubleConversionsTest.java new file mode 100644 index 0000000000..10e9fd4c36 --- /dev/null +++ b/core-java-modules/core-java-numbers-conversions/src/test/java/com/baeldung/floatdoubleconversions/FloatDoubleConversionsTest.java @@ -0,0 +1,33 @@ +package com.baeldung.floatdoubleconversions; + +import org.junit.Assert; +import org.junit.Test; + +public class FloatDoubleConversionsTest { + + @Test + public void whenDoubleType_thenFloatTypeSuccess(){ + double interestRatesYearly = 13.333333333333334; + float interest = (float) interestRatesYearly; + System.out.println(interest); //13.333333 + Assert.assertTrue(Float.class.isInstance(interest));//true + + Double monthlyRates = 2.111111111111112; + float rates = monthlyRates.floatValue(); + System.out.println(rates); //2.1111112 + Assert.assertTrue(Float.class.isInstance(rates));//true + } + @Test + public void whenFloatType_thenDoubleTypeSuccess(){ + float gradeAverage =2.05f; + double average = gradeAverage; + System.out.println(average); //2.049999952316284 + Assert.assertTrue(Double.class.isInstance(average));//true + + Float monthlyRates = 2.1111112f; + Double rates = monthlyRates.doubleValue(); + System.out.println(rates); //2.1111112 + Assert.assertTrue(Double.class.isInstance(rates));//true + } + +} diff --git a/core-java-modules/core-java-os-2/.gitignore b/core-java-modules/core-java-os-2/.gitignore new file mode 100644 index 0000000000..3de4cc647e --- /dev/null +++ b/core-java-modules/core-java-os-2/.gitignore @@ -0,0 +1,26 @@ +*.class + +0.* + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* +.resourceCache + +# Packaged files # +*.jar +*.war +*.ear + +# Files generated by integration tests +*.txt +backup-pom.xml +/bin/ +/temp + +#IntelliJ specific +.idea/ +*.iml \ No newline at end of file diff --git a/core-java-modules/core-java-os-2/README.md b/core-java-modules/core-java-os-2/README.md new file mode 100644 index 0000000000..fa9f504184 --- /dev/null +++ b/core-java-modules/core-java-os-2/README.md @@ -0,0 +1,7 @@ +## Core Java OS + +This module contains articles about working with the operating system (OS) in Java + +### Relevant Articles: + + diff --git a/core-java-modules/core-java-os-2/pom.xml b/core-java-modules/core-java-os-2/pom.xml new file mode 100644 index 0000000000..53fdafa7d4 --- /dev/null +++ b/core-java-modules/core-java-os-2/pom.xml @@ -0,0 +1,42 @@ + + + 4.0.0 + core-java-os + core-java-os + jar + + + com.baeldung.core-java-modules + core-java-modules + 0.0.1-SNAPSHOT + + + + core-java-os + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + + 1.9 + 1.9 + + + \ No newline at end of file diff --git a/core-java-modules/core-java-os-2/src/main/java/com/baeldung/system/EnvironmentExample.java b/core-java-modules/core-java-os-2/src/main/java/com/baeldung/system/EnvironmentExample.java new file mode 100644 index 0000000000..2557c0cfa8 --- /dev/null +++ b/core-java-modules/core-java-os-2/src/main/java/com/baeldung/system/EnvironmentExample.java @@ -0,0 +1,9 @@ +package com.baeldung.system; + +public class EnvironmentExample { + public void getUserName() { + String username = System.getenv("USERNAME"); + System.out.println("User: " + username); + } + +} diff --git a/core-java-modules/core-java-os-2/src/main/java/com/baeldung/system/PropertiesExample.java b/core-java-modules/core-java-os-2/src/main/java/com/baeldung/system/PropertiesExample.java new file mode 100644 index 0000000000..cb203c40c6 --- /dev/null +++ b/core-java-modules/core-java-os-2/src/main/java/com/baeldung/system/PropertiesExample.java @@ -0,0 +1,19 @@ +package com.baeldung.system; + +public class PropertiesExample { + public void getUserName() { + String username = System.getProperty("user.name"); + System.out.println("User: " + username); + } + + public void getCustomProp() { + String customProperty = System.getProperty("custom.prop"); + System.out.println("Custom property: " + customProperty); + } + + public void getCustomPropWithFallback() { + String customProperty = System.getProperty("non-existent-property", "default value"); + System.out.println("Custom property: " + customProperty); + } + +} diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/system/WhenDetectingOSUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/system/WhenDetectingOSUnitTest.java deleted file mode 100644 index 27a6dd43c6..0000000000 --- a/core-java-modules/core-java-os/src/test/java/com/baeldung/system/WhenDetectingOSUnitTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.baeldung.system; - -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class WhenDetectingOSUnitTest { - - private DetectOS os = new DetectOS(); - - @Test - public void whenUsingSystemProperty_shouldReturnOS() { - String expected = "Windows 10"; - String actual = os.getOperatingSystem(); - Assert.assertEquals(expected, actual); - } - - @Test - public void whenUsingSystemUtils_shouldReturnOS() { - String expected = "Windows 10"; - String actual = os.getOperatingSystemSystemUtils(); - Assert.assertEquals(expected, actual); - } -} diff --git a/core-java-modules/core-java-os/src/test/java/com/baeldung/system/exit/SystemExitUnitTest.java b/core-java-modules/core-java-os/src/test/java/com/baeldung/system/exit/SystemExitUnitTest.java deleted file mode 100644 index 8ad3f75623..0000000000 --- a/core-java-modules/core-java-os/src/test/java/com/baeldung/system/exit/SystemExitUnitTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.baeldung.system.exit; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import java.security.Permission; - -import static org.junit.Assert.assertEquals; - -@Ignore("This test is ignored because it tests deprecated code") -public class SystemExitUnitTest { - - private SecurityManager securityManager; - private SystemExitExample example; - - @Before - public void setUp() { - example = new SystemExitExample(); - securityManager = System.getSecurityManager(); - System.setSecurityManager(new NoExitSecurityManager()); - } - - @After - public void tearDown() throws Exception { - System.setSecurityManager(securityManager); - } - - @Test - public void testExit() throws Exception { - try { - example.readFile(); - } catch (ExitException e) { - assertEquals("Exit status", 2, e.status); - } - } - - protected static class ExitException extends SecurityException { - - private static final long serialVersionUID = 1L; - public final int status; - - public ExitException(int status) { - this.status = status; - } - } - - private static class NoExitSecurityManager extends SecurityManager { - @Override - public void checkPermission(Permission perm) { - } - - @Override - public void checkPermission(Permission perm, Object context) { - } - - @Override - public void checkExit(int status) { - super.checkExit(status); - throw new ExitException(status); - } - } -} \ No newline at end of file diff --git a/core-java-modules/core-java-regex-2/src/main/java/com/baeldung/alphanumeric/AlphanumericPerformanceBenchmark.java b/core-java-modules/core-java-regex-2/src/main/java/com/baeldung/alphanumeric/AlphanumericPerformanceBenchmark.java new file mode 100644 index 0000000000..4b2ecc4c4d --- /dev/null +++ b/core-java-modules/core-java-regex-2/src/main/java/com/baeldung/alphanumeric/AlphanumericPerformanceBenchmark.java @@ -0,0 +1,91 @@ +package com.baeldung.alphanumeric; + +import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import org.openjdk.jmh.annotations.Benchmark; +import org.openjdk.jmh.annotations.BenchmarkMode; +import org.openjdk.jmh.annotations.Fork; +import org.openjdk.jmh.annotations.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.Warmup; +import org.openjdk.jmh.infra.Blackhole; + +@Warmup(iterations = 1) +@Measurement(iterations = 1, time = 1, timeUnit = TimeUnit.MINUTES) +@Fork(1) +public class AlphanumericPerformanceBenchmark { + + private static final String TEST_STRING = "ABC123abc123"; + private static final String REGEX = "[^[a-zA-Z0-9]*$]"; + private static final Pattern PATTERN = Pattern.compile(REGEX); + + @Benchmark + @BenchmarkMode(Mode.Throughput) + public void alphanumericRegex(Blackhole blackhole) { + final Matcher matcher = PATTERN.matcher(TEST_STRING); + boolean result = matcher.matches(); + blackhole.consume(result); + } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + public void alphanumericRegexDirectlyOnString(Blackhole blackhole) { + boolean result = TEST_STRING.matches(REGEX); + blackhole.consume(result); + } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + public void alphanumericIteration(Blackhole blackhole) { + boolean result = true; + for (int i = 0; i < TEST_STRING.length(); ++i) { + final int codePoint = TEST_STRING.codePointAt(i); + if (!isAlphanumeric(codePoint)) { + result = false; + break; + } + } + blackhole.consume(result); + } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + public void alphanumericIterationWithCharacterChecks(Blackhole blackhole) { + boolean result = true; + for (int i = 0; i < TEST_STRING.length(); ++i) { + final int codePoint = TEST_STRING.codePointAt(i); + if (!Character.isAlphabetic(codePoint) || !Character.isDigit(codePoint)) { + result = false; + break; + } + } + blackhole.consume(result); + } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + public void alphanumericIterationWithCopy(Blackhole blackhole) { + boolean result = true; + for (final char c : TEST_STRING.toCharArray()) { + if (!isAlphanumeric(c)) { + result = false; + break; + } + } + blackhole.consume(result); + } + + @Benchmark + @BenchmarkMode(Mode.Throughput) + public void alphanumericIterationWithStream(Blackhole blackhole) { + boolean result = TEST_STRING.chars().allMatch(this::isAlphanumeric); + blackhole.consume(result); + } + + public boolean isAlphanumeric(final int codePoint) { + return (codePoint >= 65 && codePoint <= 90) || + (codePoint >= 97 && codePoint <= 172) || + (codePoint >= 48 && codePoint <= 57); + } +} diff --git a/core-java-modules/core-java-regex-2/src/test/java/com/baeldung/alphanumeric/AlphanumericUnitTest.java b/core-java-modules/core-java-regex-2/src/test/java/com/baeldung/alphanumeric/AlphanumericUnitTest.java new file mode 100644 index 0000000000..b00bf7c4e3 --- /dev/null +++ b/core-java-modules/core-java-regex-2/src/test/java/com/baeldung/alphanumeric/AlphanumericUnitTest.java @@ -0,0 +1,30 @@ +package com.baeldung.alphanumeric; + +import static org.junit.jupiter.api.Assertions.*; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +class AlphanumericUnitTest { + + private AlphanumericPerformanceBenchmark alphanumericPerformanceBenchmark = new AlphanumericPerformanceBenchmark(); + + @ParameterizedTest + @CsvSource({ + "A,true", + "B,true", + "C,true", + "1,true", + "2,true", + "3,true", + "!,false", + "@,false", + "#,false", + "$,false", + "%,false" + }) + void shouldCorrectlyIdentifyAlphanumericCharacterTest(char character, boolean result) { + boolean actual = alphanumericPerformanceBenchmark.isAlphanumeric(character); + assertEquals(actual, result); + } +} \ No newline at end of file diff --git a/core-java-modules/core-java-string-algorithms-3/README.md b/core-java-modules/core-java-string-algorithms-3/README.md index 2bb70f5c97..3ef07129ed 100644 --- a/core-java-modules/core-java-string-algorithms-3/README.md +++ b/core-java-modules/core-java-string-algorithms-3/README.md @@ -11,4 +11,5 @@ This module contains articles about string-related algorithms. - [Find the First Non Repeating Character in a String in Java](https://www.baeldung.com/java-find-the-first-non-repeating-character) - [Find the First Embedded Occurrence of an Integer in a Java String](https://www.baeldung.com/java-string-find-embedded-integer) - [Find the Most Frequent Characters in a String](https://www.baeldung.com/java-string-find-most-frequent-characters) -- [Checking If a String Is a Repeated Substring](https://www.baeldung.com/java-repeated-substring) \ No newline at end of file +- [Checking If a String Is a Repeated Substring](https://www.baeldung.com/java-repeated-substring) +- [Check if Letter Is Emoji With Java](https://www.baeldung.com/java-check-letter-emoji) diff --git a/core-java-modules/core-java-string-operations-5/README.md b/core-java-modules/core-java-string-operations-5/README.md index fda7f39654..dffd3c1ab6 100644 --- a/core-java-modules/core-java-string-operations-5/README.md +++ b/core-java-modules/core-java-string-operations-5/README.md @@ -11,4 +11,3 @@ - [Check if the First Letter of a String Is a Number](https://www.baeldung.com/java-check-if-string-starts-with-number) - [Print “” Quotes Around a String in Java](https://www.baeldung.com/java-string-print-quotes) - [Remove Punctuation From a String in Java](https://www.baeldung.com/java-remove-punctuation-from-string) -- [Replacing Single Quote with \’ in Java String](https://www.baeldung.com/java-replacing-single-quote-string) diff --git a/core-java-modules/core-java-string-operations-6/README.md b/core-java-modules/core-java-string-operations-6/README.md index 853d58287d..b4b78d1ad7 100644 --- a/core-java-modules/core-java-string-operations-6/README.md +++ b/core-java-modules/core-java-string-operations-6/README.md @@ -10,3 +10,5 @@ - [Check if a String Contains Non-Alphanumeric Characters](https://www.baeldung.com/java-string-test-special-characters) - [Check if a String Has All Unique Characters in Java](https://www.baeldung.com/java-check-string-all-unique-chars) - [Performance Comparison Between Different Java String Concatenation Methods](https://www.baeldung.com/java-string-concatenation-methods) +- [Replacing Single Quote with \’ in Java String](https://www.baeldung.com/java-replacing-single-quote-string) + diff --git a/core-java-modules/core-java-string-operations-5/src/test/java/com/baeldung/replace/ReplaceStringUnitTest.java b/core-java-modules/core-java-string-operations-6/src/test/java/com/baeldung/replace/ReplaceStringUnitTest.java similarity index 100% rename from core-java-modules/core-java-string-operations-5/src/test/java/com/baeldung/replace/ReplaceStringUnitTest.java rename to core-java-modules/core-java-string-operations-6/src/test/java/com/baeldung/replace/ReplaceStringUnitTest.java diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml index 34e5204868..cd31bb5845 100644 --- a/core-java-modules/pom.xml +++ b/core-java-modules/pom.xml @@ -28,13 +28,14 @@ core-java-9-improvements - core-java-collections-array-list core-java-9-streams core-java-9 core-java-10 core-java-11 core-java-11-2 core-java-11-3 + core-java-collections-array-list + core-java-collections-array-list-2 core-java-collections-list-4 core-java-collections-list-5 core-java-collections-maps-4 @@ -78,6 +79,7 @@ core-java-collections-list core-java-collections-list-2 core-java-collections-list-3 + core-java-collections-list-6 core-java-collections-maps core-java-collections-maps-2 core-java-collections-maps-3 @@ -108,6 +110,7 @@ core-java-io-2 core-java-io-3 core-java-io-4 + core-java-io-5 core-java-io-apis core-java-io-apis-2 core-java-io-conversions diff --git a/drools/src/main/java/com/baeldung/drools/config/DroolsBeanFactory.java b/drools/src/main/java/com/baeldung/drools/config/DroolsBeanFactory.java index fd2090aecb..386b2ca4a7 100644 --- a/drools/src/main/java/com/baeldung/drools/config/DroolsBeanFactory.java +++ b/drools/src/main/java/com/baeldung/drools/config/DroolsBeanFactory.java @@ -1,8 +1,15 @@ package com.baeldung.drools.config; +import java.util.Arrays; +import java.util.List; + import org.drools.decisiontable.DecisionTableProviderImpl; import org.kie.api.KieServices; -import org.kie.api.builder.*; +import org.kie.api.builder.KieBuilder; +import org.kie.api.builder.KieFileSystem; +import org.kie.api.builder.KieModule; +import org.kie.api.builder.KieRepository; +import org.kie.api.builder.ReleaseId; import org.kie.api.io.Resource; import org.kie.api.runtime.KieContainer; import org.kie.api.runtime.KieSession; @@ -10,35 +17,19 @@ import org.kie.internal.builder.DecisionTableConfiguration; import org.kie.internal.builder.DecisionTableInputType; import org.kie.internal.builder.KnowledgeBuilderFactory; import org.kie.internal.io.ResourceFactory; -import java.util.Arrays; -import java.util.List; public class DroolsBeanFactory { private static final String RULES_PATH = "com/baeldung/drools/rules/"; private KieServices kieServices = KieServices.Factory.get(); - private KieFileSystem getKieFileSystem() { + private KieFileSystem getKieFileSystem() { KieFileSystem kieFileSystem = kieServices.newKieFileSystem(); - List rules = Arrays.asList("BackwardChaining.drl", "SuggestApplicant.drl", "Product_rules.drl.xls"); - for(String rule:rules) { + List rules = Arrays.asList("com/baeldung/drools/rules/BackwardChaining.drl", "com/baeldung/drools/rules/SuggestApplicant.drl", "com/baeldung/drools/rules/Product_rules.drl.xls"); + for (String rule : rules) { kieFileSystem.write(ResourceFactory.newClassPathResource(rule)); } return kieFileSystem; - - } - - public KieContainer getKieContainer() { - getKieRepository(); - - KieBuilder kb = kieServices.newKieBuilder(getKieFileSystem()); - kb.buildAll(); - - KieModule kieModule = kb.getKieModule(); - KieContainer kContainer = kieServices.newKieContainer(kieModule.getReleaseId()); - - return kContainer; - } private void getKieRepository() { @@ -47,20 +38,14 @@ public class DroolsBeanFactory { } public KieSession getKieSession() { - getKieRepository(); - KieFileSystem kieFileSystem = kieServices.newKieFileSystem(); - - kieFileSystem.write(ResourceFactory.newClassPathResource("com/baeldung/drools/rules/BackwardChaining.drl")); - kieFileSystem.write(ResourceFactory.newClassPathResource("com/baeldung/drools/rules/SuggestApplicant.drl")); - kieFileSystem.write(ResourceFactory.newClassPathResource("com/baeldung/drools/rules/Product_rules.drl.xls")); - - KieBuilder kb = kieServices.newKieBuilder(kieFileSystem); + KieBuilder kb = kieServices.newKieBuilder(getKieFileSystem()); kb.buildAll(); - KieModule kieModule = kb.getKieModule(); - KieContainer kContainer = kieServices.newKieContainer(kieModule.getReleaseId()); + KieRepository kieRepository = kieServices.getRepository(); + ReleaseId krDefaultReleaseId = kieRepository.getDefaultReleaseId(); + KieContainer kieContainer = kieServices.newKieContainer(krDefaultReleaseId); - return kContainer.newKieSession(); + return kieContainer.newKieSession(); } public KieSession getKieSession(Resource dt) { diff --git a/jenkins-modules/plugins/pom.xml b/jenkins-modules/plugins/pom.xml index 42add1664e..c2b1408556 100644 --- a/jenkins-modules/plugins/pom.xml +++ b/jenkins-modules/plugins/pom.xml @@ -12,6 +12,7 @@ org.jenkins-ci.plugins plugin 2.33 + diff --git a/logging-modules/log4j/README.md b/logging-modules/log4j/README.md index a47d0ae89b..32ea358369 100644 --- a/logging-modules/log4j/README.md +++ b/logging-modules/log4j/README.md @@ -4,3 +4,4 @@ - [A Guide to Rolling File Appenders](http://www.baeldung.com/java-logging-rolling-file-appenders) - [Logging Exceptions Using SLF4J](https://www.baeldung.com/slf4j-log-exceptions) - [Log4j Warning: “No Appenders Could Be Found for Logger”](https://www.baeldung.com/log4j-no-appenders-found) +- [A Guide to Log4j and the log4j.properties File in Java](https://www.baeldung.com/java-log4j-properties-guide) diff --git a/logging-modules/log4j2/README.md b/logging-modules/log4j2/README.md index 87e92e0d48..fa7133ffdd 100644 --- a/logging-modules/log4j2/README.md +++ b/logging-modules/log4j2/README.md @@ -9,3 +9,4 @@ - [Log4j 2 Plugins](https://www.baeldung.com/log4j2-plugins) - [Printing Thread Info in Log File Using Log4j2](https://www.baeldung.com/log4j2-print-thread-info) - [Log4j2 – Logging to Both File and Console](https://www.baeldung.com/java-log4j2-file-and-console) +- [Log4j 2 Configuration Using a Properties File](https://www.baeldung.com/java-log4j2-config-with-prop-file) diff --git a/messaging-modules/apache-camel/pom.xml b/messaging-modules/apache-camel/pom.xml index bb20f178aa..8b49ad4893 100644 --- a/messaging-modules/apache-camel/pom.xml +++ b/messaging-modules/apache-camel/pom.xml @@ -17,30 +17,39 @@ - org.apache.camel - camel-core - ${env.camel.version} + org.apache.camel.springboot + camel-spring-boot-starter + ${camel.version} + + + org.apache.camel.springboot + camel-jackson-starter + ${camel.version} org.apache.camel - camel-spring-javaconfig - ${env.camel.version} + camel-test-spring-junit5 + ${camel.version} + test - org.apache.camel - camel-jackson - ${env.camel.version} + org.junit.platform + junit-platform-launcher + test - org.apache.camel - camel-test - ${env.camel.version} + org.springframework.boot + spring-boot-starter-web + + + org.awaitility + awaitility test - 3.14.7 + 3.21.0 \ No newline at end of file diff --git a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/Application.java b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/Application.java new file mode 100755 index 0000000000..51b2540aa8 --- /dev/null +++ b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/Application.java @@ -0,0 +1,11 @@ +package com.baeldung.camel.apache; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } +} \ No newline at end of file diff --git a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java index ce4d92e8ab..a0571e7083 100644 --- a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java +++ b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileProcessor.java @@ -5,14 +5,17 @@ import java.util.Date; import org.apache.camel.Exchange; import org.apache.camel.Processor; +import org.springframework.stereotype.Component; +@Component public class FileProcessor implements Processor { + @Override public void process(Exchange exchange) throws Exception { String originalFileName = (String) exchange.getIn().getHeader(Exchange.FILE_NAME, String.class); Date date = new Date(); - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss"); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); String changedFileName = dateFormat.format(date) + originalFileName; exchange.getIn().setHeader(Exchange.FILE_NAME, changedFileName); } diff --git a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileRouter.java b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileRouter.java index 760f37677b..b57232d41e 100644 --- a/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileRouter.java +++ b/messaging-modules/apache-camel/src/main/java/com/baeldung/camel/apache/file/FileRouter.java @@ -1,7 +1,9 @@ package com.baeldung.camel.apache.file; import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; +@Component public class FileRouter extends RouteBuilder { private static final String SOURCE_FOLDER = "src/test/source-folder"; diff --git a/messaging-modules/apache-camel/src/main/resources/camel-context-test.xml b/messaging-modules/apache-camel/src/main/resources/camel-context-test.xml index f306574868..f6177c69b5 100644 --- a/messaging-modules/apache-camel/src/main/resources/camel-context-test.xml +++ b/messaging-modules/apache-camel/src/main/resources/camel-context-test.xml @@ -1,11 +1,12 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"> - - + + diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java index bc0025b263..df7a57a984 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitArrayJacksonUnmarshalUnitTest.java @@ -1,31 +1,65 @@ package com.apache.baeldung.camel.jackson; +import com.baeldung.camel.apache.Application; +import com.baeldung.camel.apache.jackson.Fruit; +import org.apache.camel.Configuration; +import org.apache.camel.EndpointInject; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jackson.ListJacksonDataFormat; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.spring.junit5.CamelSpringBootTest; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Bean; +import org.springframework.test.annotation.DirtiesContext; + import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.jackson.ListJacksonDataFormat; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; +import static org.springframework.test.util.AssertionErrors.assertEquals; +import static org.springframework.test.util.AssertionErrors.assertNotNull; -import com.baeldung.camel.apache.jackson.Fruit; +@CamelSpringBootTest +@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD) +@SpringBootTest(classes = {Application.class, FruitArrayJacksonUnmarshalUnitTest.TestConfig.class}) +public class FruitArrayJacksonUnmarshalUnitTest { -public class FruitArrayJacksonUnmarshalUnitTest extends CamelTestSupport { + @Autowired + private ProducerTemplate template; + + @EndpointInject("mock:marshalledObject") + private MockEndpoint mock; + + @Configuration + static class TestConfig { + @Bean + RoutesBuilder route() { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:jsonInput").unmarshal(new ListJacksonDataFormat(Fruit.class)) + .to("mock:marshalledObject"); + } + }; + } + } @Test public void givenJsonFruitArray_whenUnmarshalled_thenSuccess() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:marshalledObject"); - mock.expectedMessageCount(1); + mock.setExpectedMessageCount(1); mock.message(0).body().isInstanceOf(List.class); String json = readJsonFromFile("/json/fruit-array.json"); template.sendBody("direct:jsonInput", json); - assertMockEndpointsSatisfied(); + mock.assertIsSatisfied(); @SuppressWarnings("unchecked") List fruitList = mock.getReceivedExchanges().get(0).getIn().getBody(List.class); @@ -41,22 +75,10 @@ public class FruitArrayJacksonUnmarshalUnitTest extends CamelTestSupport { assertEquals("Fruit name", "Apple", fruit.getName()); assertEquals("Fruit id", 101, fruit.getId()); } - - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - - from("direct:jsonInput").unmarshal(new ListJacksonDataFormat(Fruit.class)) - .to("mock:marshalledObject"); - } - }; - } private String readJsonFromFile(String path) throws URISyntaxException, IOException { URL resource = FruitArrayJacksonUnmarshalUnitTest.class.getResource(path); - return new String(Files.readAllBytes(Paths.get(resource.toURI()))); + return new String(Files.readAllBytes(Paths.get(resource.toURI())), StandardCharsets.UTF_8); } } diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java index 2d15ebf46b..8120eeffec 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/baeldung/camel/jackson/FruitListJacksonUnmarshalUnitTest.java @@ -1,32 +1,64 @@ package com.apache.baeldung.camel.jackson; +import com.baeldung.camel.apache.Application; +import com.baeldung.camel.apache.jackson.Fruit; +import com.baeldung.camel.apache.jackson.FruitList; +import org.apache.camel.Configuration; +import org.apache.camel.EndpointInject; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.RoutesBuilder; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.jackson.JacksonDataFormat; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.spring.junit5.CamelSpringBootTest; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.annotation.Bean; + import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.component.jackson.JacksonDataFormat; -import org.apache.camel.component.mock.MockEndpoint; -import org.apache.camel.test.junit4.CamelTestSupport; -import org.junit.Test; +import static org.springframework.test.util.AssertionErrors.assertEquals; +import static org.springframework.test.util.AssertionErrors.assertNotNull; -import com.baeldung.camel.apache.jackson.Fruit; -import com.baeldung.camel.apache.jackson.FruitList; +@CamelSpringBootTest +@SpringBootTest(classes = {Application.class, FruitListJacksonUnmarshalUnitTest.TestConfig.class}) +public class FruitListJacksonUnmarshalUnitTest { -public class FruitListJacksonUnmarshalUnitTest extends CamelTestSupport { + @Autowired + private ProducerTemplate template; + + @EndpointInject("mock:marshalledObject") + private MockEndpoint mock; + + @Configuration + static class TestConfig { + @Bean + RoutesBuilder route() { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:jsonInput").unmarshal(new JacksonDataFormat(FruitList.class)) + .to("mock:marshalledObject"); + } + }; + } + } @Test public void givenJsonFruitList_whenUnmarshalled_thenSuccess() throws Exception { - MockEndpoint mock = getMockEndpoint("mock:marshalledObject"); - mock.expectedMessageCount(1); + mock.setExpectedMessageCount(1); mock.message(0).body().isInstanceOf(FruitList.class); String json = readJsonFromFile("/json/fruit-list.json"); template.sendBody("direct:jsonInput", json); - assertMockEndpointsSatisfied(); + mock.assertIsSatisfied(); FruitList fruitList = mock.getReceivedExchanges().get(0).getIn().getBody(FruitList.class); assertNotNull("Fruit lists should not be null", fruitList); @@ -43,20 +75,9 @@ public class FruitListJacksonUnmarshalUnitTest extends CamelTestSupport { assertEquals("Fruit id", 101, fruit.getId()); } - @Override - protected RouteBuilder createRouteBuilder() throws Exception { - return new RouteBuilder() { - @Override - public void configure() throws Exception { - from("direct:jsonInput").unmarshal(new JacksonDataFormat(FruitList.class)) - .to("mock:marshalledObject"); - } - }; - } - private String readJsonFromFile(String path) throws URISyntaxException, IOException { URL resource = FruitListJacksonUnmarshalUnitTest.class.getResource(path); - return new String(Files.readAllBytes(Paths.get(resource.toURI()))); + return new String(Files.readAllBytes(Paths.get(resource.toURI())), StandardCharsets.UTF_8); } } diff --git a/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java b/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java index e4390a95e5..5003021d20 100644 --- a/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java +++ b/messaging-modules/apache-camel/src/test/java/com/apache/camel/file/processor/FileProcessorIntegrationTest.java @@ -1,16 +1,21 @@ package com.apache.camel.file.processor; -import java.io.File; - +import com.baeldung.camel.apache.file.FileProcessor; import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.DefaultCamelContext; +import org.awaitility.Awaitility; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; -import com.baeldung.camel.apache.file.FileProcessor; +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.concurrent.TimeUnit; + +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; public class FileProcessorIntegrationTest { @@ -52,7 +57,7 @@ public class FileProcessorIntegrationTest { } @Test - public void moveFolderContentJavaDSLTest() throws Exception { + public void givenJavaDSLRoute_whenCamelStart_thenMoveFolderContent() throws Exception { final CamelContext camelContext = new DefaultCamelContext(); camelContext.addRoutes(new RouteBuilder() { @Override @@ -61,15 +66,26 @@ public class FileProcessorIntegrationTest { } }); camelContext.start(); - Thread.sleep(DURATION_MILIS); + verifyFolderContent(); camelContext.stop(); } @Test - public void moveFolderContentSpringDSLTest() throws InterruptedException { + public void givenSpringDSLRoute_whenCamelStart_thenMoveFolderContent() throws InterruptedException { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("camel-context-test.xml"); - Thread.sleep(DURATION_MILIS); + verifyFolderContent(); applicationContext.close(); + } + private void verifyFolderContent() { + Date date = new Date(); + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); + File destinationFile1 = new File(DESTINATION_FOLDER + "/" + dateFormat.format(date) + "File1.txt"); + File destinationFile2 = new File(DESTINATION_FOLDER + "/" + dateFormat.format(date) + "File2.txt"); + + Awaitility.await().atMost(DURATION_MILIS, TimeUnit.MILLISECONDS).untilAsserted(() -> { + assertThat(destinationFile1.exists()).isTrue(); + assertThat(destinationFile2.exists()).isTrue(); + }); } } \ No newline at end of file diff --git a/parent-spring-6/pom.xml b/parent-spring-6/pom.xml index 77afe2072a..7b61ac524b 100644 --- a/parent-spring-6/pom.xml +++ b/parent-spring-6/pom.xml @@ -1,7 +1,7 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 parent-spring-6 0.0.1-SNAPSHOT diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index 73c6b96bba..f35b22a19d 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -101,6 +101,7 @@ spring-data-shardingsphere + spring-hibernate-6 spring-jpa spring-jpa-2 spring-jdbc @@ -114,7 +115,7 @@ java-mongodb questdb neo4j - + rethinkdb scylladb spring-data-cassandra-2 spring-data-jpa-repo-3 diff --git a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/InsertIntegrationTest.java b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/InsertIntegrationLiveTest.java similarity index 96% rename from persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/InsertIntegrationTest.java rename to persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/InsertIntegrationLiveTest.java index 244959d854..0e6cdae2b4 100644 --- a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/InsertIntegrationTest.java +++ b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/InsertIntegrationLiveTest.java @@ -10,7 +10,7 @@ import static com.rethinkdb.RethinkDB.r; /** * Some tests demonstrating inserting data. */ -public class InsertIntegrationTest extends TestBase { +public class InsertIntegrationLiveTest extends TestBase { /** * Create a table for the tests. */ diff --git a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/QueryIntegrationTest.java b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/QueryIntegrationLiveTest.java similarity index 97% rename from persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/QueryIntegrationTest.java rename to persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/QueryIntegrationLiveTest.java index 263dda9bc6..626d15bcb6 100644 --- a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/QueryIntegrationTest.java +++ b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/QueryIntegrationLiveTest.java @@ -16,7 +16,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; /** * Some tests demonstrating querying data. */ -public class QueryIntegrationTest extends TestBase { +public class QueryIntegrationLiveTest extends TestBase { /** * Create a table for the tests. */ diff --git a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/StreamingIntegrationTest.java b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/StreamingIntegrationLiveTest.java similarity index 98% rename from persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/StreamingIntegrationTest.java rename to persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/StreamingIntegrationLiveTest.java index 4ca147cf68..bc105d2e4f 100644 --- a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/StreamingIntegrationTest.java +++ b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/StreamingIntegrationLiveTest.java @@ -13,7 +13,7 @@ import static com.rethinkdb.RethinkDB.r; /** * Some tests demonstrating streaming live changes to data. */ -public class StreamingIntegrationTest extends TestBase { +public class StreamingIntegrationLiveTest extends TestBase { @Test public void getLiveInserts() throws InterruptedException { ExecutorService executorService = Executors.newCachedThreadPool(); diff --git a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/TablesIntegrationTest.java b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/TablesIntegrationLiveTest.java similarity index 94% rename from persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/TablesIntegrationTest.java rename to persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/TablesIntegrationLiveTest.java index d60e500373..7bffb189b3 100644 --- a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/TablesIntegrationTest.java +++ b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/TablesIntegrationLiveTest.java @@ -12,7 +12,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; /** * Some tests demonstrating working with tables. */ -public class TablesIntegrationTest extends TestBase { +public class TablesIntegrationLiveTest extends TestBase { @Test public void createTable() { diff --git a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/UpdateIntegrationTest.java b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/UpdateIntegrationLiveTest.java similarity index 96% rename from persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/UpdateIntegrationTest.java rename to persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/UpdateIntegrationLiveTest.java index 39fad3a878..d47caa0b5e 100644 --- a/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/UpdateIntegrationTest.java +++ b/persistence-modules/rethinkdb/src/test/java/com/baeldung/rethinkdb/UpdateIntegrationLiveTest.java @@ -8,7 +8,7 @@ import static com.rethinkdb.RethinkDB.r; /** * Some tests demonstrating updating data. */ -public class UpdateIntegrationTest extends TestBase { +public class UpdateIntegrationLiveTest extends TestBase { /** * Create a table for the tests. */ diff --git a/persistence-modules/spring-boot-persistence-mongodb-3/pom.xml b/persistence-modules/spring-boot-persistence-mongodb-3/pom.xml index c48525673a..3f144bae54 100644 --- a/persistence-modules/spring-boot-persistence-mongodb-3/pom.xml +++ b/persistence-modules/spring-boot-persistence-mongodb-3/pom.xml @@ -9,27 +9,12 @@ com.baeldung - parent-boot-2 + parent-boot-3 0.0.1-SNAPSHOT - ../../parent-boot-2 + ../../parent-boot-3 - - org.mongodb - mongodb-driver-sync - ${mongodb-driver.version} - - - org.mongodb - mongodb-driver-core - ${mongodb-driver.version} - - - org.mongodb - bson - ${mongodb-driver.version} - org.springframework.boot spring-boot-starter-web @@ -37,16 +22,6 @@ org.springframework.boot spring-boot-starter-data-mongodb - - - org.mongodb - mongodb-driver-sync - - - org.mongodb - mongodb-driver-core - - org.mongodb @@ -57,12 +32,13 @@ de.flapdoodle.embed de.flapdoodle.embed.mongo test + ${de.flapdoodle.embed.mongo.version} - 1.7.3 - 4.9.1 + com.baeldung.boot.atlassearch.MongoDbAtlasSearchApplication + 1.8.0 + 4.9.2 - diff --git a/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/MongoDbAtlasSearchApplication.java b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/MongoDbAtlasSearchApplication.java new file mode 100644 index 0000000000..afaf524829 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/MongoDbAtlasSearchApplication.java @@ -0,0 +1,12 @@ +package com.baeldung.boot.atlassearch; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class MongoDbAtlasSearchApplication { + + public static void main(String... args) { + SpringApplication.run(MongoDbAtlasSearchApplication.class, args); + } +} diff --git a/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/config/IndexConfig.java b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/config/IndexConfig.java new file mode 100644 index 0000000000..cb4fae89e4 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/config/IndexConfig.java @@ -0,0 +1,22 @@ +package com.baeldung.boot.atlassearch.config; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class IndexConfig { + + @Value("${com.baeldung.atlas-search.index.query}") + private String queryIndex; + + @Value("${com.baeldung.atlas-search.index.facet}") + private String facetIndex; + + public String getFacetIndex() { + return facetIndex; + } + + public String getQueryIndex() { + return queryIndex; + } +} diff --git a/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/service/MovieAtlasSearchService.java b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/service/MovieAtlasSearchService.java new file mode 100644 index 0000000000..55d47759d5 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/service/MovieAtlasSearchService.java @@ -0,0 +1,183 @@ +package com.baeldung.boot.atlassearch.service; + +import static com.mongodb.client.model.Aggregates.facet; +import static com.mongodb.client.model.Aggregates.limit; +import static com.mongodb.client.model.Aggregates.project; +import static com.mongodb.client.model.Aggregates.replaceWith; +import static com.mongodb.client.model.Aggregates.search; +import static com.mongodb.client.model.Aggregates.searchMeta; +import static com.mongodb.client.model.Aggregates.skip; +import static com.mongodb.client.model.Projections.excludeId; +import static com.mongodb.client.model.Projections.fields; +import static com.mongodb.client.model.Projections.include; +import static com.mongodb.client.model.Projections.metaSearchScore; +import static com.mongodb.client.model.search.SearchCount.total; +import static com.mongodb.client.model.search.SearchFacet.combineToBson; +import static com.mongodb.client.model.search.SearchFacet.numberFacet; +import static com.mongodb.client.model.search.SearchFacet.stringFacet; +import static com.mongodb.client.model.search.SearchOperator.compound; +import static com.mongodb.client.model.search.SearchOperator.numberRange; +import static com.mongodb.client.model.search.SearchOperator.of; +import static com.mongodb.client.model.search.SearchOperator.text; +import static com.mongodb.client.model.search.SearchOptions.searchOptions; +import static com.mongodb.client.model.search.SearchPath.fieldPath; +import static java.util.Arrays.asList; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; + +import org.apache.logging.log4j.LogManager; +import org.bson.Document; +import org.bson.conversions.Bson; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.stereotype.Service; + +import com.baeldung.boot.atlassearch.config.IndexConfig; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import com.mongodb.client.model.Facet; +import com.mongodb.client.model.search.SearchScore; + +@Service +public class MovieAtlasSearchService { + + @Autowired + private IndexConfig config; + + private final MongoCollection collection; + + public MovieAtlasSearchService(MongoTemplate mongoTemplate) { + MongoDatabase database = mongoTemplate.getDb(); + this.collection = database.getCollection("movies"); + } + + public static void debug(List pipeline) { + StringBuilder builder = new StringBuilder("["); + final AtomicBoolean first = new AtomicBoolean(true); + pipeline.forEach(stage -> { + builder.append((first.get() ? "" : ",") + + stage.toBsonDocument() + ); + + first.set(false); + }); + builder.append("]"); + + LogManager.getLogger(MovieAtlasSearchService.class) + .debug(builder.toString()); + } + + public Document late90sMovies(int skip, int limit, String keywords, SearchScore modifier) { + List pipeline = asList( + search( + compound() + .must(asList( + numberRange( + fieldPath("year")) + .gteLt(1995, 2000) + )) + .should(asList( + text( + fieldPath("fullplot"), keywords + ) + .score(modifier) + )), + searchOptions() + .index(config.getQueryIndex()) + ), + project(fields( + excludeId(), + include("title", "year", "fullplot", "imdb.rating"), + metaSearchScore("score") + )), + facet( + new Facet("rows", + skip(skip), + limit(limit) + ), + new Facet("totalRows", + replaceWith("$$SEARCH_META"), + limit(1) + ) + ) + ); + + debug(pipeline); + return collection.aggregate(pipeline) + .first(); + } + + public Document countLate90sMovies(String keywords) { + List pipeline = asList( + searchMeta( + compound() + .must(asList( + numberRange( + fieldPath("year")) + .gteLt(1995, 2000), + text( + fieldPath("fullplot"), keywords + ) + )), + searchOptions() + .index(config.getQueryIndex()) + .count(total()) + ) + ); + + debug(pipeline); + return collection.aggregate(pipeline) + .first(); + } + + public Collection moviesByKeywords(String keywords) { + List pipeline = asList( + search( + text( + fieldPath("fullplot"), keywords + ), + searchOptions() + .index(config.getQueryIndex()) + ), + project(fields( + excludeId(), + include("title", "year", "fullplot", "imdb.rating") + )) + ); + + debug(pipeline); + return collection.aggregate(pipeline) + .into(new ArrayList()); + } + + public Document genresThroughTheDecades(String genre) { + List pipeline = asList( + searchMeta(of( + new Document("facet", + new Document("operator", + text( + fieldPath("genres"), genre + ) + ).append("facets", combineToBson(asList( + stringFacet("genresFacet", + fieldPath("genres") + ).numBuckets(5), + numberFacet("yearFacet", + fieldPath("year"), + asList(1900, 1930, 1960, 1990, 2020) + ) + ))) + )), + searchOptions() + .index(config.getFacetIndex()) + ) + ); + + debug(pipeline); + return collection.aggregate(pipeline) + .first(); + } +} diff --git a/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/web/MovieAtlasSearchController.java b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/web/MovieAtlasSearchController.java new file mode 100644 index 0000000000..4c41915347 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/java/com/baeldung/boot/atlassearch/web/MovieAtlasSearchController.java @@ -0,0 +1,48 @@ +package com.baeldung.boot.atlassearch.web; + +import java.util.Collection; + +import org.bson.Document; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import com.baeldung.boot.atlassearch.service.MovieAtlasSearchService; +import com.mongodb.client.model.search.SearchScore; + +@RestController +@RequestMapping("/movies") +public class MovieAtlasSearchController { + + @Autowired + private MovieAtlasSearchService service; + + @GetMapping("with/{keywords}") + Collection getMoviesWithKeywords(@PathVariable String keywords) { + return service.moviesByKeywords(keywords); + } + + @GetMapping("90s/with/{keywords}/count") + Document getCount90sMoviesWithKeywords(@PathVariable String keywords) { + return service.countLate90sMovies(keywords); + } + + @GetMapping("90s/{skip}/{limit}/with/{keywords}") + Document getMoviesUsingScoreBoost(@PathVariable int skip, @PathVariable int limit, @PathVariable String keywords) { + return service.late90sMovies(skip, limit, keywords, SearchScore.boost(2)); + } + + @PostMapping("90s/{skip}/{limit}/with/{keywords}") + Document getMoviesUsingScoringFunction(@RequestBody String jsonFunction, @PathVariable int skip, @PathVariable int limit, @PathVariable String keywords) { + return service.late90sMovies(skip, limit, keywords, SearchScore.of(new Document("function", Document.parse(jsonFunction)))); + } + + @GetMapping("by-genre/{genre}") + Document getMoviesWithFacets(@PathVariable String genre) { + return service.genresThroughTheDecades(genre); + } +} diff --git a/persistence-modules/spring-boot-persistence-mongodb-3/src/main/resources/application.properties b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/resources/application.properties index 8309c4461f..02ba79e336 100644 --- a/persistence-modules/spring-boot-persistence-mongodb-3/src/main/resources/application.properties +++ b/persistence-modules/spring-boot-persistence-mongodb-3/src/main/resources/application.properties @@ -1 +1,4 @@ spring.application.name=spring-boot-persistence-mongodb-3 + +com.baeldung.atlas-search.index.query=idx-queries +com.baeldung.atlas-search.index.facet=idx-facets \ No newline at end of file diff --git a/persistence-modules/spring-boot-persistence-mongodb-3/src/test/java/com/baeldung/boot/atlassearch/MovieAtlasSearchServiceLiveTest.java b/persistence-modules/spring-boot-persistence-mongodb-3/src/test/java/com/baeldung/boot/atlassearch/MovieAtlasSearchServiceLiveTest.java new file mode 100644 index 0000000000..190ebc19d9 --- /dev/null +++ b/persistence-modules/spring-boot-persistence-mongodb-3/src/test/java/com/baeldung/boot/atlassearch/MovieAtlasSearchServiceLiveTest.java @@ -0,0 +1,67 @@ +package com.baeldung.boot.atlassearch; + +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.bson.Document; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.boot.atlassearch.service.MovieAtlasSearchService; +import com.mongodb.client.model.search.SearchScore; + +@DirtiesContext +@RunWith(SpringRunner.class) +@TestPropertySource("/embedded.properties") +@SpringBootTest(classes = MongoDbAtlasSearchApplication.class) +public class MovieAtlasSearchServiceLiveTest { + + @Autowired + private MovieAtlasSearchService service; + + @Test + public void givenScoreBoost_thenFirstItemContainsPlot() { + final String plot = "space"; + + Document movies = service.late90sMovies(0, 1, plot, SearchScore.boost(2)); + + assertTrue(movies.getList("rows", Document.class) + .iterator() + .next() + .getString("fullplot") + .contains(plot)); + } + + @Test + public void givenFacetOperator_thenCorrespondingBucketsReturned() { + final String genre = "Sci-Fi"; + + Document meta = service.genresThroughTheDecades(genre); + + Long lowerBound = meta + .get("count", Document.class) + .getLong("lowerBound"); + + Document genresFacetFirstBucket = meta.get("facet", Document.class) + .get("genresFacet", Document.class) + .getList("buckets", Document.class) + .iterator() + .next(); + + Document yearFacetFirstBucket = meta.get("facet", Document.class) + .get("yearFacet", Document.class) + .getList("buckets", Document.class) + .iterator() + .next(); + + assertEquals(lowerBound, genresFacetFirstBucket.getLong("count")); + assertEquals(genre, genresFacetFirstBucket.getString("_id")); + assertNotNull(yearFacetFirstBucket); + } +} diff --git a/persistence-modules/spring-boot-persistence-mongodb-3/src/test/resources/embedded.properties b/persistence-modules/spring-boot-persistence-mongodb-3/src/test/resources/embedded.properties index cd1c1d43c7..f47eca5023 100644 --- a/persistence-modules/spring-boot-persistence-mongodb-3/src/test/resources/embedded.properties +++ b/persistence-modules/spring-boot-persistence-mongodb-3/src/test/resources/embedded.properties @@ -1,4 +1,4 @@ -spring.mongodb.embedded.version=4.4.9 +spring.mongodb.embedded.version=4.9.2 #spring.data.mongodb.uri=changeit #spring.data.mongodb.database=changeit diff --git a/persistence-modules/spring-data-cassandra-2/src/test/java/org/baeldung/cassandra/inquery/ProductRepositoryNestedLiveTest.java b/persistence-modules/spring-data-cassandra-2/src/test/java/org/baeldung/cassandra/inquery/ProductRepositoryNestedLiveTest.java index 3d2433814e..3592c8b80d 100644 --- a/persistence-modules/spring-data-cassandra-2/src/test/java/org/baeldung/cassandra/inquery/ProductRepositoryNestedLiveTest.java +++ b/persistence-modules/spring-data-cassandra-2/src/test/java/org/baeldung/cassandra/inquery/ProductRepositoryNestedLiveTest.java @@ -23,7 +23,7 @@ import static org.junit.jupiter.api.Assertions.*; @Testcontainers @SpringBootTest -class ProductRepositoryIntegrationTest { +class ProductRepositoryNestedLiveTest { private static final String KEYSPACE_NAME = "mynamespace"; diff --git a/persistence-modules/spring-data-cassandra-2/src/test/java/org/baeldung/objectmapper/MapperLiveTest.java b/persistence-modules/spring-data-cassandra-2/src/test/java/org/baeldung/objectmapper/MapperLiveTest.java index b61663d622..50681d36c5 100644 --- a/persistence-modules/spring-data-cassandra-2/src/test/java/org/baeldung/objectmapper/MapperLiveTest.java +++ b/persistence-modules/spring-data-cassandra-2/src/test/java/org/baeldung/objectmapper/MapperLiveTest.java @@ -1,7 +1,8 @@ package org.baeldung.objectmapper; -import com.datastax.oss.driver.api.core.CqlIdentifier; -import com.datastax.oss.driver.api.core.CqlSession; +import java.net.InetSocketAddress; +import java.util.List; + import org.baeldung.objectmapper.dao.CounterDao; import org.baeldung.objectmapper.dao.UserDao; import org.baeldung.objectmapper.entity.Counter; @@ -14,7 +15,8 @@ import org.testcontainers.containers.CassandraContainer; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; -import java.util.List; +import com.datastax.oss.driver.api.core.CqlIdentifier; +import com.datastax.oss.driver.api.core.CqlSession; @Testcontainers @SpringBootTest @@ -23,35 +25,30 @@ public class MapperLiveTest { private static final String KEYSPACE_NAME = "baeldung"; @Container - private static final CassandraContainer cassandra = (CassandraContainer) new CassandraContainer("cassandra:3.11.2") - .withExposedPorts(9042); + private static final CassandraContainer cassandra = (CassandraContainer) new CassandraContainer("cassandra:3.11.2").withExposedPorts(9042); + @BeforeAll static void setupCassandraConnectionProperties() { System.setProperty("spring.data.cassandra.keyspace-name", KEYSPACE_NAME); - System.setProperty("spring.data.cassandra.contact-points", cassandra.getContainerIpAddress()); + System.setProperty("spring.data.cassandra.contact-points", cassandra.getHost()); System.setProperty("spring.data.cassandra.port", String.valueOf(cassandra.getMappedPort(9042))); + setupCassandra(new InetSocketAddress(cassandra.getHost(), cassandra.getMappedPort(9042)), cassandra.getLocalDatacenter()); } static UserDao userDao; static CounterDao counterDao; - @BeforeAll - static void setup() { - setupCassandraConnectionProperties(); - CqlSession session = CqlSession.builder().build(); + static void setupCassandra(InetSocketAddress cassandraEndpoint, String localDataCenter) { + CqlSession session = CqlSession.builder() + .withLocalDatacenter(localDataCenter) + .addContactPoint(cassandraEndpoint) + .build(); - String createKeyspace = "CREATE KEYSPACE IF NOT EXISTS baeldung " + - "WITH replication = {'class':'SimpleStrategy', 'replication_factor':1};"; + String createKeyspace = "CREATE KEYSPACE IF NOT EXISTS baeldung " + "WITH replication = {'class':'SimpleStrategy', 'replication_factor':1};"; String useKeyspace = "USE baeldung;"; - String createUserTable = "CREATE TABLE IF NOT EXISTS user_profile " + - "(id int, username text, user_age int, writetime bigint, PRIMARY KEY (id, user_age)) " + - "WITH CLUSTERING ORDER BY (user_age DESC);"; - String createAdminTable = "CREATE TABLE IF NOT EXISTS admin_profile " + - "(id int, username text, user_age int, role text, writetime bigint, department text, " + - "PRIMARY KEY (id, user_age)) " + - "WITH CLUSTERING ORDER BY (user_age DESC);"; - String createCounter = "CREATE TABLE IF NOT EXISTS counter " + - "(id text, count counter, PRIMARY KEY (id));"; + String createUserTable = "CREATE TABLE IF NOT EXISTS user_profile " + "(id int, username text, user_age int, writetime bigint, PRIMARY KEY (id, user_age)) " + "WITH CLUSTERING ORDER BY (user_age DESC);"; + String createAdminTable = "CREATE TABLE IF NOT EXISTS admin_profile " + "(id int, username text, user_age int, role text, writetime bigint, department text, " + "PRIMARY KEY (id, user_age)) " + "WITH CLUSTERING ORDER BY (user_age DESC);"; + String createCounter = "CREATE TABLE IF NOT EXISTS counter " + "(id text, count counter, PRIMARY KEY (id));"; session.execute(createKeyspace); session.execute(useKeyspace); @@ -75,22 +72,25 @@ public class MapperLiveTest { @Test void givenCounter_whenIncrement_thenIncremented() { Counter users = counterDao.getCounterById("users"); - long initialCount = users != null ? users.getCount(): 0; + long initialCount = users != null ? users.getCount() : 0; counterDao.incrementCounter("users", 1); users = counterDao.getCounterById("users"); - long finalCount = users != null ? users.getCount(): 0; + long finalCount = users != null ? users.getCount() : 0; Assertions.assertEquals(finalCount - initialCount, 1); } @Test void givenUser_whenGetUsersOlderThan_thenRetrieved() { - User user = new User(2, "JaneDoe", 20); + User user = new User(2, "JaneDoe", 32); + User userTwo = new User(3, "JohnDoe", 20); userDao.insertUser(user); - List retrievedUsers = userDao.getUsersOlderThanAge(30).all(); - Assertions.assertEquals(retrievedUsers.size(), 1); + userDao.insertUser(userTwo); + List retrievedUsers = userDao.getUsersOlderThanAge(30) + .all(); + Assertions.assertEquals(1, retrievedUsers.size()); } } \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-5/README.md b/persistence-modules/spring-hibernate-5/README.md index e2344fd585..ce78e5a0df 100644 --- a/persistence-modules/spring-hibernate-5/README.md +++ b/persistence-modules/spring-hibernate-5/README.md @@ -4,10 +4,7 @@ This module contains articles about Hibernate 5 with Spring. ### Relevant articles -- [Programmatic Transactions in the Spring TestContext Framework](https://www.baeldung.com/spring-test-programmatic-transactions) - [Introduction to Hibernate Search](https://www.baeldung.com/hibernate-search) -- [@DynamicUpdate with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-dynamicupdate) - [Hibernate Second-Level Cache](http://www.baeldung.com/hibernate-second-level-cache) - [Deleting Objects with Hibernate](http://www.baeldung.com/delete-with-hibernate) - [Spring, Hibernate and a JNDI Datasource](http://www.baeldung.com/spring-persistence-jpa-jndi-datasource) -- [Bootstrapping Hibernate 5 with Spring](https://www.baeldung.com/hibernate-5-spring) diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/HibernateXMLConf.java b/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/HibernateXMLConf.java deleted file mode 100644 index b3e979478f..0000000000 --- a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/HibernateXMLConf.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.baeldung.hibernate.bootstrap; - -import com.google.common.base.Preconditions; -import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.ImportResource; -import org.springframework.context.annotation.PropertySource; -import org.springframework.core.env.Environment; -import org.springframework.orm.hibernate5.HibernateTransactionManager; -import org.springframework.orm.hibernate5.LocalSessionFactoryBean; -import org.springframework.transaction.PlatformTransactionManager; -import org.springframework.transaction.annotation.EnableTransactionManagement; - -import javax.sql.DataSource; -import java.util.Properties; - -@Configuration -@EnableTransactionManagement -@ImportResource({ "classpath:hibernate5Configuration.xml" }) -public class HibernateXMLConf { - -} diff --git a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateIntegrationTest.java b/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateIntegrationTest.java deleted file mode 100644 index fc183d1f19..0000000000 --- a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateIntegrationTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.baeldung.hibernate.dynamicupdate; - -import javax.transaction.Transactional; - -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.MethodSorters; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.annotation.Commit; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.support.AnnotationConfigContextLoader; - -import com.baeldung.hibernate.dynamicupdate.model.Account; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = DynamicUpdateConfig.class, loader = AnnotationConfigContextLoader.class) -@Transactional -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -public class DynamicUpdateIntegrationTest { - - private static final Integer ACCOUNT_ID = 1; - - @Autowired - private AccountRepository accountRepository; - - @Test - @Commit - public void testA_whenTestAccountIsSaved_thenSuccess() { - Account account = new Account(ACCOUNT_ID, "account1", "regional", true); - accountRepository.save(account); - } - - @Test - @Commit - // Enable Hibernate's debug logging in logback.xml to see the generated SQL statement. - public void testB_whenAccountNameUpdated_thenSuccess() { - Account account = accountRepository.findOne(ACCOUNT_ID); - account.setName("Test Account"); - accountRepository.save(account); - } - -} diff --git a/persistence-modules/spring-hibernate-6/.gitignore b/persistence-modules/spring-hibernate-6/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/persistence-modules/spring-hibernate-6/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-6/README.md b/persistence-modules/spring-hibernate-6/README.md new file mode 100644 index 0000000000..08fe6216fd --- /dev/null +++ b/persistence-modules/spring-hibernate-6/README.md @@ -0,0 +1,9 @@ +## Hibernate 6 with Spring + +This module contains articles about Hibernate 6 with Spring. + +### Relevant articles + +- [Programmatic Transactions in the Spring TestContext Framework](https://www.baeldung.com/spring-test-programmatic-transactions) +- [@DynamicUpdate with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-dynamicupdate) +- [Bootstrapping Hibernate 5 with Spring](https://www.baeldung.com/hibernate-5-spring) diff --git a/persistence-modules/spring-hibernate-6/pom.xml b/persistence-modules/spring-hibernate-6/pom.xml new file mode 100644 index 0000000000..a13117e68c --- /dev/null +++ b/persistence-modules/spring-hibernate-6/pom.xml @@ -0,0 +1,109 @@ + + + 4.0.0 + spring-hibernate-6 + 0.1-SNAPSHOT + spring-hibernate-6 + + + com.baeldung + persistence-modules + 1.0.0-SNAPSHOT + + + + + + org.springframework + spring-context + ${org.springframework.version} + + + commons-logging + commons-logging + + + + + org.springframework + spring-aspects + ${org.springframework.version} + + + + org.springframework + spring-orm + ${org.springframework.version} + + + org.springframework.data + spring-data-jpa + ${org.springframework.data.version} + + + org.hibernate.orm + hibernate-core + ${hibernate.version} + + + org.apache.tomcat + tomcat-dbcp + ${tomcat-dbcp.version} + + + + + com.google.guava + guava + ${guava.version} + + + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + test + + + org.springframework + spring-test + ${org.springframework.version} + test + + + org.springframework.security + spring-security-test + ${org.springframework.security.version} + test + + + org.hsqldb + hsqldb + ${hsqldb.version} + + + mysql + mysql-connector-java + ${mysql-connector-java.version} + + + com.h2database + h2 + ${h2.version} + + + + + + 6.0.11 + 3.1.3 + 6.1.3 + + 6.2.8.Final + 8.0.7-dmr + 9.0.80 + + + \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/BarHibernateDAO.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/BarHibernateDAO.java similarity index 100% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/BarHibernateDAO.java rename to persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/BarHibernateDAO.java diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/HibernateConf.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/HibernateConf.java similarity index 100% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/HibernateConf.java rename to persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/HibernateConf.java diff --git a/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/HibernateXMLConf.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/HibernateXMLConf.java new file mode 100644 index 0000000000..220c18bccf --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/HibernateXMLConf.java @@ -0,0 +1,12 @@ +package com.baeldung.hibernate.bootstrap; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@Configuration +@EnableTransactionManagement +@ImportResource({ "classpath:hibernate6Configuration.xml" }) +public class HibernateXMLConf { + +} diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/model/TestEntity.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/model/TestEntity.java similarity index 86% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/model/TestEntity.java rename to persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/model/TestEntity.java index cae41db831..d260fed7a1 100644 --- a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/bootstrap/model/TestEntity.java +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/bootstrap/model/TestEntity.java @@ -1,7 +1,7 @@ package com.baeldung.hibernate.bootstrap.model; -import javax.persistence.Entity; -import javax.persistence.Id; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; @Entity public class TestEntity { diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/dynamicupdate/AccountRepository.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/dynamicupdate/AccountRepository.java similarity index 100% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/dynamicupdate/AccountRepository.java rename to persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/dynamicupdate/AccountRepository.java diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateConfig.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateConfig.java similarity index 98% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateConfig.java rename to persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateConfig.java index 23e28a9e3b..766295f67a 100644 --- a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateConfig.java +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateConfig.java @@ -2,7 +2,7 @@ package com.baeldung.hibernate.dynamicupdate; import java.util.Properties; -import javax.persistence.EntityManagerFactory; +import jakarta.persistence.EntityManagerFactory; import javax.sql.DataSource; import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; diff --git a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/dynamicupdate/model/Account.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/dynamicupdate/model/Account.java similarity index 94% rename from persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/dynamicupdate/model/Account.java rename to persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/dynamicupdate/model/Account.java index b3753112fe..808ffe99ee 100644 --- a/persistence-modules/spring-hibernate-5/src/main/java/com/baeldung/hibernate/dynamicupdate/model/Account.java +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/hibernate/dynamicupdate/model/Account.java @@ -2,9 +2,9 @@ package com.baeldung.hibernate.dynamicupdate.model; import java.text.MessageFormat; -import javax.persistence.Column; -import javax.persistence.Entity; -import javax.persistence.Id; +import jakarta.persistence.Column; +import jakarta.persistence.Entity; +import jakarta.persistence.Id; import org.hibernate.annotations.DynamicUpdate; diff --git a/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/IFooDao.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/IFooDao.java new file mode 100644 index 0000000000..0935772dbd --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/IFooDao.java @@ -0,0 +1,8 @@ +package com.baeldung.persistence.dao; + +import com.baeldung.persistence.model.Foo; +import com.baeldung.persistence.dao.common.IOperations; + +public interface IFooDao extends IOperations { + // +} diff --git a/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/AbstractDao.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/AbstractDao.java new file mode 100644 index 0000000000..5a6c76a93a --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/AbstractDao.java @@ -0,0 +1,14 @@ +package com.baeldung.persistence.dao.common; + +import java.io.Serializable; + +import com.google.common.base.Preconditions; + +public abstract class AbstractDao implements IOperations { + + protected Class clazz; + + protected final void setClazz(final Class clazzToSet) { + clazz = Preconditions.checkNotNull(clazzToSet); + } +} diff --git a/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/AbstractHibernateDao.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/AbstractHibernateDao.java new file mode 100644 index 0000000000..f34866d883 --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/AbstractHibernateDao.java @@ -0,0 +1,59 @@ +package com.baeldung.persistence.dao.common; + +import java.io.Serializable; +import java.util.List; + +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.springframework.beans.factory.annotation.Autowired; + +import com.google.common.base.Preconditions; + +@SuppressWarnings("unchecked") +public abstract class AbstractHibernateDao extends AbstractDao implements IOperations { + + @Autowired + protected SessionFactory sessionFactory; + + // API + + @Override + public T findOne(final long id) { + return (T) getCurrentSession().get(clazz, id); + } + + @Override + public List findAll() { + return getCurrentSession().createQuery("from " + clazz.getName()).getResultList(); + } + + @Override + public void create(final T entity) { + Preconditions.checkNotNull(entity); + getCurrentSession().saveOrUpdate(entity); + } + + @Override + public T update(final T entity) { + Preconditions.checkNotNull(entity); + return (T) getCurrentSession().merge(entity); + } + + @Override + public void delete(final T entity) { + Preconditions.checkNotNull(entity); + getCurrentSession().delete(entity); + } + + @Override + public void deleteById(final long entityId) { + final T entity = findOne(entityId); + Preconditions.checkState(entity != null); + delete(entity); + } + + protected Session getCurrentSession() { + return sessionFactory.getCurrentSession(); + } + +} \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/IOperations.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/IOperations.java new file mode 100644 index 0000000000..4ef99221ab --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/common/IOperations.java @@ -0,0 +1,20 @@ +package com.baeldung.persistence.dao.common; + +import java.io.Serializable; +import java.util.List; + +public interface IOperations { + + T findOne(final long id); + + List findAll(); + + void create(final T entity); + + T update(final T entity); + + void delete(final T entity); + + void deleteById(final long entityId); + +} diff --git a/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/impl/FooHibernateDao.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/impl/FooHibernateDao.java new file mode 100644 index 0000000000..5411073360 --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/dao/impl/FooHibernateDao.java @@ -0,0 +1,19 @@ +package com.baeldung.persistence.dao.impl; + +import com.baeldung.persistence.dao.common.AbstractHibernateDao; +import com.baeldung.persistence.dao.IFooDao; +import com.baeldung.persistence.model.Foo; +import org.springframework.stereotype.Repository; + +@Repository +public class FooHibernateDao extends AbstractHibernateDao implements IFooDao { + + public FooHibernateDao() { + super(); + + setClazz(Foo.class); + } + + // API + +} diff --git a/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/model/Foo.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/model/Foo.java new file mode 100644 index 0000000000..c9a541290d --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/persistence/model/Foo.java @@ -0,0 +1,73 @@ +package com.baeldung.persistence.model; + +import jakarta.persistence.*; +import java.io.Serializable; + +@Entity +public class Foo implements Serializable{ + + @Id + @GeneratedValue(strategy = GenerationType.AUTO) + @Column(name = "id") + private long id; + + @Column(name = "name") + private String name; + + public Foo() { + super(); + } + + public Foo(final String name) { + super(); + this.name = name; + } + + public long getId() { + return id; + } + + public void setId(final long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(final String name) { + this.name = name; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + return result; + } + + @Override + public boolean equals(final Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final Foo other = (Foo) obj; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + return true; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("Foo [name=").append(name).append("]"); + return builder.toString(); + } +} diff --git a/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/spring/PersistenceConfig.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/spring/PersistenceConfig.java new file mode 100644 index 0000000000..04961c3c49 --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/spring/PersistenceConfig.java @@ -0,0 +1,82 @@ +package com.baeldung.spring; + +import com.baeldung.persistence.dao.IFooDao; +import com.baeldung.persistence.dao.impl.FooHibernateDao; +import com.google.common.base.Preconditions; +import org.apache.tomcat.dbcp.dbcp2.BasicDataSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor; +import org.springframework.orm.hibernate5.HibernateTransactionManager; +import org.springframework.orm.hibernate5.LocalSessionFactoryBean; +import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +import javax.sql.DataSource; +import java.util.Properties; + +@Configuration +@EnableTransactionManagement +@PropertySource({ "classpath:persistence-h2.properties" }) +@ComponentScan({ "com.baeldung.persistence" }) +public class PersistenceConfig { + + @Autowired + private Environment env; + + @Bean + public LocalSessionFactoryBean sessionFactory() { + final LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean(); + sessionFactory.setDataSource(myDataSource()); + sessionFactory.setPackagesToScan(new String[] { "com.baeldung.persistence.model" }); + sessionFactory.setHibernateProperties(hibernateProperties()); + + return sessionFactory; + } + + @Bean + public DataSource myDataSource() { + final BasicDataSource dataSource = new BasicDataSource(); + dataSource.setDriverClassName(Preconditions.checkNotNull(env.getProperty("jdbc.driverClassName"))); + dataSource.setUrl(Preconditions.checkNotNull(env.getProperty("jdbc.url"))); + dataSource.setUsername(Preconditions.checkNotNull(env.getProperty("jdbc.user"))); + dataSource.setPassword(Preconditions.checkNotNull(env.getProperty("jdbc.pass"))); + + return dataSource; + } + + @Bean + public PlatformTransactionManager hibernateTransactionManager() { + final HibernateTransactionManager transactionManager = new HibernateTransactionManager(); + transactionManager.setSessionFactory(sessionFactory().getObject()); + return transactionManager; + } + + @Bean + public PersistenceExceptionTranslationPostProcessor exceptionTranslation() { + return new PersistenceExceptionTranslationPostProcessor(); + } + + @Bean + public IFooDao fooHibernateDao() { + return new FooHibernateDao(); + } + + private final Properties hibernateProperties() { + final Properties hibernateProperties = new Properties(); + hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); + hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); + + hibernateProperties.setProperty("hibernate.show_sql", "false"); + + // Envers properties + hibernateProperties.setProperty("org.hibernate.envers.audit_table_suffix", env.getProperty("envers.audit_table_suffix")); + + return hibernateProperties; + } + +} \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/spring/PersistenceXmlConfig.java b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/spring/PersistenceXmlConfig.java new file mode 100644 index 0000000000..14caf5c88c --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/java/com/baeldung/spring/PersistenceXmlConfig.java @@ -0,0 +1,14 @@ +package com.baeldung.spring; + +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportResource; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@Configuration +@EnableTransactionManagement +@ComponentScan({ "com.baeldung.persistence.dao", "com.baeldung.persistence.service" }) +@ImportResource({ "classpath:hibernate6Config.xml" }) +public class PersistenceXmlConfig { + +} \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-6/src/main/resources/hibernate6Config.xml b/persistence-modules/spring-hibernate-6/src/main/resources/hibernate6Config.xml new file mode 100644 index 0000000000..bbb61cb3e0 --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/resources/hibernate6Config.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + ${hibernate.hbm2ddl.auto} + ${hibernate.dialect} + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-6/src/main/resources/hibernate6Configuration.xml b/persistence-modules/spring-hibernate-6/src/main/resources/hibernate6Configuration.xml new file mode 100644 index 0000000000..cb6cf0aa5c --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/resources/hibernate6Configuration.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + ${hibernate.hbm2ddl.auto} + ${hibernate.dialect} + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-6/src/main/resources/logback.xml b/persistence-modules/spring-hibernate-6/src/main/resources/logback.xml new file mode 100644 index 0000000000..ec0dc2469a --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/resources/logback.xml @@ -0,0 +1,19 @@ + + + + + web - %date [%thread] %-5level %logger{36} - %message%n + + + + + + + + + + + + + + \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-6/src/main/resources/persistence-h2.properties b/persistence-modules/spring-hibernate-6/src/main/resources/persistence-h2.properties new file mode 100644 index 0000000000..2ed7022eab --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/resources/persistence-h2.properties @@ -0,0 +1,22 @@ +# jdbc.X +jdbc.driverClassName=org.h2.Driver +jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1 +jdbc.eventGeneratedId=sa +jdbc.user=sa +jdbc.pass= + +# hibernate.X +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=false +hibernate.hbm2ddl.auto=create-drop +hibernate.cache.use_second_level_cache=true +hibernate.cache.use_query_cache=true +hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory + + +# hibernate.search.X +hibernate.search.default.directory_provider = filesystem +hibernate.search.default.indexBase = /data/index/default + +# envers.X +envers.audit_table_suffix=_audit_log diff --git a/persistence-modules/spring-hibernate-6/src/main/resources/persistence-jndi.properties b/persistence-modules/spring-hibernate-6/src/main/resources/persistence-jndi.properties new file mode 100644 index 0000000000..16d750d7f8 --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/resources/persistence-jndi.properties @@ -0,0 +1,8 @@ +# jdbc.X +jdbc.url=java:comp/env/jdbc/BaeldungDatabase + +# hibernate.X +hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect +hibernate.show_sql=false +#hibernate.hbm2ddl.auto=create +hibernate.hbm2ddl.auto=update \ No newline at end of file diff --git a/persistence-modules/spring-hibernate-6/src/main/resources/persistence-mysql.properties b/persistence-modules/spring-hibernate-6/src/main/resources/persistence-mysql.properties new file mode 100644 index 0000000000..b3cfd31f46 --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/main/resources/persistence-mysql.properties @@ -0,0 +1,13 @@ +# jdbc.X +jdbc.driverClassName=com.mysql.cj.jdbc.Driver +jdbc.url=jdbc:mysql://localhost:3306/spring_hibernate5_01?createDatabaseIfNotExist=true +jdbc.eventGeneratedId=tutorialuser +jdbc.pass=tutorialmy5ql + +# hibernate.X +hibernate.dialect=org.hibernate.dialect.MySQL5Dialect +hibernate.show_sql=false +hibernate.hbm2ddl.auto=create-drop + +# envers.X +envers.audit_table_suffix=_audit_log diff --git a/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/SpringContextTest.java b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/SpringContextTest.java new file mode 100644 index 0000000000..4ec83cda3e --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/SpringContextTest.java @@ -0,0 +1,19 @@ +package com.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +import com.baeldung.spring.PersistenceConfig; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) +public class SpringContextTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + + } +} diff --git a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/bootstrap/HibernateBootstrapIntegrationTest.java b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/hibernate/bootstrap/HibernateBootstrapIntegrationTest.java similarity index 79% rename from persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/bootstrap/HibernateBootstrapIntegrationTest.java rename to persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/hibernate/bootstrap/HibernateBootstrapIntegrationTest.java index c41423643a..31522288b6 100644 --- a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/bootstrap/HibernateBootstrapIntegrationTest.java +++ b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/hibernate/bootstrap/HibernateBootstrapIntegrationTest.java @@ -1,33 +1,36 @@ package com.baeldung.hibernate.bootstrap; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import com.baeldung.hibernate.bootstrap.model.TestEntity; + + import org.hibernate.Session; import org.hibernate.SessionFactory; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.annotation.Commit; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.support.AnnotationConfigContextLoader; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.transaction.TestTransaction; import org.springframework.transaction.annotation.Transactional; -import static junit.framework.TestCase.assertFalse; -import static junit.framework.TestCase.assertTrue; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { HibernateConf.class }) @Transactional -public class HibernateBootstrapIntegrationTest { +@ContextConfiguration(classes = { HibernateXMLConf.class }) +@ExtendWith(SpringExtension.class) +class HibernateBootstrapIntegrationTest { @Autowired private SessionFactory sessionFactory; @Test - public void whenBootstrapHibernateSession_thenNoException() { + void whenBootstrapHibernateSession_thenNoException() { Session session = sessionFactory.getCurrentSession(); @@ -37,11 +40,11 @@ public class HibernateBootstrapIntegrationTest { TestEntity searchEntity = session.find(TestEntity.class, 1); - Assert.assertNotNull(searchEntity); + assertNotNull(searchEntity); } @Test - public void whenProgrammaticTransactionCommit_thenEntityIsInDatabase() { + void whenProgrammaticTransactionCommit_thenEntityIsInDatabase() { assertTrue(TestTransaction.isActive()); //Save an entity and commit. @@ -53,7 +56,7 @@ public class HibernateBootstrapIntegrationTest { TestEntity searchEntity = session.find(TestEntity.class, 1); - Assert.assertNotNull(searchEntity); + assertTrue(TestTransaction.isFlaggedForRollback()); TestTransaction.flagForCommit(); @@ -72,7 +75,7 @@ public class HibernateBootstrapIntegrationTest { session = sessionFactory.getCurrentSession(); searchEntity = session.find(TestEntity.class, 1); - Assert.assertNotNull(searchEntity); + assertNotNull(searchEntity); session.delete(searchEntity); session.flush(); @@ -88,7 +91,7 @@ public class HibernateBootstrapIntegrationTest { session = sessionFactory.getCurrentSession(); searchEntity = session.find(TestEntity.class, 1); - Assert.assertNotNull(searchEntity); + assertNotNull(searchEntity); session.delete(searchEntity); session.flush(); @@ -108,12 +111,12 @@ public class HibernateBootstrapIntegrationTest { session = sessionFactory.getCurrentSession(); searchEntity = session.find(TestEntity.class, 1); - Assert.assertNull(searchEntity); + assertNull(searchEntity); } @Test @Commit - public void givenTransactionCommitDefault_whenProgrammaticTransactionCommit_thenEntityIsInDatabase() { + void givenTransactionCommitDefault_whenProgrammaticTransactionCommit_thenEntityIsInDatabase() { assertTrue(TestTransaction.isActive()); //Save an entity and commit. @@ -125,7 +128,7 @@ public class HibernateBootstrapIntegrationTest { TestEntity searchEntity = session.find(TestEntity.class, 1); - Assert.assertNotNull(searchEntity); + assertNotNull(searchEntity); assertFalse(TestTransaction.isFlaggedForRollback()); TestTransaction.end(); @@ -143,7 +146,7 @@ public class HibernateBootstrapIntegrationTest { session = sessionFactory.getCurrentSession(); searchEntity = session.find(TestEntity.class, 1); - Assert.assertNotNull(searchEntity); + assertNotNull(searchEntity); session.delete(searchEntity); session.flush(); @@ -160,7 +163,7 @@ public class HibernateBootstrapIntegrationTest { session = sessionFactory.getCurrentSession(); searchEntity = session.find(TestEntity.class, 1); - Assert.assertNotNull(searchEntity); + assertNotNull(searchEntity); session.delete(searchEntity); session.flush(); @@ -179,7 +182,7 @@ public class HibernateBootstrapIntegrationTest { session = sessionFactory.getCurrentSession(); searchEntity = session.find(TestEntity.class, 1); - Assert.assertNull(searchEntity); + assertNull(searchEntity); } } diff --git a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/bootstrap/HibernateXMLBootstrapIntegrationTest.java b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/hibernate/bootstrap/HibernateXMLBootstrapIntegrationTest.java similarity index 65% rename from persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/bootstrap/HibernateXMLBootstrapIntegrationTest.java rename to persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/hibernate/bootstrap/HibernateXMLBootstrapIntegrationTest.java index 5b811ad576..153e6736f1 100644 --- a/persistence-modules/spring-hibernate-5/src/test/java/com/baeldung/hibernate/bootstrap/HibernateXMLBootstrapIntegrationTest.java +++ b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/hibernate/bootstrap/HibernateXMLBootstrapIntegrationTest.java @@ -1,26 +1,27 @@ package com.baeldung.hibernate.bootstrap; +import static org.junit.jupiter.api.Assertions.assertNotNull; + import com.baeldung.hibernate.bootstrap.model.TestEntity; import org.hibernate.Session; import org.hibernate.SessionFactory; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.transaction.annotation.Transactional; -@RunWith(SpringJUnit4ClassRunner.class) +@ExtendWith(SpringExtension.class) @ContextConfiguration(classes = { HibernateXMLConf.class }) @Transactional -public class HibernateXMLBootstrapIntegrationTest { +class HibernateXMLBootstrapIntegrationTest { @Autowired private SessionFactory sessionFactory; @Test - public void whenBootstrapHibernateSession_thenNoException() { + void whenBootstrapHibernateSession_thenNoException() { Session session = sessionFactory.getCurrentSession(); @@ -30,7 +31,7 @@ public class HibernateXMLBootstrapIntegrationTest { TestEntity searchEntity = session.find(TestEntity.class, 1); - Assert.assertNotNull(searchEntity); + assertNotNull(searchEntity); } } diff --git a/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateIntegrationTest.java b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateIntegrationTest.java new file mode 100644 index 0000000000..9a52599842 --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/hibernate/dynamicupdate/DynamicUpdateIntegrationTest.java @@ -0,0 +1,52 @@ +package com.baeldung.hibernate.dynamicupdate; + +import java.util.Optional; + +import jakarta.transaction.Transactional; + +import org.junit.jupiter.api.MethodOrderer; +import org.junit.jupiter.api.Order; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestMethodOrder; +import org.junit.jupiter.api.extension.ExtendWith; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.annotation.Commit; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +import com.baeldung.hibernate.dynamicupdate.model.Account; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = { DynamicUpdateConfig.class }, loader = AnnotationConfigContextLoader.class) +@Transactional +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +class DynamicUpdateIntegrationTest { + + private static final Integer ACCOUNT_ID = 1; + + @Autowired + private AccountRepository accountRepository; + + @Test + @Commit + @Order(1) + void testA_whenTestAccountIsSaved_thenSuccess() { + Account account = new Account(ACCOUNT_ID, "account1", "regional", true); + accountRepository.save(account); + } + + @Test + @Commit + @Order(2) + // Enable Hibernate's debug logging in logback.xml to see the generated SQL statement. + void testB_whenAccountNameUpdated_thenSuccess() { + Optional account = accountRepository.findById(ACCOUNT_ID); + if(account.isPresent()){ + account.get().setName("Test Account"); + accountRepository.save(account.get()); + } + } + +} diff --git a/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/persistence/dao/common/HibernateDaoIntegrationTest.java b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/persistence/dao/common/HibernateDaoIntegrationTest.java new file mode 100644 index 0000000000..d7069c62c9 --- /dev/null +++ b/persistence-modules/spring-hibernate-6/src/test/java/com/baeldung/persistence/dao/common/HibernateDaoIntegrationTest.java @@ -0,0 +1,46 @@ +package com.baeldung.persistence.dao.common; + +import com.baeldung.persistence.model.Foo; +import com.baeldung.spring.PersistenceConfig; +import org.apache.commons.lang3.RandomStringUtils; +import org.hibernate.Session; +import org.hibernate.SessionFactory; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.support.AnnotationConfigContextLoader; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) +class HibernateDaoIntegrationTest { + + @Autowired + private SessionFactory sessionFactory; + + private Session session; + + @BeforeEach + public final void before() { + session = sessionFactory.openSession(); + } + + @AfterEach + public final void after() { + session.close(); + } + + @Test + final void whenContextIsBootstrapped_thenNoExceptions() { + // + } + + @Test + final void whenPersistEntity_thenSuccess() { + session.persist(new Foo(RandomStringUtils.randomAlphabetic(5).toUpperCase())); + } + +} diff --git a/persistence-modules/spring-jdbc/README.md b/persistence-modules/spring-jdbc/README.md index 21d25915de..19f8537a4e 100644 --- a/persistence-modules/spring-jdbc/README.md +++ b/persistence-modules/spring-jdbc/README.md @@ -7,3 +7,4 @@ - [Obtaining Auto-generated Keys in Spring JDBC](https://www.baeldung.com/spring-jdbc-autogenerated-keys) - [Spring JDBC Batch Inserts](https://www.baeldung.com/spring-jdbc-batch-inserts) - [Fix EmptyResultDataAccessException When Using JdbcTemplate](https://www.baeldung.com/jdbctemplate-fix-emptyresultdataaccessexception) +- [How to replace deprecated jdbcTemplate.queryForObject and jdbcTemplate.query in spring boot 2.4.X and above](https://www.baeldung.com/spring-boot-replace-deprecated-jdbctemplate-queryforobject-query) diff --git a/pom.xml b/pom.xml index 060f158888..6853b10587 100644 --- a/pom.xml +++ b/pom.xml @@ -723,9 +723,12 @@ spring-boot-rest spring-drools spring-cloud-modules/spring-cloud-azure + spring-cloud-modules/spring-cloud-circuit-breaker spring-cloud-modules/spring-cloud-contract spring-cloud-modules/spring-cloud-data-flow - spring-cloud-modules/spring-cloud-circuit-breaker + spring-cloud-modules/spring-cloud-netflix-feign + spring-cloud-modules/spring-cloud-stream-starters + spring-cloud-modules/spring-cloud-zuul-eureka-integration spring-exceptions spring-jenkins-pipeline spring-core @@ -892,6 +895,7 @@ spring-5 spring-5-webflux spring-5-webflux-2 + spring-6-rsocket spring-activiti spring-actuator spring-core-2 @@ -1000,6 +1004,10 @@ spring-drools spring-cloud-modules/spring-cloud-azure spring-cloud-modules/spring-cloud-circuit-breaker + spring-cloud-modules/spring-cloud-contract + spring-cloud-modules/spring-cloud-netflix-feign + spring-cloud-modules/spring-cloud-stream-starters + spring-cloud-modules/spring-cloud-zuul-eureka-integration spring-exceptions spring-jenkins-pipeline spring-core @@ -1212,7 +1220,6 @@ gradle-modules/gradle/maven-to-gradle persistence-modules/spring-data-neo4j spring-actuator - spring-cloud-modules/spring-cloud-contract diff --git a/quarkus-modules/quarkus/pom.xml b/quarkus-modules/quarkus/pom.xml index 99d18579c3..fc3d294beb 100644 --- a/quarkus-modules/quarkus/pom.xml +++ b/quarkus-modules/quarkus/pom.xml @@ -152,11 +152,8 @@ - native-image + image-build - - true - diff --git a/quarkus-modules/quarkus/src/test/java/com/baeldung/quarkus/NativeHelloResourceIT.java b/quarkus-modules/quarkus/src/test/java/com/baeldung/quarkus/NativeHelloResourceIT.java index e6c8a3b8fb..b8567a8609 100644 --- a/quarkus-modules/quarkus/src/test/java/com/baeldung/quarkus/NativeHelloResourceIT.java +++ b/quarkus-modules/quarkus/src/test/java/com/baeldung/quarkus/NativeHelloResourceIT.java @@ -2,9 +2,9 @@ package com.baeldung.quarkus; import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.h2.H2DatabaseTestResource; -import io.quarkus.test.junit.NativeImageTest; +import io.quarkus.test.junit.QuarkusIntegrationTest; -@NativeImageTest +@QuarkusIntegrationTest @QuarkusTestResource(H2DatabaseTestResource.class) public class NativeHelloResourceIT extends HelloResourceUnitTest { diff --git a/quarkus-modules/quarkus/src/test/java/com/baeldung/quarkus/NativeLibraryResourceIT.java b/quarkus-modules/quarkus/src/test/java/com/baeldung/quarkus/NativeLibraryResourceIT.java index 0c11fa6fb4..10539d78d7 100644 --- a/quarkus-modules/quarkus/src/test/java/com/baeldung/quarkus/NativeLibraryResourceIT.java +++ b/quarkus-modules/quarkus/src/test/java/com/baeldung/quarkus/NativeLibraryResourceIT.java @@ -2,9 +2,9 @@ package com.baeldung.quarkus; import io.quarkus.test.common.QuarkusTestResource; import io.quarkus.test.h2.H2DatabaseTestResource; -import io.quarkus.test.junit.NativeImageTest; +import io.quarkus.test.junit.QuarkusIntegrationTest; -@NativeImageTest +@QuarkusIntegrationTest @QuarkusTestResource(H2DatabaseTestResource.class) class NativeLibraryResourceIT extends LibraryHttpEndpointIntegrationTest { } diff --git a/spring-6-rsocket/README.md b/spring-6-rsocket/README.md new file mode 100644 index 0000000000..21ab282bd1 --- /dev/null +++ b/spring-6-rsocket/README.md @@ -0,0 +1,7 @@ +## RSocket + +This module contains articles about RSocket in Spring Framework 6. + +### Relevant articles + +- [Introduction to RSocket](#) \ No newline at end of file diff --git a/spring-6-rsocket/pom.xml b/spring-6-rsocket/pom.xml new file mode 100644 index 0000000000..5d15a605ae --- /dev/null +++ b/spring-6-rsocket/pom.xml @@ -0,0 +1,74 @@ + + + 4.0.0 + com.bealdung + rsocket + 0.0.1-SNAPSHOT + rsocket + + + com.baeldung + parent-spring-6 + 0.0.1-SNAPSHOT + ../parent-spring-6 + + + + + + org.springframework.boot + spring-boot-starter-rsocket + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit + junit-bom + ${junit-jupiter.version} + pom + import + + + ch.qos.logback + logback-classic + ${logback.version} + + + ch.qos.logback + logback-core + ${logback.version} + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + jcl-over-slf4j + ${slf4j.version} + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + + 3.1.3 + 1.4.11 + 2.0.9 + + diff --git a/spring-6-rsocket/src/main/java/com/bealdung/rsocket/requester/MessageClient.java b/spring-6-rsocket/src/main/java/com/bealdung/rsocket/requester/MessageClient.java new file mode 100644 index 0000000000..8fed6bee9b --- /dev/null +++ b/spring-6-rsocket/src/main/java/com/bealdung/rsocket/requester/MessageClient.java @@ -0,0 +1,21 @@ +package com.bealdung.rsocket.requester; + +import org.springframework.messaging.rsocket.service.RSocketExchange; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +public interface MessageClient { + + @RSocketExchange("MyDestination") + Mono sendMessage(Mono input); + + @RSocketExchange("Counter") + Flux Counter(); + + @RSocketExchange("Warning") + Mono Warning(Mono warning); + + @RSocketExchange("channel") + Flux channel(Flux input); +} diff --git a/spring-6-rsocket/src/main/java/com/bealdung/rsocket/responder/MessageController.java b/spring-6-rsocket/src/main/java/com/bealdung/rsocket/responder/MessageController.java new file mode 100644 index 0000000000..a2cfcc69ca --- /dev/null +++ b/spring-6-rsocket/src/main/java/com/bealdung/rsocket/responder/MessageController.java @@ -0,0 +1,45 @@ +package com.bealdung.rsocket.responder; + +import org.springframework.messaging.handler.annotation.MessageMapping; +import org.springframework.stereotype.Controller; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +@Controller +public class MessageController { + + @MessageMapping("MyDestination") + public Mono message(Mono input) { + return input.doOnNext(msg -> System.out.println("Request is:" + msg + ",Request!")) + .map(msg -> msg + ",Response!"); + } + + @MessageMapping("Counter") + public Flux Counter() { + return Flux.range(1, 10) + .map(i -> "Count is: " + i); + } + + @MessageMapping("Warning") + public Mono Warning(Mono error) { + error.doOnNext(e -> System.out.println("warning is :" + e)) + .subscribe(); + return Mono.empty(); + } + + @MessageMapping("channel") + public Flux channel(Flux input) { + return input.doOnNext(i -> { + System.out.println("Received message is : " + i); + }) + .map(m -> m.toUpperCase()) + .doOnNext(r -> { + System.out.println("RESPONSE IS :" + r); + }); + } + +} + + + diff --git a/spring-6-rsocket/src/main/java/com/bealdung/rsocket/responder/RSocketApplication.java b/spring-6-rsocket/src/main/java/com/bealdung/rsocket/responder/RSocketApplication.java new file mode 100644 index 0000000000..9e763007fe --- /dev/null +++ b/spring-6-rsocket/src/main/java/com/bealdung/rsocket/responder/RSocketApplication.java @@ -0,0 +1,73 @@ +package com.bealdung.rsocket.responder; + +import org.springframework.boot.ApplicationRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.messaging.rsocket.RSocketRequester; +import org.springframework.messaging.rsocket.service.RSocketServiceProxyFactory; + +import com.bealdung.rsocket.requester.MessageClient; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +@SpringBootApplication +public class RSocketApplication { + public static void main(String[] args) { + SpringApplication.run(RSocketApplication.class, args); + } + + @Bean + public RSocketServiceProxyFactory getRSocketServiceProxyFactory(RSocketRequester.Builder requestBuilder) { + RSocketRequester requester = requestBuilder.tcp("localhost", 7000); + return RSocketServiceProxyFactory.builder(requester) + .build(); + } + + @Bean + public MessageClient getClient(RSocketServiceProxyFactory factory) { + return factory.createClient(MessageClient.class); + } + + @Bean + public ApplicationRunner runRequestResponseModel(MessageClient client) { + return args -> { + client.sendMessage(Mono.just("Request-Response test ")) + .doOnNext(message -> { + System.out.println("Response is :" + message); + }) + .subscribe(); + }; + } + + @Bean + public ApplicationRunner runStreamModel(MessageClient client) { + return args -> { + client.Counter() + .doOnNext(t -> { + System.out.println("message is :" + t); + }) + .subscribe(); + }; + } + + @Bean + public ApplicationRunner runFireAndForget(MessageClient client) { + return args -> { + client.Warning(Mono.just("Important Warning")) + .subscribe(); + }; + } + + @Bean + public ApplicationRunner runChannel(MessageClient client) { + return args -> { + client.channel(Flux.just("a", "b", "c", "d", "e")) + .doOnNext(i -> { + System.out.println(i); + }) + .subscribe(); + }; + } +} \ No newline at end of file diff --git a/spring-6-rsocket/src/main/resources/application.properties b/spring-6-rsocket/src/main/resources/application.properties new file mode 100644 index 0000000000..cab786cd30 --- /dev/null +++ b/spring-6-rsocket/src/main/resources/application.properties @@ -0,0 +1 @@ +spring.rsocket.server.port=7000 \ No newline at end of file diff --git a/spring-6-rsocket/src/test/java/com/bealdung/rsocket/RSocketRequestResponseIntegrationTest.java b/spring-6-rsocket/src/test/java/com/bealdung/rsocket/RSocketRequestResponseIntegrationTest.java new file mode 100644 index 0000000000..4b85c4c6fc --- /dev/null +++ b/spring-6-rsocket/src/test/java/com/bealdung/rsocket/RSocketRequestResponseIntegrationTest.java @@ -0,0 +1,35 @@ +package com.bealdung.rsocket; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.messaging.rsocket.RSocketRequester; +import org.springframework.messaging.rsocket.service.RSocketServiceProxyFactory; + +import com.bealdung.rsocket.requester.MessageClient; +import com.bealdung.rsocket.responder.RSocketApplication; + +import reactor.core.publisher.Mono; + +@SpringBootTest(classes = RSocketApplication.class) +public class RSocketRequestResponseIntegrationTest { + + MessageClient client; + + public RSocketRequestResponseIntegrationTest() { + RSocketRequester.Builder requesterBuilder = RSocketRequester.builder(); + RSocketRequester requester = requesterBuilder.tcp("localhost", 7000); + RSocketServiceProxyFactory factory = RSocketServiceProxyFactory.builder(requester) + .build(); + client = factory.createClient(MessageClient.class); + } + + @Test + public void whenSendingStream_thenReceiveTheSameStream() { + String message = "test message"; + assertEquals(message, client.sendMessage(Mono.just(message)) + .block()); + } + +} diff --git a/spring-boot-modules/pom.xml b/spring-boot-modules/pom.xml index 1c4b2bb38f..2b4a94a7a5 100644 --- a/spring-boot-modules/pom.xml +++ b/spring-boot-modules/pom.xml @@ -104,6 +104,7 @@ spring-boot-springdoc-2 spring-boot-documentation spring-boot-3-url-matching + spring-boot-graalvm-docker diff --git a/spring-boot-modules/spring-boot-3/pom.xml b/spring-boot-modules/spring-boot-3/pom.xml index a1f3ee6203..e28931243d 100644 --- a/spring-boot-modules/spring-boot-3/pom.xml +++ b/spring-boot-modules/spring-boot-3/pom.xml @@ -41,6 +41,27 @@ mockserver-netty ${mockserver.version} + + org.junit.jupiter + junit-jupiter + ${jupiter.version} + + + org.junit.jupiter + junit-jupiter-api + ${jupiter.version} + + + org.junit.jupiter + junit-jupiter-engine + ${jupiter.version} + + + org.junit.jupiter + junit-jupiter-params + ${jupiter.version} + test + org.mock-server mockserver-client-java @@ -256,9 +277,47 @@ 3.0.0-M7 com.baeldung.sample.TodoApplication 5.14.0 - 3.1.0 + 3.2.0-SNAPSHOT 0.2.0 + 5.10.0 1.18.3 + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + false + + + + + + spring-milestones + Spring Milestones + https://repo.spring.io/milestone + + false + + + + spring-snapshots + Spring Snapshots + https://repo.spring.io/snapshot + + false + + + + \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/Article.java b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/Article.java new file mode 100644 index 0000000000..a69d5989af --- /dev/null +++ b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/Article.java @@ -0,0 +1,34 @@ +package com.baeldung.restclient; + +import java.util.Objects; + +public class Article { + Integer id; + String title; + + public Article(Integer id, String title) { + this.id = id; + this.title = title; + } + + public Integer getId() { + return id; + } + + public String getTitle() { + return title; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Article article = (Article) o; + return Objects.equals(id, article.id) && Objects.equals(title, article.title); + } + + @Override + public int hashCode() { + return Objects.hash(id, title); + } +} diff --git a/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/ArticleController.java b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/ArticleController.java new file mode 100644 index 0000000000..62922bdcee --- /dev/null +++ b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/ArticleController.java @@ -0,0 +1,45 @@ +package com.baeldung.restclient; + +import org.springframework.web.bind.annotation.*; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +@RestController +@RequestMapping("/articles") +public class ArticleController { + Map database = new HashMap<>(); + + @GetMapping + public Collection
getArticles() { + return database.values(); + } + + @GetMapping("/{id}") + public Article getArticle(@PathVariable Integer id) { + return database.get(id); + } + + @PostMapping + public void createArticle(@RequestBody Article article) { + database.put(article.getId(), article); + } + + @PutMapping("/{id}") + public void updateArticle(@PathVariable Integer id, @RequestBody Article article) { + assert Objects.equals(id, article.getId()); + database.remove(id); + database.put(id, article); + } + + @DeleteMapping("/{id}") + public void deleteArticle(@PathVariable Integer id) { + database.remove(id); + } + @DeleteMapping() + public void deleteArticles() { + database.clear(); + } +} diff --git a/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/RestClientApplication.java b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/RestClientApplication.java new file mode 100644 index 0000000000..c411a8f74a --- /dev/null +++ b/spring-boot-modules/spring-boot-3/src/main/java/com/baeldung/restclient/RestClientApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.restclient; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class RestClientApplication { + + public static void main(String[] args) { + SpringApplication.run(RestClientApplication.class, args); + } + +} diff --git a/spring-boot-modules/spring-boot-3/src/test/java/com/baeldung/restclient/RestClientIntegrationTest.java b/spring-boot-modules/spring-boot-3/src/test/java/com/baeldung/restclient/RestClientIntegrationTest.java new file mode 100644 index 0000000000..92474c88f0 --- /dev/null +++ b/spring-boot-modules/spring-boot-3/src/test/java/com/baeldung/restclient/RestClientIntegrationTest.java @@ -0,0 +1,114 @@ +package com.baeldung.restclient; + +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.MediaType; +import org.springframework.web.client.RestClient; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class RestClientIntegrationTest { + + @LocalServerPort + private int port; + private String uriBase; + RestClient restClient = RestClient.create(); + + @BeforeAll + public void setup() { + uriBase = "http://localhost:" + port; + } + + @AfterEach + public void teardown() { + restClient.delete() + .uri(uriBase + "/articles") + .retrieve() + .toBodilessEntity(); + } + + @Test + void shouldGetArticlesAndReturnString() { + String articlesAsString = restClient.get() + .uri(uriBase + "/articles") + .retrieve() + .body(String.class); + + assertThat(articlesAsString).isEqualTo("[]"); + } + + @Test + void shouldPostAndGetArticles() { + Article article = new Article(1, "How to use RestClient"); + restClient.post() + .uri(uriBase + "/articles") + .contentType(MediaType.APPLICATION_JSON) + .body(article) + .retrieve() + .toBodilessEntity(); + + List
articles = restClient.get() + .uri(uriBase + "/articles") + .retrieve() + .body(new ParameterizedTypeReference<>() {}); + + assertThat(articles).isEqualTo(List.of(article)); + } + + @Test + void shouldPostAndPutAndGetArticles() { + Article article = new Article(1, "How to use RestClient"); + restClient.post() + .uri(uriBase + "/articles") + .contentType(MediaType.APPLICATION_JSON) + .body(article) + .retrieve() + .toBodilessEntity(); + + Article articleChanged = new Article(1, "How to use RestClient even better"); + restClient.put() + .uri(uriBase + "/articles/1") + .contentType(MediaType.APPLICATION_JSON) + .body(articleChanged) + .retrieve() + .toBodilessEntity(); + + List
articles = restClient.get() + .uri(uriBase + "/articles") + .retrieve() + .body(new ParameterizedTypeReference<>() {}); + + assertThat(articles).isEqualTo(List.of(articleChanged)); + } + + @Test + void shouldPostAndDeleteArticles() { + Article article = new Article(1, "How to use RestClient"); + restClient.post() + .uri(uriBase + "/articles") + .contentType(MediaType.APPLICATION_JSON) + .body(article) + .retrieve() + .toBodilessEntity(); + + restClient.delete() + .uri(uriBase + "/articles") + .retrieve() + .toBodilessEntity(); + + List
articles = restClient.get() + .uri(uriBase + "/articles") + .retrieve() + .body(new ParameterizedTypeReference<>() {}); + + assertThat(articles).isEqualTo(List.of()); + } +} diff --git a/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories b/spring-boot-modules/spring-boot-autoconfiguration/src/main/resources/META-INF/spring.factories deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/spring-boot-modules/spring-boot-graalvm-docker/Dockerfile b/spring-boot-modules/spring-boot-graalvm-docker/Dockerfile new file mode 100644 index 0000000000..91a63074c1 --- /dev/null +++ b/spring-boot-modules/spring-boot-graalvm-docker/Dockerfile @@ -0,0 +1,3 @@ +FROM ubuntu:jammy +COPY target/springboot-graalvm-docker /springboot-graalvm-docker +CMD ["/springboot-graalvm-docker"] diff --git a/spring-boot-modules/spring-boot-graalvm-docker/pom.xml b/spring-boot-modules/spring-boot-graalvm-docker/pom.xml new file mode 100644 index 0000000000..a3a1b148c2 --- /dev/null +++ b/spring-boot-modules/spring-boot-graalvm-docker/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3 + + + com.baeldung + spring-boot-graalvm-docker + 1.0.0 + spring-boot-graalvm-docker + Spring Boot GrralVM with Docker + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + org.graalvm.buildtools + native-maven-plugin + + + org.springframework.boot + spring-boot-maven-plugin + + + + diff --git a/spring-boot-modules/spring-boot-graalvm-docker/src/main/java/com/baeldung/graalvmdockerimage/GraalvmDockerImageApplication.java b/spring-boot-modules/spring-boot-graalvm-docker/src/main/java/com/baeldung/graalvmdockerimage/GraalvmDockerImageApplication.java new file mode 100644 index 0000000000..53e11aa749 --- /dev/null +++ b/spring-boot-modules/spring-boot-graalvm-docker/src/main/java/com/baeldung/graalvmdockerimage/GraalvmDockerImageApplication.java @@ -0,0 +1,24 @@ +package com.baeldung.graalvmdockerimage; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@SpringBootApplication +public class GraalvmDockerImageApplication { + + public static void main(String[] args) { + SpringApplication.run(GraalvmDockerImageApplication.class, args); + } + +} + +@RestController +class HelloController { + + @GetMapping + public String hello() { + return "Hello GraalVM"; + } +} diff --git a/spring-boot-modules/spring-boot-graalvm-docker/src/main/resources/application.properties b/spring-boot-modules/spring-boot-graalvm-docker/src/main/resources/application.properties new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/spring-boot-modules/spring-boot-graalvm-docker/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/spring-boot-modules/spring-boot-keycloak-2/pom.xml b/spring-boot-modules/spring-boot-keycloak-2/pom.xml index 39a7283328..7909e2e153 100644 --- a/spring-boot-modules/spring-boot-keycloak-2/pom.xml +++ b/spring-boot-modules/spring-boot-keycloak-2/pom.xml @@ -11,10 +11,9 @@ This is a simple application demonstrating integration between Keycloak and Spring Boot. - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT diff --git a/spring-boot-modules/spring-boot-keycloak-adapters/pom.xml b/spring-boot-modules/spring-boot-keycloak-adapters/pom.xml index 035c226b6d..34c0653fbd 100644 --- a/spring-boot-modules/spring-boot-keycloak-adapters/pom.xml +++ b/spring-boot-modules/spring-boot-keycloak-adapters/pom.xml @@ -11,10 +11,9 @@ This is a simple application demonstrating integration between Keycloak and Spring Boot. - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT diff --git a/spring-boot-modules/spring-boot-keycloak/pom.xml b/spring-boot-modules/spring-boot-keycloak/pom.xml index 64fb39d085..bada9ab52d 100644 --- a/spring-boot-modules/spring-boot-keycloak/pom.xml +++ b/spring-boot-modules/spring-boot-keycloak/pom.xml @@ -11,10 +11,9 @@ This is a simple application demonstrating integration between Keycloak and Spring Boot. - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT diff --git a/spring-boot-modules/spring-boot-logging-log4j2/pom.xml b/spring-boot-modules/spring-boot-logging-log4j2/pom.xml index b429339417..31c0f4bd02 100644 --- a/spring-boot-modules/spring-boot-logging-log4j2/pom.xml +++ b/spring-boot-modules/spring-boot-logging-log4j2/pom.xml @@ -9,10 +9,9 @@ Demo project for Spring Boot Logging with Log4J2 - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT diff --git a/spring-boot-modules/spring-boot-mvc-birt/pom.xml b/spring-boot-modules/spring-boot-mvc-birt/pom.xml index 274932f06c..cc4b7f8283 100644 --- a/spring-boot-modules/spring-boot-mvc-birt/pom.xml +++ b/spring-boot-modules/spring-boot-mvc-birt/pom.xml @@ -10,10 +10,9 @@ Module For Spring Boot Integration with BIRT - com.baeldung - parent-boot-2 - 0.0.1-SNAPSHOT - ../../parent-boot-2 + com.baeldung.spring-boot-modules + spring-boot-modules + 1.0.0-SNAPSHOT diff --git a/spring-boot-modules/spring-boot-security/README.md b/spring-boot-modules/spring-boot-security/README.md index d848f798ba..2fd9e77c92 100644 --- a/spring-boot-modules/spring-boot-security/README.md +++ b/spring-boot-modules/spring-boot-security/README.md @@ -11,7 +11,7 @@ This module contains articles about Spring Boot Security - [Disable Security for a Profile in Spring Boot](https://www.baeldung.com/spring-security-disable-profile) - [Spring @EnableWebSecurity vs. @EnableGlobalMethodSecurity](https://www.baeldung.com/spring-enablewebsecurity-vs-enableglobalmethodsecurity) - [Spring Security – Configuring Different URLs](https://www.baeldung.com/spring-security-configuring-urls) - +- [Difference Between permitAll() and anonymous() in Spring Security](https://www.baeldung.com/spring-security-permitall-vs-anonymous) ### Spring Boot Security Auto-Configuration diff --git a/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/permitallanonymous/SecuredEcommerceApplication.java b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/permitallanonymous/SecuredEcommerceApplication.java new file mode 100644 index 0000000000..150fe399d1 --- /dev/null +++ b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/permitallanonymous/SecuredEcommerceApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.permitallanonymous; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +@SpringBootApplication +@ComponentScan("com.baeldung.permitallanonymous.*") +public class SecuredEcommerceApplication { + public static void main(String[] args) { + SpringApplication.run(SecuredEcommerceApplication.class, args); + } +} diff --git a/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/permitallanonymous/controller/EcommerceController.java b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/permitallanonymous/controller/EcommerceController.java new file mode 100644 index 0000000000..8f20baee10 --- /dev/null +++ b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/permitallanonymous/controller/EcommerceController.java @@ -0,0 +1,29 @@ +package com.baeldung.permitallanonymous.controller; + +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class EcommerceController { + + //can be accessed by only logged-in users + @GetMapping("/private/showCart") + public @ResponseBody String showCart() { + return "Show Cart"; + } + + //can we accessed by both anonymous and authenticated users + @GetMapping("/public/showProducts") + public @ResponseBody String listProducts() { + return "List Products"; + } + + //can be access by only anonymous users not by authenticated users + @GetMapping("/public/registerUser") + public @ResponseBody String registerUser() { + return "Register User"; + } + +} + diff --git a/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/permitallanonymous/filter/AuditInterceptor.java b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/permitallanonymous/filter/AuditInterceptor.java new file mode 100644 index 0000000000..c0a5f6972f --- /dev/null +++ b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/permitallanonymous/filter/AuditInterceptor.java @@ -0,0 +1,33 @@ +package com.baeldung.permitallanonymous.filter; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.security.authentication.AnonymousAuthenticationToken; +import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.web.filter.OncePerRequestFilter; + +import javax.servlet.FilterChain; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +public class AuditInterceptor extends OncePerRequestFilter { + private final Logger logger = LoggerFactory.getLogger(AuditInterceptor.class); + + @Override + protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) + throws ServletException, IOException { + + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (authentication instanceof AnonymousAuthenticationToken) { + logger.info("Audit anonymous user"); + } + if (authentication instanceof UsernamePasswordAuthenticationToken) { + logger.info("Audit registered user"); + } + filterChain.doFilter(request, response); + } +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/permitallanonymous/security/EcommerceWebSecurityConfig.java b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/permitallanonymous/security/EcommerceWebSecurityConfig.java new file mode 100644 index 0000000000..566ec49e42 --- /dev/null +++ b/spring-boot-modules/spring-boot-security/src/main/java/com/baeldung/permitallanonymous/security/EcommerceWebSecurityConfig.java @@ -0,0 +1,46 @@ +package com.baeldung.permitallanonymous.security; + +import com.baeldung.permitallanonymous.filter.AuditInterceptor; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.provisioning.InMemoryUserDetailsManager; +import org.springframework.security.web.SecurityFilterChain; +import org.springframework.security.web.authentication.AnonymousAuthenticationFilter; + +@Configuration +@EnableWebSecurity +public class EcommerceWebSecurityConfig { + @Bean + public InMemoryUserDetailsManager userDetailsService(PasswordEncoder passwordEncoder) { + UserDetails user = User.withUsername("spring") + .password(passwordEncoder.encode("secret")) + .roles("USER") + .build(); + + return new InMemoryUserDetailsManager(user); + } + + @Bean + public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { + http.addFilterAfter(new AuditInterceptor(), AnonymousAuthenticationFilter.class) + .authorizeRequests() + .antMatchers("/private/**").authenticated().and().httpBasic() + .and().authorizeRequests() + .antMatchers("/public/showProducts").permitAll() + .antMatchers("/public/registerUser").anonymous(); + + return http.build(); + } + + @Bean + public BCryptPasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } + +} \ No newline at end of file diff --git a/spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/permitallanonymous/SecureEcommerceApplicationUnitTest.java b/spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/permitallanonymous/SecureEcommerceApplicationUnitTest.java new file mode 100644 index 0000000000..3c73caf1fd --- /dev/null +++ b/spring-boot-modules/spring-boot-security/src/test/java/com/baeldung/permitallanonymous/SecureEcommerceApplicationUnitTest.java @@ -0,0 +1,70 @@ +package com.baeldung.permitallanonymous; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.security.test.context.support.WithAnonymousUser; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; + +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SecuredEcommerceApplication.class) +@AutoConfigureMockMvc +public class SecureEcommerceApplicationUnitTest { + @Autowired + private MockMvc mockMvc; + private static final Logger logger = LoggerFactory.getLogger(SecureEcommerceApplicationUnitTest.class); + + @WithAnonymousUser + @Test + public void givenAnonymousUser_whenAccessToUserRegisterPage_thenAllowAccess() throws Exception { + mockMvc.perform(MockMvcRequestBuilders.get("/public/registerUser")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().string("Register User")); + } + + @WithMockUser(username = "spring", password = "secret") + @Test + public void givenAuthenticatedUser_whenAccessToUserRegisterPage_thenDenyAccess() throws Exception { + mockMvc.perform(MockMvcRequestBuilders.get("/public/registerUser")) + .andExpect(MockMvcResultMatchers.status().isForbidden()); + } + + @WithMockUser(username = "spring", password = "secret") + @Test + public void givenAuthenticatedUser_whenAccessToProductLinePage_thenAllowAccess() throws Exception { + mockMvc.perform(MockMvcRequestBuilders.get("/public/showProducts")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().string("List Products")); + } + + @WithAnonymousUser + @Test + public void givenAnonymousUser_whenAccessToProductLinePage_thenAllowAccess() throws Exception { + mockMvc.perform(MockMvcRequestBuilders.get("/public/showProducts")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().string("List Products")); + } + + @WithMockUser(username = "spring", password = "secret") + @Test + public void givenAuthenticatedUser_whenAccessToCartPage_thenAllowAccess() throws Exception { + mockMvc.perform(MockMvcRequestBuilders.get("/private/showCart")) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.content().string("Show Cart")); + } + + @WithAnonymousUser + @Test + public void givenAnonymousUser_whenAccessToCartPage_thenDenyAccess() throws Exception { + mockMvc.perform(MockMvcRequestBuilders.get("/private/showCart")) + .andExpect(MockMvcResultMatchers.status().isUnauthorized()); + } +} diff --git a/spring-boot-modules/spring-boot-ssl-bundles/pom.xml b/spring-boot-modules/spring-boot-ssl-bundles/pom.xml index 056d0308c2..4802e9ec58 100644 --- a/spring-boot-modules/spring-boot-ssl-bundles/pom.xml +++ b/spring-boot-modules/spring-boot-ssl-bundles/pom.xml @@ -4,10 +4,10 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.springframework.boot - spring-boot-starter-parent - 3.1.3 - + com.baeldung + parent-boot-3 + 0.0.1-SNAPSHOT + ../../parent-boot-3 springbootsslbundles spring-boot-ssl-bundles diff --git a/spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/SSLBundleApplicationTests.java b/spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/SpringContextTest.java similarity index 85% rename from spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/SSLBundleApplicationTests.java rename to spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/SpringContextTest.java index 876641c8b5..6c9a2fb3f0 100644 --- a/spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/SSLBundleApplicationTests.java +++ b/spring-boot-modules/spring-boot-ssl-bundles/src/test/java/com/baeldung/springbootsslbundles/SpringContextTest.java @@ -4,7 +4,7 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest -class SSLBundleApplicationTests { +class SpringContextTest { @Test void contextLoads() { diff --git a/spring-cloud-modules/pom.xml b/spring-cloud-modules/pom.xml index 9c926bbe61..b21b208414 100644 --- a/spring-cloud-modules/pom.xml +++ b/spring-cloud-modules/pom.xml @@ -27,11 +27,11 @@ spring-cloud-gateway spring-cloud-gateway-2 spring-cloud-stream - spring-cloud-stream-starters + spring-cloud-connectors-heroku spring-cloud-aws spring-cloud-consul - spring-cloud-zuul-eureka-integration + spring-cloud-kubernetes spring-cloud-open-service-broker @@ -46,7 +46,7 @@ spring-cloud-eureka-self-preservation spring-cloud-openfeign - spring-cloud-netflix-feign + spring-cloud-netflix-sidecar spring-cloud-sentinel spring-cloud-dapr diff --git a/spring-cloud-modules/spring-cloud-archaius/pom.xml b/spring-cloud-modules/spring-cloud-archaius/pom.xml index 4d7ca3943d..3e90c7390c 100644 --- a/spring-cloud-modules/spring-cloud-archaius/pom.xml +++ b/spring-cloud-modules/spring-cloud-archaius/pom.xml @@ -40,6 +40,7 @@ org.springframework.cloud spring-cloud-starter-netflix-archaius + ${spring-cloud-starter-netflix-archaius.version} org.springframework.boot @@ -54,7 +55,8 @@ - 2.0.3.RELEASE + 2.2.10.RELEASE + 2.2.10.RELEASE \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-dynamodb-config/pom.xml b/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-dynamodb-config/pom.xml index 6e25ace6a8..600fedc774 100644 --- a/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-dynamodb-config/pom.xml +++ b/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-dynamodb-config/pom.xml @@ -36,7 +36,7 @@ org.projectlombok lombok - provided + ${lombok.version} @@ -44,6 +44,7 @@ 1.11.407 5.0.3 0.7.6 + 1.18.26 \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-extra-configs/pom.xml b/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-extra-configs/pom.xml index f90570abc2..383ad6a780 100644 --- a/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-extra-configs/pom.xml +++ b/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-extra-configs/pom.xml @@ -37,6 +37,22 @@ + + + + org.apache.maven.plugins + maven-surefire-plugin + + + --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.util=ALL-UNNAMED + --add-opens java.base/java.lang.reflect=ALL-UNNAMED + + + + + + 2.0.1.RELEASE diff --git a/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-jdbc-config/pom.xml b/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-jdbc-config/pom.xml index 7fb5747739..2871f129b5 100644 --- a/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-jdbc-config/pom.xml +++ b/spring-cloud-modules/spring-cloud-archaius/spring-cloud-archaius-jdbc-config/pom.xml @@ -27,6 +27,15 @@ h2 runtime + + org.projectlombok + lombok + ${lombok.version} + + + 1.18.26 + + \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-guide/travel-agency-service/mongo-deployment.yaml b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-guide/travel-agency-service/mongo-deployment.yaml index 3d40581578..77a5efa13c 100644 --- a/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-guide/travel-agency-service/mongo-deployment.yaml +++ b/spring-cloud-modules/spring-cloud-kubernetes/kubernetes-guide/travel-agency-service/mongo-deployment.yaml @@ -14,22 +14,24 @@ spec: selector: service: mongo --- -apiVersion: extensions/v1beta1 +apiVersion: apps/v1 kind: Deployment metadata: name: mongo spec: replicas: 1 + selector: + matchLabels: + name: mongodb-service template: metadata: labels: service: mongo - name: mongodb-service + name: mongodb-service spec: containers: - args: - mongod - - --smallfiles image: mongo:latest name: mongo env: diff --git a/spring-cloud-modules/spring-cloud-netflix-feign/pom.xml b/spring-cloud-modules/spring-cloud-netflix-feign/pom.xml index f519b6316b..92d66c03df 100644 --- a/spring-cloud-modules/spring-cloud-netflix-feign/pom.xml +++ b/spring-cloud-modules/spring-cloud-netflix-feign/pom.xml @@ -58,6 +58,20 @@ + + + + org.apache.maven.plugins + maven-surefire-plugin + + + --add-opens java.base/java.lang=ALL-UNNAMED + + + + + + Camden.SR7 8.18.0 diff --git a/spring-cloud-modules/spring-cloud-stream-starters/pom.xml b/spring-cloud-modules/spring-cloud-stream-starters/pom.xml index eee5b27396..95176d1e5c 100644 --- a/spring-cloud-modules/spring-cloud-stream-starters/pom.xml +++ b/spring-cloud-modules/spring-cloud-stream-starters/pom.xml @@ -3,7 +3,6 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - com.baeldung.spring.cloud spring-cloud-stream-starters 1.0.0-SNAPSHOT spring-cloud-stream-starters @@ -32,7 +31,7 @@ - 2021.0.0 + 2022.0.4 \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-stream-starters/twitterhdfs/pom.xml b/spring-cloud-modules/spring-cloud-stream-starters/twitterhdfs/pom.xml index 51e8703e6e..1a19415a3f 100644 --- a/spring-cloud-modules/spring-cloud-stream-starters/twitterhdfs/pom.xml +++ b/spring-cloud-modules/spring-cloud-stream-starters/twitterhdfs/pom.xml @@ -61,16 +61,21 @@ org.junit.vintage junit-vintage-engine + + org.codehaus.groovy + groovy + ${groovy.version} + + twitterhdfs org.springframework.boot spring-boot-maven-plugin - twitterhdfs @@ -83,6 +88,7 @@ 4.13.2 5.8.1 2.17.1 + 3.0.8 \ No newline at end of file diff --git a/spring-cloud-modules/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml b/spring-cloud-modules/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml index 3960cfde5d..46b3e7047f 100644 --- a/spring-cloud-modules/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml +++ b/spring-cloud-modules/spring-cloud-zuul-eureka-integration/eureka-client/pom.xml @@ -53,6 +53,24 @@ + + + + org.apache.maven.plugins + maven-surefire-plugin + + + --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.util=ALL-UNNAMED + --add-opens java.base/java.lang.reflect=ALL-UNNAMED + --add-opens java.base/java.text=ALL-UNNAMED + --add-opens java.desktop/java.awt.font=ALL-UNNAMED + + + + + + 2.17.1 diff --git a/spring-cloud-modules/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml b/spring-cloud-modules/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml index c9bc120e4d..796b908bca 100644 --- a/spring-cloud-modules/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml +++ b/spring-cloud-modules/spring-cloud-zuul-eureka-integration/eureka-server/pom.xml @@ -53,6 +53,24 @@ + + + + org.apache.maven.plugins + maven-surefire-plugin + + + --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.util=ALL-UNNAMED + --add-opens java.base/java.lang.reflect=ALL-UNNAMED + --add-opens java.base/java.text=ALL-UNNAMED + --add-opens java.desktop/java.awt.font=ALL-UNNAMED + + + + + + 2.17.1 diff --git a/spring-cloud-modules/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml b/spring-cloud-modules/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml index 76d899447f..11cc992523 100644 --- a/spring-cloud-modules/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml +++ b/spring-cloud-modules/spring-cloud-zuul-eureka-integration/zuul-server/pom.xml @@ -61,6 +61,24 @@ + + + + org.apache.maven.plugins + maven-surefire-plugin + + + --add-opens java.base/java.lang=ALL-UNNAMED + --add-opens java.base/java.util=ALL-UNNAMED + --add-opens java.base/java.lang.reflect=ALL-UNNAMED + --add-opens java.base/java.text=ALL-UNNAMED + --add-opens java.desktop/java.awt.font=ALL-UNNAMED + + + + + + 2.17.1 diff --git a/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/topicsandpartitions/TemperatureConsumer.java b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/topicsandpartitions/TemperatureConsumer.java index 7cfbdd5fb0..2919ae1d7b 100644 --- a/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/topicsandpartitions/TemperatureConsumer.java +++ b/spring-kafka-2/src/main/java/com/baeldung/spring/kafka/topicsandpartitions/TemperatureConsumer.java @@ -8,29 +8,22 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.CountDownLatch; @Service public class TemperatureConsumer { - private CountDownLatch latch = new CountDownLatch(1); - Map> consumedRecords = new ConcurrentHashMap<>(); @KafkaListener(topics = "celcius-scale-topic", groupId = "group-1") public void consumer1(ConsumerRecord consumerRecord) { - computeConsumedRecord("consumer-1", consumerRecord.partition()); + trackConsumedPartitions("consumer-1", consumerRecord.partition()); } - private void computeConsumedRecord(String key, int consumerRecord) { - consumedRecords.computeIfAbsent(key, k -> new HashSet<>()); - consumedRecords.computeIfPresent(key, (k, v) -> { - v.add(String.valueOf(consumerRecord)); + private void trackConsumedPartitions(String consumerName, int partitionNumber) { + consumedRecords.computeIfAbsent(consumerName, k -> new HashSet<>()); + consumedRecords.computeIfPresent(consumerName, (k, v) -> { + v.add(String.valueOf(partitionNumber)); return v; }); } - - public CountDownLatch getLatch() { - return latch; - } } diff --git a/spring-kafka-2/src/test/java/com/baeldung/spring/kafka/topicsandpartitions/KafkaTopicsAndPartitionsIntegrationTest.java b/spring-kafka-2/src/test/java/com/baeldung/spring/kafka/topicsandpartitions/KafkaTopicsAndPartitionsIntegrationTest.java index 309c87125a..de720ef955 100644 --- a/spring-kafka-2/src/test/java/com/baeldung/spring/kafka/topicsandpartitions/KafkaTopicsAndPartitionsIntegrationTest.java +++ b/spring-kafka-2/src/test/java/com/baeldung/spring/kafka/topicsandpartitions/KafkaTopicsAndPartitionsIntegrationTest.java @@ -7,8 +7,6 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.kafka.test.EmbeddedKafkaBroker; import org.springframework.kafka.test.context.EmbeddedKafka; -import java.util.concurrent.TimeUnit; - @SpringBootTest(classes = ThermostatApplicationKafkaApp.class) @EmbeddedKafka(partitions = 2, brokerProperties = {"listeners=PLAINTEXT://localhost:9092", "port=9092"}) public class KafkaTopicsAndPartitionsIntegrationTest { @@ -24,7 +22,7 @@ public class KafkaTopicsAndPartitionsIntegrationTest { @Test public void givenTopic_andConsumerGroup_whenConsumersListenToEvents_thenConsumeItCorrectly() throws Exception { service.measureCelsiusAndPublish(10000); - consumer.getLatch().await(1, TimeUnit.SECONDS); + Thread.sleep(1000); System.out.println(consumer.consumedRecords); } } diff --git a/spring-reactive-modules/pom.xml b/spring-reactive-modules/pom.xml index 309687f011..06519d723a 100644 --- a/spring-reactive-modules/pom.xml +++ b/spring-reactive-modules/pom.xml @@ -17,16 +17,16 @@ - spring-5-data-reactive - spring-5-data-reactive-2 + spring-reactive-data + spring-reactive-data-2 spring-5-reactive - spring-5-reactive-2 - spring-5-reactive-3 - spring-5-reactive-client - spring-5-reactive-client-2 - spring-5-reactive-filters - spring-5-reactive-oauth - spring-5-reactive-security + spring-reactive-2 + spring-reactive-3 + spring-reactive-client + spring-reactive-client-2 + spring-reactive-filters + spring-reactive-oauth + spring-reactive-security spring-data-couchbase spring-reactive spring-reactive-exceptions diff --git a/spring-reactive-modules/spring-5-reactive/README.md b/spring-reactive-modules/spring-5-reactive/README.md index f3148fe696..3f44267234 100644 --- a/spring-reactive-modules/spring-5-reactive/README.md +++ b/spring-reactive-modules/spring-5-reactive/README.md @@ -1,6 +1,6 @@ ## Spring 5 Reactive Project -This module contains articles about reactive Spring 5 +This module contains articles about reactive Spring Boot ### The Course The "REST With Spring" Classes: https://bit.ly/restwithspring @@ -11,4 +11,4 @@ The "REST With Spring" Classes: https://bit.ly/restwithspring - [Reactive WebSockets with Spring 5](https://www.baeldung.com/spring-5-reactive-websockets) - [How to Set a Header on a Response with Spring 5](https://www.baeldung.com/spring-response-header) - [A Guide to Spring Session Reactive Support: WebSession](https://www.baeldung.com/spring-session-reactive) -- More articles: [[next -->]](../spring-5-reactive-2) +- More articles: [[next -->]](../spring-5-reactive-2) \ No newline at end of file diff --git a/spring-reactive-modules/spring-5-reactive/pom.xml b/spring-reactive-modules/spring-5-reactive/pom.xml index 212281b6f9..fd47c70a07 100644 --- a/spring-reactive-modules/spring-5-reactive/pom.xml +++ b/spring-reactive-modules/spring-5-reactive/pom.xml @@ -1,7 +1,6 @@ - + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-5-reactive 0.0.1-SNAPSHOT diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/webapp/WEB-INF/web.xml b/spring-reactive-modules/spring-5-reactive/src/main/WEB-INF/web.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/webapp/WEB-INF/web.xml rename to spring-reactive-modules/spring-5-reactive/src/main/WEB-INF/web.xml diff --git a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/WebSocketController.java b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/WebSocketController.java index bf4a463ae6..0c8f9debc9 100644 --- a/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/WebSocketController.java +++ b/spring-reactive-modules/spring-5-reactive/src/main/java/com/baeldung/websocket/WebSocketController.java @@ -6,8 +6,6 @@ import org.slf4j.LoggerFactory; import javax.websocket.*; import javax.websocket.server.ServerEndpoint; import java.io.IOException; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; @ServerEndpoint("/event-emitter") public class WebSocketController { diff --git a/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java b/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java index a77a67c6ba..113376318e 100644 --- a/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java +++ b/spring-reactive-modules/spring-5-reactive/src/test/java/com/baeldung/reactive/urlmatch/ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest.java @@ -108,7 +108,7 @@ public class ExploreSpring5URLPatternUsingRouterFunctionsIntegrationTest { } @Test - public void givenRouter_whenAccess_thenGot() throws Exception { + public void givenRouter_whenAccess_thenGot() { client.get() .uri("/resources/test/test.txt") .exchange() diff --git a/spring-reactive-modules/spring-data-couchbase/pom.xml b/spring-reactive-modules/spring-data-couchbase/pom.xml index 68ddd1cefa..d7b36f97fa 100644 --- a/spring-reactive-modules/spring-data-couchbase/pom.xml +++ b/spring-reactive-modules/spring-data-couchbase/pom.xml @@ -1,7 +1,7 @@ + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 spring-data-couchbase spring-data-couchbase diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/ReactiveCouchbaseApplication.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/ReactiveCouchbaseApplication.java index 4e5bf9d5dc..0ca7c9a8d1 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/ReactiveCouchbaseApplication.java +++ b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/ReactiveCouchbaseApplication.java @@ -10,4 +10,4 @@ public class ReactiveCouchbaseApplication { public static void main(String[] args) { SpringApplication.run(ReactiveCouchbaseApplication.class, args); } -} +} \ No newline at end of file diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/CouchbaseProperties.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/CouchbaseProperties.java index 81f19eebd6..cc9540eecb 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/CouchbaseProperties.java +++ b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/CouchbaseProperties.java @@ -40,4 +40,4 @@ public class CouchbaseProperties { public int getPort() { return port; } -} +} \ No newline at end of file diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/N1QLReactiveCouchbaseConfiguration.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/N1QLReactiveCouchbaseConfiguration.java index 059bd36cae..7ba12db2c6 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/N1QLReactiveCouchbaseConfiguration.java +++ b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/N1QLReactiveCouchbaseConfiguration.java @@ -12,4 +12,4 @@ public class N1QLReactiveCouchbaseConfiguration extends ReactiveCouchbaseConfigu public N1QLReactiveCouchbaseConfiguration(CouchbaseProperties couchbaseProperties) { super(couchbaseProperties); } -} +} \ No newline at end of file diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ReactiveCouchbaseConfiguration.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ReactiveCouchbaseConfiguration.java index a51b19ee22..1816082f7c 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ReactiveCouchbaseConfiguration.java +++ b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ReactiveCouchbaseConfiguration.java @@ -45,4 +45,4 @@ public abstract class ReactiveCouchbaseConfiguration extends AbstractReactiveCou public IndexManager couchbaseIndexManager() { return new IndexManager(true, true, false); } -} +} \ No newline at end of file diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ViewReactiveCouchbaseConfiguration.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ViewReactiveCouchbaseConfiguration.java index 9b4d9b0319..578a03ae19 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ViewReactiveCouchbaseConfiguration.java +++ b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/configuration/ViewReactiveCouchbaseConfiguration.java @@ -10,4 +10,4 @@ public class ViewReactiveCouchbaseConfiguration extends ReactiveCouchbaseConfigu public ViewReactiveCouchbaseConfiguration(CouchbaseProperties couchbaseProperties) { super(couchbaseProperties); } -} +} \ No newline at end of file diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/Person.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/Person.java index 285de34df8..5a1b1eec18 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/Person.java +++ b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/Person.java @@ -40,4 +40,4 @@ public class Person { public int hashCode() { return Objects.hash(id, firstName); } -} +} \ No newline at end of file diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepository.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepository.java index 6f73a77ceb..e78316e218 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepository.java +++ b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepository.java @@ -13,4 +13,4 @@ import java.util.UUID; public interface N1QLPersonRepository extends ReactiveCrudRepository { Flux findAllByFirstName(final String firstName); -} +} \ No newline at end of file diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepository.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepository.java index 57dd149425..1225ed914a 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepository.java +++ b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepository.java @@ -10,4 +10,4 @@ import java.util.UUID; @Repository @N1qlPrimaryIndexed public interface N1QLSortingPersonRepository extends ReactiveSortingRepository { -} +} \ No newline at end of file diff --git a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepository.java b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepository.java index 06c47c2393..4b3f0a7f1c 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepository.java +++ b/spring-reactive-modules/spring-data-couchbase/src/main/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepository.java @@ -17,4 +17,4 @@ public interface ViewPersonRepository extends ReactiveCrudRepository findByFirstName(String firstName); -} +} \ No newline at end of file diff --git a/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/CouchbaseMockConfiguration.java b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/CouchbaseMockConfiguration.java index 2a09fce4b0..082ad5061b 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/CouchbaseMockConfiguration.java +++ b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/CouchbaseMockConfiguration.java @@ -1,16 +1,18 @@ package com.baeldung.couchbase.domain.repository; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.util.Collections; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +import org.springframework.boot.test.context.TestConfiguration; + import com.baeldung.couchbase.configuration.CouchbaseProperties; import com.couchbase.mock.Bucket; import com.couchbase.mock.BucketConfiguration; import com.couchbase.mock.CouchbaseMock; -import org.springframework.boot.test.context.TestConfiguration; - -import javax.annotation.PostConstruct; -import javax.annotation.PreDestroy; -import java.io.IOException; -import java.io.UncheckedIOException; -import java.util.Collections; @TestConfiguration public class CouchbaseMockConfiguration { diff --git a/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepositoryLiveTest.java b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepositoryLiveTest.java index c8dbbf429e..51bca948c0 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepositoryLiveTest.java +++ b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLPersonRepositoryLiveTest.java @@ -1,16 +1,19 @@ package com.baeldung.couchbase.domain.repository.n1ql; -import com.baeldung.couchbase.domain.Person; +import java.util.UUID; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.couchbase.domain.Person; +import com.baeldung.couchbase.domain.repository.n1ql.N1QLPersonRepository; + import reactor.core.publisher.Flux; import reactor.test.StepVerifier; -import java.util.UUID; - @RunWith(SpringRunner.class) @SpringBootTest(properties = {"spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration"}) public class N1QLPersonRepositoryLiveTest { diff --git a/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepositoryLiveTest.java b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepositoryLiveTest.java index 8c6ce137f1..dbc353a94b 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepositoryLiveTest.java +++ b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/n1ql/N1QLSortingPersonRepositoryLiveTest.java @@ -1,17 +1,20 @@ package com.baeldung.couchbase.domain.repository.n1ql; -import com.baeldung.couchbase.domain.Person; +import java.util.UUID; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.Sort; import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.couchbase.domain.Person; +import com.baeldung.couchbase.domain.repository.n1ql.N1QLSortingPersonRepository; + import reactor.core.publisher.Flux; import reactor.test.StepVerifier; -import java.util.UUID; - @RunWith(SpringRunner.class) @SpringBootTest(properties = {"spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration"}) public class N1QLSortingPersonRepositoryLiveTest { diff --git a/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepositoryIntegrationTest.java b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepositoryIntegrationTest.java index 15688e1b80..038d4dec31 100644 --- a/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepositoryIntegrationTest.java +++ b/spring-reactive-modules/spring-data-couchbase/src/test/java/com/baeldung/couchbase/domain/repository/view/ViewPersonRepositoryIntegrationTest.java @@ -1,21 +1,22 @@ package com.baeldung.couchbase.domain.repository.view; +import java.util.UUID; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + import com.baeldung.couchbase.configuration.CouchbaseProperties; import com.baeldung.couchbase.configuration.ViewReactiveCouchbaseConfiguration; import com.baeldung.couchbase.domain.Person; import com.baeldung.couchbase.domain.repository.CouchbaseMockConfiguration; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; + import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.util.UUID; - @RunWith(SpringRunner.class) @SpringBootTest(properties = { "spring.couchbase.port=10010", "spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration,org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration" }, classes = { CouchbaseMockConfiguration.class, ViewReactiveCouchbaseConfiguration.class, CouchbaseProperties.class }) diff --git a/spring-reactive-modules/spring-5-reactive-2/.gitignore b/spring-reactive-modules/spring-reactive-2/.gitignore similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/.gitignore rename to spring-reactive-modules/spring-reactive-2/.gitignore diff --git a/spring-reactive-modules/spring-5-reactive-2/README.md b/spring-reactive-modules/spring-reactive-2/README.md similarity index 91% rename from spring-reactive-modules/spring-5-reactive-2/README.md rename to spring-reactive-modules/spring-reactive-2/README.md index 1cd3bf46c6..a5df5187bf 100644 --- a/spring-reactive-modules/spring-5-reactive-2/README.md +++ b/spring-reactive-modules/spring-reactive-2/README.md @@ -1,6 +1,6 @@ ## Spring 5 Reactive Project -This module contains articles about reactive Spring 5. +This module contains articles about reactive Spring Boot. - [Validation for Functional Endpoints in Spring 5](https://www.baeldung.com/spring-functional-endpoints-validation) - [Testing Reactive Streams Using StepVerifier and TestPublisher](https://www.baeldung.com/reactive-streams-step-verifier-test-publisher) diff --git a/spring-reactive-modules/spring-5-reactive-2/pom.xml b/spring-reactive-modules/spring-reactive-2/pom.xml similarity index 98% rename from spring-reactive-modules/spring-5-reactive-2/pom.xml rename to spring-reactive-modules/spring-reactive-2/pom.xml index 41c434fb92..ba40f3b48a 100644 --- a/spring-reactive-modules/spring-5-reactive-2/pom.xml +++ b/spring-reactive-modules/spring-reactive-2/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - spring-5-reactive-2 + spring-reactive-2 0.0.1-SNAPSHOT spring-5-reactive-2 jar diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/ConsumerSSEApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/controller/ClientController.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/controller/ClientController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/controller/ClientController.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/consumer/controller/ClientController.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/ServerSSEApplication.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/ServerSSEApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/ServerSSEApplication.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/ServerSSEApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/controllers/ServerController.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/controllers/ServerController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/controllers/ServerController.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/reactive/serversentevents/server/controllers/ServerController.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentApplication.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentApplication.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentConfig.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentConfig.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/staticcontent/StaticContentConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/FunctionalValidationsApplication.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/FunctionalValidationsApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/FunctionalValidationsApplication.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/FunctionalValidationsApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/AbstractValidationHandler.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/AbstractValidationHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/AbstractValidationHandler.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/AbstractValidationHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/FunctionalHandler.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/FunctionalHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/FunctionalHandler.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/FunctionalHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/AnnotatedRequestEntityValidationHandler.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/AnnotatedRequestEntityValidationHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/AnnotatedRequestEntityValidationHandler.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/AnnotatedRequestEntityValidationHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/CustomRequestEntityValidationHandler.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/CustomRequestEntityValidationHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/CustomRequestEntityValidationHandler.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/CustomRequestEntityValidationHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/OtherEntityValidationHandler.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/OtherEntityValidationHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/OtherEntityValidationHandler.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/handlers/impl/OtherEntityValidationHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/model/AnnotatedRequestEntity.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/AnnotatedRequestEntity.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/model/AnnotatedRequestEntity.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/AnnotatedRequestEntity.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/model/CustomRequestEntity.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/CustomRequestEntity.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/model/CustomRequestEntity.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/CustomRequestEntity.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/model/OtherEntity.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/OtherEntity.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/model/OtherEntity.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/model/OtherEntity.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/routers/ValidationsRouters.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/routers/ValidationsRouters.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/routers/ValidationsRouters.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/routers/ValidationsRouters.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/validators/CustomRequestEntityValidator.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/validators/CustomRequestEntityValidator.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/validators/CustomRequestEntityValidator.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/validators/CustomRequestEntityValidator.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/validators/OtherEntityValidator.java b/spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/validators/OtherEntityValidator.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/java/com/baeldung/validations/functional/validators/OtherEntityValidator.java rename to spring-reactive-modules/spring-reactive-2/src/main/java/com/baeldung/validations/functional/validators/OtherEntityValidator.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/main/resources/application-assets-custom-location.properties b/spring-reactive-modules/spring-reactive-2/src/main/resources/application-assets-custom-location.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/main/resources/application-assets-custom-location.properties rename to spring-reactive-modules/spring-reactive-2/src/main/resources/application-assets-custom-location.properties diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java rename to spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/backpressure/BackpressureUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/reactive/serversentsevents/ServiceSentEventLiveTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/reactive/serversentsevents/ServiceSentEventLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/reactive/serversentsevents/ServiceSentEventLiveTest.java rename to spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/reactive/serversentsevents/ServiceSentEventLiveTest.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/staticcontent/StaticContentCustomLocationIntegrationTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/staticcontent/StaticContentCustomLocationIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/staticcontent/StaticContentCustomLocationIntegrationTest.java rename to spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/staticcontent/StaticContentCustomLocationIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/staticcontent/StaticContentDefaultLocationIntegrationTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/staticcontent/StaticContentDefaultLocationIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/staticcontent/StaticContentDefaultLocationIntegrationTest.java rename to spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/staticcontent/StaticContentDefaultLocationIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/stepverifier/PostExecutionUnitTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/stepverifier/PostExecutionUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/stepverifier/PostExecutionUnitTest.java rename to spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/stepverifier/PostExecutionUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/stepverifier/StepByStepUnitTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/stepverifier/StepByStepUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/stepverifier/StepByStepUnitTest.java rename to spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/stepverifier/StepByStepUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/stepverifier/TestingTestPublisherUnitTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/stepverifier/TestingTestPublisherUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/stepverifier/TestingTestPublisherUnitTest.java rename to spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/stepverifier/TestingTestPublisherUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/stepverifier/TimeBasedUnitTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/stepverifier/TimeBasedUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/stepverifier/TimeBasedUnitTest.java rename to spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/stepverifier/TimeBasedUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/validations/functional/FunctionalEndpointValidationsLiveTest.java b/spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/validations/functional/FunctionalEndpointValidationsLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/java/com/baeldung/validations/functional/FunctionalEndpointValidationsLiveTest.java rename to spring-reactive-modules/spring-reactive-2/src/test/java/com/baeldung/validations/functional/FunctionalEndpointValidationsLiveTest.java diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/resources/assets/index.html b/spring-reactive-modules/spring-reactive-2/src/test/resources/assets/index.html similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/resources/assets/index.html rename to spring-reactive-modules/spring-reactive-2/src/test/resources/assets/index.html diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/resources/img/example-image.png b/spring-reactive-modules/spring-reactive-2/src/test/resources/img/example-image.png similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/resources/img/example-image.png rename to spring-reactive-modules/spring-reactive-2/src/test/resources/img/example-image.png diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/resources/logback-test.xml b/spring-reactive-modules/spring-reactive-2/src/test/resources/logback-test.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/resources/logback-test.xml rename to spring-reactive-modules/spring-reactive-2/src/test/resources/logback-test.xml diff --git a/spring-reactive-modules/spring-5-reactive-2/src/test/resources/public/index.html b/spring-reactive-modules/spring-reactive-2/src/test/resources/public/index.html similarity index 100% rename from spring-reactive-modules/spring-5-reactive-2/src/test/resources/public/index.html rename to spring-reactive-modules/spring-reactive-2/src/test/resources/public/index.html diff --git a/spring-reactive-modules/spring-5-reactive-3/.gitignore b/spring-reactive-modules/spring-reactive-3/.gitignore similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/.gitignore rename to spring-reactive-modules/spring-reactive-3/.gitignore diff --git a/spring-reactive-modules/spring-5-reactive-3/README.md b/spring-reactive-modules/spring-reactive-3/README.md similarity index 72% rename from spring-reactive-modules/spring-5-reactive-3/README.md rename to spring-reactive-modules/spring-reactive-3/README.md index 38036f929b..640a60d63d 100644 --- a/spring-reactive-modules/spring-5-reactive-3/README.md +++ b/spring-reactive-modules/spring-reactive-3/README.md @@ -1,9 +1,8 @@ ## Spring 5 Reactive Project -This module contains articles about reactive Spring 5. +This module contains articles about reactive Spring Boot. - [Logging a Reactive Sequence](https://www.baeldung.com/spring-reactive-sequence-logging) - [Reading Flux Into a Single InputStream Using Spring Reactive WebClient](https://www.baeldung.com/spring-reactive-read-flux-into-inputstream) -- [Spring Boot FeignClient vs. WebClient](https://www.baeldung.com/spring-boot-feignclient-vs-webclient) - [Cancel an Ongoing Flux in Spring WebFlux](https://www.baeldung.com/spring-webflux-cancel-flux) - More articles: [[<-- prev]](../spring-5-reactive-2) diff --git a/spring-reactive-modules/spring-5-reactive-3/pom.xml b/spring-reactive-modules/spring-reactive-3/pom.xml similarity index 98% rename from spring-reactive-modules/spring-5-reactive-3/pom.xml rename to spring-reactive-modules/spring-reactive-3/pom.xml index d33b63e921..7672fa29f3 100644 --- a/spring-reactive-modules/spring-5-reactive-3/pom.xml +++ b/spring-reactive-modules/spring-reactive-3/pom.xml @@ -3,7 +3,7 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - spring-5-reactive-3 + spring-reactive-3 0.0.1-SNAPSHOT spring-5-reactive-3 jar diff --git a/spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/databuffer/DataBufferToInputStream.java b/spring-reactive-modules/spring-reactive-3/src/main/java/com/baeldung/databuffer/DataBufferToInputStream.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/databuffer/DataBufferToInputStream.java rename to spring-reactive-modules/spring-reactive-3/src/main/java/com/baeldung/databuffer/DataBufferToInputStream.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webflux/logging/WebFluxLoggingExample.java b/spring-reactive-modules/spring-reactive-3/src/main/java/com/baeldung/webflux/logging/WebFluxLoggingExample.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webflux/logging/WebFluxLoggingExample.java rename to spring-reactive-modules/spring-reactive-3/src/main/java/com/baeldung/webflux/logging/WebFluxLoggingExample.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/main/resources/application.properties b/spring-reactive-modules/spring-reactive-3/src/main/resources/application.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/main/resources/application.properties rename to spring-reactive-modules/spring-reactive-3/src/main/resources/application.properties diff --git a/spring-reactive-modules/spring-5-reactive-3/src/test/java/com/baeldung/cancelflux/CancelFluxUnitTest.java b/spring-reactive-modules/spring-reactive-3/src/test/java/com/baeldung/cancelflux/CancelFluxUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/test/java/com/baeldung/cancelflux/CancelFluxUnitTest.java rename to spring-reactive-modules/spring-reactive-3/src/test/java/com/baeldung/cancelflux/CancelFluxUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/test/java/com/baeldung/databuffer/DataBufferToInputStreamUnitTest.java b/spring-reactive-modules/spring-reactive-3/src/test/java/com/baeldung/databuffer/DataBufferToInputStreamUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/test/java/com/baeldung/databuffer/DataBufferToInputStreamUnitTest.java rename to spring-reactive-modules/spring-reactive-3/src/test/java/com/baeldung/databuffer/DataBufferToInputStreamUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/test/resources/logback-test.xml b/spring-reactive-modules/spring-reactive-3/src/test/resources/logback-test.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/test/resources/logback-test.xml rename to spring-reactive-modules/spring-reactive-3/src/test/resources/logback-test.xml diff --git a/spring-reactive-modules/spring-5-reactive-3/src/test/resources/user-response.json b/spring-reactive-modules/spring-reactive-3/src/test/resources/user-response.json similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/test/resources/user-response.json rename to spring-reactive-modules/spring-reactive-3/src/test/resources/user-response.json diff --git a/spring-reactive-modules/spring-5-reactive-client-2/README.md b/spring-reactive-modules/spring-reactive-client-2/README.md similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/README.md rename to spring-reactive-modules/spring-reactive-client-2/README.md diff --git a/spring-reactive-modules/spring-5-reactive-client-2/pom.xml b/spring-reactive-modules/spring-reactive-client-2/pom.xml similarity index 94% rename from spring-reactive-modules/spring-5-reactive-client-2/pom.xml rename to spring-reactive-modules/spring-reactive-client-2/pom.xml index e86134badc..5d5f3ebc2e 100644 --- a/spring-reactive-modules/spring-5-reactive-client-2/pom.xml +++ b/spring-reactive-modules/spring-reactive-client-2/pom.xml @@ -3,10 +3,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - spring-5-reactive-client-2 - spring-5-reactive-client-2 + spring-reactive-client-2 + spring-reactive-client-2 jar - spring 5 sample project about new features + spring boot sample project about new features com.baeldung.spring.reactive @@ -93,10 +93,6 @@ org.apache.maven.plugins maven-compiler-plugin - - 1.8 - 1.8 - diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/LimitRequestsApp.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/LimitRequestsApp.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/LimitRequestsApp.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/LimitRequestsApp.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/DelayElements.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/DelayElements.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/DelayElements.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/DelayElements.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/GuavaRateLimit.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/GuavaRateLimit.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/GuavaRateLimit.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/GuavaRateLimit.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/LimitConcurrency.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/LimitConcurrency.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/LimitConcurrency.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/LimitConcurrency.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/Resilience4jRateLimit.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/Resilience4jRateLimit.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/Resilience4jRateLimit.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/Resilience4jRateLimit.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/ZipWithInterval.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/ZipWithInterval.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/ZipWithInterval.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/ZipWithInterval.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/utils/Client.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/utils/Client.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/utils/Client.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/utils/Client.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/utils/RandomConsumer.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/utils/RandomConsumer.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/utils/RandomConsumer.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/client/utils/RandomConsumer.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/server/Concurrency.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/server/Concurrency.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/server/Concurrency.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/server/Concurrency.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/server/RandomController.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/server/RandomController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/limitrequests/server/RandomController.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/limitrequests/server/RandomController.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/streamlargefile/StreamLargeFileApp.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/streamlargefile/StreamLargeFileApp.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/streamlargefile/StreamLargeFileApp.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/streamlargefile/StreamLargeFileApp.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/streamlargefile/client/LargeFileDownloadWebClient.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/streamlargefile/client/LargeFileDownloadWebClient.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/streamlargefile/client/LargeFileDownloadWebClient.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/streamlargefile/client/LargeFileDownloadWebClient.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/streamlargefile/client/LimitedFileDownloadWebClient.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/streamlargefile/client/LimitedFileDownloadWebClient.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/streamlargefile/client/LimitedFileDownloadWebClient.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/streamlargefile/client/LimitedFileDownloadWebClient.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/streamlargefile/server/LargeFileController.java b/spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/streamlargefile/server/LargeFileController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/java/com/baeldung/streamlargefile/server/LargeFileController.java rename to spring-reactive-modules/spring-reactive-client-2/src/main/java/com/baeldung/streamlargefile/server/LargeFileController.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/resources/application.properties b/spring-reactive-modules/spring-reactive-client-2/src/main/resources/application.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/resources/application.properties rename to spring-reactive-modules/spring-reactive-client-2/src/main/resources/application.properties diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/resources/logback.xml b/spring-reactive-modules/spring-reactive-client-2/src/main/resources/logback.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/resources/logback.xml rename to spring-reactive-modules/spring-reactive-client-2/src/main/resources/logback.xml diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/resources/streamlargefile/generate-sample-files.sh b/spring-reactive-modules/spring-reactive-client-2/src/main/resources/streamlargefile/generate-sample-files.sh old mode 100755 new mode 100644 similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/resources/streamlargefile/generate-sample-files.sh rename to spring-reactive-modules/spring-reactive-client-2/src/main/resources/streamlargefile/generate-sample-files.sh diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/main/resources/streamlargefile/run.sh b/spring-reactive-modules/spring-reactive-client-2/src/main/resources/streamlargefile/run.sh old mode 100755 new mode 100644 similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/main/resources/streamlargefile/run.sh rename to spring-reactive-modules/spring-reactive-client-2/src/main/resources/streamlargefile/run.sh diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/test/java/com/baeldung/limitrequests/RandomControllerLiveTest.java b/spring-reactive-modules/spring-reactive-client-2/src/test/java/com/baeldung/limitrequests/RandomControllerLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/test/java/com/baeldung/limitrequests/RandomControllerLiveTest.java rename to spring-reactive-modules/spring-reactive-client-2/src/test/java/com/baeldung/limitrequests/RandomControllerLiveTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/test/java/com/baeldung/streamlargefile/LargeFileControllerLiveTest.java b/spring-reactive-modules/spring-reactive-client-2/src/test/java/com/baeldung/streamlargefile/LargeFileControllerLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/test/java/com/baeldung/streamlargefile/LargeFileControllerLiveTest.java rename to spring-reactive-modules/spring-reactive-client-2/src/test/java/com/baeldung/streamlargefile/LargeFileControllerLiveTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client-2/src/test/resources/logback-test.xml b/spring-reactive-modules/spring-reactive-client-2/src/test/resources/logback-test.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client-2/src/test/resources/logback-test.xml rename to spring-reactive-modules/spring-reactive-client-2/src/test/resources/logback-test.xml diff --git a/spring-reactive-modules/spring-5-reactive-client/.gitignore b/spring-reactive-modules/spring-reactive-client/.gitignore similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/.gitignore rename to spring-reactive-modules/spring-reactive-client/.gitignore diff --git a/spring-reactive-modules/spring-5-reactive-client/README.md b/spring-reactive-modules/spring-reactive-client/README.md similarity index 89% rename from spring-reactive-modules/spring-5-reactive-client/README.md rename to spring-reactive-modules/spring-reactive-client/README.md index f1793070b3..fc67a4f16e 100644 --- a/spring-reactive-modules/spring-5-reactive-client/README.md +++ b/spring-reactive-modules/spring-reactive-client/README.md @@ -9,8 +9,8 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Logging Spring WebClient Calls](https://www.baeldung.com/spring-log-webclient-calls) - [Simultaneous Spring WebClient Calls](https://www.baeldung.com/spring-webclient-simultaneous-calls) - [Mocking a WebClient in Spring](https://www.baeldung.com/spring-mocking-webclient) -- [Spring WebClient Filters](https://www.baeldung.com/spring-webclient-filters) - [Get List of JSON Objects with WebClient](https://www.baeldung.com/spring-webclient-json-list) - [Upload a File with WebClient](https://www.baeldung.com/spring-webclient-upload-file) - [How to Get Response Body When Testing the Status Code in WebFlux WebClient](https://www.baeldung.com/spring-webclient-get-response-body) +- [Spring Boot FeignClient vs. WebClient](https://www.baeldung.com/spring-boot-feignclient-vs-webclient) - More articles: [[next -->]](../spring-5-reactive-client-2) diff --git a/spring-reactive-modules/spring-5-reactive-client/pom.xml b/spring-reactive-modules/spring-reactive-client/pom.xml similarity index 93% rename from spring-reactive-modules/spring-5-reactive-client/pom.xml rename to spring-reactive-modules/spring-reactive-client/pom.xml index a0e5f7794e..94134e5271 100644 --- a/spring-reactive-modules/spring-5-reactive-client/pom.xml +++ b/spring-reactive-modules/spring-reactive-client/pom.xml @@ -3,10 +3,10 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - spring-5-reactive-client - spring-5-reactive-client + spring-reactive-client + spring-reactive-client jar - spring 5 sample project about new features + spring boot sample project about new features com.baeldung.spring.reactive @@ -32,8 +32,9 @@ spring-boot-starter-webflux - org.springframework.boot - spring-boot-starter-security + org.springframework.cloud + spring-cloud-starter-openfeign + ${spring-cloud-starter-openfeign.version} org.projectreactor @@ -176,13 +177,12 @@ 1.0.1.RELEASE - 1.1.3 - 1.0 1.0 1.1.6 4.0.1 3.5.3 2.26.0 + 3.1.4 \ No newline at end of file diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/controller/UploadController.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/controller/UploadController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/controller/UploadController.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/controller/UploadController.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/enums/Role.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/enums/Role.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/enums/Role.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/enums/Role.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/exception/ServiceException.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/exception/ServiceException.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/exception/ServiceException.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/exception/ServiceException.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/model/Employee.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/model/Employee.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/model/Employee.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/model/Employee.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/model/Foo.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/model/Foo.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/model/Foo.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/model/Foo.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/service/EmployeeService.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/service/EmployeeService.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/service/EmployeeService.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/service/EmployeeService.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/service/ReactiveUploadService.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/service/ReactiveUploadService.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/service/ReactiveUploadService.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/service/ReactiveUploadService.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Client.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Client.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Client.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Client.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Item.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Item.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Item.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/Item.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/User.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/User.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/User.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/User.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/UserWithItem.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/UserWithItem.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/UserWithItem.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/reactive/webclient/simultaneous/UserWithItem.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/Product.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/Product.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/Product.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/Product.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/ProductsFeignClient.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/ProductsFeignClient.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/ProductsFeignClient.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/ProductsFeignClient.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/ProductsSlowServiceController.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/ProductsSlowServiceController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/ProductsSlowServiceController.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/ProductsSlowServiceController.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/WebClientApplication.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/WebClientApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/WebClientApplication.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/WebClientApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/WebController.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/WebController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/main/java/com/baeldung/webclient/WebController.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/WebController.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerService.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/json/ReaderConsumerServiceImpl.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Book.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/json/model/Book.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Book.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/json/model/Book.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/json/model/Reader.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/status/WebClientStatusCodeHandler.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/status/WebClientStatusCodeHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/status/WebClientStatusCodeHandler.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/status/WebClientStatusCodeHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/status/exception/CustomBadRequestException.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/status/exception/CustomBadRequestException.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/status/exception/CustomBadRequestException.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/status/exception/CustomBadRequestException.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/status/exception/CustomServerErrorException.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/status/exception/CustomServerErrorException.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/status/exception/CustomServerErrorException.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/status/exception/CustomServerErrorException.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/timeout/WebClientTimeoutProvider.java b/spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/timeout/WebClientTimeoutProvider.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/timeout/WebClientTimeoutProvider.java rename to spring-reactive-modules/spring-reactive-client/src/main/java/com/baeldung/webclient/timeout/WebClientTimeoutProvider.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/resources/application.properties b/spring-reactive-modules/spring-reactive-client/src/main/resources/application.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/resources/application.properties rename to spring-reactive-modules/spring-reactive-client/src/main/resources/application.properties diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/resources/logback.xml b/spring-reactive-modules/spring-reactive-client/src/main/resources/logback.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/main/resources/logback.xml rename to spring-reactive-modules/spring-reactive-client/src/main/resources/logback.xml diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/webapp/WEB-INF/web.xml b/spring-reactive-modules/spring-reactive-client/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/webapp/WEB-INF/web.xml rename to spring-reactive-modules/spring-reactive-client/src/main/webapp/WEB-INF/web.xml diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/SpringContextTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/SpringContextTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/ReactiveIntegrationTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/ReactiveIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/ReactiveIntegrationTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/ReactiveIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/Spring5ReactiveTestApplication.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/Spring5ReactiveTestApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/Spring5ReactiveTestApplication.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/Spring5ReactiveTestApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/logging/WebClientLoggingIntegrationTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/logging/WebClientLoggingIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/logging/WebClientLoggingIntegrationTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/logging/WebClientLoggingIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/logging/filters/LogFilters.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/logging/filters/LogFilters.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/logging/filters/LogFilters.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/logging/filters/LogFilters.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/logging/jetty/RequestLogEnhancer.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/logging/jetty/RequestLogEnhancer.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/logging/jetty/RequestLogEnhancer.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/logging/jetty/RequestLogEnhancer.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/service/EmployeeServiceIntegrationTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/service/EmployeeServiceIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/service/EmployeeServiceIntegrationTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/service/EmployeeServiceIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/service/EmployeeServiceUnitTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/service/EmployeeServiceUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/service/EmployeeServiceUnitTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/service/EmployeeServiceUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/service/ReactiveUploadServiceUnitTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/service/ReactiveUploadServiceUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/service/ReactiveUploadServiceUnitTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/service/ReactiveUploadServiceUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/webclient/simultaneous/ClientIntegrationTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/webclient/simultaneous/ClientIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/reactive/webclient/simultaneous/ClientIntegrationTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/reactive/webclient/simultaneous/ClientIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/webclient/WebClientStatusCodeHandlerIntegrationTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/webclient/WebClientStatusCodeHandlerIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/webclient/WebClientStatusCodeHandlerIntegrationTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/webclient/WebClientStatusCodeHandlerIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-3/src/test/java/com/baeldung/webclient/WebControllerIntegrationTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/webclient/WebControllerIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-3/src/test/java/com/baeldung/webclient/WebControllerIntegrationTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/webclient/WebControllerIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/webclient/json/ReaderConsumerServiceImplUnitTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/webclient/timeout/WebClientTimeoutIntegrationTest.java b/spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/webclient/timeout/WebClientTimeoutIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/webclient/timeout/WebClientTimeoutIntegrationTest.java rename to spring-reactive-modules/spring-reactive-client/src/test/java/com/baeldung/webclient/timeout/WebClientTimeoutIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/resources/logback-test.xml b/spring-reactive-modules/spring-reactive-client/src/test/resources/logback-test.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-client/src/test/resources/logback-test.xml rename to spring-reactive-modules/spring-reactive-client/src/test/resources/logback-test.xml diff --git a/spring-reactive-modules/spring-5-data-reactive-2/README.md b/spring-reactive-modules/spring-reactive-data-2/README.md similarity index 80% rename from spring-reactive-modules/spring-5-data-reactive-2/README.md rename to spring-reactive-modules/spring-reactive-data-2/README.md index ffc664b8af..c13171cbc6 100644 --- a/spring-reactive-modules/spring-5-data-reactive-2/README.md +++ b/spring-reactive-modules/spring-reactive-data-2/README.md @@ -1,6 +1,6 @@ ## Spring Data Reactive Project -This module contains articles about reactive Spring 5 Data +This module contains articles about reactive Spring Boot Data ### The Course diff --git a/spring-reactive-modules/spring-5-data-reactive-2/pom.xml b/spring-reactive-modules/spring-reactive-data-2/pom.xml similarity index 85% rename from spring-reactive-modules/spring-5-data-reactive-2/pom.xml rename to spring-reactive-modules/spring-reactive-data-2/pom.xml index 3d88e672eb..64ce278973 100644 --- a/spring-reactive-modules/spring-5-data-reactive-2/pom.xml +++ b/spring-reactive-modules/spring-reactive-data-2/pom.xml @@ -3,8 +3,8 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - spring-5-data-reactive-2 - spring-5-data-reactive-2 + spring-reactive-data-2 + spring-reactive-data-2 jar @@ -14,8 +14,6 @@ - 8 - 8 UTF-8 @@ -56,11 +54,6 @@ lombok true - - org.springframework.boot - spring-boot-starter-test - test - io.projectreactor reactor-test diff --git a/spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/PaginationApplication.java b/spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/PaginationApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/PaginationApplication.java rename to spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/PaginationApplication.java diff --git a/spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/config/CustomWebMvcConfigurationSupport.java b/spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/config/CustomWebMvcConfigurationSupport.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/config/CustomWebMvcConfigurationSupport.java rename to spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/config/CustomWebMvcConfigurationSupport.java diff --git a/spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/config/DatabaseConfig.java b/spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/config/DatabaseConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/config/DatabaseConfig.java rename to spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/config/DatabaseConfig.java diff --git a/spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/controller/ProductPaginationController.java b/spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/controller/ProductPaginationController.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/controller/ProductPaginationController.java rename to spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/controller/ProductPaginationController.java diff --git a/spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/model/Product.java b/spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/model/Product.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/model/Product.java rename to spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/model/Product.java diff --git a/spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/repository/ProductRepository.java b/spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/repository/ProductRepository.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive-2/src/main/java/com/baeldung/pagination/repository/ProductRepository.java rename to spring-reactive-modules/spring-reactive-data-2/src/main/java/com/baeldung/pagination/repository/ProductRepository.java diff --git a/spring-reactive-modules/spring-5-data-reactive-2/src/main/resources/application.properties b/spring-reactive-modules/spring-reactive-data-2/src/main/resources/application.properties similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive-2/src/main/resources/application.properties rename to spring-reactive-modules/spring-reactive-data-2/src/main/resources/application.properties diff --git a/spring-reactive-modules/spring-5-data-reactive-2/src/main/resources/init.sql b/spring-reactive-modules/spring-reactive-data-2/src/main/resources/init.sql similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive-2/src/main/resources/init.sql rename to spring-reactive-modules/spring-reactive-data-2/src/main/resources/init.sql diff --git a/spring-reactive-modules/spring-5-data-reactive-2/src/test/java/com/baeldung/pagination/controller/ProductPaginationControllerIntegrationTest.java b/spring-reactive-modules/spring-reactive-data-2/src/test/java/com/baeldung/pagination/controller/ProductPaginationControllerIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive-2/src/test/java/com/baeldung/pagination/controller/ProductPaginationControllerIntegrationTest.java rename to spring-reactive-modules/spring-reactive-data-2/src/test/java/com/baeldung/pagination/controller/ProductPaginationControllerIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-data-reactive/README.md b/spring-reactive-modules/spring-reactive-data/README.md similarity index 77% rename from spring-reactive-modules/spring-5-data-reactive/README.md rename to spring-reactive-modules/spring-reactive-data/README.md index 3522d9681b..cafd0c502f 100644 --- a/spring-reactive-modules/spring-5-data-reactive/README.md +++ b/spring-reactive-modules/spring-reactive-data/README.md @@ -1,6 +1,6 @@ ## Spring Data Reactive Project -This module contains articles about reactive Spring 5 Data +This module contains articles about reactive Spring Boot Data ### The Course The "REST With Spring" Classes: http://bit.ly/restwithspring diff --git a/spring-reactive-modules/spring-5-data-reactive/pom.xml b/spring-reactive-modules/spring-reactive-data/pom.xml similarity index 96% rename from spring-reactive-modules/spring-5-data-reactive/pom.xml rename to spring-reactive-modules/spring-reactive-data/pom.xml index dc4a5b9bd1..91c4dca6e8 100644 --- a/spring-reactive-modules/spring-5-data-reactive/pom.xml +++ b/spring-reactive-modules/spring-reactive-data/pom.xml @@ -3,8 +3,8 @@ xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - spring-5-data-reactive - spring-5-data-reactive + spring-reactive-data + spring-reactive-data jar diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/r2dbc/R2dbcApplication.java b/spring-reactive-modules/spring-reactive-data/src/main/java/com/baeldung/r2dbc/R2dbcApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/r2dbc/R2dbcApplication.java rename to spring-reactive-modules/spring-reactive-data/src/main/java/com/baeldung/r2dbc/R2dbcApplication.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/r2dbc/configuration/R2DBCConfiguration.java b/spring-reactive-modules/spring-reactive-data/src/main/java/com/baeldung/r2dbc/configuration/R2DBCConfiguration.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/r2dbc/configuration/R2DBCConfiguration.java rename to spring-reactive-modules/spring-reactive-data/src/main/java/com/baeldung/r2dbc/configuration/R2DBCConfiguration.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/r2dbc/model/Player.java b/spring-reactive-modules/spring-reactive-data/src/main/java/com/baeldung/r2dbc/model/Player.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/r2dbc/model/Player.java rename to spring-reactive-modules/spring-reactive-data/src/main/java/com/baeldung/r2dbc/model/Player.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/r2dbc/repository/PlayerRepository.java b/spring-reactive-modules/spring-reactive-data/src/main/java/com/baeldung/r2dbc/repository/PlayerRepository.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/java/com/baeldung/r2dbc/repository/PlayerRepository.java rename to spring-reactive-modules/spring-reactive-data/src/main/java/com/baeldung/r2dbc/repository/PlayerRepository.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/main/resources/logback.xml b/spring-reactive-modules/spring-reactive-data/src/main/resources/logback.xml similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/main/resources/logback.xml rename to spring-reactive-modules/spring-reactive-data/src/main/resources/logback.xml diff --git a/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/SpringContextTest.java b/spring-reactive-modules/spring-reactive-data/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/SpringContextTest.java rename to spring-reactive-modules/spring-reactive-data/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/r2dbc/R2dbcApplicationIntegrationTest.java b/spring-reactive-modules/spring-reactive-data/src/test/java/com/baeldung/r2dbc/R2dbcApplicationIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-data-reactive/src/test/java/com/baeldung/r2dbc/R2dbcApplicationIntegrationTest.java rename to spring-reactive-modules/spring-reactive-data/src/test/java/com/baeldung/r2dbc/R2dbcApplicationIntegrationTest.java diff --git a/spring-reactive-modules/spring-reactive-exceptions/README.md b/spring-reactive-modules/spring-reactive-exceptions/README.md index fc1a31b26f..f10774d188 100644 --- a/spring-reactive-modules/spring-reactive-exceptions/README.md +++ b/spring-reactive-modules/spring-reactive-exceptions/README.md @@ -1,3 +1,3 @@ ## Relevant Articles - [How to Resolve Spring Webflux DataBufferLimitException](https://www.baeldung.com/spring-webflux-databufferlimitexception) -- [Custom WebFlux Exceptions in Spring Boot 3](https://www.baeldung.com/spring-boot-custom-webflux-exceptions) +- [Custom WebFlux Exceptions in Spring Boot 3](https://www.baeldung.com/spring-boot-custom-webflux-exceptions) \ No newline at end of file diff --git a/spring-reactive-modules/spring-5-reactive-filters/.gitignore b/spring-reactive-modules/spring-reactive-filters/.gitignore similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/.gitignore rename to spring-reactive-modules/spring-reactive-filters/.gitignore diff --git a/spring-reactive-modules/spring-5-reactive-filters/README.md b/spring-reactive-modules/spring-reactive-filters/README.md similarity index 76% rename from spring-reactive-modules/spring-5-reactive-filters/README.md rename to spring-reactive-modules/spring-reactive-filters/README.md index 815ca35442..9d73eae9ee 100644 --- a/spring-reactive-modules/spring-5-reactive-filters/README.md +++ b/spring-reactive-modules/spring-reactive-filters/README.md @@ -8,3 +8,4 @@ The "REST With Spring" Classes: https://bit.ly/restwithspring ### Relevant Articles - [Spring WebFlux Filters](https://www.baeldung.com/spring-webflux-filters) +- [Spring WebClient Filters](https://www.baeldung.com/spring-webclient-filters) diff --git a/spring-reactive-modules/spring-5-reactive-filters/pom.xml b/spring-reactive-modules/spring-reactive-filters/pom.xml similarity index 81% rename from spring-reactive-modules/spring-5-reactive-filters/pom.xml rename to spring-reactive-modules/spring-reactive-filters/pom.xml index c9503d631a..67f7a11cb4 100644 --- a/spring-reactive-modules/spring-5-reactive-filters/pom.xml +++ b/spring-reactive-modules/spring-reactive-filters/pom.xml @@ -3,11 +3,11 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - spring-5-reactive-filters + spring-reactive-filters 0.0.1-SNAPSHOT - spring-5-reactive-filters + spring-reactive-filters jar - spring 5 sample project about new features + spring boot sample project about new features com.baeldung.spring.reactive @@ -49,6 +49,12 @@ netty-all test + + com.github.tomakehurst + wiremock-standalone + ${wiremock-standalone.version} + test + @@ -65,4 +71,8 @@ + + 2.26.0 + + \ No newline at end of file diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/Spring5ReactiveFiltersApplication.java b/spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/Spring5ReactiveFiltersApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/Spring5ReactiveFiltersApplication.java rename to spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/Spring5ReactiveFiltersApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/ExampleHandlerFilterFunction.java b/spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/ExampleHandlerFilterFunction.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/ExampleHandlerFilterFunction.java rename to spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/ExampleHandlerFilterFunction.java diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/ExampleWebFilter.java b/spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/ExampleWebFilter.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/ExampleWebFilter.java rename to spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/ExampleWebFilter.java diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/PlayerHandler.java b/spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/PlayerHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/PlayerHandler.java rename to spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/PlayerHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/PlayerRouter.java b/spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/PlayerRouter.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/PlayerRouter.java rename to spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/PlayerRouter.java diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/UserController.java b/spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/UserController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/main/java/com/baeldung/reactive/filters/UserController.java rename to spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/UserController.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/filter/WebClientFilters.java b/spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/WebClientFilters.java similarity index 98% rename from spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/filter/WebClientFilters.java rename to spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/WebClientFilters.java index c98caf67b4..34fff3c4cb 100644 --- a/spring-reactive-modules/spring-5-reactive-client/src/main/java/com/baeldung/webclient/filter/WebClientFilters.java +++ b/spring-reactive-modules/spring-reactive-filters/src/main/java/com/baeldung/reactive/filters/WebClientFilters.java @@ -1,4 +1,4 @@ -package com.baeldung.webclient.filter; +package com.baeldung.reactive.filters; import java.io.PrintStream; import java.net.URI; diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/main/resources/application.properties b/spring-reactive-modules/spring-reactive-filters/src/main/resources/application.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/main/resources/application.properties rename to spring-reactive-modules/spring-reactive-filters/src/main/resources/application.properties diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/main/resources/logback.xml b/spring-reactive-modules/spring-reactive-filters/src/main/resources/logback.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/main/resources/logback.xml rename to spring-reactive-modules/spring-reactive-filters/src/main/resources/logback.xml diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/test/java/com/baeldung/SpringContextTest.java b/spring-reactive-modules/spring-reactive-filters/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/test/java/com/baeldung/SpringContextTest.java rename to spring-reactive-modules/spring-reactive-filters/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/webclient/filter/FilteredWebClientUnitTest.java b/spring-reactive-modules/spring-reactive-filters/src/test/java/com/baeldung/reactive/filters/FilteredWebClientUnitTest.java similarity index 95% rename from spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/webclient/filter/FilteredWebClientUnitTest.java rename to spring-reactive-modules/spring-reactive-filters/src/test/java/com/baeldung/reactive/filters/FilteredWebClientUnitTest.java index 675cd03d10..1350db0752 100644 --- a/spring-reactive-modules/spring-5-reactive-client/src/test/java/com/baeldung/webclient/filter/FilteredWebClientUnitTest.java +++ b/spring-reactive-modules/spring-reactive-filters/src/test/java/com/baeldung/reactive/filters/FilteredWebClientUnitTest.java @@ -1,8 +1,8 @@ -package com.baeldung.webclient.filter; +package com.baeldung.reactive.filters; -import static com.baeldung.webclient.filter.WebClientFilters.countingFilter; -import static com.baeldung.webclient.filter.WebClientFilters.loggingFilter; -import static com.baeldung.webclient.filter.WebClientFilters.urlModifyingFilter; +import static com.baeldung.reactive.filters.WebClientFilters.countingFilter; +import static com.baeldung.reactive.filters.WebClientFilters.loggingFilter; +import static com.baeldung.reactive.filters.WebClientFilters.urlModifyingFilter; import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.containing; import static com.github.tomakehurst.wiremock.client.WireMock.get; diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/test/java/com/baeldung/reactive/filters/PlayerHandlerIntegrationTest.java b/spring-reactive-modules/spring-reactive-filters/src/test/java/com/baeldung/reactive/filters/PlayerHandlerIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/test/java/com/baeldung/reactive/filters/PlayerHandlerIntegrationTest.java rename to spring-reactive-modules/spring-reactive-filters/src/test/java/com/baeldung/reactive/filters/PlayerHandlerIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-filters/src/test/java/com/baeldung/reactive/filters/UserControllerIntegrationTest.java b/spring-reactive-modules/spring-reactive-filters/src/test/java/com/baeldung/reactive/filters/UserControllerIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-filters/src/test/java/com/baeldung/reactive/filters/UserControllerIntegrationTest.java rename to spring-reactive-modules/spring-reactive-filters/src/test/java/com/baeldung/reactive/filters/UserControllerIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/README.md b/spring-reactive-modules/spring-reactive-oauth/README.md similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/README.md rename to spring-reactive-modules/spring-reactive-oauth/README.md diff --git a/spring-reactive-modules/spring-5-reactive-oauth/pom.xml b/spring-reactive-modules/spring-reactive-oauth/pom.xml similarity index 96% rename from spring-reactive-modules/spring-5-reactive-oauth/pom.xml rename to spring-reactive-modules/spring-reactive-oauth/pom.xml index 9c237607ba..9d2dbf6126 100644 --- a/spring-reactive-modules/spring-5-reactive-oauth/pom.xml +++ b/spring-reactive-modules/spring-reactive-oauth/pom.xml @@ -4,9 +4,9 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 com.baeldung.reactive.oauth - spring-5-reactive-oauth + spring-reactive-oauth 1.0.0-SNAPSHOT - spring-5-reactive-oauth + spring-reactive-oauth jar WebFlux and Spring Security OAuth diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/SecurityConfig.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/SecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/SecurityConfig.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/SecurityConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/Spring5ReactiveOauthApplication.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/Spring5ReactiveOauthApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/Spring5ReactiveOauthApplication.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/Spring5ReactiveOauthApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/web/MainController.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/web/MainController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/web/MainController.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/web/MainController.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/web/dto/Foo.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/web/dto/Foo.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/web/dto/Foo.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/reactive/oauth/web/dto/Foo.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/OauthClientApplication.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/OauthClientApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/OauthClientApplication.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/OauthClientApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/configuration/WebClientConfig.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/configuration/WebClientConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/configuration/WebClientConfig.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/configuration/WebClientConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/configuration/WebSecurityConfig.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/configuration/WebSecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/configuration/WebSecurityConfig.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/configuration/WebSecurityConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/web/ClientRestController.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/web/ClientRestController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/web/ClientRestController.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodeclient/web/ClientRestController.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/OauthClientLoginApplication.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/OauthClientLoginApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/OauthClientLoginApplication.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/OauthClientLoginApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/configuration/WebClientConfig.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/configuration/WebClientConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/configuration/WebClientConfig.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/configuration/WebClientConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/configuration/WebSecurityConfig.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/configuration/WebSecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/configuration/WebSecurityConfig.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/configuration/WebSecurityConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/web/ClientRestController.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/web/ClientRestController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/web/ClientRestController.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/authorizationcodelogin/web/ClientRestController.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/ClientCredentialsOauthApplication.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/ClientCredentialsOauthApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/ClientCredentialsOauthApplication.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/ClientCredentialsOauthApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/configuration/WebClientConfig.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/configuration/WebClientConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/configuration/WebClientConfig.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/configuration/WebClientConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/service/WebClientChonJob.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/service/WebClientChonJob.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/service/WebClientChonJob.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/clientcredentials/service/WebClientChonJob.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/ManualRequestApplication.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/ManualRequestApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/ManualRequestApplication.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/ManualRequestApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/configure/WebClientConfig.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/configure/WebClientConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/configure/WebClientConfig.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/configure/WebClientConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/configure/WebSecurityConfig.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/configure/WebSecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/configure/WebSecurityConfig.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/configure/WebSecurityConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/web/ManualOauthRequestController.java b/spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/web/ManualOauthRequestController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/web/ManualOauthRequestController.java rename to spring-reactive-modules/spring-reactive-oauth/src/main/java/com/baeldung/webclient/manualrequest/web/ManualOauthRequestController.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/application.yml b/spring-reactive-modules/spring-reactive-oauth/src/main/resources/application.yml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/application.yml rename to spring-reactive-modules/spring-reactive-oauth/src/main/resources/application.yml diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/default-application.yml b/spring-reactive-modules/spring-reactive-oauth/src/main/resources/default-application.yml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/default-application.yml rename to spring-reactive-modules/spring-reactive-oauth/src/main/resources/default-application.yml diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/webclient-auth-code-client-application.properties b/spring-reactive-modules/spring-reactive-oauth/src/main/resources/webclient-auth-code-client-application.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/webclient-auth-code-client-application.properties rename to spring-reactive-modules/spring-reactive-oauth/src/main/resources/webclient-auth-code-client-application.properties diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/webclient-auth-code-login-application.properties b/spring-reactive-modules/spring-reactive-oauth/src/main/resources/webclient-auth-code-login-application.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/webclient-auth-code-login-application.properties rename to spring-reactive-modules/spring-reactive-oauth/src/main/resources/webclient-auth-code-login-application.properties diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/webclient-client-credentials-oauth-application.properties b/spring-reactive-modules/spring-reactive-oauth/src/main/resources/webclient-client-credentials-oauth-application.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/webclient-client-credentials-oauth-application.properties rename to spring-reactive-modules/spring-reactive-oauth/src/main/resources/webclient-client-credentials-oauth-application.properties diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/webclient-manual-request-oauth-application.properties b/spring-reactive-modules/spring-reactive-oauth/src/main/resources/webclient-manual-request-oauth-application.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/main/resources/webclient-manual-request-oauth-application.properties rename to spring-reactive-modules/spring-reactive-oauth/src/main/resources/webclient-manual-request-oauth-application.properties diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/test/java/com/baeldung/reactive/oauth/Spring5ReactiveOauthIntegrationTest.java b/spring-reactive-modules/spring-reactive-oauth/src/test/java/com/baeldung/reactive/oauth/Spring5ReactiveOauthIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/test/java/com/baeldung/reactive/oauth/Spring5ReactiveOauthIntegrationTest.java rename to spring-reactive-modules/spring-reactive-oauth/src/test/java/com/baeldung/reactive/oauth/Spring5ReactiveOauthIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/test/java/com/baeldung/webclient/clientcredentials/OAuth2ClientCredentialsLiveTest.java b/spring-reactive-modules/spring-reactive-oauth/src/test/java/com/baeldung/webclient/clientcredentials/OAuth2ClientCredentialsLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/test/java/com/baeldung/webclient/clientcredentials/OAuth2ClientCredentialsLiveTest.java rename to spring-reactive-modules/spring-reactive-oauth/src/test/java/com/baeldung/webclient/clientcredentials/OAuth2ClientCredentialsLiveTest.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/test/java/com/baeldung/webclient/manualrequest/OAuth2ManualRequestLiveTest.java b/spring-reactive-modules/spring-reactive-oauth/src/test/java/com/baeldung/webclient/manualrequest/OAuth2ManualRequestLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/test/java/com/baeldung/webclient/manualrequest/OAuth2ManualRequestLiveTest.java rename to spring-reactive-modules/spring-reactive-oauth/src/test/java/com/baeldung/webclient/manualrequest/OAuth2ManualRequestLiveTest.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/test/java/com/baeldung/webclient/utils/ListAppender.java b/spring-reactive-modules/spring-reactive-oauth/src/test/java/com/baeldung/webclient/utils/ListAppender.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/test/java/com/baeldung/webclient/utils/ListAppender.java rename to spring-reactive-modules/spring-reactive-oauth/src/test/java/com/baeldung/webclient/utils/ListAppender.java diff --git a/spring-reactive-modules/spring-5-reactive-oauth/src/test/resources/logback-test.xml b/spring-reactive-modules/spring-reactive-oauth/src/test/resources/logback-test.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-oauth/src/test/resources/logback-test.xml rename to spring-reactive-modules/spring-reactive-oauth/src/test/resources/logback-test.xml diff --git a/spring-reactive-modules/spring-5-reactive-security/.gitignore b/spring-reactive-modules/spring-reactive-security/.gitignore similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/.gitignore rename to spring-reactive-modules/spring-reactive-security/.gitignore diff --git a/spring-reactive-modules/spring-5-reactive-security/README.md b/spring-reactive-modules/spring-reactive-security/README.md similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/README.md rename to spring-reactive-modules/spring-reactive-security/README.md diff --git a/spring-reactive-modules/spring-5-reactive-security/pom.xml b/spring-reactive-modules/spring-reactive-security/pom.xml similarity index 93% rename from spring-reactive-modules/spring-5-reactive-security/pom.xml rename to spring-reactive-modules/spring-reactive-security/pom.xml index e455940d83..8ed976c572 100644 --- a/spring-reactive-modules/spring-5-reactive-security/pom.xml +++ b/spring-reactive-modules/spring-reactive-security/pom.xml @@ -3,11 +3,11 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - spring-5-reactive-security + spring-reactive-security 0.0.1-SNAPSHOT - spring-5-reactive-security + spring-reactive-security jar - spring 5 security sample project about new features + spring boot security sample project about new features com.baeldung.spring.reactive @@ -66,10 +66,6 @@ spring-boot-devtools runtime - - org.springframework - spring-test - org.springframework.boot spring-boot-starter-test diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/DownstreamServiceHealthIndicator.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/DownstreamServiceHealthIndicator.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/DownstreamServiceHealthIndicator.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/DownstreamServiceHealthIndicator.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/FeaturesEndpoint.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/FeaturesEndpoint.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/FeaturesEndpoint.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/FeaturesEndpoint.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/InfoWebEndpointExtension.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/InfoWebEndpointExtension.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/InfoWebEndpointExtension.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/InfoWebEndpointExtension.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/Spring5ReactiveApplication.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/Spring5ReactiveApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/Spring5ReactiveApplication.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/Spring5ReactiveApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/WebSecurityConfig.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/WebSecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/actuator/WebSecurityConfig.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/actuator/WebSecurityConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/authresolver/AuthResolverApplication.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/authresolver/AuthResolverApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/authresolver/AuthResolverApplication.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/authresolver/AuthResolverApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/authresolver/AuthResolverController.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/authresolver/AuthResolverController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/authresolver/AuthResolverController.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/authresolver/AuthResolverController.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/authresolver/CustomWebSecurityConfig.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/authresolver/CustomWebSecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/authresolver/CustomWebSecurityConfig.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/authresolver/CustomWebSecurityConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/CorsOnAnnotatedElementsApplication.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/CorsOnAnnotatedElementsApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/CorsOnAnnotatedElementsApplication.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/CorsOnAnnotatedElementsApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnClassController.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnClassController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnClassController.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnClassController.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnMethodsController.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnMethodsController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnMethodsController.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/annotated/controllers/CorsOnMethodsController.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/CorsGlobalConfigApplication.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/CorsGlobalConfigApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/CorsGlobalConfigApplication.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/CorsGlobalConfigApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/config/CorsGlobalConfiguration.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/config/CorsGlobalConfiguration.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/config/CorsGlobalConfiguration.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/config/CorsGlobalConfiguration.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/FurtherCorsConfigsController.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/FurtherCorsConfigsController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/FurtherCorsConfigsController.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/FurtherCorsConfigsController.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/RegularRestController.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/RegularRestController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/RegularRestController.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/controllers/RegularRestController.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/handlers/CorsGlobalFunctionalHandler.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/handlers/CorsGlobalFunctionalHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/handlers/CorsGlobalFunctionalHandler.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/handlers/CorsGlobalFunctionalHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/routers/CorsRouterFunctions.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/routers/CorsRouterFunctions.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/routers/CorsRouterFunctions.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/global/functional/routers/CorsRouterFunctions.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/CorsWebFilterApplication.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/CorsWebFilterApplication.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/CorsWebFilterApplication.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/CorsWebFilterApplication.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/config/CorsWebFilterConfig.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/config/CorsWebFilterConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/config/CorsWebFilterConfig.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/config/CorsWebFilterConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/FurtherCorsConfigsController.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/FurtherCorsConfigsController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/FurtherCorsConfigsController.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/FurtherCorsConfigsController.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/RegularRestController.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/RegularRestController.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/RegularRestController.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/controllers/RegularRestController.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/handlers/CorsWithWebFilterHandler.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/handlers/CorsWithWebFilterHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/handlers/CorsWithWebFilterHandler.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/handlers/CorsWithWebFilterHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/routers/CorsWithWebFilterRouterFunctions.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/routers/CorsWithWebFilterRouterFunctions.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/routers/CorsWithWebFilterRouterFunctions.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/reactive/cors/webfilter/functional/routers/CorsWithWebFilterRouterFunctions.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/Employee.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/Employee.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/Employee.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/Employee.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeConfig.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeConfig.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeCreationEvent.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeCreationEvent.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeCreationEvent.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeCreationEvent.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSecurityConfig.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSecurityConfig.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSecurityConfig.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSecurityConfig.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSocketClient.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSocketClient.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSocketClient.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSocketClient.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSocketHandler.java b/spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSocketHandler.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSocketHandler.java rename to spring-reactive-modules/spring-reactive-security/src/main/java/com/baeldung/webflux/EmployeeWebSocketHandler.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/resources/application.properties b/spring-reactive-modules/spring-reactive-security/src/main/resources/application.properties similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/resources/application.properties rename to spring-reactive-modules/spring-reactive-security/src/main/resources/application.properties diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/resources/files/hello.txt b/spring-reactive-modules/spring-reactive-security/src/main/resources/files/hello.txt similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/resources/files/hello.txt rename to spring-reactive-modules/spring-reactive-security/src/main/resources/files/hello.txt diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/resources/files/test/test.txt b/spring-reactive-modules/spring-reactive-security/src/main/resources/files/test/test.txt similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/resources/files/test/test.txt rename to spring-reactive-modules/spring-reactive-security/src/main/resources/files/test/test.txt diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/resources/logback.xml b/spring-reactive-modules/spring-reactive-security/src/main/resources/logback.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/resources/logback.xml rename to spring-reactive-modules/spring-reactive-security/src/main/resources/logback.xml diff --git a/spring-reactive-modules/spring-5-reactive-security/src/main/resources/static/client-websocket.html b/spring-reactive-modules/spring-reactive-security/src/main/resources/static/client-websocket.html similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/main/resources/static/client-websocket.html rename to spring-reactive-modules/spring-reactive-security/src/main/resources/static/client-websocket.html diff --git a/spring-reactive-modules/spring-5-reactive/src/main/webapp/WEB-INF/web.xml b/spring-reactive-modules/spring-reactive-security/src/main/webapp/WEB-INF/web.xml similarity index 100% rename from spring-reactive-modules/spring-5-reactive/src/main/webapp/WEB-INF/web.xml rename to spring-reactive-modules/spring-reactive-security/src/main/webapp/WEB-INF/web.xml diff --git a/spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/SpringContextTest.java b/spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/SpringContextTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/SpringContextTest.java rename to spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/SpringContextTest.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/actuator/ActuatorInfoIntegrationTest.java b/spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/actuator/ActuatorInfoIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/actuator/ActuatorInfoIntegrationTest.java rename to spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/actuator/ActuatorInfoIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/authresolver/AuthResolverIntegrationTest.java b/spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/authresolver/AuthResolverIntegrationTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/authresolver/AuthResolverIntegrationTest.java rename to spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/authresolver/AuthResolverIntegrationTest.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnAnnotatedElementsLiveTest.java b/spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnAnnotatedElementsLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnAnnotatedElementsLiveTest.java rename to spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnAnnotatedElementsLiveTest.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnGlobalConfigLiveTest.java b/spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnGlobalConfigLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnGlobalConfigLiveTest.java rename to spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnGlobalConfigLiveTest.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnWebFilterLiveTest.java b/spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnWebFilterLiveTest.java similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnWebFilterLiveTest.java rename to spring-reactive-modules/spring-reactive-security/src/test/java/com/baeldung/reactive/cors/CorsOnWebFilterLiveTest.java diff --git a/spring-reactive-modules/spring-5-reactive-security/src/test/resources/baeldung-weekly.png b/spring-reactive-modules/spring-reactive-security/src/test/resources/baeldung-weekly.png similarity index 100% rename from spring-reactive-modules/spring-5-reactive-security/src/test/resources/baeldung-weekly.png rename to spring-reactive-modules/spring-reactive-security/src/test/resources/baeldung-weekly.png diff --git a/spring-reactive-modules/spring-reactive/README.md b/spring-reactive-modules/spring-reactive/README.md index 7dfc7b2952..61d781b312 100644 --- a/spring-reactive-modules/spring-reactive/README.md +++ b/spring-reactive-modules/spring-reactive/README.md @@ -1,6 +1,5 @@ -### Spring Reactive Articles that are also part of the e-book -This module contains articles about Spring Reactive that are also part of an Ebook. +This module contains articles about Spring Reactive that **are also part of an Ebook.** ## Spring Reactive @@ -21,4 +20,4 @@ This module contains articles describing reactive processing in Spring. ### NOTE: -Since this is a module tied to an e-book, it should **not** be moved or used to store the code for any further article. +## Since this is a module tied to an e-book, it should **not** be moved or used to store the code for any further article. diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorAttributes.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorAttributes.java index 3458a175e4..549ae749f2 100644 --- a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorAttributes.java +++ b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorAttributes.java @@ -1,13 +1,13 @@ package com.baeldung.reactive.errorhandling; +import java.util.Map; + import org.springframework.boot.web.error.ErrorAttributeOptions; import org.springframework.boot.web.reactive.error.DefaultErrorAttributes; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.server.ServerRequest; -import java.util.Map; - @Component public class GlobalErrorAttributes extends DefaultErrorAttributes { diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorWebExceptionHandler.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorWebExceptionHandler.java index 24583308cd..69f9a0420e 100644 --- a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorWebExceptionHandler.java +++ b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/GlobalErrorWebExceptionHandler.java @@ -1,5 +1,7 @@ package com.baeldung.reactive.errorhandling; +import java.util.Map; + import org.springframework.boot.autoconfigure.web.WebProperties; import org.springframework.boot.autoconfigure.web.reactive.error.AbstractErrorWebExceptionHandler; import org.springframework.boot.web.error.ErrorAttributeOptions; @@ -16,15 +18,15 @@ import org.springframework.web.reactive.function.server.RouterFunction; import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerRequest; import org.springframework.web.reactive.function.server.ServerResponse; -import reactor.core.publisher.Mono; -import java.util.Map; +import reactor.core.publisher.Mono; @Component @Order(-2) public class GlobalErrorWebExceptionHandler extends AbstractErrorWebExceptionHandler { - public GlobalErrorWebExceptionHandler(GlobalErrorAttributes g, ApplicationContext applicationContext, + public GlobalErrorWebExceptionHandler( + GlobalErrorAttributes g, ApplicationContext applicationContext, ServerCodecConfigurer serverCodecConfigurer) { super(g, new WebProperties.Resources(), applicationContext); super.setMessageWriters(serverCodecConfigurer.getWriters()); diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Handler.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Handler.java index d49d9b4be2..f9e4ee4c35 100644 --- a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Handler.java +++ b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Handler.java @@ -5,6 +5,7 @@ import org.springframework.http.MediaType; import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.server.ServerRequest; import org.springframework.web.reactive.function.server.ServerResponse; + import reactor.core.publisher.Mono; @Component diff --git a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Router.java b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Router.java index 5f130ec035..aeea202c31 100644 --- a/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Router.java +++ b/spring-reactive-modules/spring-reactive/src/main/java/com/baeldung/reactive/errorhandling/Router.java @@ -1,15 +1,15 @@ package com.baeldung.reactive.errorhandling; +import static org.springframework.http.MediaType.TEXT_PLAIN; +import static org.springframework.web.reactive.function.server.RequestPredicates.GET; +import static org.springframework.web.reactive.function.server.RequestPredicates.accept; + import org.springframework.context.annotation.Bean; import org.springframework.stereotype.Component; import org.springframework.web.reactive.function.server.RouterFunction; import org.springframework.web.reactive.function.server.RouterFunctions; import org.springframework.web.reactive.function.server.ServerResponse; -import static org.springframework.http.MediaType.TEXT_PLAIN; -import static org.springframework.web.reactive.function.server.RequestPredicates.GET; -import static org.springframework.web.reactive.function.server.RequestPredicates.accept; - @Component public class Router { diff --git a/spring-reactive-modules/spring-reactor/pom.xml b/spring-reactive-modules/spring-reactor/pom.xml index 22eaa898bd..c2635765f0 100644 --- a/spring-reactive-modules/spring-reactor/pom.xml +++ b/spring-reactive-modules/spring-reactor/pom.xml @@ -37,7 +37,6 @@ - 2.0.2.RELEASE 2.0.8.RELEASE diff --git a/testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Circle.java b/testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Circle.java new file mode 100644 index 0000000000..b0e63155f4 --- /dev/null +++ b/testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Circle.java @@ -0,0 +1,19 @@ +package com.baeldung.interfaces.unittest; + +public class Circle implements Shape { + + private double radius; + + Circle(double radius) { + this.radius = radius; + } + + @Override + public double area() { + return 3.14 * radius * radius; + } + + public double circumference() { + return 2 * 3.14 * radius; + } +} diff --git a/testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Rectangle.java b/testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Rectangle.java new file mode 100644 index 0000000000..a88233e83b --- /dev/null +++ b/testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Rectangle.java @@ -0,0 +1,21 @@ +package com.baeldung.interfaces.unittest; + +public class Rectangle implements Shape { + + private double length; + private double breadth; + + public Rectangle(double length, double breadth) { + this.length = length; + this.breadth = breadth; + } + + @Override + public double area() { + return length * breadth; + } + + public double perimeter() { + return 2 * (length + breadth); + } +} diff --git a/testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Shape.java b/testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Shape.java new file mode 100644 index 0000000000..bac42fb246 --- /dev/null +++ b/testing-modules/junit-5-advanced/src/main/java/com/baeldung/interfaces/unittest/Shape.java @@ -0,0 +1,6 @@ +package com.baeldung.interfaces.unittest; + +public interface Shape { + + double area(); +} diff --git a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/CircleExtendsBaseUnitTest.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/CircleExtendsBaseUnitTest.java new file mode 100644 index 0000000000..08ce2bc779 --- /dev/null +++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/CircleExtendsBaseUnitTest.java @@ -0,0 +1,26 @@ +package com.baeldung.interfaces.unittest; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +class CircleExtendsBaseUnitTest extends ShapeUnitTest { + + @Override + public Map instantiateShapeWithExpectedArea() { + Map shapeAreaMap = new HashMap<>(); + shapeAreaMap.put("shape", new Circle(5)); + shapeAreaMap.put("area", 78.5); + return shapeAreaMap; + } + + @Test + void whenCircumferenceIsCalculated_thenSuccessful() { + Circle circle = new Circle(2); + double circumference = circle.circumference(); + assertEquals(12.56, circumference); + } +} \ No newline at end of file diff --git a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/CircleUnitTest.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/CircleUnitTest.java new file mode 100644 index 0000000000..c0b4eecedc --- /dev/null +++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/CircleUnitTest.java @@ -0,0 +1,22 @@ +package com.baeldung.interfaces.unittest; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +class CircleUnitTest { + + @Test + void whenAreaIsCalculated_thenSuccessful() { + Shape circle = new Circle(5); + double area = circle.area(); + assertEquals(78.5, area); + } + + @Test + void whenCircumferenceIsCalculated_thenSuccessful() { + Circle circle = new Circle(2); + double circumference = circle.circumference(); + assertEquals(12.56, circumference); + } +} \ No newline at end of file diff --git a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/ParameterizedUnitTest.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/ParameterizedUnitTest.java new file mode 100644 index 0000000000..6b5cd6b6ab --- /dev/null +++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/ParameterizedUnitTest.java @@ -0,0 +1,27 @@ +package com.baeldung.interfaces.unittest; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Arrays; +import java.util.Collection; + +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +public class ParameterizedUnitTest { + + @ParameterizedTest + @MethodSource("data") + void givenShapeInstance_whenAreaIsCalculated_thenSuccessful(Shape shapeInstance, double expectedArea) { + double area = shapeInstance.area(); + assertEquals(expectedArea, area); + + } + + private static Collection data() { + return Arrays.asList(new Object[][] { + { new Circle(5), 78.5 }, + { new Rectangle(4, 5), 20 } + }); + } +} diff --git a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/RectangleExtendsBaseUnitTest.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/RectangleExtendsBaseUnitTest.java new file mode 100644 index 0000000000..b6771ad648 --- /dev/null +++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/RectangleExtendsBaseUnitTest.java @@ -0,0 +1,26 @@ +package com.baeldung.interfaces.unittest; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.jupiter.api.Test; + +class RectangleExtendsBaseUnitTest extends ShapeUnitTest { + + @Override + public Map instantiateShapeWithExpectedArea() { + Map shapeAreaMap = new HashMap<>(); + shapeAreaMap.put("shape", new Rectangle(5, 4)); + shapeAreaMap.put("area", 20.0); + return shapeAreaMap; + } + + @Test + void whenPerimeterIsCalculated_thenSuccessful() { + Rectangle rectangle = new Rectangle(5, 4); + double perimeter = rectangle.perimeter(); + assertEquals(18, perimeter); + } +} \ No newline at end of file diff --git a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/RectangleUnitTest.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/RectangleUnitTest.java new file mode 100644 index 0000000000..1983353667 --- /dev/null +++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/RectangleUnitTest.java @@ -0,0 +1,22 @@ +package com.baeldung.interfaces.unittest; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; + +class RectangleUnitTest { + + @Test + void whenAreaIsCalculated_thenSuccessful() { + Shape rectangle = new Rectangle(5, 4); + double area = rectangle.area(); + assertEquals(20, area); + } + + @Test + void whenPerimeterIsCalculated_thenSuccessful() { + Rectangle rectangle = new Rectangle(5, 4); + double perimeter = rectangle.perimeter(); + assertEquals(18, perimeter); + } +} \ No newline at end of file diff --git a/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/ShapeUnitTest.java b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/ShapeUnitTest.java new file mode 100644 index 0000000000..a9d318f698 --- /dev/null +++ b/testing-modules/junit-5-advanced/src/test/java/com/baeldung/interfaces/unittest/ShapeUnitTest.java @@ -0,0 +1,21 @@ +package com.baeldung.interfaces.unittest; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.Map; + +import org.junit.jupiter.api.Test; + +public abstract class ShapeUnitTest { + + public abstract Map instantiateShapeWithExpectedArea(); + + @Test + void givenShapeInstance_whenAreaIsCalculated_thenSuccessful() { + Map shapeAreaMap = instantiateShapeWithExpectedArea(); + Shape shape = (Shape) shapeAreaMap.get("shape"); + double expectedArea = (double) shapeAreaMap.get("area"); + double area = shape.area(); + assertEquals(expectedArea, area); + } +} diff --git a/testing-modules/mockito-2/README.md b/testing-modules/mockito-2/README.md index b60885c6d5..da8f339e56 100644 --- a/testing-modules/mockito-2/README.md +++ b/testing-modules/mockito-2/README.md @@ -8,3 +8,4 @@ This module contains articles about Mockito - [Matching Null With Mockito](https://www.baeldung.com/mockito-match-null) - [Mock Same Method with Different Parameters](https://www.baeldung.com/java-mock-same-method-other-parameters) - [How to Mock Constructors for Unit Testing using Mockito](https://www.baeldung.com/java-mockito-constructors-unit-testing) +- [Overview of Mockito MockedConstruction](https://www.baeldung.com/java-mockito-mockedconstruction)