From e98a39ba255eda7ec75d1a5ca62814cfb153fb3d Mon Sep 17 00:00:00 2001 From: mikr Date: Sun, 10 Mar 2019 19:28:09 +0100 Subject: [PATCH 01/53] BAEL-2562 New section in Generics article --- .../src/main/java/com/baeldung/generics/Generics.java | 7 +++++++ .../java/com/baeldung/generics/GenericsUnitTest.java | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/core-java-lang-syntax/src/main/java/com/baeldung/generics/Generics.java b/core-java-lang-syntax/src/main/java/com/baeldung/generics/Generics.java index e0536ca02e..1c4082c58b 100644 --- a/core-java-lang-syntax/src/main/java/com/baeldung/generics/Generics.java +++ b/core-java-lang-syntax/src/main/java/com/baeldung/generics/Generics.java @@ -1,5 +1,6 @@ package com.baeldung.generics; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.function.Function; @@ -28,4 +29,10 @@ public class Generics { buildings.forEach(Building::paint); } + public static List createList(int a) { + List list = new ArrayList<>(); + list.add(a); + return list; + } + } \ No newline at end of file diff --git a/core-java-lang-syntax/src/test/java/com/baeldung/generics/GenericsUnitTest.java b/core-java-lang-syntax/src/test/java/com/baeldung/generics/GenericsUnitTest.java index aca0b182a0..0bdf0afc15 100644 --- a/core-java-lang-syntax/src/test/java/com/baeldung/generics/GenericsUnitTest.java +++ b/core-java-lang-syntax/src/test/java/com/baeldung/generics/GenericsUnitTest.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.List; import static org.hamcrest.CoreMatchers.hasItems; +import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.fail; @@ -66,4 +67,12 @@ public class GenericsUnitTest { } } + @Test + public void givenAnInt_whenAddedToAGenericIntegerList_thenAListItemCanBeAssignedToAnInt() { + int number = 7; + List list = Generics.createList(number); + int otherNumber = list.get(0); + assertThat(otherNumber, is(number)); + } + } \ No newline at end of file From 7d87f2963c2fbc727d488f0b4c0b66bf12f4199d Mon Sep 17 00:00:00 2001 From: macroscopic64 Date: Mon, 25 Mar 2019 23:04:50 +0530 Subject: [PATCH 02/53] [BAEL-2073] Java 9 Migration Issues and Resolution --- prejpms/pom.xml | 73 +++++++++++++++++ .../main/java/com/baeldung/prejpms/App.java | 79 +++++++++++++++++++ .../main/java/com/baeldung/prejpms/Book.java | 39 +++++++++ prejpms/src/main/resources/logback.xml | 10 +++ 4 files changed, 201 insertions(+) create mode 100644 prejpms/pom.xml create mode 100644 prejpms/src/main/java/com/baeldung/prejpms/App.java create mode 100644 prejpms/src/main/java/com/baeldung/prejpms/Book.java create mode 100644 prejpms/src/main/resources/logback.xml diff --git a/prejpms/pom.xml b/prejpms/pom.xml new file mode 100644 index 0000000000..0f0216682e --- /dev/null +++ b/prejpms/pom.xml @@ -0,0 +1,73 @@ + + 4.0.0 + prejpms + 0.0.1-SNAPSHOT + jar + pre-jpms + + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + + + + + org.slf4j + slf4j-api + 1.7.25 + + + + pre-jpms + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-dependency-plugin + 3.1.1 + + + copy-dependencies + package + + copy-dependencies + + + + ${project.build.directory}/dependency-jars/ + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + com.baeldung.prejpms.App + true + dependency-jars/ + + + + + + + + + UTF-8 + + diff --git a/prejpms/src/main/java/com/baeldung/prejpms/App.java b/prejpms/src/main/java/com/baeldung/prejpms/App.java new file mode 100644 index 0000000000..0b38201302 --- /dev/null +++ b/prejpms/src/main/java/com/baeldung/prejpms/App.java @@ -0,0 +1,79 @@ +package com.baeldung.prejpms; + +import java.io.StringWriter; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Marshaller; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.sun.crypto.provider.SunJCE; + +import sun.misc.BASE64Encoder; +import sun.reflect.Reflection; + +public class App { + + private static final Logger logger = LoggerFactory.getLogger(App.class); + + public static void main(String[] args) throws Exception { + + getCrytpographyProviderName(); + getCallStackClassNames(); + getXmlFromObject(new Book(100, "Java Modules Architecture")); + getBase64EncodedString("Java"); + } + + private static void getCrytpographyProviderName() { + try { + logger.info("1. Java Cryptography Extension - Provider Name: " + new SunJCE().getName() + "\n"); + } catch (Throwable e) { + logger.error(e.toString()); + } + } + + private static void getCallStackClassNames() { + try { + int i = 0; + StringBuffer sbStack = new StringBuffer(); + while (true) { + Class caller = Reflection.getCallerClass(i++); + if (caller == null) { + break; + } else { + sbStack.append(caller.getName()) + .append("\n"); + } + } + logger.info("2. Call Stack Class Names:\n" + sbStack.toString()); + } catch (Throwable e) { + logger.error(e.toString()); + } + } + + private static void getXmlFromObject(Book book) { + try { + Marshaller marshallerObj = JAXBContext.newInstance(Book.class) + .createMarshaller(); + marshallerObj.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); + + StringWriter sw = new StringWriter(); + marshallerObj.marshal(book, sw); + logger.info("3. Xml for Book object:\n" + sw); + } catch (Throwable e) { + logger.error(e.toString()); + } + + } + + private static void getBase64EncodedString(String inputString) { + try { + String encodedString = new BASE64Encoder().encode(inputString.getBytes()); + logger.info("4. Base Encoded String: " + encodedString); + } catch (Throwable e) { + logger.error(e.toString()); + } + } +} diff --git a/prejpms/src/main/java/com/baeldung/prejpms/Book.java b/prejpms/src/main/java/com/baeldung/prejpms/Book.java new file mode 100644 index 0000000000..57b19bf3c1 --- /dev/null +++ b/prejpms/src/main/java/com/baeldung/prejpms/Book.java @@ -0,0 +1,39 @@ +package com.baeldung.prejpms; + +import javax.xml.bind.annotation.XmlAttribute; +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "book") +public class Book { + private long id; + private String name; + + public Book() { + + } + + public Book(long id, String name) { + this.id = id; + this.name = name; + } + + @XmlAttribute + public void setId(Long id) { + this.id = id; + } + + @XmlElement(name = "title") + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public Long getId() { + return id; + } + +} diff --git a/prejpms/src/main/resources/logback.xml b/prejpms/src/main/resources/logback.xml new file mode 100644 index 0000000000..7c5914e58e --- /dev/null +++ b/prejpms/src/main/resources/logback.xml @@ -0,0 +1,10 @@ + + + + [%level] %msg%n + + + + + + \ No newline at end of file From cef5964b6b5781b8b2bebb7b5e7a95d8c4378d09 Mon Sep 17 00:00:00 2001 From: Josephine Barboza Date: Sat, 30 Mar 2019 14:28:28 +0530 Subject: [PATCH 03/53] BAEL-2766 Maps in Groovy --- .../groovy/com/baeldung/map/MapTest.groovy | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 core-groovy/src/test/groovy/com/baeldung/map/MapTest.groovy diff --git a/core-groovy/src/test/groovy/com/baeldung/map/MapTest.groovy b/core-groovy/src/test/groovy/com/baeldung/map/MapTest.groovy new file mode 100644 index 0000000000..8bd9302412 --- /dev/null +++ b/core-groovy/src/test/groovy/com/baeldung/map/MapTest.groovy @@ -0,0 +1,146 @@ +package com.baeldung.groovy.map; + +import static groovy.test.GroovyAssert.* +import org.junit.Test + +class MapTest{ + + @Test + void createMap() { + + def emptyMap = [:] + assertNotNull(emptyMap) + + assertTrue(emptyMap instanceof java.util.LinkedHashMap) + + def map = [name:"Jerry", age: 42, city: "New York"] + assertTrue(map.size() == 3) + } + + @Test + void addItemsToMap() { + + def map = [name:"Jerry"] + + map["age"] = 42 + + map.city = "New York" + + def hobbyLiteral = "hobby" + def hobbyMap = [(hobbyLiteral): "Singing"] + map.putAll(hobbyMap) + + assertTrue(map == [name:"Jerry", age: 42, city: "New York", hobby:"Singing"]) + + map.plus([1:20]) // returns new map + + map << [2:30] + + } + + @Test + void getItemsFromMap() { + + def map = [name:"Jerry", age: 42, city: "New York", hobby:"Singing"] + + assertTrue(map["name"] == "Jerry") + + assertTrue(map.name == "Jerry") + + def propertyAge = "age" + assertTrue(map[propertyAge] == 42) + } + + @Test + void removeItemsFromMap() { + + def map = [1:20, a:30, 2:42, 4:34, ba:67, 6:39, 7:49] + + def minusMap = map.minus([2:42, 4:34]); + assertTrue(minusMap == [1:20, a:30, ba:67, 6:39, 7:49]) + + minusMap.removeAll{it -> it.key instanceof String} + assertTrue( minusMap == [ 1:20, 6:39, 7:49]) + + minusMap.retainAll{it -> it.value %2 == 0} + assertTrue( minusMap == [1:20]) + } + + @Test + void iteratingOnMaps(){ + def map = [name:"Jerry", age: 42, city: "New York", hobby:"Singing"] + + map.each{ entry -> println "$entry.key: $entry.value" } + + map.eachWithIndex{ entry, i -> println "$i $entry.key: $entry.value" } + + map.eachWithIndex{ key, value, i -> println "$i $key: $value" } + } + + @Test + void filteringAndSearchingMaps(){ + def map = [name:"Jerry", age: 42, city: "New York", hobby:"Singing"] + + assertTrue(map.find{ it.value == "New York"}.key == "city") + + assertTrue(map.findAll{ it.value == "New York"} == [city : "New York"]) + + map.grep{it.value == "New York"}.each{ it -> assertTrue(it.key == "city" && it.value == "New York")} + + assertTrue(map.every{it -> it.value instanceof String} == false) + + assertTrue(map.any{it -> it.value instanceof String} == true) + } + + @Test + void collect(){ + + def map = [1: [name:"Jerry", age: 42, city: "New York"], + 2: [name:"Long", age: 25, city: "New York"], + 3: [name:"Dustin", age: 29, city: "New York"], + 4: [name:"Dustin", age: 34, city: "New York"]] + + def names = map.collect{entry -> entry.value.name} // returns only list + assertTrue(names == ["Jerry", "Long", "Dustin", "Dustin"]) + + def uniqueNames = map.collect([] as HashSet){entry -> entry.value.name} + assertTrue(uniqueNames == ["Jerry", "Long", "Dustin"] as Set) + + def idNames = map.collectEntries{key, value -> [key, value.name]} + assertTrue(idNames == [1:"Jerry", 2: "Long", 3:"Dustin", 4: "Dustin"]) + + def below30Names = map.findAll{it.value.age < 30}.collect{key, value -> value.name} + assertTrue(below30Names == ["Long", "Dustin"]) + + + } + + @Test + void group(){ + def map = [1:20, 2: 40, 3: 11, 4: 93] + + def subMap = map.groupBy{it.value % 2} + println subMap + assertTrue(subMap == [0:[1:20, 2:40 ], 1:[3:11, 4:93]]) + + def keySubMap = map.subMap([1, 2]) + assertTrue(keySubMap == [1:20, 2:40]) + + } + + @Test + void sorting(){ + def map = [ab:20, a: 40, cb: 11, ba: 93] + + def naturallyOrderedMap = map.sort() + assertTrue([a:40, ab:20, ba:93, cb:11] == naturallyOrderedMap) + + def compSortedMap = map.sort({ k1, k2 -> k1 <=> k2 } as Comparator) + assertTrue([a:40, ab:20, ba:93, cb:11] == compSortedMap) + + def cloSortedMap = map.sort({ it1, it2 -> it1.value <=> it1.value }) + assertTrue([cb:11, ab:20, a:40, ba:93] == cloSortedMap) + + } + +} \ No newline at end of file From af4e221fa85c8a171581e9136528d2255c351445 Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Sun, 31 Mar 2019 08:15:02 +0800 Subject: [PATCH 04/53] BAEL-2779 Guide to classgraph library --- libraries/pom.xml | 7 ++ .../classgraph/ClassGraphUnitTest.java | 78 +++++++++++++++++++ .../classgraph/ClassWithAnnotation.java | 5 ++ .../classgraph/FieldWithAnnotation.java | 7 ++ .../classgraph/MethodWithAnnotation.java | 8 ++ .../MethodWithAnnotationParameterDao.java | 8 ++ .../MethodWithAnnotationParameterWeb.java | 8 ++ .../baeldung/classgraph/TestAnnotation.java | 14 ++++ .../src/test/resources/classgraph/my.config | 1 + 9 files changed, 136 insertions(+) create mode 100644 libraries/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java create mode 100644 libraries/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java create mode 100644 libraries/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java create mode 100644 libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java create mode 100644 libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java create mode 100644 libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java create mode 100644 libraries/src/test/java/com/baeldung/classgraph/TestAnnotation.java create mode 100644 libraries/src/test/resources/classgraph/my.config diff --git a/libraries/pom.xml b/libraries/pom.xml index 7823732224..a6179a843d 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -699,6 +699,12 @@ ${reflections.version} + + io.github.classgraph + classgraph + ${classgraph.version} + + @@ -916,6 +922,7 @@ 2.7.1 3.6 0.9.11 + 4.8.22 diff --git a/libraries/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java b/libraries/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java new file mode 100644 index 0000000000..5767396948 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java @@ -0,0 +1,78 @@ +package com.baeldung.classgraph; + +import io.github.classgraph.*; +import org.junit.Test; + +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Consumer; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ClassGraphUnitTest { + + @Test + public void whenClassAnnotationFilterIsDefined_thenTargetClassesCanBeFound() { + doTest(result -> { + ClassInfoList classInfos = result.getClassesWithAnnotation(TestAnnotation.class.getName()); + assertThat(classInfos).extracting(ClassInfo::getName).contains(ClassWithAnnotation.class.getName()); + }); + } + + @Test + public void whenMethodAnnotationFilterIsDefined_thenTargetClassesCanBeFound() { + doTest(result -> { + ClassInfoList classInfos = result.getClassesWithMethodAnnotation(TestAnnotation.class.getName()); + assertThat(classInfos).extracting(ClassInfo::getName).contains(MethodWithAnnotation.class.getName()); + }); + } + + @Test + public void whenMethodAnnotationValueFilterIsDefined_thenTargetClassesCanBeFound() { + doTest(result -> { + ClassInfoList classInfos = result.getClassesWithMethodAnnotation(TestAnnotation.class.getName()); + ClassInfoList filteredClassInfos = classInfos.filter(classInfo -> { + return classInfo.getMethodInfo().stream().anyMatch(methodInfo -> { + AnnotationInfo annotationInfo = methodInfo.getAnnotationInfo(TestAnnotation.class.getName()); + if (annotationInfo == null) { + return false; + } + + return "web".equals(annotationInfo.getParameterValues().getValue("value")); + }); + }); + assertThat(filteredClassInfos) + .extracting(ClassInfo::getName) + .contains(MethodWithAnnotationParameterWeb.class.getName()); + }); + } + + @Test + public void whenFieldAnnotationFilterIsDefined_thenTargetClassesCanBeFound() { + doTest(result -> { + ClassInfoList classInfos = result.getClassesWithFieldAnnotation(TestAnnotation.class.getName()); + assertThat(classInfos).extracting(ClassInfo::getName).contains(FieldWithAnnotation.class.getName()); + }); + } + + @Test + public void whenResourceIsUsed_thenItCanBeFoundAndLoaded() throws IOException { + try (ScanResult result = new ClassGraph().whitelistPaths("classgraph").scan()) { + ResourceList resources = result.getResourcesWithExtension("config"); + assertThat(resources).extracting(Resource::getPath).containsOnly("classgraph/my.config"); + assertThat(resources.get(0).getContentAsString()).isEqualTo("my data"); + } + } + + private void doTest(Consumer checker) { + try (ScanResult result = new ClassGraph().enableAllInfo() + .whitelistPackages(getClass().getPackage().getName()) + .scan()) + { + checker.accept(result); + } + } +} diff --git a/libraries/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java b/libraries/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java new file mode 100644 index 0000000000..0f3eeef293 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java @@ -0,0 +1,5 @@ +package com.baeldung.classgraph; + +@TestAnnotation +public class ClassWithAnnotation { +} diff --git a/libraries/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java b/libraries/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java new file mode 100644 index 0000000000..c5d1cc6062 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java @@ -0,0 +1,7 @@ +package com.baeldung.classgraph; + +public class FieldWithAnnotation { + + @TestAnnotation + private String s; +} diff --git a/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java b/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java new file mode 100644 index 0000000000..12d0c9927c --- /dev/null +++ b/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java @@ -0,0 +1,8 @@ +package com.baeldung.classgraph; + +public class MethodWithAnnotation { + + @TestAnnotation + public void service() { + } +} diff --git a/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java b/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java new file mode 100644 index 0000000000..9e38f42013 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java @@ -0,0 +1,8 @@ +package com.baeldung.classgraph; + +public class MethodWithAnnotationParameterDao { + + @TestAnnotation("dao") + public void service() { + } +} diff --git a/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java b/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java new file mode 100644 index 0000000000..1ef3d46b6f --- /dev/null +++ b/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java @@ -0,0 +1,8 @@ +package com.baeldung.classgraph; + +public class MethodWithAnnotationParameterWeb { + + @TestAnnotation("web") + public void service() { + } +} diff --git a/libraries/src/test/java/com/baeldung/classgraph/TestAnnotation.java b/libraries/src/test/java/com/baeldung/classgraph/TestAnnotation.java new file mode 100644 index 0000000000..f47ec180a9 --- /dev/null +++ b/libraries/src/test/java/com/baeldung/classgraph/TestAnnotation.java @@ -0,0 +1,14 @@ +package com.baeldung.classgraph; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; + +@Target({TYPE, METHOD, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestAnnotation { + + String value() default ""; +} diff --git a/libraries/src/test/resources/classgraph/my.config b/libraries/src/test/resources/classgraph/my.config new file mode 100644 index 0000000000..b99df573f6 --- /dev/null +++ b/libraries/src/test/resources/classgraph/my.config @@ -0,0 +1 @@ +my data \ No newline at end of file From b6bf4415a204bb604f8c17dabd92c96d8d07dc89 Mon Sep 17 00:00:00 2001 From: macroscopic64 Date: Wed, 3 Apr 2019 00:04:39 +0530 Subject: [PATCH 05/53] [BAEL-2073] Java 9 Migration Issues and Resolution --- .../main/java/com/baeldung/prejpms/App.java | 36 +++++++++---------- .../main/java/com/baeldung/prejpms/Book.java | 4 +-- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/prejpms/src/main/java/com/baeldung/prejpms/App.java b/prejpms/src/main/java/com/baeldung/prejpms/App.java index 0b38201302..1afaae30e4 100644 --- a/prejpms/src/main/java/com/baeldung/prejpms/App.java +++ b/prejpms/src/main/java/com/baeldung/prejpms/App.java @@ -16,7 +16,7 @@ import sun.reflect.Reflection; public class App { - private static final Logger logger = LoggerFactory.getLogger(App.class); + private static final Logger LOGGER = LoggerFactory.getLogger(App.class); public static void main(String[] args) throws Exception { @@ -28,28 +28,26 @@ public class App { private static void getCrytpographyProviderName() { try { - logger.info("1. Java Cryptography Extension - Provider Name: " + new SunJCE().getName() + "\n"); + LOGGER.info("1. JCE Provider Name: {}\n", new SunJCE().getName()); } catch (Throwable e) { - logger.error(e.toString()); + LOGGER.error(e.toString()); } } private static void getCallStackClassNames() { try { - int i = 0; StringBuffer sbStack = new StringBuffer(); - while (true) { - Class caller = Reflection.getCallerClass(i++); - if (caller == null) { - break; - } else { - sbStack.append(caller.getName()) - .append("\n"); - } - } - logger.info("2. Call Stack Class Names:\n" + sbStack.toString()); + int i = 0; + Class caller = Reflection.getCallerClass(i++); + do { + sbStack.append(i + ".") + .append(caller.getName()) + .append("\n"); + caller = Reflection.getCallerClass(i++); + } while (caller != null); + LOGGER.info("2. Call Stack:\n{}", sbStack); } catch (Throwable e) { - logger.error(e.toString()); + LOGGER.error(e.toString()); } } @@ -61,9 +59,9 @@ public class App { StringWriter sw = new StringWriter(); marshallerObj.marshal(book, sw); - logger.info("3. Xml for Book object:\n" + sw); + LOGGER.info("3. Xml for Book object:\n{}", sw); } catch (Throwable e) { - logger.error(e.toString()); + LOGGER.error(e.toString()); } } @@ -71,9 +69,9 @@ public class App { private static void getBase64EncodedString(String inputString) { try { String encodedString = new BASE64Encoder().encode(inputString.getBytes()); - logger.info("4. Base Encoded String: " + encodedString); + LOGGER.info("4. Base Encoded String: {}", encodedString); } catch (Throwable e) { - logger.error(e.toString()); + LOGGER.error(e.toString()); } } } diff --git a/prejpms/src/main/java/com/baeldung/prejpms/Book.java b/prejpms/src/main/java/com/baeldung/prejpms/Book.java index 57b19bf3c1..6780c73738 100644 --- a/prejpms/src/main/java/com/baeldung/prejpms/Book.java +++ b/prejpms/src/main/java/com/baeldung/prejpms/Book.java @@ -10,9 +10,8 @@ public class Book { private String name; public Book() { - } - + public Book(long id, String name) { this.id = id; this.name = name; @@ -35,5 +34,4 @@ public class Book { public Long getId() { return id; } - } From 5a3d6a0c518ebf57910fa677c0d986db590b3118 Mon Sep 17 00:00:00 2001 From: josephine-barboza Date: Sun, 14 Apr 2019 22:56:48 +0530 Subject: [PATCH 06/53] BAEL-2766 Added more asserts to add items to map --- core-groovy/src/test/groovy/com/baeldung/map/MapTest.groovy | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core-groovy/src/test/groovy/com/baeldung/map/MapTest.groovy b/core-groovy/src/test/groovy/com/baeldung/map/MapTest.groovy index 8bd9302412..f1d528207f 100644 --- a/core-groovy/src/test/groovy/com/baeldung/map/MapTest.groovy +++ b/core-groovy/src/test/groovy/com/baeldung/map/MapTest.groovy @@ -31,7 +31,9 @@ class MapTest{ map.putAll(hobbyMap) assertTrue(map == [name:"Jerry", age: 42, city: "New York", hobby:"Singing"]) - + assertTrue(hobbyMap.hobby == "Singing") + assertTrue(hobbyMap[hobbyLiteral] == "Singing") + map.plus([1:20]) // returns new map map << [2:30] @@ -143,4 +145,4 @@ class MapTest{ } -} \ No newline at end of file +} From c587c0b5dd0cbbff2687b7915a9aac5472f4678c Mon Sep 17 00:00:00 2001 From: macroscopic64 Date: Fri, 19 Apr 2019 07:04:58 +0530 Subject: [PATCH 07/53] [BAEL-2073] Java 9 Migration Issues and Resolution --- {prejpms => core-java-modules/pre-jpms}/pom.xml | 3 ++- .../pre-jpms}/src/main/java/com/baeldung/prejpms/App.java | 0 .../pre-jpms}/src/main/java/com/baeldung/prejpms/Book.java | 0 .../pre-jpms}/src/main/resources/logback.xml | 0 4 files changed, 2 insertions(+), 1 deletion(-) rename {prejpms => core-java-modules/pre-jpms}/pom.xml (96%) rename {prejpms => core-java-modules/pre-jpms}/src/main/java/com/baeldung/prejpms/App.java (100%) rename {prejpms => core-java-modules/pre-jpms}/src/main/java/com/baeldung/prejpms/Book.java (100%) rename {prejpms => core-java-modules/pre-jpms}/src/main/resources/logback.xml (100%) diff --git a/prejpms/pom.xml b/core-java-modules/pre-jpms/pom.xml similarity index 96% rename from prejpms/pom.xml rename to core-java-modules/pre-jpms/pom.xml index 0f0216682e..169cd21f3e 100644 --- a/prejpms/pom.xml +++ b/core-java-modules/pre-jpms/pom.xml @@ -2,7 +2,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 - prejpms + pre-jpms 0.0.1-SNAPSHOT jar pre-jpms @@ -11,6 +11,7 @@ parent-modules com.baeldung 1.0.0-SNAPSHOT + ../../ diff --git a/prejpms/src/main/java/com/baeldung/prejpms/App.java b/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/App.java similarity index 100% rename from prejpms/src/main/java/com/baeldung/prejpms/App.java rename to core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/App.java diff --git a/prejpms/src/main/java/com/baeldung/prejpms/Book.java b/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/Book.java similarity index 100% rename from prejpms/src/main/java/com/baeldung/prejpms/Book.java rename to core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/Book.java diff --git a/prejpms/src/main/resources/logback.xml b/core-java-modules/pre-jpms/src/main/resources/logback.xml similarity index 100% rename from prejpms/src/main/resources/logback.xml rename to core-java-modules/pre-jpms/src/main/resources/logback.xml From 923019269cf8200221b109eda7ceabf55e1a7c4d Mon Sep 17 00:00:00 2001 From: Pavan Shankar Koli Date: Fri, 19 Apr 2019 17:12:33 +0530 Subject: [PATCH 08/53] BAEL-2770 Added code and test cases --- .../array/AddElementToEndOfArray.java | 34 ++++++++++++++ .../array/AddElementToEndOfArrayUnitTest.java | 46 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 core-java-arrays/src/main/java/com/baeldung/array/AddElementToEndOfArray.java create mode 100644 core-java-arrays/src/test/java/com/baeldung/array/AddElementToEndOfArrayUnitTest.java diff --git a/core-java-arrays/src/main/java/com/baeldung/array/AddElementToEndOfArray.java b/core-java-arrays/src/main/java/com/baeldung/array/AddElementToEndOfArray.java new file mode 100644 index 0000000000..1dc6600600 --- /dev/null +++ b/core-java-arrays/src/main/java/com/baeldung/array/AddElementToEndOfArray.java @@ -0,0 +1,34 @@ +package com.baeldung.array; + +import java.util.ArrayList; +import java.util.Arrays; + +public class AddElementToEndOfArray { + + public Integer[] addElementUsingArraysCopyOf(Integer[] srcArray, int elementToAdd) { + Integer[] destArray = Arrays.copyOf(srcArray, srcArray.length + 1); + + destArray[destArray.length-1] = elementToAdd; + return destArray; + } + + public Integer[] addElementUsingArrayList(Integer[] srcArray, int elementToAdd) { + Integer[] destArray = new Integer[srcArray.length + 1]; + + ArrayList arrayList = new ArrayList<>(Arrays.asList(srcArray)); + arrayList.add(elementToAdd); + + return arrayList.toArray(destArray); + } + + public Integer[] addElementUsingSystemArrayCopy(Integer[] srcArray, int elementToAdd) { + Integer[] destArray = new Integer[srcArray.length + 1]; + + System.arraycopy(srcArray, 0, destArray, 0, srcArray.length); + + destArray[destArray.length-1] = elementToAdd; + + return destArray; + } + +} \ No newline at end of file diff --git a/core-java-arrays/src/test/java/com/baeldung/array/AddElementToEndOfArrayUnitTest.java b/core-java-arrays/src/test/java/com/baeldung/array/AddElementToEndOfArrayUnitTest.java new file mode 100644 index 0000000000..beeed1a313 --- /dev/null +++ b/core-java-arrays/src/test/java/com/baeldung/array/AddElementToEndOfArrayUnitTest.java @@ -0,0 +1,46 @@ +package com.baeldung.array; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class AddElementToEndOfArrayUnitTest { + + AddElementToEndOfArray addElementToEndOfArray; + + @Before + public void init(){ + addElementToEndOfArray = new AddElementToEndOfArray(); + } + + @Test + public void givenSourceArrayAndElement_whenAddElementUsingArraysCopyIsInvoked_thenNewElementMustBeAdded(){ + Integer[] sourceArray = {1,2,3,4}; + int elementToAdd = 5; + + Integer[] destArray = addElementToEndOfArray.addElementUsingArraysCopyOf(sourceArray, elementToAdd); + + assertEquals(elementToAdd, destArray[destArray.length-1].intValue()); + } + + @Test + public void givenSourceArrayAndElement_whenAddElementUsingArrayListIsInvoked_thenNewElementMustBeAdded(){ + Integer[] sourceArray = {1,2,3,4}; + int elementToAdd = 5; + + Integer[] destArray = addElementToEndOfArray.addElementUsingArrayList(sourceArray, elementToAdd); + + assertEquals(elementToAdd, destArray[destArray.length-1].intValue()); + } + + @Test + public void givenSourceArrayAndElement_whenAddElementUsingSystemArrayCopyIsInvoked_thenNewElementMustBeAdded(){ + Integer[] sourceArray = {1,2,3,4}; + int elementToAdd = 5; + + Integer[] destArray = addElementToEndOfArray.addElementUsingSystemArrayCopy(sourceArray, elementToAdd); + + assertEquals(elementToAdd, destArray[destArray.length-1].intValue()); + } +} From f8d76eb5ac00d786c9cb35dbdc8067e1d89fcf97 Mon Sep 17 00:00:00 2001 From: isaolmez Date: Sat, 20 Apr 2019 22:53:09 +0300 Subject: [PATCH 09/53] BAEL-2809: Added code samples --- persistence-modules/spring-data-jpa-2/pom.xml | 19 ++-- .../DatasourceProxyBeanPostProcessor.java | 53 +++++++++++ .../baeldung/batchinserts/model/School.java | 45 +++++++++ .../baeldung/batchinserts/model/Student.java | 44 +++++++++ .../application-batchinserts.properties | 4 + .../JpaBatchInsertsIntegrationTest.java | 92 +++++++++++++++++++ .../JpaNoBatchInsertsIntegrationTest.java | 39 ++++++++ .../batchinserts/TestObjectHelper.java | 20 ++++ 8 files changed, 309 insertions(+), 7 deletions(-) create mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/DatasourceProxyBeanPostProcessor.java create mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/School.java create mode 100644 persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/Student.java create mode 100644 persistence-modules/spring-data-jpa-2/src/main/resources/application-batchinserts.properties create mode 100644 persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaNoBatchInsertsIntegrationTest.java create mode 100644 persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/TestObjectHelper.java diff --git a/persistence-modules/spring-data-jpa-2/pom.xml b/persistence-modules/spring-data-jpa-2/pom.xml index 8e46112659..8d79647544 100644 --- a/persistence-modules/spring-data-jpa-2/pom.xml +++ b/persistence-modules/spring-data-jpa-2/pom.xml @@ -1,12 +1,12 @@ + 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 + com.baeldung spring-data-jpa-2 - spring-data-jpa - + spring-data-jpa + parent-boot-2 com.baeldung @@ -19,12 +19,17 @@ org.springframework.boot spring-boot-starter-data-jpa - + com.h2database h2 - + + + net.ttddyy + datasource-proxy + 1.4.1 + \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/DatasourceProxyBeanPostProcessor.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/DatasourceProxyBeanPostProcessor.java new file mode 100644 index 0000000000..504357db44 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/DatasourceProxyBeanPostProcessor.java @@ -0,0 +1,53 @@ +package com.baeldung.batchinserts; + +import java.lang.reflect.Method; +import javax.sql.DataSource; +import net.ttddyy.dsproxy.support.ProxyDataSourceBuilder; +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; +import org.springframework.aop.framework.ProxyFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; +import org.springframework.util.ReflectionUtils; + +@Component +@Profile("batchinserts") +public class DatasourceProxyBeanPostProcessor implements BeanPostProcessor { + + @Override + public Object postProcessBeforeInitialization(final Object bean, final String beanName) throws BeansException { + return bean; + } + + @Override + public Object postProcessAfterInitialization(final Object bean, final String beanName) throws BeansException { + if (bean instanceof DataSource) { + ProxyFactory factory = new ProxyFactory(bean); + factory.setProxyTargetClass(true); + factory.addAdvice(new ProxyDataSourceInterceptor((DataSource) bean)); + return factory.getProxy(); + } + + return bean; + } + + private static class ProxyDataSourceInterceptor implements MethodInterceptor { + + private final DataSource dataSource; + + public ProxyDataSourceInterceptor(final DataSource dataSource) { + this.dataSource = ProxyDataSourceBuilder.create(dataSource).name("Batch-Insert-Logger").asJson().countQuery().logQueryToSysOut().build(); + } + + @Override + public Object invoke(final MethodInvocation invocation) throws Throwable { + Method proxyMethod = ReflectionUtils.findMethod(dataSource.getClass(), invocation.getMethod().getName()); + if (proxyMethod != null) { + return proxyMethod.invoke(dataSource, invocation.getArguments()); + } + return invocation.proceed(); + } + } +} \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/School.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/School.java new file mode 100644 index 0000000000..6d2f333ac7 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/School.java @@ -0,0 +1,45 @@ +package com.baeldung.batchinserts.model; + +import java.util.List; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.OneToMany; + +@Entity +public class School { + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private long id; + + private String name; + + @OneToMany(mappedBy = "school") + private List students; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public List getStudents() { + return students; + } + + public void setStudents(List students) { + this.students = students; + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/Student.java b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/Student.java new file mode 100644 index 0000000000..d38214f122 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/java/com/baeldung/batchinserts/model/Student.java @@ -0,0 +1,44 @@ +package com.baeldung.batchinserts.model; + +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.ManyToOne; + +@Entity +public class Student { + + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) + private long id; + + private String name; + + @ManyToOne + private School school; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public School getSchool() { + return school; + } + + public void setSchool(School school) { + this.school = school; + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/main/resources/application-batchinserts.properties b/persistence-modules/spring-data-jpa-2/src/main/resources/application-batchinserts.properties new file mode 100644 index 0000000000..bd37e8c155 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/resources/application-batchinserts.properties @@ -0,0 +1,4 @@ +spring.jpa.show-sql=false + +spring.jpa.properties.hibernate.jdbc.batch_size=5 +spring.jpa.properties.hibernate.order_inserts=true \ No newline at end of file diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java new file mode 100644 index 0000000000..dd61b7b6df --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java @@ -0,0 +1,92 @@ +package com.baeldung.batchinserts; + +import static com.baeldung.batchinserts.TestObjectHelper.createSchool; +import static com.baeldung.batchinserts.TestObjectHelper.createStudent; + +import com.baeldung.batchinserts.model.School; +import com.baeldung.batchinserts.model.Student; +import java.util.List; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import javax.persistence.TypedQuery; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +@RunWith(SpringRunner.class) +@SpringBootTest +@Transactional +@ActiveProfiles("batchinserts") +public class JpaBatchInsertsIntegrationTest { + + @PersistenceContext + private EntityManager entityManager; + + private static final int BATCH_SIZE = 5; + + @Test + public void whenInsertingSingleTypeOfEntity_thenCreatesSingleBatch() { + for (int i = 0; i < 10; i++) { + School school = createSchool(i); + entityManager.persist(school); + } + + entityManager.flush(); + } + + @Test + public void whenFlushingAfterBatch_ThenClearsMemory() { + for (int i = 0; i < 10; i++) { + if (i > 0 && i % BATCH_SIZE == 0) { + entityManager.flush(); + entityManager.clear(); + } + + School school = createSchool(i); + entityManager.persist(school); + } + + entityManager.flush(); + } + + @Test + public void whenThereAreMultipleEntities_ThenCreatesNewBatch() { + for (int i = 0; i < 10; i++) { + if (i > 0 && i % BATCH_SIZE == 0) { + entityManager.flush(); + entityManager.clear(); + } + + School school = createSchool(i); + entityManager.persist(school); + Student firstStudent = createStudent(school); + Student secondStudent = createStudent(school); + entityManager.persist(firstStudent); + entityManager.persist(secondStudent); + } + + entityManager.flush(); + } + + @Test + public void whenUpdatingEntities_thenCreatesBatch() { + for (int i = 0; i < 10; i++) { + School school = createSchool(i); + entityManager.persist(school); + } + + entityManager.flush(); + + TypedQuery schoolQuery = entityManager.createQuery("SELECT s from School s", School.class); + List allSchools = schoolQuery.getResultList(); + + for (School school : allSchools) { + school.setName("Updated_" + school.getName()); + } + + entityManager.flush(); + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaNoBatchInsertsIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaNoBatchInsertsIntegrationTest.java new file mode 100644 index 0000000000..20502c793d --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaNoBatchInsertsIntegrationTest.java @@ -0,0 +1,39 @@ +package com.baeldung.batchinserts; + +import static com.baeldung.batchinserts.TestObjectHelper.createSchool; + +import com.baeldung.batchinserts.model.School; +import javax.persistence.EntityManager; +import javax.persistence.PersistenceContext; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.transaction.annotation.Transactional; + +@RunWith(SpringRunner.class) +@SpringBootTest +@Transactional +@ActiveProfiles("batchinserts") +@TestPropertySource(properties = "spring.jpa.properties.hibernate.jdbc.batch_size=-1") +public class JpaNoBatchInsertsIntegrationTest { + + @PersistenceContext + private EntityManager entityManager; + + @Test + public void whenNotConfigured_ThenSendsInsertsSeparately() { + for (int i = 0; i < 10; i++) { + School school = createSchool(i); + entityManager.persist(school); + } + } + + @After + public void tearDown() { + entityManager.flush(); + } +} diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/TestObjectHelper.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/TestObjectHelper.java new file mode 100644 index 0000000000..fcd26cb721 --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/TestObjectHelper.java @@ -0,0 +1,20 @@ +package com.baeldung.batchinserts; + +import com.baeldung.batchinserts.model.School; +import com.baeldung.batchinserts.model.Student; + +public class TestObjectHelper { + + public static School createSchool(int nameIdentifier) { + School school = new School(); + school.setName("School" + (nameIdentifier + 1)); + return school; + } + + public static Student createStudent(School school) { + Student student = new Student(); + student.setName("Student-" + school.getName()); + student.setSchool(school); + return student; + } +} From 004b2cc5a8851dca573c6eb3f335345081257257 Mon Sep 17 00:00:00 2001 From: isaolmez Date: Sat, 20 Apr 2019 22:56:02 +0300 Subject: [PATCH 10/53] BAEL-2809: Added code samples --- .../src/main/resources/application-batchinserts.properties | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/persistence-modules/spring-data-jpa-2/src/main/resources/application-batchinserts.properties b/persistence-modules/spring-data-jpa-2/src/main/resources/application-batchinserts.properties index bd37e8c155..4141f5668e 100644 --- a/persistence-modules/spring-data-jpa-2/src/main/resources/application-batchinserts.properties +++ b/persistence-modules/spring-data-jpa-2/src/main/resources/application-batchinserts.properties @@ -1,4 +1,6 @@ spring.jpa.show-sql=false spring.jpa.properties.hibernate.jdbc.batch_size=5 -spring.jpa.properties.hibernate.order_inserts=true \ No newline at end of file +spring.jpa.properties.hibernate.order_inserts=true +spring.jpa.properties.hibernate.order_updates=true +spring.jpa.properties.hibernate.batch_versioned_data=true \ No newline at end of file From a9f1bb2f69139e6badbf005540d892622ef5b16f Mon Sep 17 00:00:00 2001 From: macroscopic64 Date: Sun, 21 Apr 2019 11:47:01 +0530 Subject: [PATCH 11/53] [BAEL-2073] Java 9 Migration Issues and Resolution --- pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pom.xml b/pom.xml index 0de4a36336..129e2a3e8e 100644 --- a/pom.xml +++ b/pom.xml @@ -397,6 +397,7 @@ core-java-lang core-java-lang-oop core-java-lang-oop-2 + core-java-modules core-java-networking core-java-perf core-java-sun @@ -1067,6 +1068,7 @@ core-java-lang core-java-lang-oop core-java-lang-oop-2 + core-java-modules core-java-networking core-java-perf core-java-sun From d3b1630927a7ebd76a0ddceaeea54137952fac51 Mon Sep 17 00:00:00 2001 From: Loredana Date: Sun, 21 Apr 2019 11:37:57 +0300 Subject: [PATCH 12/53] rename config project, formatting --- pom.xml | 3 +- spring-boot-configuration/README.MD | 0 spring-boot-configuration/pom.xml | 41 ------------------- .../.gitignore | 0 spring-boot-ops-2/README.MD | 3 ++ spring-boot-ops-2/pom.xml | 41 +++++++++++++++++++ .../SpringBootConfigurationApplication.java | 6 +-- .../resources/application-tomcat.properties | 0 .../src/main/resources/application.properties | 0 .../SpringContextIntegrationTest.java | 6 +-- 10 files changed, 52 insertions(+), 48 deletions(-) delete mode 100644 spring-boot-configuration/README.MD delete mode 100644 spring-boot-configuration/pom.xml rename {spring-boot-configuration => spring-boot-ops-2}/.gitignore (100%) create mode 100644 spring-boot-ops-2/README.MD create mode 100644 spring-boot-ops-2/pom.xml rename {spring-boot-configuration => spring-boot-ops-2}/src/main/java/com/baeldung/springbootconfiguration/SpringBootConfigurationApplication.java (65%) rename {spring-boot-configuration => spring-boot-ops-2}/src/main/resources/application-tomcat.properties (100%) rename {spring-boot-configuration => spring-boot-ops-2}/src/main/resources/application.properties (100%) rename {spring-boot-configuration => spring-boot-ops-2}/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java (86%) diff --git a/pom.xml b/pom.xml index 0de4a36336..f09ea36d4f 100644 --- a/pom.xml +++ b/pom.xml @@ -631,6 +631,7 @@ spring-boot-mvc spring-boot-mvc-birt spring-boot-ops + spring-boot-ops-2 spring-boot-rest spring-boot-data spring-boot-property-exp @@ -1275,7 +1276,6 @@ spring-boot-camel spring-boot-client - spring-boot-configuration spring-boot-crud spring-boot-ctx-fluent spring-boot-custom-starter @@ -1287,6 +1287,7 @@ spring-boot-mvc spring-boot-mvc-birt spring-boot-ops + spring-boot-ops-2 spring-boot-rest spring-boot-data spring-boot-property-exp diff --git a/spring-boot-configuration/README.MD b/spring-boot-configuration/README.MD deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/spring-boot-configuration/pom.xml b/spring-boot-configuration/pom.xml deleted file mode 100644 index 2ecef7bb02..0000000000 --- a/spring-boot-configuration/pom.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - 4.0.0 - - - parent-boot-2 - com.baeldung - 0.0.1-SNAPSHOT - ../parent-boot-2 - - - com.baeldung - spring-boot-configuration - 0.0.1-SNAPSHOT - spring-boot-configuration - Demo project for Spring Boot configuration - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/spring-boot-configuration/.gitignore b/spring-boot-ops-2/.gitignore similarity index 100% rename from spring-boot-configuration/.gitignore rename to spring-boot-ops-2/.gitignore diff --git a/spring-boot-ops-2/README.MD b/spring-boot-ops-2/README.MD new file mode 100644 index 0000000000..20b30515fb --- /dev/null +++ b/spring-boot-ops-2/README.MD @@ -0,0 +1,3 @@ +### Relevant Articles + +- [How to Configure Spring Boot Tomcat](https://www.baeldung.com/spring-boot-configure-tomcat) \ No newline at end of file diff --git a/spring-boot-ops-2/pom.xml b/spring-boot-ops-2/pom.xml new file mode 100644 index 0000000000..dc5280df48 --- /dev/null +++ b/spring-boot-ops-2/pom.xml @@ -0,0 +1,41 @@ + + + 4.0.0 + + + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../parent-boot-2 + + + com.baeldung + spring-boot-ops-2 + 0.0.1-SNAPSHOT + spring-boot-ops-2 + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/spring-boot-configuration/src/main/java/com/baeldung/springbootconfiguration/SpringBootConfigurationApplication.java b/spring-boot-ops-2/src/main/java/com/baeldung/springbootconfiguration/SpringBootConfigurationApplication.java similarity index 65% rename from spring-boot-configuration/src/main/java/com/baeldung/springbootconfiguration/SpringBootConfigurationApplication.java rename to spring-boot-ops-2/src/main/java/com/baeldung/springbootconfiguration/SpringBootConfigurationApplication.java index b4f5681475..96297459a4 100644 --- a/spring-boot-configuration/src/main/java/com/baeldung/springbootconfiguration/SpringBootConfigurationApplication.java +++ b/spring-boot-ops-2/src/main/java/com/baeldung/springbootconfiguration/SpringBootConfigurationApplication.java @@ -6,8 +6,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class SpringBootConfigurationApplication { - public static void main(String[] args) { - SpringApplication.run(SpringBootConfigurationApplication.class, args); - } + public static void main(String[] args) { + SpringApplication.run(SpringBootConfigurationApplication.class, args); + } } diff --git a/spring-boot-configuration/src/main/resources/application-tomcat.properties b/spring-boot-ops-2/src/main/resources/application-tomcat.properties similarity index 100% rename from spring-boot-configuration/src/main/resources/application-tomcat.properties rename to spring-boot-ops-2/src/main/resources/application-tomcat.properties diff --git a/spring-boot-configuration/src/main/resources/application.properties b/spring-boot-ops-2/src/main/resources/application.properties similarity index 100% rename from spring-boot-configuration/src/main/resources/application.properties rename to spring-boot-ops-2/src/main/resources/application.properties diff --git a/spring-boot-configuration/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java b/spring-boot-ops-2/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java similarity index 86% rename from spring-boot-configuration/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java rename to spring-boot-ops-2/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java index d6b2b50a2f..8ae49f6696 100644 --- a/spring-boot-configuration/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java +++ b/spring-boot-ops-2/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java @@ -9,8 +9,8 @@ import org.springframework.test.context.junit4.SpringRunner; @SpringBootTest public class SpringContextIntegrationTest { - @Test - public void contextLoads() { - } + @Test + public void contextLoads() { + } } From 884f0a7d8a230563683e2df4bb8f3fc22a7416d7 Mon Sep 17 00:00:00 2001 From: Loredana Date: Sun, 21 Apr 2019 11:39:44 +0300 Subject: [PATCH 13/53] update pom --- pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/pom.xml b/pom.xml index f09ea36d4f..f4bc47dd44 100644 --- a/pom.xml +++ b/pom.xml @@ -821,7 +821,6 @@ spring-boot-bootstrap spring-boot-camel spring-boot-client - spring-boot-configuration spring-boot-custom-starter greeter-spring-boot-autoconfigure greeter-spring-boot-sample-app From 37c3ac1a1fffff689aec26683d623caf1bc9784f Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 21 Apr 2019 15:45:49 +0530 Subject: [PATCH 14/53] [BAEL-13602] - Updated HttpClient Basic Authentication article --- httpclient-simple/README.md | 3 ++- .../baeldung/httpclient/sec/HttpClientAuthLiveTest.java | 7 +++---- httpclient/README.md | 1 - 3 files changed, 5 insertions(+), 6 deletions(-) rename {httpclient => httpclient-simple}/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java (96%) diff --git a/httpclient-simple/README.md b/httpclient-simple/README.md index d1224359e0..96d9e9ec0e 100644 --- a/httpclient-simple/README.md +++ b/httpclient-simple/README.md @@ -8,4 +8,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: - [HttpClient 4 – Get the Status Code](http://www.baeldung.com/httpclient-status-code) -- [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl) \ No newline at end of file +- [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl) +- [HttpClient Basic Authentication](http://www.baeldung.com/httpclient-4-basic-authentication) diff --git a/httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java b/httpclient-simple/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java similarity index 96% rename from httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java rename to httpclient-simple/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java index c9956e5852..96278b481a 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java +++ b/httpclient-simple/src/test/java/org/baeldung/httpclient/sec/HttpClientAuthLiveTest.java @@ -23,19 +23,18 @@ import org.junit.Before; import org.junit.Test; import java.io.IOException; -import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; /* - * NOTE : Need module spring-security-rest-basic-auth to be running + * NOTE : Need module httpclient-simple to be running */ public class HttpClientAuthLiveTest { - private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://localhost:8081/spring-security-rest-basic-auth/api/foos/1"; + private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://localhost:8082/httpclient-simple/api/foos/1"; private static final String DEFAULT_USER = "user1"; private static final String DEFAULT_PASS = "user1Pass"; @@ -111,7 +110,7 @@ public class HttpClientAuthLiveTest { } private HttpContext context() { - final HttpHost targetHost = new HttpHost("localhost", 8080, "http"); + final HttpHost targetHost = new HttpHost("localhost", 8082, "http"); final CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(DEFAULT_USER, DEFAULT_PASS)); diff --git a/httpclient/README.md b/httpclient/README.md index ce98d7e72e..cab538be85 100644 --- a/httpclient/README.md +++ b/httpclient/README.md @@ -13,7 +13,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Unshorten URLs with HttpClient](http://www.baeldung.com/unshorten-url-httpclient) - [HttpClient 4 – Follow Redirects for POST](http://www.baeldung.com/httpclient-redirect-on-http-post) - [Custom HTTP Header with the HttpClient](http://www.baeldung.com/httpclient-custom-http-header) -- [HttpClient Basic Authentication](http://www.baeldung.com/httpclient-4-basic-authentication) - [Multipart Upload with HttpClient 4](http://www.baeldung.com/httpclient-multipart-upload) - [HttpAsyncClient Tutorial](http://www.baeldung.com/httpasyncclient-tutorial) - [HttpClient 4 Tutorial](http://www.baeldung.com/httpclient-guide) From 382216bdb1d464334916e6efc25f666ee6eb8ee4 Mon Sep 17 00:00:00 2001 From: dupirefr Date: Sun, 21 Apr 2019 13:25:11 +0200 Subject: [PATCH 15/53] [BAEL-2882] Picocli --- picocli/pom.xml | 28 +++++++++++++ .../com/baeldung/picocli/git/Application.java | 41 +++++++++++++++++++ .../git/commands/declarative/GitCommand.java | 32 +++++++++++++++ .../git/commands/methods/GitCommand.java | 27 ++++++++++++ .../commands/programmative/GitCommand.java | 26 ++++++++++++ .../commands/subcommands/GitAddCommand.java | 31 ++++++++++++++ .../subcommands/GitCommitCommand.java | 26 ++++++++++++ .../subcommands/GitConfigCommand.java | 24 +++++++++++ .../picocli/git/model/ConfigElement.java | 25 +++++++++++ .../picocli/helloworld/HelloWorldCommand.java | 20 +++++++++ pom.xml | 1 + 11 files changed, 281 insertions(+) create mode 100644 picocli/pom.xml create mode 100644 picocli/src/main/java/com/baeldung/picocli/git/Application.java create mode 100644 picocli/src/main/java/com/baeldung/picocli/git/commands/declarative/GitCommand.java create mode 100644 picocli/src/main/java/com/baeldung/picocli/git/commands/methods/GitCommand.java create mode 100644 picocli/src/main/java/com/baeldung/picocli/git/commands/programmative/GitCommand.java create mode 100644 picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitAddCommand.java create mode 100644 picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitCommitCommand.java create mode 100644 picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitConfigCommand.java create mode 100644 picocli/src/main/java/com/baeldung/picocli/git/model/ConfigElement.java create mode 100644 picocli/src/main/java/com/baeldung/picocli/helloworld/HelloWorldCommand.java diff --git a/picocli/pom.xml b/picocli/pom.xml new file mode 100644 index 0000000000..0334f5463d --- /dev/null +++ b/picocli/pom.xml @@ -0,0 +1,28 @@ + + + 4.0.0 + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../parent-java + + + picocli + + + + info.picocli + picocli + 3.9.6 + + + + org.springframework.boot + spring-boot-starter + 2.1.4.RELEASE + + + \ No newline at end of file diff --git a/picocli/src/main/java/com/baeldung/picocli/git/Application.java b/picocli/src/main/java/com/baeldung/picocli/git/Application.java new file mode 100644 index 0000000000..04af524e45 --- /dev/null +++ b/picocli/src/main/java/com/baeldung/picocli/git/Application.java @@ -0,0 +1,41 @@ +package com.baeldung.picocli.git; + +import com.baeldung.picocli.git.commands.programmative.GitCommand; +import com.baeldung.picocli.git.commands.subcommands.GitAddCommand; +import com.baeldung.picocli.git.commands.subcommands.GitCommitCommand; +import com.baeldung.picocli.git.commands.subcommands.GitConfigCommand; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import picocli.CommandLine; + +@SpringBootApplication +public class Application implements CommandLineRunner { + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + + private GitCommand gitCommand; + private GitAddCommand addCommand; + private GitCommitCommand commitCommand; + private GitConfigCommand configCommand; + + @Autowired + public Application(GitCommand gitCommand, GitAddCommand addCommand, GitCommitCommand commitCommand, GitConfigCommand configCommand) { + this.gitCommand = gitCommand; + this.addCommand = addCommand; + this.commitCommand = commitCommand; + this.configCommand = configCommand; + } + + @Override + public void run(String... args) { + CommandLine commandLine = new CommandLine(gitCommand); + commandLine.addSubcommand("add", addCommand); + commandLine.addSubcommand("commit", commitCommand); + commandLine.addSubcommand("config", configCommand); + + commandLine.parseWithHandler(new CommandLine.RunLast(), args); + } +} diff --git a/picocli/src/main/java/com/baeldung/picocli/git/commands/declarative/GitCommand.java b/picocli/src/main/java/com/baeldung/picocli/git/commands/declarative/GitCommand.java new file mode 100644 index 0000000000..f3c690a3e6 --- /dev/null +++ b/picocli/src/main/java/com/baeldung/picocli/git/commands/declarative/GitCommand.java @@ -0,0 +1,32 @@ +package com.baeldung.picocli.git.commands.declarative; + +import com.baeldung.picocli.git.model.ConfigElement; +import com.baeldung.picocli.git.commands.subcommands.GitAddCommand; +import com.baeldung.picocli.git.commands.subcommands.GitCommitCommand; +import com.baeldung.picocli.git.commands.subcommands.GitConfigCommand; +import picocli.CommandLine; + +import static picocli.CommandLine.*; +import static picocli.CommandLine.Command; + +@Command( + name = "git", + subcommands = { + GitAddCommand.class, + GitCommitCommand.class, + GitConfigCommand.class + } +) +public class GitCommand implements Runnable { + public static void main(String[] args) { + CommandLine commandLine = new CommandLine(new GitCommand()); + commandLine.registerConverter(ConfigElement.class, ConfigElement::from); + + commandLine.parseWithHandler(new RunLast(), args); + } + + @Override + public void run() { + System.out.println("The popular git command"); + } +} diff --git a/picocli/src/main/java/com/baeldung/picocli/git/commands/methods/GitCommand.java b/picocli/src/main/java/com/baeldung/picocli/git/commands/methods/GitCommand.java new file mode 100644 index 0000000000..2c3e440b8b --- /dev/null +++ b/picocli/src/main/java/com/baeldung/picocli/git/commands/methods/GitCommand.java @@ -0,0 +1,27 @@ +package com.baeldung.picocli.git.commands.methods; + +import picocli.CommandLine; + +import static picocli.CommandLine.Command; + +@Command(name = "git") +public class GitCommand implements Runnable { + public static void main(String[] args) { + CommandLine.run(new GitCommand(), args); + } + + @Override + public void run() { + System.out.println("The popular git command"); + } + + @Command(name = "add") + public void addCommand() { + System.out.println("Adding some files to the staging area"); + } + + @Command(name = "commit") + public void commitCommand() { + System.out.println("Committing files in the staging area, how wonderful?"); + } +} diff --git a/picocli/src/main/java/com/baeldung/picocli/git/commands/programmative/GitCommand.java b/picocli/src/main/java/com/baeldung/picocli/git/commands/programmative/GitCommand.java new file mode 100644 index 0000000000..81ecfd78be --- /dev/null +++ b/picocli/src/main/java/com/baeldung/picocli/git/commands/programmative/GitCommand.java @@ -0,0 +1,26 @@ +package com.baeldung.picocli.git.commands.programmative; + +import com.baeldung.picocli.git.commands.subcommands.GitAddCommand; +import com.baeldung.picocli.git.commands.subcommands.GitCommitCommand; +import org.springframework.stereotype.Component; +import picocli.CommandLine; + +import static picocli.CommandLine.Command; +import static picocli.CommandLine.RunLast; + +@Command(name = "git") +@Component +public class GitCommand implements Runnable { + public static void main(String[] args) { + CommandLine commandLine = new CommandLine(new GitCommand()); + commandLine.addSubcommand("add", new GitAddCommand()); + commandLine.addSubcommand("commit", new GitCommitCommand()); + + commandLine.parseWithHandler(new RunLast(), args); + } + + @Override + public void run() { + System.out.println("The popular git command"); + } +} diff --git a/picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitAddCommand.java b/picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitAddCommand.java new file mode 100644 index 0000000000..803cd8dc7d --- /dev/null +++ b/picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitAddCommand.java @@ -0,0 +1,31 @@ +package com.baeldung.picocli.git.commands.subcommands; + +import org.springframework.stereotype.Component; + +import java.nio.file.Path; +import java.util.List; + +import static picocli.CommandLine.*; + +@Command( + name = "add" +) +@Component +public class GitAddCommand implements Runnable { + @Option(names = "-A") + private boolean allFiles; + + @Parameters(index = "0..*") + private List files; + + @Override + public void run() { + if (allFiles) { + System.out.println("Adding all files to the staging area"); + } + + if (files != null) { + files.forEach(path -> System.out.println("Adding " + path + " to the staging area")); + } + } +} diff --git a/picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitCommitCommand.java b/picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitCommitCommand.java new file mode 100644 index 0000000000..df4928983c --- /dev/null +++ b/picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitCommitCommand.java @@ -0,0 +1,26 @@ +package com.baeldung.picocli.git.commands.subcommands; + +import org.springframework.stereotype.Component; + +import static picocli.CommandLine.Command; +import static picocli.CommandLine.Option; + +@Command( + name = "commit" +) +@Component +public class GitCommitCommand implements Runnable { + @Option(names = {"-m", "--message"}, required = true) + private String[] messages; + + @Override + public void run() { + System.out.println("Committing files in the staging area, how wonderful?"); + if (messages != null) { + System.out.println("The commit message is"); + for (String message : messages) { + System.out.println(message); + } + } + } +} diff --git a/picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitConfigCommand.java b/picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitConfigCommand.java new file mode 100644 index 0000000000..80e14c0121 --- /dev/null +++ b/picocli/src/main/java/com/baeldung/picocli/git/commands/subcommands/GitConfigCommand.java @@ -0,0 +1,24 @@ +package com.baeldung.picocli.git.commands.subcommands; + +import com.baeldung.picocli.git.model.ConfigElement; +import org.springframework.stereotype.Component; + +import static picocli.CommandLine.Command; +import static picocli.CommandLine.Parameters; + +@Command( + name = "config" +) +@Component +public class GitConfigCommand implements Runnable { + @Parameters(index = "0") + private ConfigElement element; + + @Parameters(index = "1") + private String value; + + @Override + public void run() { + System.out.println("Setting " + element.value() + " to " + value); + } +} diff --git a/picocli/src/main/java/com/baeldung/picocli/git/model/ConfigElement.java b/picocli/src/main/java/com/baeldung/picocli/git/model/ConfigElement.java new file mode 100644 index 0000000000..edc6573d88 --- /dev/null +++ b/picocli/src/main/java/com/baeldung/picocli/git/model/ConfigElement.java @@ -0,0 +1,25 @@ +package com.baeldung.picocli.git.model; + +import java.util.Arrays; + +public enum ConfigElement { + USERNAME("user.name"), + EMAIL("user.email"); + + private final String value; + + ConfigElement(String value) { + this.value = value; + } + + public String value() { + return value; + } + + public static ConfigElement from(String value) { + return Arrays.stream(values()) + .filter(element -> element.value.equals(value)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("The argument " + value + " doesn't match any ConfigElement")); + } +} diff --git a/picocli/src/main/java/com/baeldung/picocli/helloworld/HelloWorldCommand.java b/picocli/src/main/java/com/baeldung/picocli/helloworld/HelloWorldCommand.java new file mode 100644 index 0000000000..97a861e2f0 --- /dev/null +++ b/picocli/src/main/java/com/baeldung/picocli/helloworld/HelloWorldCommand.java @@ -0,0 +1,20 @@ +package com.baeldung.picocli.helloworld; + +import picocli.CommandLine; + +import static picocli.CommandLine.Command; + +@Command( + name = "hello", + description = "Says hello" +) +public class HelloWorldCommand implements Runnable { + public static void main(String[] args) { + CommandLine.run(new HelloWorldCommand(), args); + } + + @Override + public void run() { + System.out.println("Hello World!"); + } +} diff --git a/pom.xml b/pom.xml index 0de4a36336..f237134112 100644 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,7 @@ lombok-custom + picocli From 705b310302061a63d78192a9e08528514d55ec26 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 21 Apr 2019 19:36:14 +0530 Subject: [PATCH 16/53] [BAEL-13601] - Updated Custom Cookie article and moved code --- httpclient-simple/README.md | 3 ++- .../org/baeldung/httpclient/sec/HttpClientCookieLiveTest.java | 0 httpclient/README.md | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) rename {httpclient => httpclient-simple}/src/test/java/org/baeldung/httpclient/sec/HttpClientCookieLiveTest.java (100%) diff --git a/httpclient-simple/README.md b/httpclient-simple/README.md index d1224359e0..a25bde04be 100644 --- a/httpclient-simple/README.md +++ b/httpclient-simple/README.md @@ -8,4 +8,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: - [HttpClient 4 – Get the Status Code](http://www.baeldung.com/httpclient-status-code) -- [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl) \ No newline at end of file +- [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl) +- [HttpClient 4 – Send Custom Cookie](http://www.baeldung.com/httpclient-4-cookies) \ No newline at end of file diff --git a/httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientCookieLiveTest.java b/httpclient-simple/src/test/java/org/baeldung/httpclient/sec/HttpClientCookieLiveTest.java similarity index 100% rename from httpclient/src/test/java/org/baeldung/httpclient/sec/HttpClientCookieLiveTest.java rename to httpclient-simple/src/test/java/org/baeldung/httpclient/sec/HttpClientCookieLiveTest.java diff --git a/httpclient/README.md b/httpclient/README.md index ce98d7e72e..25270bdc98 100644 --- a/httpclient/README.md +++ b/httpclient/README.md @@ -7,7 +7,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: -- [HttpClient 4 – Send Custom Cookie](http://www.baeldung.com/httpclient-4-cookies) - [HttpClient 4 – Cancel Request](http://www.baeldung.com/httpclient-cancel-request) - [HttpClient 4 Cookbook](http://www.baeldung.com/httpclient4) - [Unshorten URLs with HttpClient](http://www.baeldung.com/unshorten-url-httpclient) From 0ae452d0a6f1e1ff59a9003434ebc3e4f6f310bb Mon Sep 17 00:00:00 2001 From: Loredana Date: Sun, 21 Apr 2019 17:14:55 +0300 Subject: [PATCH 17/53] update pom --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f4bc47dd44..b0c350fb6a 100644 --- a/pom.xml +++ b/pom.xml @@ -619,7 +619,7 @@ spring-boot-camel spring-boot-client - spring-boot-configuration + spring-boot-crud spring-boot-ctx-fluent spring-boot-custom-starter From 6ee4fba3275d258f40327a4147ab9053cc275138 Mon Sep 17 00:00:00 2001 From: Loredana Date: Sun, 21 Apr 2019 17:41:00 +0300 Subject: [PATCH 18/53] update post controller --- .../com/baeldung/modelmapper/controller/PostRestController.java | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-boot-rest/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java index c0cbca5220..68c17975d4 100644 --- a/spring-boot-rest/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java +++ b/spring-boot-rest/src/main/java/com/baeldung/modelmapper/controller/PostRestController.java @@ -21,6 +21,7 @@ import com.baeldung.modelmapper.service.IPostService; import com.baeldung.modelmapper.service.IUserService; @Controller +@RequestMapping("/posts") public class PostRestController { @Autowired From 73ede4124c3aa5e121bdc4c20ba1b26c001e7702 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 21 Apr 2019 20:12:40 +0530 Subject: [PATCH 19/53] [BAEL-13599] - Updated Custom Header article and moved article to httpclient-simple --- httpclient-simple/README.md | 3 ++- .../org/baeldung/httpclient/HttpClientHeadersLiveTest.java | 0 httpclient/README.md | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) rename {httpclient => httpclient-simple}/src/test/java/org/baeldung/httpclient/HttpClientHeadersLiveTest.java (100%) diff --git a/httpclient-simple/README.md b/httpclient-simple/README.md index d1224359e0..5a679c0a70 100644 --- a/httpclient-simple/README.md +++ b/httpclient-simple/README.md @@ -8,4 +8,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: - [HttpClient 4 – Get the Status Code](http://www.baeldung.com/httpclient-status-code) -- [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl) \ No newline at end of file +- [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl) +- [Custom HTTP Header with the HttpClient](http://www.baeldung.com/httpclient-custom-http-header) \ No newline at end of file diff --git a/httpclient/src/test/java/org/baeldung/httpclient/HttpClientHeadersLiveTest.java b/httpclient-simple/src/test/java/org/baeldung/httpclient/HttpClientHeadersLiveTest.java similarity index 100% rename from httpclient/src/test/java/org/baeldung/httpclient/HttpClientHeadersLiveTest.java rename to httpclient-simple/src/test/java/org/baeldung/httpclient/HttpClientHeadersLiveTest.java diff --git a/httpclient/README.md b/httpclient/README.md index ce98d7e72e..ae5b741820 100644 --- a/httpclient/README.md +++ b/httpclient/README.md @@ -12,7 +12,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [HttpClient 4 Cookbook](http://www.baeldung.com/httpclient4) - [Unshorten URLs with HttpClient](http://www.baeldung.com/unshorten-url-httpclient) - [HttpClient 4 – Follow Redirects for POST](http://www.baeldung.com/httpclient-redirect-on-http-post) -- [Custom HTTP Header with the HttpClient](http://www.baeldung.com/httpclient-custom-http-header) - [HttpClient Basic Authentication](http://www.baeldung.com/httpclient-4-basic-authentication) - [Multipart Upload with HttpClient 4](http://www.baeldung.com/httpclient-multipart-upload) - [HttpAsyncClient Tutorial](http://www.baeldung.com/httpasyncclient-tutorial) From f6166bc514b5f89d6508aec63b9a8462f2c633ba Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 21 Apr 2019 21:17:28 +0530 Subject: [PATCH 20/53] [BAEL-13533] - Updated Posting with HttpClient article. moved article --- httpclient-simple/README.md | 3 ++- .../org/baeldung/httpclient/HttpClientPostingLiveTest.java | 0 .../java/org/baeldung/httpclient/ProgressEntityWrapper.java | 0 3 files changed, 2 insertions(+), 1 deletion(-) rename {httpclient => httpclient-simple}/src/test/java/org/baeldung/httpclient/HttpClientPostingLiveTest.java (100%) rename {httpclient => httpclient-simple}/src/test/java/org/baeldung/httpclient/ProgressEntityWrapper.java (100%) diff --git a/httpclient-simple/README.md b/httpclient-simple/README.md index d1224359e0..ca94a8c110 100644 --- a/httpclient-simple/README.md +++ b/httpclient-simple/README.md @@ -8,4 +8,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: - [HttpClient 4 – Get the Status Code](http://www.baeldung.com/httpclient-status-code) -- [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl) \ No newline at end of file +- [HttpClient with SSL](http://www.baeldung.com/httpclient-ssl) +- [Posting with HttpClient](https://www.baeldung.com/httpclient-post-http-request) \ No newline at end of file diff --git a/httpclient/src/test/java/org/baeldung/httpclient/HttpClientPostingLiveTest.java b/httpclient-simple/src/test/java/org/baeldung/httpclient/HttpClientPostingLiveTest.java similarity index 100% rename from httpclient/src/test/java/org/baeldung/httpclient/HttpClientPostingLiveTest.java rename to httpclient-simple/src/test/java/org/baeldung/httpclient/HttpClientPostingLiveTest.java diff --git a/httpclient/src/test/java/org/baeldung/httpclient/ProgressEntityWrapper.java b/httpclient-simple/src/test/java/org/baeldung/httpclient/ProgressEntityWrapper.java similarity index 100% rename from httpclient/src/test/java/org/baeldung/httpclient/ProgressEntityWrapper.java rename to httpclient-simple/src/test/java/org/baeldung/httpclient/ProgressEntityWrapper.java From 2041089e74f2070b47ae927feec9a109d7fa2a71 Mon Sep 17 00:00:00 2001 From: Jacob Stopak Date: Sun, 21 Apr 2019 13:13:28 -0700 Subject: [PATCH 21/53] Add code for BAEL-2892 v0.0.1: pass-exception-client-json-spring-boot --- .../.gitignore | 29 +++++++++++++ .../pom.xml | 43 +++++++++++++++++++ .../CustomException.java | 11 +++++ .../ErrorHandler.java | 21 +++++++++ .../MainController.java | 20 +++++++++ ...tionToClientJsonSpringBootApplication.java | 13 ++++++ .../src/main/resources/application.properties | 1 + .../src/main/resources/static/.gitignore | 4 ++ .../src/main/resources/templates/.gitignore | 4 ++ ...oClientJsonSpringBootApplicationTests.java | 16 +++++++ 10 files changed, 162 insertions(+) create mode 100644 spring-boot-exceptions/pass-exception-to-client-json-spring-boot/.gitignore create mode 100644 spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml create mode 100644 spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/CustomException.java create mode 100644 spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/ErrorHandler.java create mode 100644 spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/MainController.java create mode 100644 spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/PassExceptionToClientJsonSpringBootApplication.java create mode 100644 spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/resources/application.properties create mode 100644 spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/resources/static/.gitignore create mode 100644 spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/resources/templates/.gitignore create mode 100644 spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/test/java/com/baeldung/passexceptiontoclientjsonspringboot/PassExceptionToClientJsonSpringBootApplicationTests.java diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/.gitignore b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/.gitignore new file mode 100644 index 0000000000..153c9335eb --- /dev/null +++ b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/.gitignore @@ -0,0 +1,29 @@ +HELP.md +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +/build/ + +### VS Code ### +.vscode/ diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml new file mode 100644 index 0000000000..28a699ad98 --- /dev/null +++ b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml @@ -0,0 +1,43 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.1.4.RELEASE + + + com.baeldung + pass-exception-to-client-json-spring-boot + 0.0.1-SNAPSHOT + pass-exception-to-client-json-spring-boot + Baeldung article code on how to pass exceptions to client in JSON format using Spring Boot + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/CustomException.java b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/CustomException.java new file mode 100644 index 0000000000..56fe80cd9a --- /dev/null +++ b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/CustomException.java @@ -0,0 +1,11 @@ +package com.baeldung.passexceptiontoclientjsonspringboot; + +public class CustomException extends RuntimeException { + + private static final long serialVersionUID = 1L; + + public CustomException() { + super("Custom exception message."); + } + +} \ No newline at end of file diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/ErrorHandler.java b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/ErrorHandler.java new file mode 100644 index 0000000000..823689adb9 --- /dev/null +++ b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/ErrorHandler.java @@ -0,0 +1,21 @@ +package com.baeldung.passexceptiontoclientjsonspringboot; + +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ControllerAdvice +public class ErrorHandler { + + @ExceptionHandler(CustomException.class) + @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) + @ResponseBody + public CustomException handleCustomException(CustomException ce) { + + return ce; + + } + +} \ No newline at end of file diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/MainController.java b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/MainController.java new file mode 100644 index 0000000000..68df38fb73 --- /dev/null +++ b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/MainController.java @@ -0,0 +1,20 @@ +package com.baeldung.passexceptiontoclientjsonspringboot; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class MainController { + + @GetMapping("/") + public String index() throws CustomException { + + if (true) { + throw new CustomException(); + } + + return "index"; + + } + +} \ No newline at end of file diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/PassExceptionToClientJsonSpringBootApplication.java b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/PassExceptionToClientJsonSpringBootApplication.java new file mode 100644 index 0000000000..77833c28fd --- /dev/null +++ b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/PassExceptionToClientJsonSpringBootApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.passexceptiontoclientjsonspringboot; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class PassExceptionToClientJsonSpringBootApplication { + + public static void main(String[] args) { + SpringApplication.run(PassExceptionToClientJsonSpringBootApplication.class, args); + } + +} \ No newline at end of file diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/resources/application.properties b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/resources/application.properties new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/resources/application.properties @@ -0,0 +1 @@ + diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/resources/static/.gitignore b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/resources/static/.gitignore new file mode 100644 index 0000000000..5e7d2734cf --- /dev/null +++ b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/resources/static/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/resources/templates/.gitignore b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/resources/templates/.gitignore new file mode 100644 index 0000000000..5e7d2734cf --- /dev/null +++ b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/resources/templates/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/test/java/com/baeldung/passexceptiontoclientjsonspringboot/PassExceptionToClientJsonSpringBootApplicationTests.java b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/test/java/com/baeldung/passexceptiontoclientjsonspringboot/PassExceptionToClientJsonSpringBootApplicationTests.java new file mode 100644 index 0000000000..5e35c21f4c --- /dev/null +++ b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/test/java/com/baeldung/passexceptiontoclientjsonspringboot/PassExceptionToClientJsonSpringBootApplicationTests.java @@ -0,0 +1,16 @@ +package com.baeldung.passexceptiontoclientjsonspringboot; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class PassExceptionToClientJsonSpringBootApplicationTests { + + @Test + public void contextLoads() { + } + +} From bac59e78bf7690cddacd4721fb0910770aa355aa Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sun, 21 Apr 2019 23:39:19 +0300 Subject: [PATCH 22/53] Update FooUnitTest.java --- .../com/baeldung/convertcollectiontoarraylist/FooUnitTest.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/java-collections-conversions/src/test/java/com/baeldung/convertcollectiontoarraylist/FooUnitTest.java b/java-collections-conversions/src/test/java/com/baeldung/convertcollectiontoarraylist/FooUnitTest.java index 5be4121bc7..1de600aebf 100644 --- a/java-collections-conversions/src/test/java/com/baeldung/convertcollectiontoarraylist/FooUnitTest.java +++ b/java-collections-conversions/src/test/java/com/baeldung/convertcollectiontoarraylist/FooUnitTest.java @@ -33,9 +33,6 @@ public class FooUnitTest { srcCollection.add(sam); srcCollection.add(alice); srcCollection.add(buffy); - - // make sure the collection isn't sorted accidentally - assertFalse("Oops: source collection is already sorted!", isSorted(srcCollection)); } /** From b5baab70929f8fa7cd83ca51f807d0ebdc3e0a74 Mon Sep 17 00:00:00 2001 From: Jacob Stopak Date: Sun, 21 Apr 2019 15:22:14 -0700 Subject: [PATCH 23/53] Move @ResponseBody to class level, bump version to 0.0.2 --- .../pass-exception-to-client-json-spring-boot/pom.xml | 2 +- .../passexceptiontoclientjsonspringboot/ErrorHandler.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml index 28a699ad98..d592cae351 100644 --- a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml +++ b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml @@ -10,7 +10,7 @@ com.baeldung pass-exception-to-client-json-spring-boot - 0.0.1-SNAPSHOT + 0.0.2-SNAPSHOT pass-exception-to-client-json-spring-boot Baeldung article code on how to pass exceptions to client in JSON format using Spring Boot diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/ErrorHandler.java b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/ErrorHandler.java index 823689adb9..d69f60b75e 100644 --- a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/ErrorHandler.java +++ b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/ErrorHandler.java @@ -7,11 +7,11 @@ import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseStatus; @ControllerAdvice +@ResponseBody public class ErrorHandler { @ExceptionHandler(CustomException.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) - @ResponseBody public CustomException handleCustomException(CustomException ce) { return ce; From 732a7413f419a40123e263ab2854c3d2a306d451 Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Mon, 22 Apr 2019 08:13:32 +0800 Subject: [PATCH 24/53] Revert "BAEL-2779 Guide to classgraph library" This reverts commit af4e221f as it was asked to move it to libraries-2 --- libraries/pom.xml | 7 -- .../classgraph/ClassGraphUnitTest.java | 78 ------------------- .../classgraph/ClassWithAnnotation.java | 5 -- .../classgraph/FieldWithAnnotation.java | 7 -- .../classgraph/MethodWithAnnotation.java | 8 -- .../MethodWithAnnotationParameterDao.java | 8 -- .../MethodWithAnnotationParameterWeb.java | 8 -- .../baeldung/classgraph/TestAnnotation.java | 14 ---- .../src/test/resources/classgraph/my.config | 1 - 9 files changed, 136 deletions(-) delete mode 100644 libraries/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java delete mode 100644 libraries/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java delete mode 100644 libraries/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java delete mode 100644 libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java delete mode 100644 libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java delete mode 100644 libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java delete mode 100644 libraries/src/test/java/com/baeldung/classgraph/TestAnnotation.java delete mode 100644 libraries/src/test/resources/classgraph/my.config diff --git a/libraries/pom.xml b/libraries/pom.xml index a6179a843d..7823732224 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -699,12 +699,6 @@ ${reflections.version} - - io.github.classgraph - classgraph - ${classgraph.version} - - @@ -922,7 +916,6 @@ 2.7.1 3.6 0.9.11 - 4.8.22 diff --git a/libraries/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java b/libraries/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java deleted file mode 100644 index 5767396948..0000000000 --- a/libraries/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.baeldung.classgraph; - -import io.github.classgraph.*; -import org.junit.Test; - -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Consumer; - -import static org.assertj.core.api.Assertions.assertThat; - -public class ClassGraphUnitTest { - - @Test - public void whenClassAnnotationFilterIsDefined_thenTargetClassesCanBeFound() { - doTest(result -> { - ClassInfoList classInfos = result.getClassesWithAnnotation(TestAnnotation.class.getName()); - assertThat(classInfos).extracting(ClassInfo::getName).contains(ClassWithAnnotation.class.getName()); - }); - } - - @Test - public void whenMethodAnnotationFilterIsDefined_thenTargetClassesCanBeFound() { - doTest(result -> { - ClassInfoList classInfos = result.getClassesWithMethodAnnotation(TestAnnotation.class.getName()); - assertThat(classInfos).extracting(ClassInfo::getName).contains(MethodWithAnnotation.class.getName()); - }); - } - - @Test - public void whenMethodAnnotationValueFilterIsDefined_thenTargetClassesCanBeFound() { - doTest(result -> { - ClassInfoList classInfos = result.getClassesWithMethodAnnotation(TestAnnotation.class.getName()); - ClassInfoList filteredClassInfos = classInfos.filter(classInfo -> { - return classInfo.getMethodInfo().stream().anyMatch(methodInfo -> { - AnnotationInfo annotationInfo = methodInfo.getAnnotationInfo(TestAnnotation.class.getName()); - if (annotationInfo == null) { - return false; - } - - return "web".equals(annotationInfo.getParameterValues().getValue("value")); - }); - }); - assertThat(filteredClassInfos) - .extracting(ClassInfo::getName) - .contains(MethodWithAnnotationParameterWeb.class.getName()); - }); - } - - @Test - public void whenFieldAnnotationFilterIsDefined_thenTargetClassesCanBeFound() { - doTest(result -> { - ClassInfoList classInfos = result.getClassesWithFieldAnnotation(TestAnnotation.class.getName()); - assertThat(classInfos).extracting(ClassInfo::getName).contains(FieldWithAnnotation.class.getName()); - }); - } - - @Test - public void whenResourceIsUsed_thenItCanBeFoundAndLoaded() throws IOException { - try (ScanResult result = new ClassGraph().whitelistPaths("classgraph").scan()) { - ResourceList resources = result.getResourcesWithExtension("config"); - assertThat(resources).extracting(Resource::getPath).containsOnly("classgraph/my.config"); - assertThat(resources.get(0).getContentAsString()).isEqualTo("my data"); - } - } - - private void doTest(Consumer checker) { - try (ScanResult result = new ClassGraph().enableAllInfo() - .whitelistPackages(getClass().getPackage().getName()) - .scan()) - { - checker.accept(result); - } - } -} diff --git a/libraries/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java b/libraries/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java deleted file mode 100644 index 0f3eeef293..0000000000 --- a/libraries/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.baeldung.classgraph; - -@TestAnnotation -public class ClassWithAnnotation { -} diff --git a/libraries/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java b/libraries/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java deleted file mode 100644 index c5d1cc6062..0000000000 --- a/libraries/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.baeldung.classgraph; - -public class FieldWithAnnotation { - - @TestAnnotation - private String s; -} diff --git a/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java b/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java deleted file mode 100644 index 12d0c9927c..0000000000 --- a/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.classgraph; - -public class MethodWithAnnotation { - - @TestAnnotation - public void service() { - } -} diff --git a/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java b/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java deleted file mode 100644 index 9e38f42013..0000000000 --- a/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.classgraph; - -public class MethodWithAnnotationParameterDao { - - @TestAnnotation("dao") - public void service() { - } -} diff --git a/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java b/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java deleted file mode 100644 index 1ef3d46b6f..0000000000 --- a/libraries/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.baeldung.classgraph; - -public class MethodWithAnnotationParameterWeb { - - @TestAnnotation("web") - public void service() { - } -} diff --git a/libraries/src/test/java/com/baeldung/classgraph/TestAnnotation.java b/libraries/src/test/java/com/baeldung/classgraph/TestAnnotation.java deleted file mode 100644 index f47ec180a9..0000000000 --- a/libraries/src/test/java/com/baeldung/classgraph/TestAnnotation.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.baeldung.classgraph; - -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -import static java.lang.annotation.ElementType.*; - -@Target({TYPE, METHOD, FIELD}) -@Retention(RetentionPolicy.RUNTIME) -public @interface TestAnnotation { - - String value() default ""; -} diff --git a/libraries/src/test/resources/classgraph/my.config b/libraries/src/test/resources/classgraph/my.config deleted file mode 100644 index b99df573f6..0000000000 --- a/libraries/src/test/resources/classgraph/my.config +++ /dev/null @@ -1 +0,0 @@ -my data \ No newline at end of file From 541e0cc9d55e28c095c757f95e6330fe94b8d92e Mon Sep 17 00:00:00 2001 From: Denis Zhdanov Date: Mon, 22 Apr 2019 08:17:20 +0800 Subject: [PATCH 25/53] BAEL-2779 Guide to classgraph library --- libraries-2/pom.xml | 12 +++ .../classgraph/ClassGraphUnitTest.java | 74 +++++++++++++++++++ .../classgraph/ClassWithAnnotation.java | 5 ++ .../classgraph/FieldWithAnnotation.java | 7 ++ .../classgraph/MethodWithAnnotation.java | 8 ++ .../MethodWithAnnotationParameterDao.java | 8 ++ .../MethodWithAnnotationParameterWeb.java | 8 ++ .../baeldung/classgraph/TestAnnotation.java | 14 ++++ .../src/test/resources/classgraph/my.config | 1 + 9 files changed, 137 insertions(+) create mode 100644 libraries-2/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java create mode 100644 libraries-2/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java create mode 100644 libraries-2/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java create mode 100644 libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java create mode 100644 libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java create mode 100644 libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java create mode 100644 libraries-2/src/test/java/com/baeldung/classgraph/TestAnnotation.java create mode 100644 libraries-2/src/test/resources/classgraph/my.config diff --git a/libraries-2/pom.xml b/libraries-2/pom.xml index a839f56b56..965cb195bf 100644 --- a/libraries-2/pom.xml +++ b/libraries-2/pom.xml @@ -30,6 +30,16 @@ + + org.assertj + assertj-core + ${assertj.version} + + + io.github.classgraph + classgraph + ${classgraph.version} + org.jbpm jbpm-test @@ -38,6 +48,8 @@ + 3.6.2 + 4.8.22 6.0.0.Final diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java b/libraries-2/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java new file mode 100644 index 0000000000..3dc99e6a32 --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/ClassGraphUnitTest.java @@ -0,0 +1,74 @@ +package com.baeldung.classgraph; + +import io.github.classgraph.*; +import org.junit.Test; + +import java.io.IOException; +import java.util.function.Consumer; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ClassGraphUnitTest { + + @Test + public void whenClassAnnotationFilterIsDefined_thenTargetClassesCanBeFound() { + doTest(result -> { + ClassInfoList classInfos = result.getClassesWithAnnotation(TestAnnotation.class.getName()); + assertThat(classInfos).extracting(ClassInfo::getName).contains(ClassWithAnnotation.class.getName()); + }); + } + + @Test + public void whenMethodAnnotationFilterIsDefined_thenTargetClassesCanBeFound() { + doTest(result -> { + ClassInfoList classInfos = result.getClassesWithMethodAnnotation(TestAnnotation.class.getName()); + assertThat(classInfos).extracting(ClassInfo::getName).contains(MethodWithAnnotation.class.getName()); + }); + } + + @Test + public void whenMethodAnnotationValueFilterIsDefined_thenTargetClassesCanBeFound() { + doTest(result -> { + ClassInfoList classInfos = result.getClassesWithMethodAnnotation(TestAnnotation.class.getName()); + ClassInfoList filteredClassInfos = classInfos.filter(classInfo -> { + return classInfo.getMethodInfo().stream().anyMatch(methodInfo -> { + AnnotationInfo annotationInfo = methodInfo.getAnnotationInfo(TestAnnotation.class.getName()); + if (annotationInfo == null) { + return false; + } + + return "web".equals(annotationInfo.getParameterValues().getValue("value")); + }); + }); + assertThat(filteredClassInfos) + .extracting(ClassInfo::getName) + .contains(MethodWithAnnotationParameterWeb.class.getName()); + }); + } + + @Test + public void whenFieldAnnotationFilterIsDefined_thenTargetClassesCanBeFound() { + doTest(result -> { + ClassInfoList classInfos = result.getClassesWithFieldAnnotation(TestAnnotation.class.getName()); + assertThat(classInfos).extracting(ClassInfo::getName).contains(FieldWithAnnotation.class.getName()); + }); + } + + @Test + public void whenResourceIsUsed_thenItCanBeFoundAndLoaded() throws IOException { + try (ScanResult result = new ClassGraph().whitelistPaths("classgraph").scan()) { + ResourceList resources = result.getResourcesWithExtension("config"); + assertThat(resources).extracting(Resource::getPath).containsOnly("classgraph/my.config"); + assertThat(resources.get(0).getContentAsString()).isEqualTo("my data"); + } + } + + private void doTest(Consumer checker) { + try (ScanResult result = new ClassGraph().enableAllInfo() + .whitelistPackages(getClass().getPackage().getName()) + .scan()) + { + checker.accept(result); + } + } +} \ No newline at end of file diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java b/libraries-2/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java new file mode 100644 index 0000000000..fe476769a6 --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/ClassWithAnnotation.java @@ -0,0 +1,5 @@ +package com.baeldung.classgraph; + +@TestAnnotation +public class ClassWithAnnotation { +} \ No newline at end of file diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java b/libraries-2/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java new file mode 100644 index 0000000000..f72a7621f9 --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/FieldWithAnnotation.java @@ -0,0 +1,7 @@ +package com.baeldung.classgraph; + +public class FieldWithAnnotation { + + @TestAnnotation + private String s; +} \ No newline at end of file diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java new file mode 100644 index 0000000000..29a59c09ea --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotation.java @@ -0,0 +1,8 @@ +package com.baeldung.classgraph; + +public class MethodWithAnnotation { + + @TestAnnotation + public void service() { + } +} \ No newline at end of file diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java new file mode 100644 index 0000000000..f01c2743eb --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterDao.java @@ -0,0 +1,8 @@ +package com.baeldung.classgraph; + +public class MethodWithAnnotationParameterDao { + + @TestAnnotation("dao") + public void service() { + } +} \ No newline at end of file diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java new file mode 100644 index 0000000000..bf01f7d23c --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/MethodWithAnnotationParameterWeb.java @@ -0,0 +1,8 @@ +package com.baeldung.classgraph; + +public class MethodWithAnnotationParameterWeb { + + @TestAnnotation("web") + public void service() { + } +} \ No newline at end of file diff --git a/libraries-2/src/test/java/com/baeldung/classgraph/TestAnnotation.java b/libraries-2/src/test/java/com/baeldung/classgraph/TestAnnotation.java new file mode 100644 index 0000000000..e3f5df92ed --- /dev/null +++ b/libraries-2/src/test/java/com/baeldung/classgraph/TestAnnotation.java @@ -0,0 +1,14 @@ +package com.baeldung.classgraph; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; + +@Target({TYPE, METHOD, FIELD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface TestAnnotation { + + String value() default ""; +} \ No newline at end of file diff --git a/libraries-2/src/test/resources/classgraph/my.config b/libraries-2/src/test/resources/classgraph/my.config new file mode 100644 index 0000000000..b99df573f6 --- /dev/null +++ b/libraries-2/src/test/resources/classgraph/my.config @@ -0,0 +1 @@ +my data \ No newline at end of file From 5d09d7c7b93a650e04580b7be1ecef6fef1eb0bf Mon Sep 17 00:00:00 2001 From: eric-martin Date: Sun, 21 Apr 2019 19:57:25 -0500 Subject: [PATCH 26/53] Fix vaadin-maven-plugin configuration --- vaadin/pom.xml | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/vaadin/pom.xml b/vaadin/pom.xml index 145a6af293..ec69e240e2 100644 --- a/vaadin/pom.xml +++ b/vaadin/pom.xml @@ -70,17 +70,6 @@ com.vaadin vaadin-maven-plugin ${vaadin.plugin.version} - - - - update-theme - update-widgetset - compile - - compile-theme - - - org.apache.maven.plugins From 16553936c7aed6022bc735466237e430321f34e8 Mon Sep 17 00:00:00 2001 From: "Sadanand S. Koli" Date: Mon, 22 Apr 2019 20:48:49 +0530 Subject: [PATCH 27/53] BAEL-2770 Fixed code formatting and improved test cases --- .../array/AddElementToEndOfArray.java | 6 ++--- .../array/AddElementToEndOfArrayUnitTest.java | 25 +++++++++++-------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/core-java-arrays/src/main/java/com/baeldung/array/AddElementToEndOfArray.java b/core-java-arrays/src/main/java/com/baeldung/array/AddElementToEndOfArray.java index 1dc6600600..dcd61cdfa7 100644 --- a/core-java-arrays/src/main/java/com/baeldung/array/AddElementToEndOfArray.java +++ b/core-java-arrays/src/main/java/com/baeldung/array/AddElementToEndOfArray.java @@ -8,7 +8,7 @@ public class AddElementToEndOfArray { public Integer[] addElementUsingArraysCopyOf(Integer[] srcArray, int elementToAdd) { Integer[] destArray = Arrays.copyOf(srcArray, srcArray.length + 1); - destArray[destArray.length-1] = elementToAdd; + destArray[destArray.length - 1] = elementToAdd; return destArray; } @@ -26,9 +26,9 @@ public class AddElementToEndOfArray { System.arraycopy(srcArray, 0, destArray, 0, srcArray.length); - destArray[destArray.length-1] = elementToAdd; + destArray[destArray.length - 1] = elementToAdd; return destArray; } -} \ No newline at end of file +} diff --git a/core-java-arrays/src/test/java/com/baeldung/array/AddElementToEndOfArrayUnitTest.java b/core-java-arrays/src/test/java/com/baeldung/array/AddElementToEndOfArrayUnitTest.java index beeed1a313..f6f1f954f6 100644 --- a/core-java-arrays/src/test/java/com/baeldung/array/AddElementToEndOfArrayUnitTest.java +++ b/core-java-arrays/src/test/java/com/baeldung/array/AddElementToEndOfArrayUnitTest.java @@ -3,44 +3,47 @@ package com.baeldung.array; import org.junit.Before; import org.junit.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertArrayEquals; public class AddElementToEndOfArrayUnitTest { AddElementToEndOfArray addElementToEndOfArray; @Before - public void init(){ + public void init() { addElementToEndOfArray = new AddElementToEndOfArray(); } @Test - public void givenSourceArrayAndElement_whenAddElementUsingArraysCopyIsInvoked_thenNewElementMustBeAdded(){ - Integer[] sourceArray = {1,2,3,4}; + public void givenSourceArrayAndElement_whenAddElementUsingArraysCopyIsInvoked_thenNewElementMustBeAdded() { + Integer[] sourceArray = {1, 2, 3, 4}; int elementToAdd = 5; Integer[] destArray = addElementToEndOfArray.addElementUsingArraysCopyOf(sourceArray, elementToAdd); - assertEquals(elementToAdd, destArray[destArray.length-1].intValue()); + Integer[] expectedArray = {1, 2, 3, 4, 5}; + assertArrayEquals(expectedArray, destArray); } @Test - public void givenSourceArrayAndElement_whenAddElementUsingArrayListIsInvoked_thenNewElementMustBeAdded(){ - Integer[] sourceArray = {1,2,3,4}; + public void givenSourceArrayAndElement_whenAddElementUsingArrayListIsInvoked_thenNewElementMustBeAdded() { + Integer[] sourceArray = {1, 2, 3, 4}; int elementToAdd = 5; Integer[] destArray = addElementToEndOfArray.addElementUsingArrayList(sourceArray, elementToAdd); - assertEquals(elementToAdd, destArray[destArray.length-1].intValue()); + Integer[] expectedArray = {1, 2, 3, 4, 5}; + assertArrayEquals(expectedArray, destArray); } @Test - public void givenSourceArrayAndElement_whenAddElementUsingSystemArrayCopyIsInvoked_thenNewElementMustBeAdded(){ - Integer[] sourceArray = {1,2,3,4}; + public void givenSourceArrayAndElement_whenAddElementUsingSystemArrayCopyIsInvoked_thenNewElementMustBeAdded() { + Integer[] sourceArray = {1, 2, 3, 4}; int elementToAdd = 5; Integer[] destArray = addElementToEndOfArray.addElementUsingSystemArrayCopy(sourceArray, elementToAdd); - assertEquals(elementToAdd, destArray[destArray.length-1].intValue()); + Integer[] expectedArray = {1, 2, 3, 4, 5}; + assertArrayEquals(expectedArray, destArray); } } From b63f8882eab774d4a036bfae9deef937b5599a09 Mon Sep 17 00:00:00 2001 From: pcoates33 Date: Mon, 22 Apr 2019 18:12:56 +0100 Subject: [PATCH 28/53] BAEL-2837 Add sample Set operations in Java (#6697) * BAEL-2837: Add sample set operations in Java * BAEL-2837 add new module core-java-collections-set * BAEL-2837 Updated readme.md file * BAEL-2837 Tidy dependencies in pom.xml * BAEL-2837 tidy white space in pom.xml * BAEL-2837 Rename unit test class * BAEL-2837 Removed unused logback-xml --- core-java-collections-set/README.md | 6 ++ core-java-collections-set/pom.xml | 33 +++++++ .../baeldung/set/SetOperationsUnitTest.java | 93 +++++++++++++++++++ pom.xml | 2 + 4 files changed, 134 insertions(+) create mode 100644 core-java-collections-set/README.md create mode 100644 core-java-collections-set/pom.xml create mode 100644 core-java-collections-set/src/test/java/com/baeldung/set/SetOperationsUnitTest.java diff --git a/core-java-collections-set/README.md b/core-java-collections-set/README.md new file mode 100644 index 0000000000..710484a2e1 --- /dev/null +++ b/core-java-collections-set/README.md @@ -0,0 +1,6 @@ +========= + +## Core Java Sets Cookbooks and Examples + +### Relevant Articles: +- [Set Operations in Java](http://www.baeldung.com/set-operations-in-java) diff --git a/core-java-collections-set/pom.xml b/core-java-collections-set/pom.xml new file mode 100644 index 0000000000..d5f7937645 --- /dev/null +++ b/core-java-collections-set/pom.xml @@ -0,0 +1,33 @@ + + 4.0.0 + core-java-collections-set + 0.1.0-SNAPSHOT + core-java-collections-set + jar + + + com.baeldung + parent-java + 0.0.1-SNAPSHOT + ../parent-java + + + + + com.google.guava + guava + ${guava.version} + + + org.apache.commons + commons-collections4 + ${commons-collections4.version} + + + + + 4.3 + 27.1-jre + + diff --git a/core-java-collections-set/src/test/java/com/baeldung/set/SetOperationsUnitTest.java b/core-java-collections-set/src/test/java/com/baeldung/set/SetOperationsUnitTest.java new file mode 100644 index 0000000000..7c25585e49 --- /dev/null +++ b/core-java-collections-set/src/test/java/com/baeldung/set/SetOperationsUnitTest.java @@ -0,0 +1,93 @@ +package com.baeldung.set; + +import static org.junit.Assert.*; + +import org.apache.commons.collections4.SetUtils; +import org.junit.Test; + +import com.google.common.collect.Sets; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +public class SetOperationsUnitTest { + + private Set setA = setOf(1,2,3,4); + private Set setB = setOf(2,4,6,8); + + private static Set setOf(Integer... values) { + return new HashSet(Arrays.asList(values)); + } + + @Test + public void givenTwoSets_WhenWeRetainAll_ThenWeIntersectThem() { + Set intersectSet = new HashSet<>(setA); + intersectSet.retainAll(setB); + assertEquals(setOf(2,4), intersectSet); + } + + @Test + public void givenTwoSets_WhenWeAddAll_ThenWeUnionThem() { + Set unionSet = new HashSet<>(setA); + unionSet.addAll(setB); + assertEquals(setOf(1,2,3,4,6,8), unionSet); + } + + @Test + public void givenTwoSets_WhenRemoveAll_ThenWeGetTheDifference() { + Set differenceSet = new HashSet<>(setA); + differenceSet.removeAll(setB); + assertEquals(setOf(1,3), differenceSet); + } + + @Test + public void givenTwoStreams_WhenWeFilterThem_ThenWeCanGetTheIntersect() { + Set intersectSet = setA.stream() + .filter(setB::contains) + .collect(Collectors.toSet()); + assertEquals(setOf(2,4), intersectSet); + } + + @Test + public void givenTwoStreams_WhenWeConcatThem_ThenWeGetTheUnion() { + Set unionSet = Stream.concat(setA.stream(), setB.stream()) + .collect(Collectors.toSet()); + assertEquals(setOf(1,2,3,4,6,8), unionSet); + } + + @Test + public void givenTwoStreams_WhenWeFilterThem_ThenWeCanGetTheDifference() { + Set differenceSet = setA.stream() + .filter(val -> !setB.contains(val)) + .collect(Collectors.toSet()); + assertEquals(setOf(1,3), differenceSet); + } + + @Test + public void givenTwoSets_WhenWeUseApacheCommonsIntersect_ThenWeGetTheIntersect() { + Set intersectSet = SetUtils.intersection(setA, setB); + assertEquals(setOf(2,4), intersectSet); + } + + @Test + public void givenTwoSets_WhenWeUseApacheCommonsUnion_ThenWeGetTheUnion() { + Set unionSet = SetUtils.union(setA, setB); + assertEquals(setOf(1,2,3,4,6,8), unionSet); + } + + + @Test + public void givenTwoSets_WhenWeUseGuavaIntersect_ThenWeGetTheIntersect() { + Set intersectSet = Sets.intersection(setA, setB); + assertEquals(setOf(2,4), intersectSet); + } + + @Test + public void givenTwoSets_WhenWeUseGuavaUnion_ThenWeGetTheUnion() { + Set unionSet = Sets.union(setA, setB); + assertEquals(setOf(1,2,3,4,6,8), unionSet); + } +} diff --git a/pom.xml b/pom.xml index 0de4a36336..901bc94f96 100644 --- a/pom.xml +++ b/pom.xml @@ -389,6 +389,7 @@ core-java-collections core-java-collections-map core-java-collections-list + core-java-collections-set core-java-concurrency-basic core-java-concurrency-collections core-java-io @@ -1059,6 +1060,7 @@ core-java-collections core-java-collections-map core-java-collections-list + core-java-collections-set core-java-concurrency-basic core-java-concurrency-collections core-java-io From 77338c7fb1326625a2bc9f8d43cac224d352fcd5 Mon Sep 17 00:00:00 2001 From: Adrian Precub Date: Mon, 22 Apr 2019 20:21:41 +0300 Subject: [PATCH 29/53] BAEL-2587: Spring Security integration with Amazon Cognito (#6730) * BAEL-2587: Spring Security integration with Amazon Cognito * BAEL-2587: Spring Security integration with Amazon Cognito - remove unnecessary stuff * BAEL-2587: Spring Security integration with Amazon Cognito - rename config file * BAEL-2587: Spring Security integration with Amazon Cognito - separate folder for cognito --- .../cognito/CognitoWebConfiguration.java | 16 ++++++++++ .../cognito/SpringCognitoApplication.java | 14 ++++++++ .../resources/cognito/application_cognito.yml | 15 +++++++++ .../src/main/resources/cognito/home.html | 32 +++++++++++++++++++ .../src/main/resources/cognito/style.css | 9 ++++++ 5 files changed, 86 insertions(+) create mode 100644 spring-5-security-oauth/src/main/java/com/baeldung/cognito/CognitoWebConfiguration.java create mode 100644 spring-5-security-oauth/src/main/java/com/baeldung/cognito/SpringCognitoApplication.java create mode 100644 spring-5-security-oauth/src/main/resources/cognito/application_cognito.yml create mode 100644 spring-5-security-oauth/src/main/resources/cognito/home.html create mode 100644 spring-5-security-oauth/src/main/resources/cognito/style.css diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/cognito/CognitoWebConfiguration.java b/spring-5-security-oauth/src/main/java/com/baeldung/cognito/CognitoWebConfiguration.java new file mode 100644 index 0000000000..ae03e0a802 --- /dev/null +++ b/spring-5-security-oauth/src/main/java/com/baeldung/cognito/CognitoWebConfiguration.java @@ -0,0 +1,16 @@ +package com.baeldung.cognito; + +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; + +@Configuration +@PropertySource("cognito/application_cognito.yml") +public class CognitoWebConfiguration implements WebMvcConfigurer { + + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/").setViewName("home"); + } +} diff --git a/spring-5-security-oauth/src/main/java/com/baeldung/cognito/SpringCognitoApplication.java b/spring-5-security-oauth/src/main/java/com/baeldung/cognito/SpringCognitoApplication.java new file mode 100644 index 0000000000..7f7b751cd9 --- /dev/null +++ b/spring-5-security-oauth/src/main/java/com/baeldung/cognito/SpringCognitoApplication.java @@ -0,0 +1,14 @@ +package com.baeldung.cognito; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.PropertySource; + +@SpringBootApplication +@PropertySource("cognito/application_cognito.yml") +public class SpringCognitoApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringCognitoApplication.class, args); + } +} diff --git a/spring-5-security-oauth/src/main/resources/cognito/application_cognito.yml b/spring-5-security-oauth/src/main/resources/cognito/application_cognito.yml new file mode 100644 index 0000000000..0a28dbccb4 --- /dev/null +++ b/spring-5-security-oauth/src/main/resources/cognito/application_cognito.yml @@ -0,0 +1,15 @@ +spring: + security: + oauth2: + client: + registration: + cognito: + client-id: clientId + client-secret: clientSecret + scope: openid + redirectUriTemplate: "http://localhost:8080/login/oauth2/code/cognito" + clientName: cognito-client-name + provider: + cognito: + issuerUri: https://cognito-idp.{region}.amazonaws.com/{poolId} + usernameAttribute: cognito:username diff --git a/spring-5-security-oauth/src/main/resources/cognito/home.html b/spring-5-security-oauth/src/main/resources/cognito/home.html new file mode 100644 index 0000000000..f0bd9e52a8 --- /dev/null +++ b/spring-5-security-oauth/src/main/resources/cognito/home.html @@ -0,0 +1,32 @@ + + + + + + OAuth2 Cognito Demo + + + + + +
+
+
+

OAuth2 Spring Security Cognito Demo

+ +
+
+ Hello, ! +
+
+ + +
+
+
+ + diff --git a/spring-5-security-oauth/src/main/resources/cognito/style.css b/spring-5-security-oauth/src/main/resources/cognito/style.css new file mode 100644 index 0000000000..45190d6d70 --- /dev/null +++ b/spring-5-security-oauth/src/main/resources/cognito/style.css @@ -0,0 +1,9 @@ +.login { + background-color: #7289da; + color: #fff; +} + +.login:hover { + background-color: #697ec4; + color: #fff; +} From a90ea4c46b0a4133b1a45eb7f37cfc7d18665e51 Mon Sep 17 00:00:00 2001 From: Saravanan Kandaswamy Date: Tue, 23 Apr 2019 09:35:48 +0530 Subject: [PATCH 30/53] Fixed the Compilation issue for AutoValue module --- .../baeldung/autofactory/provided/IntermediateAssembler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java b/autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java index e0ee8879a5..65d0eb6f58 100644 --- a/autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java +++ b/autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java @@ -1,8 +1,9 @@ package com.baeldung.autofactory.provided; +import com.baeldung.autofactory.model.Camera; import com.google.auto.factory.AutoFactory; import com.google.auto.factory.Provided; -import javafx.scene.Camera; + import javax.inject.Provider; From 21ea070f21a9eb1f72fc9a6a2ad7f41a1441365b Mon Sep 17 00:00:00 2001 From: Saravanan Kandaswamy Date: Tue, 23 Apr 2019 09:35:48 +0530 Subject: [PATCH 31/53] Fixed the Compilation issue for AutoValue module --- .../baeldung/autofactory/provided/IntermediateAssembler.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java b/autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java index e0ee8879a5..65d0eb6f58 100644 --- a/autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java +++ b/autovalue/src/main/java/com/baeldung/autofactory/provided/IntermediateAssembler.java @@ -1,8 +1,9 @@ package com.baeldung.autofactory.provided; +import com.baeldung.autofactory.model.Camera; import com.google.auto.factory.AutoFactory; import com.google.auto.factory.Provided; -import javafx.scene.Camera; + import javax.inject.Provider; From 5d989661f3e9eccd88cf0745b14ef5403dd47c64 Mon Sep 17 00:00:00 2001 From: mikr Date: Tue, 23 Apr 2019 09:09:01 +0200 Subject: [PATCH 32/53] BAEL-2580 JVM Platform Annotations in Kotlin --- .../com/baeldung/jvmannotations/Document.kt | 31 +++++++++ .../baeldung/jvmannotations/HtmlDocument.java | 9 +++ .../com/baeldung/jvmannotations/Message.kt | 66 +++++++++++++++++++ .../jvmannotations/MessageConverter.kt | 6 ++ 4 files changed, 112 insertions(+) create mode 100644 core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/Document.kt create mode 100644 core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/HtmlDocument.java create mode 100644 core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/Message.kt create mode 100644 core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/MessageConverter.kt diff --git a/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/Document.kt b/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/Document.kt new file mode 100644 index 0000000000..3f9922b88b --- /dev/null +++ b/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/Document.kt @@ -0,0 +1,31 @@ +package com.baeldung.jvmannotations + +import java.util.* + +interface Document { + + @JvmDefault + fun getType() = "document" +} + +class TextDocument : Document { + override fun getType() = "text" + + fun transformList(list : List) : List { + return list.filter { n -> n.toInt() > 1 } + } + + fun transformListInverseWildcards(list : List<@JvmSuppressWildcards Number>) : List<@JvmWildcard Number> { + return list.filter { n -> n.toInt() > 1 } + } + + var list : List<@JvmWildcard Any> = ArrayList() +} + +class XmlDocument(d : Document) : Document by d + +fun main() { + val myDocument = TextDocument() + val myTextDocument = XmlDocument(myDocument) + println("${myDocument.getType()} ${myTextDocument.getType()}") +} diff --git a/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/HtmlDocument.java b/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/HtmlDocument.java new file mode 100644 index 0000000000..feb71772cb --- /dev/null +++ b/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/HtmlDocument.java @@ -0,0 +1,9 @@ +package com.baeldung.jvmannotations; + +public class HtmlDocument implements Document { + + @Override + public String getType() { + return "HTML"; + } +} \ No newline at end of file diff --git a/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/Message.kt b/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/Message.kt new file mode 100644 index 0000000000..80180bd924 --- /dev/null +++ b/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/Message.kt @@ -0,0 +1,66 @@ +@file:JvmName("MessageHelper") +@file:JvmMultifileClass //used +package com.baeldung.jvmannotations + +import java.util.* + +@JvmName("getMyUsername") +fun getMyName() : String { + return "myUserId" +} + +object MessageBroker { + @JvmStatic + var totalMessagesSent = 0 + + const val maxMessageLength = 0 + + @JvmStatic + fun clearAllMessages() { + } + + @JvmStatic + @JvmOverloads + @Throws(Exception::class) + fun findMessages(sender : String, type : String = "text", maxResults : Int = 10) : List { + if(sender.isEmpty()) { + throw Exception() + } + return ArrayList() + } +} + +class Message { + + // this would cause a compilation error since sender is immutable + // @set:JvmName("setSender") + val sender = "myself" + + // this works as name is overridden + @JvmName("getSenderName") + fun getSender() : String = "from:$sender" + + @get:JvmName("getReceiverName") + @set:JvmName("setReceiverName") + var receiver : String = "" + + @get:JvmName("getContent") + @set:JvmName("setContent") + var text = "" + + // generates a warning + @get:JvmName("getId") + private val id = 0 + + @get:JvmName("hasAttachment") + var hasAttachment = true + + var isEncrypted = true + + fun setReceivers(receiverNames : List) { + } + + @JvmName("setReceiverIds") + fun setReceivers(receiverNames : List) { + } +} \ No newline at end of file diff --git a/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/MessageConverter.kt b/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/MessageConverter.kt new file mode 100644 index 0000000000..3b19b12e10 --- /dev/null +++ b/core-kotlin/src/main/kotlin/com/baeldung/jvmannotations/MessageConverter.kt @@ -0,0 +1,6 @@ +@file:JvmMultifileClass +@file:JvmName("MessageHelper") //applies to all top level functions / variables / constants +package com.baeldung.jvmannotations + +fun convert(message: Message) { +} From 8463567986d58dac5cfbb60971a7ba95840354f3 Mon Sep 17 00:00:00 2001 From: Jacob Stopak Date: Tue, 23 Apr 2019 15:57:57 -0700 Subject: [PATCH 33/53] Minor refactor, bump to version 0.0.3 --- .../pass-exception-to-client-json-spring-boot/pom.xml | 2 +- .../MainController.java | 10 ++-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml index d592cae351..33a3aba03b 100644 --- a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml +++ b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml @@ -10,7 +10,7 @@ com.baeldung pass-exception-to-client-json-spring-boot - 0.0.2-SNAPSHOT + 0.0.3-SNAPSHOT pass-exception-to-client-json-spring-boot Baeldung article code on how to pass exceptions to client in JSON format using Spring Boot diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/MainController.java b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/MainController.java index 68df38fb73..82c0c022a8 100644 --- a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/MainController.java +++ b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/MainController.java @@ -7,14 +7,8 @@ import org.springframework.web.bind.annotation.GetMapping; public class MainController { @GetMapping("/") - public String index() throws CustomException { - - if (true) { - throw new CustomException(); - } - - return "index"; - + public void index() throws CustomException { + throw new CustomException(); } } \ No newline at end of file From 21512f008d1da4bdd653d08628dfb8f4e46154e6 Mon Sep 17 00:00:00 2001 From: KevinGilmore Date: Tue, 23 Apr 2019 22:14:19 -0500 Subject: [PATCH 34/53] BAEL-2840: update README (#6809) * BAEL-2246: add link back to article * BAEL-2174: rename core-java-net module to core-java-networking * BAEL-2174: add link back to article * BAEL-2363 BAEL-2337 BAEL-1996 BAEL-2277 add links back to articles * BAEL-2367: add link back to article * BAEL-2335: add link back to article * BAEL-2413: add link back to article * Update README.MD * BAEL-2577: add link back to article * BAEL-2490: add link back to article * BAEL-2471: add link back to article * BAEL-2583: add link back to article * BAEL-2738: add link back to article * BAEL-2711: Add spring-boot-angular module to root pom * BAEL-2544 BAEL-2711 BAEL-2575 BAEL-2657 Add links back to articles * BAEL-2736: Add link back to article * BAEL-2789: Add link back to article * BAEL-2489: add link back to article * BAEL-2840: add link back to article --- spring-data-rest/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-data-rest/README.md b/spring-data-rest/README.md index 1624a3abfd..abbacb69cc 100644 --- a/spring-data-rest/README.md +++ b/spring-data-rest/README.md @@ -22,3 +22,4 @@ To view the running application, visit [http://localhost:8080](http://localhost: - [Spring Data REST Events with @RepositoryEventHandler](http://www.baeldung.com/spring-data-rest-events) - [Customizing HTTP Endpoints in Spring Data REST](https://www.baeldung.com/spring-data-rest-customize-http-endpoints) - [Spring Boot with SQLite](https://www.baeldung.com/spring-boot-sqlite) +- [Spring Data Web Support](https://www.baeldung.com/spring-data-web-support) From a2002dde521fe0191a5d73c438aa75ee99e58300 Mon Sep 17 00:00:00 2001 From: Jacob Stopak Date: Tue, 23 Apr 2019 23:38:51 -0700 Subject: [PATCH 35/53] Add integration test, bump version to 0.0.4 --- .../pom.xml | 2 +- .../ErrorHandler.java | 2 -- .../MainControllerIntegrationTest.java | 16 ++++++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/test/java/com/baeldung/passexceptiontoclientjsonspringboot/MainControllerIntegrationTest.java diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml index 33a3aba03b..8237955aef 100644 --- a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml +++ b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml @@ -10,7 +10,7 @@ com.baeldung pass-exception-to-client-json-spring-boot - 0.0.3-SNAPSHOT + 0.0.4-SNAPSHOT pass-exception-to-client-json-spring-boot Baeldung article code on how to pass exceptions to client in JSON format using Spring Boot diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/ErrorHandler.java b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/ErrorHandler.java index d69f60b75e..b39d2811dd 100644 --- a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/ErrorHandler.java +++ b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/ErrorHandler.java @@ -13,9 +13,7 @@ public class ErrorHandler { @ExceptionHandler(CustomException.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public CustomException handleCustomException(CustomException ce) { - return ce; - } } \ No newline at end of file diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/test/java/com/baeldung/passexceptiontoclientjsonspringboot/MainControllerIntegrationTest.java b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/test/java/com/baeldung/passexceptiontoclientjsonspringboot/MainControllerIntegrationTest.java new file mode 100644 index 0000000000..a615dc5096 --- /dev/null +++ b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/test/java/com/baeldung/passexceptiontoclientjsonspringboot/MainControllerIntegrationTest.java @@ -0,0 +1,16 @@ +package com.baeldung.passexceptiontoclientjsonspringboot; + +import org.junit.Test; + +public class MainControllerIntegrationTest { + + @Test(expected = CustomException.class) + public void givenIndex_thenCustomException() throws CustomException { + + MainController mainController = new MainController(); + + mainController.index(); + + } + +} \ No newline at end of file From f9a337f7cff758e2e432b831dec32b6041483e8f Mon Sep 17 00:00:00 2001 From: Juan Moreno Date: Wed, 24 Apr 2019 09:30:30 -0300 Subject: [PATCH 36/53] CHORE Moved BAEL-2655's code from core-kotlin-2 to core-kotlin-io (#6807) --- core-kotlin-io/pom.xml | 33 +++++++++++++++---- .../com/baeldung/console/ConsoleIOUnitTest.kt | 0 .../org.mockito.plugins.MockMaker | 0 3 files changed, 26 insertions(+), 7 deletions(-) rename {core-kotlin-2 => core-kotlin-io}/src/test/kotlin/com/baeldung/console/ConsoleIOUnitTest.kt (100%) rename {core-kotlin-2 => core-kotlin-io}/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker (100%) diff --git a/core-kotlin-io/pom.xml b/core-kotlin-io/pom.xml index 2e21079d7f..a0b688a223 100644 --- a/core-kotlin-io/pom.xml +++ b/core-kotlin-io/pom.xml @@ -20,9 +20,21 @@ ${kotlin.version} - org.junit.platform - junit-platform-runner - ${junit.platform.version} + org.junit.jupiter + junit-jupiter + ${junit.jupiter.version} + test + + + org.mockito + mockito-core + ${mockito.version} + test + + + net.bytebuddy + byte-buddy + ${byte-buddy.version} test @@ -37,6 +49,12 @@ ${kotlin.version} test + + org.jetbrains.kotlin + kotlin-test-junit5 + ${kotlin.version} + test + @@ -69,10 +87,11 @@ - 1.2.71 - 1.1.1 - 5.2.0 + 1.3.30 + 5.4.2 + 2.27.0 + 1.9.12 3.10.0 - \ No newline at end of file + diff --git a/core-kotlin-2/src/test/kotlin/com/baeldung/console/ConsoleIOUnitTest.kt b/core-kotlin-io/src/test/kotlin/com/baeldung/console/ConsoleIOUnitTest.kt similarity index 100% rename from core-kotlin-2/src/test/kotlin/com/baeldung/console/ConsoleIOUnitTest.kt rename to core-kotlin-io/src/test/kotlin/com/baeldung/console/ConsoleIOUnitTest.kt diff --git a/core-kotlin-2/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/core-kotlin-io/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker similarity index 100% rename from core-kotlin-2/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker rename to core-kotlin-io/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker From ebde3334395b0050503ed3c38d9cb04d55892116 Mon Sep 17 00:00:00 2001 From: Alejandro Gervasio Date: Wed, 24 Apr 2019 09:49:12 -0300 Subject: [PATCH 37/53] Multi-module Maven Project using Java Modules (#6766) * Initial Commit * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update root pom.xml * Update root pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml * Update pom.xml --- .../daomodule/pom.xml | 14 +++++ .../src/main/java/com/baeldung/dao/Dao.java | 12 ++++ .../daomodule/src/main/java/module-info.java | 3 + .../entitiymodule/pom.xml | 18 ++++++ .../main/java/com/baeldung/entity/User.java | 19 ++++++ .../src/main/java/module-info.java | 3 + .../mainppmodule/pom.xml | 32 ++++++++++ .../com/baeldung/mainapp/Application.java | 19 ++++++ .../src/main/java/module-info.java | 6 ++ .../multimodule-maven-project/pom.xml | 58 +++++++++++++++++++ .../userdaomodule/pom.xml | 31 ++++++++++ .../java/com/baeldung/userdao/UserDao.java | 32 ++++++++++ .../src/main/java/module-info.java | 6 ++ .../userdao/test/UserDaoUnitTest.java | 36 ++++++++++++ maven-java-11/pom.xml | 22 +++++++ pom.xml | 1 + 16 files changed, 312 insertions(+) create mode 100644 maven-java-11/multimodule-maven-project/daomodule/pom.xml create mode 100644 maven-java-11/multimodule-maven-project/daomodule/src/main/java/com/baeldung/dao/Dao.java create mode 100644 maven-java-11/multimodule-maven-project/daomodule/src/main/java/module-info.java create mode 100644 maven-java-11/multimodule-maven-project/entitiymodule/pom.xml create mode 100644 maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/com/baeldung/entity/User.java create mode 100644 maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/module-info.java create mode 100644 maven-java-11/multimodule-maven-project/mainppmodule/pom.xml create mode 100644 maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/com/baeldung/mainapp/Application.java create mode 100644 maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/module-info.java create mode 100644 maven-java-11/multimodule-maven-project/pom.xml create mode 100644 maven-java-11/multimodule-maven-project/userdaomodule/pom.xml create mode 100644 maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/com/baeldung/userdao/UserDao.java create mode 100644 maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/module-info.java create mode 100644 maven-java-11/multimodule-maven-project/userdaomodule/src/test/java/com/baeldung/userdao/test/UserDaoUnitTest.java create mode 100644 maven-java-11/pom.xml diff --git a/maven-java-11/multimodule-maven-project/daomodule/pom.xml b/maven-java-11/multimodule-maven-project/daomodule/pom.xml new file mode 100644 index 0000000000..de9be656d4 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/daomodule/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + + com.baeldung.multimodule-maven-project + multimodule-maven-project + 1.0 + + com.baeldung.daomodule + daomodule + jar + 1.0 + daomodule + diff --git a/maven-java-11/multimodule-maven-project/daomodule/src/main/java/com/baeldung/dao/Dao.java b/maven-java-11/multimodule-maven-project/daomodule/src/main/java/com/baeldung/dao/Dao.java new file mode 100644 index 0000000000..f86ae8abb3 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/daomodule/src/main/java/com/baeldung/dao/Dao.java @@ -0,0 +1,12 @@ +package com.baeldung.dao; + +import java.util.List; +import java.util.Optional; + +public interface Dao { + + Optional findById(int id); + + List findAll(); + +} diff --git a/maven-java-11/multimodule-maven-project/daomodule/src/main/java/module-info.java b/maven-java-11/multimodule-maven-project/daomodule/src/main/java/module-info.java new file mode 100644 index 0000000000..072d7ad007 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/daomodule/src/main/java/module-info.java @@ -0,0 +1,3 @@ +module com.baeldung.dao { + exports com.baeldung.dao; +} diff --git a/maven-java-11/multimodule-maven-project/entitiymodule/pom.xml b/maven-java-11/multimodule-maven-project/entitiymodule/pom.xml new file mode 100644 index 0000000000..8e700e62b5 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/entitiymodule/pom.xml @@ -0,0 +1,18 @@ + + + 4.0.0 + + com.baeldung.multimodule-maven-project + multimodule-maven-project + 1.0 + + com.baeldung.entitymodule + entitymodule + jar + 1.0 + entitymodule + + 11 + 11 + + diff --git a/maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/com/baeldung/entity/User.java b/maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/com/baeldung/entity/User.java new file mode 100644 index 0000000000..22022a2e6d --- /dev/null +++ b/maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/com/baeldung/entity/User.java @@ -0,0 +1,19 @@ +package com.baeldung.entity; + +public class User { + + private final String name; + + public User(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public String toString() { + return "User{" + "name=" + name + '}'; + } +} diff --git a/maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/module-info.java b/maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/module-info.java new file mode 100644 index 0000000000..67a3097352 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/entitiymodule/src/main/java/module-info.java @@ -0,0 +1,3 @@ +module com.baeldung.entity { + exports com.baeldung.entity; +} diff --git a/maven-java-11/multimodule-maven-project/mainppmodule/pom.xml b/maven-java-11/multimodule-maven-project/mainppmodule/pom.xml new file mode 100644 index 0000000000..d2c94527f1 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/mainppmodule/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + com.baeldung.multimodule-maven-project + multimodule-maven-project + 1.0 + + com.baeldung.mainappmodule + mainappmodule + 1.0 + jar + mainappmodule + + + + com.baeldung.entitymodule + entitymodule + 1.0 + + + com.baeldung.daomodule + daomodule + 1.0 + + + com.baeldung.userdaomodule + userdaomodule + 1.0 + + + diff --git a/maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/com/baeldung/mainapp/Application.java b/maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/com/baeldung/mainapp/Application.java new file mode 100644 index 0000000000..0c0df7461b --- /dev/null +++ b/maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/com/baeldung/mainapp/Application.java @@ -0,0 +1,19 @@ +package com.baeldung.mainapp; + +import com.baeldung.dao.Dao; +import com.baeldung.entity.User; +import com.baeldung.userdao.UserDao; +import java.util.HashMap; +import java.util.Map; + +public class Application { + + public static void main(String[] args) { + Map users = new HashMap<>(); + users.put(1, new User("Julie")); + users.put(2, new User("David")); + Dao userDao = new UserDao(users); + userDao.findAll().forEach(System.out::println); + } + +} diff --git a/maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/module-info.java b/maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/module-info.java new file mode 100644 index 0000000000..c688fcf7de --- /dev/null +++ b/maven-java-11/multimodule-maven-project/mainppmodule/src/main/java/module-info.java @@ -0,0 +1,6 @@ +module com.baeldung.mainapp { + requires com.baeldung.entity; + requires com.baeldung.userdao; + requires com.baeldung.dao; + uses com.baeldung.dao.Dao; +} diff --git a/maven-java-11/multimodule-maven-project/pom.xml b/maven-java-11/multimodule-maven-project/pom.xml new file mode 100644 index 0000000000..f22541738c --- /dev/null +++ b/maven-java-11/multimodule-maven-project/pom.xml @@ -0,0 +1,58 @@ + + + 4.0.0 + com.baeldung.multimodule-maven-project + multimodule-maven-project + 1.0 + pom + multimodule-maven-project + + com.baeldung.maven-java-11 + maven-java-11 + 1.0 + + + + + + junit + junit + 4.12 + test + + + org.assertj + assertj-core + 3.12.2 + test + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.0 + + 11 + 11 + + + + + + + + entitymodule + daomodule + userdaomodule + mainappmodule + + + + UTF-8 + + diff --git a/maven-java-11/multimodule-maven-project/userdaomodule/pom.xml b/maven-java-11/multimodule-maven-project/userdaomodule/pom.xml new file mode 100644 index 0000000000..b4fe7f0398 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/userdaomodule/pom.xml @@ -0,0 +1,31 @@ + + + 4.0.0 + + com.baeldung.multimodule-maven-project + multimodule-maven-project + 1.0 + + com.baeldung.userdaomodule + userdaomodule + 1.0 + jar + userdaomodule + + + com.baeldung.entitymodule + entitymodule + 1.0 + + + com.baeldung.daomodule + daomodule + 1.0 + + + junit + junit + test + + + diff --git a/maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/com/baeldung/userdao/UserDao.java b/maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/com/baeldung/userdao/UserDao.java new file mode 100644 index 0000000000..1f1ea38a60 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/com/baeldung/userdao/UserDao.java @@ -0,0 +1,32 @@ +package com.baeldung.userdao; + +import com.baeldung.dao.Dao; +import com.baeldung.entity.User; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +public class UserDao implements Dao { + + private final Map users; + + public UserDao() { + users = new HashMap<>(); + } + + public UserDao(Map users) { + this.users = users; + } + + @Override + public List findAll() { + return new ArrayList<>(users.values()); + } + + @Override + public Optional findById(int id) { + return Optional.ofNullable(users.get(id)); + } +} \ No newline at end of file diff --git a/maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/module-info.java b/maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/module-info.java new file mode 100644 index 0000000000..f1cb217e23 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/userdaomodule/src/main/java/module-info.java @@ -0,0 +1,6 @@ +module com.baeldung.userdao { + requires com.baeldung.entity; + requires com.baeldung.dao; + provides com.baeldung.dao.Dao with com.baeldung.userdao.UserDao; + exports com.baeldung.userdao; +} diff --git a/maven-java-11/multimodule-maven-project/userdaomodule/src/test/java/com/baeldung/userdao/test/UserDaoUnitTest.java b/maven-java-11/multimodule-maven-project/userdaomodule/src/test/java/com/baeldung/userdao/test/UserDaoUnitTest.java new file mode 100644 index 0000000000..191d17ff32 --- /dev/null +++ b/maven-java-11/multimodule-maven-project/userdaomodule/src/test/java/com/baeldung/userdao/test/UserDaoUnitTest.java @@ -0,0 +1,36 @@ +package com.baeldung.userdao.test; + +import com.baeldung.dao.Dao; +import com.baeldung.entity.User; +import com.baeldung.userdao.UserDao; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import static org.junit.Assert.*; +import static org.hamcrest.CoreMatchers.*; +import org.junit.Before; +import org.junit.Test; + +public class UserDaoUnitTest { + + private Dao userDao; + + @Before + public void setUpUserDaoInstance() { + Map users = new HashMap<>(); + users.put(1, new User("Julie")); + users.put(2, new User("David")); + userDao = new UserDao(users); + } + + @Test + public void givenUserDaoIntance_whenCalledFindById_thenCorrect() { + assertThat(userDao.findById(1), isA(Optional.class)); + } + + @Test + public void givenUserDaoIntance_whenCalledFindAll_thenCorrect() { + assertThat(userDao.findAll(), isA(List.class)); + } +} diff --git a/maven-java-11/pom.xml b/maven-java-11/pom.xml new file mode 100644 index 0000000000..4342fa740f --- /dev/null +++ b/maven-java-11/pom.xml @@ -0,0 +1,22 @@ + + + 4.0.0 + com.baeldung.maven-java-11 + maven-java-11 + 1.0 + pom + maven-java-11 + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + + + multimodule-maven-project + + + UTF-8 + 11 + 11 + + diff --git a/pom.xml b/pom.xml index 901bc94f96..4590056154 100644 --- a/pom.xml +++ b/pom.xml @@ -1170,6 +1170,7 @@ mapstruct maven + maven-java-11 maven-archetype maven-polyglot/maven-polyglot-json-extension From a89a07db5fab44296bb8bbf7d8005653b80cd213 Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Wed, 24 Apr 2019 13:49:04 +0000 Subject: [PATCH 38/53] [BAEL-2732] Adding in BSON examples from article --- persistence-modules/java-mongodb/pom.xml | 4 +- .../java/com/baeldung/MongoBsonExample.java | 79 +++++++++++++++++++ 2 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 persistence-modules/java-mongodb/src/main/java/com/baeldung/MongoBsonExample.java diff --git a/persistence-modules/java-mongodb/pom.xml b/persistence-modules/java-mongodb/pom.xml index 9658ef567f..0f5efedb96 100644 --- a/persistence-modules/java-mongodb/pom.xml +++ b/persistence-modules/java-mongodb/pom.xml @@ -35,8 +35,8 @@ 1.8 1.8 - 3.4.1 + 3.10.1 1.11 - \ No newline at end of file + diff --git a/persistence-modules/java-mongodb/src/main/java/com/baeldung/MongoBsonExample.java b/persistence-modules/java-mongodb/src/main/java/com/baeldung/MongoBsonExample.java new file mode 100644 index 0000000000..0ad3dfae30 --- /dev/null +++ b/persistence-modules/java-mongodb/src/main/java/com/baeldung/MongoBsonExample.java @@ -0,0 +1,79 @@ +package com.baeldung; + +import com.mongodb.client.MongoClient; +import com.mongodb.client.MongoClients; +import com.mongodb.client.MongoCollection; +import com.mongodb.client.MongoDatabase; +import org.bson.Document; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class MongoBsonExample +{ + public static void main(String[] args) + { + // + // 4.1 Connect to cluster (default is localhost:27017) + // + + MongoClient mongoClient = MongoClients.create(); + MongoDatabase database = mongoClient.getDatabase("myDB"); + MongoCollection collection = database.getCollection("employees"); + + // + // 4.2 Insert new document + // + + Document employee = new Document() + .append("first_name", "Joe") + .append("last_name", "Smith") + .append("title", "Java Developer") + .append("years_of_service", 3) + .append("skills", Arrays.asList("java", "spring", "mongodb")) + .append("manager", new Document() + .append("first_name", "Sally") + .append("last_name", "Johanson")); + collection.insertOne(employee); + + // + // 4.3 Find documents + // + + + Document query = new Document("last_name", "Smith"); + List results = new ArrayList<>(); + collection.find(query).into(results); + + query = + new Document("$or", Arrays.asList( + new Document("last_name", "Smith"), + new Document("first_name", "Joe"))); + results = new ArrayList<>(); + collection.find(query).into(results); + + // + // 4.4 Update document + // + + query = new Document( + "skills", + new Document( + "$elemMatch", + new Document("$eq", "spring"))); + Document update = new Document( + "$push", + new Document("skills", "security")); + collection.updateMany(query, update); + + // + // 4.5 Delete documents + // + + query = new Document( + "years_of_service", + new Document("$lt", 0)); + collection.deleteMany(query); + } +} From b798326b2960404c7c2438c1c814655e034d3190 Mon Sep 17 00:00:00 2001 From: Seun Matt Date: Wed, 24 Apr 2019 16:05:24 +0100 Subject: [PATCH 39/53] improvement BAEL-2897 (#6795) * added example code for BAEL-2083 * updated example code for BAEL-2083 * added example code for BAEL-2849 * updated the example code with data.sql * improvement BAEL-2897 * updated the persistence module * updated readme --- persistence-modules/pom.xml | 2 +- .../.gitignore | 0 .../{spring-boot-h2 => spring-boot-persistence-h2}/README.md | 1 + .../pom.xml | 2 +- .../baeldung/h2db/auto/configuration/AutoConfigurationDemo.java | 0 .../java/com/baeldung/h2db/demo/client/ClientSpringBootApp.java | 0 .../main/java/com/baeldung/h2db/demo/server/SpringBootApp.java | 0 .../com/baeldung/h2db/springboot/SpringBootH2Application.java | 0 .../java/com/baeldung/h2db/springboot/daos/UserRepository.java | 0 .../src/main/java/com/baeldung/h2db/springboot/models/User.java | 0 .../src/main/resources/application.properties | 0 .../src/main/resources/data.sql | 0 .../src/test/java/com/baeldung/SpringBootH2IntegrationTest.java | 0 .../test/java/com/baeldung/SpringContextIntegrationTest.java | 0 14 files changed, 3 insertions(+), 2 deletions(-) rename persistence-modules/{spring-boot-h2/spring-boot-h2-database => spring-boot-persistence-h2}/.gitignore (100%) rename persistence-modules/{spring-boot-h2 => spring-boot-persistence-h2}/README.md (67%) rename persistence-modules/{spring-boot-h2/spring-boot-h2-database => spring-boot-persistence-h2}/pom.xml (97%) rename persistence-modules/{spring-boot-h2/spring-boot-h2-database => spring-boot-persistence-h2}/src/main/java/com/baeldung/h2db/auto/configuration/AutoConfigurationDemo.java (100%) rename persistence-modules/{spring-boot-h2/spring-boot-h2-database => spring-boot-persistence-h2}/src/main/java/com/baeldung/h2db/demo/client/ClientSpringBootApp.java (100%) rename persistence-modules/{spring-boot-h2/spring-boot-h2-database => spring-boot-persistence-h2}/src/main/java/com/baeldung/h2db/demo/server/SpringBootApp.java (100%) rename persistence-modules/{spring-boot-h2/spring-boot-h2-database => spring-boot-persistence-h2}/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java (100%) rename persistence-modules/{spring-boot-h2/spring-boot-h2-database => spring-boot-persistence-h2}/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java (100%) rename persistence-modules/{spring-boot-h2/spring-boot-h2-database => spring-boot-persistence-h2}/src/main/java/com/baeldung/h2db/springboot/models/User.java (100%) rename persistence-modules/{spring-boot-h2/spring-boot-h2-database => spring-boot-persistence-h2}/src/main/resources/application.properties (100%) rename persistence-modules/{spring-boot-h2/spring-boot-h2-database => spring-boot-persistence-h2}/src/main/resources/data.sql (100%) rename persistence-modules/{spring-boot-h2/spring-boot-h2-database => spring-boot-persistence-h2}/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java (100%) rename persistence-modules/{spring-boot-h2/spring-boot-h2-database => spring-boot-persistence-h2}/src/test/java/com/baeldung/SpringContextIntegrationTest.java (100%) diff --git a/persistence-modules/pom.xml b/persistence-modules/pom.xml index ee55325b20..67a5c36fed 100644 --- a/persistence-modules/pom.xml +++ b/persistence-modules/pom.xml @@ -35,7 +35,7 @@ querydsl redis solr - spring-boot-h2/spring-boot-h2-database + spring-boot-persistence-h2 spring-boot-persistence spring-boot-persistence-mongodb spring-data-cassandra diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/.gitignore b/persistence-modules/spring-boot-persistence-h2/.gitignore similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/.gitignore rename to persistence-modules/spring-boot-persistence-h2/.gitignore diff --git a/persistence-modules/spring-boot-h2/README.md b/persistence-modules/spring-boot-persistence-h2/README.md similarity index 67% rename from persistence-modules/spring-boot-h2/README.md rename to persistence-modules/spring-boot-persistence-h2/README.md index af5f395440..377b7c8939 100644 --- a/persistence-modules/spring-boot-h2/README.md +++ b/persistence-modules/spring-boot-persistence-h2/README.md @@ -1,2 +1,3 @@ ### Relevant Articles: - [Access the Same In-Memory H2 Database in Multiple Spring Boot Applications](https://www.baeldung.com/spring-boot-access-h2-database-multiple-apps) +- [Spring Boot With H2 Database](https://www.baeldung.com/spring-boot-h2-database) \ No newline at end of file diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/pom.xml b/persistence-modules/spring-boot-persistence-h2/pom.xml similarity index 97% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/pom.xml rename to persistence-modules/spring-boot-persistence-h2/pom.xml index 882b88b535..4c8073ddb4 100644 --- a/persistence-modules/spring-boot-h2/spring-boot-h2-database/pom.xml +++ b/persistence-modules/spring-boot-persistence-h2/pom.xml @@ -14,7 +14,7 @@ parent-boot-2 com.baeldung 0.0.1-SNAPSHOT - ../../../parent-boot-2 + ../../parent-boot-2 diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/auto/configuration/AutoConfigurationDemo.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/auto/configuration/AutoConfigurationDemo.java similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/auto/configuration/AutoConfigurationDemo.java rename to persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/auto/configuration/AutoConfigurationDemo.java diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/demo/client/ClientSpringBootApp.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/demo/client/ClientSpringBootApp.java similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/demo/client/ClientSpringBootApp.java rename to persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/demo/client/ClientSpringBootApp.java diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/demo/server/SpringBootApp.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/demo/server/SpringBootApp.java similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/demo/server/SpringBootApp.java rename to persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/demo/server/SpringBootApp.java diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java rename to persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/SpringBootH2Application.java diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java rename to persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/daos/UserRepository.java diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/models/User.java b/persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/User.java similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/java/com/baeldung/h2db/springboot/models/User.java rename to persistence-modules/spring-boot-persistence-h2/src/main/java/com/baeldung/h2db/springboot/models/User.java diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/resources/application.properties b/persistence-modules/spring-boot-persistence-h2/src/main/resources/application.properties similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/resources/application.properties rename to persistence-modules/spring-boot-persistence-h2/src/main/resources/application.properties diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/resources/data.sql b/persistence-modules/spring-boot-persistence-h2/src/main/resources/data.sql similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/main/resources/data.sql rename to persistence-modules/spring-boot-persistence-h2/src/main/resources/data.sql diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java b/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java rename to persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringBootH2IntegrationTest.java diff --git a/persistence-modules/spring-boot-h2/spring-boot-h2-database/src/test/java/com/baeldung/SpringContextIntegrationTest.java b/persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringContextIntegrationTest.java similarity index 100% rename from persistence-modules/spring-boot-h2/spring-boot-h2-database/src/test/java/com/baeldung/SpringContextIntegrationTest.java rename to persistence-modules/spring-boot-persistence-h2/src/test/java/com/baeldung/SpringContextIntegrationTest.java From fb70eda7b8d348729b4c28c115e61b2d3c9207be Mon Sep 17 00:00:00 2001 From: Sam Millington Date: Wed, 24 Apr 2019 18:53:46 +0100 Subject: [PATCH 40/53] [BAEL-2835] Added Guide to FastUtil code (#6805) --- fastUtil/pom.xml | 44 ++++++++++++++ .../java/com/baeldung/BigArraysUnitTest.java | 23 ++++++++ ...FastUtilTypeSpecificBenchmarkUnitTest.java | 58 +++++++++++++++++++ .../FastUtilTypeSpecificUnitTest.java | 20 +++++++ 4 files changed, 145 insertions(+) create mode 100644 fastUtil/pom.xml create mode 100644 fastUtil/src/test/java/com/baeldung/BigArraysUnitTest.java create mode 100644 fastUtil/src/test/java/com/baeldung/FastUtilTypeSpecificBenchmarkUnitTest.java create mode 100644 fastUtil/src/test/java/com/baeldung/FastUtilTypeSpecificUnitTest.java diff --git a/fastUtil/pom.xml b/fastUtil/pom.xml new file mode 100644 index 0000000000..fcd9020747 --- /dev/null +++ b/fastUtil/pom.xml @@ -0,0 +1,44 @@ + + + 4.0.0 + + com.baeldung + fastUtil + 1.0-SNAPSHOT + + + + + it.unimi.dsi + fastutil + 8.2.2 + + + + junit + junit + 4.12 + test + + + + org.openjdk.jmh + jmh-core + 1.19 + test + + + org.openjdk.jmh + jmh-generator-annprocess + 1.19 + test + + + + + + + + \ No newline at end of file diff --git a/fastUtil/src/test/java/com/baeldung/BigArraysUnitTest.java b/fastUtil/src/test/java/com/baeldung/BigArraysUnitTest.java new file mode 100644 index 0000000000..a794d1a2f6 --- /dev/null +++ b/fastUtil/src/test/java/com/baeldung/BigArraysUnitTest.java @@ -0,0 +1,23 @@ +package com.baeldung; + +import it.unimi.dsi.fastutil.ints.IntBigArrays; +import org.junit.Test; + +import static junit.framework.Assert.assertEquals; + +public class BigArraysUnitTest { + + @Test + public void givenValidAray_whenWrapped_checkAccessFromIntBigArraysMethodsCorrect() { + int[] oneDArray = new int[] { 2, 1, 5, 2, 1, 7 }; + int[][] twoDArray = IntBigArrays.wrap(oneDArray.clone()); + + int firstIndex = IntBigArrays.get(twoDArray, 0); + int lastIndex = IntBigArrays.get(twoDArray, IntBigArrays.length(twoDArray)-1); + + assertEquals(2, firstIndex); + assertEquals(7, lastIndex); + + } + +} diff --git a/fastUtil/src/test/java/com/baeldung/FastUtilTypeSpecificBenchmarkUnitTest.java b/fastUtil/src/test/java/com/baeldung/FastUtilTypeSpecificBenchmarkUnitTest.java new file mode 100644 index 0000000000..2c77989fe5 --- /dev/null +++ b/fastUtil/src/test/java/com/baeldung/FastUtilTypeSpecificBenchmarkUnitTest.java @@ -0,0 +1,58 @@ +package com.baeldung; + +import it.unimi.dsi.fastutil.ints.IntOpenHashSet; +import it.unimi.dsi.fastutil.ints.IntSet; +import org.openjdk.jmh.annotations.*; +import org.openjdk.jmh.infra.Blackhole; +import org.openjdk.jmh.runner.Runner; +import org.openjdk.jmh.runner.RunnerException; +import org.openjdk.jmh.runner.options.Options; +import org.openjdk.jmh.runner.options.OptionsBuilder; + +import java.util.*; +import java.util.concurrent.TimeUnit; + +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.MICROSECONDS) +@State(Scope.Benchmark) +public class FastUtilTypeSpecificBenchmarkUnitTest { + + @Param({"100", "1000", "10000", "100000"}) + public int setSize; + + @Benchmark + public IntSet givenFastUtilsIntSetWithInitialSizeSet_whenPopulated_checkTimeTaken() { + IntSet intSet = new IntOpenHashSet(setSize); + for(int i = 0; i < setSize; i++){ + intSet.add(i); + } + return intSet; + } + + + @Benchmark + public Set givenCollectionsHashSetWithInitialSizeSet_whenPopulated_checkTimeTaken() { + Set intSet = new HashSet(setSize); + for(int i = 0; i < setSize; i++){ + intSet.add(i); + } + return intSet; + } + + public static void main(String... args) throws RunnerException { + Options opts = new OptionsBuilder() + .include(".*") + .warmupIterations(1) + .measurementIterations(2) + .jvmArgs("-Xms2g", "-Xmx2g") + .shouldDoGC(true) + .forks(1) + .build(); + + new Runner(opts).run(); + } + + + + +} diff --git a/fastUtil/src/test/java/com/baeldung/FastUtilTypeSpecificUnitTest.java b/fastUtil/src/test/java/com/baeldung/FastUtilTypeSpecificUnitTest.java new file mode 100644 index 0000000000..61295cc6f1 --- /dev/null +++ b/fastUtil/src/test/java/com/baeldung/FastUtilTypeSpecificUnitTest.java @@ -0,0 +1,20 @@ +package com.baeldung; + +import it.unimi.dsi.fastutil.doubles.Double2DoubleMap; +import it.unimi.dsi.fastutil.doubles.Double2DoubleOpenHashMap; +import org.junit.Test; + +import static junit.framework.Assert.assertEquals; + + +public class FastUtilTypeSpecificUnitTest { + + @Test + public void givenValidDouble2DoubleMap_whenContentsQueried_checkCorrect(){ + Double2DoubleMap d2dMap = new Double2DoubleOpenHashMap(); + d2dMap.put(2.0, 5.5); + d2dMap.put(3.0, 6.6); + assertEquals(5.5, d2dMap.get(2.0)); + } + +} From cf98eefb624296a7301247fdc723c4725537b166 Mon Sep 17 00:00:00 2001 From: Muhammad Asif Anwar Date: Wed, 24 Apr 2019 21:55:46 +0400 Subject: [PATCH 41/53] gitflow-incremental-builder upgrade (#6811) --- pom.xml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 4590056154..745275488c 100644 --- a/pom.xml +++ b/pom.xml @@ -1498,8 +1498,9 @@ UTF-8 UTF-8 - refs/remotes/origin/master - true + refs/remotes/origin/master + true + false false false false @@ -1540,7 +1541,7 @@ 0.3.1 2.5.1 0.0.1 - 3.4 + 3.8 2.3 3.8 From d5ba7790ef71f3611b4ffce2e41f746fbedd4c9c Mon Sep 17 00:00:00 2001 From: kwoyke Date: Wed, 24 Apr 2019 20:02:04 +0200 Subject: [PATCH 42/53] BAEL-2855 Add a new section in ConfigurationProperties article (#6808) --- .../baeldung/properties/ConfigProperties.java | 7 +++++ .../java/org/baeldung/properties/Item.java | 31 +++++++++++++++++++ .../src/main/resources/configprops.properties | 4 +++ .../ConfigPropertiesIntegrationTest.java | 7 +++++ .../resources/configprops-test.properties | 3 ++ 5 files changed, 52 insertions(+) create mode 100644 spring-boot/src/main/java/org/baeldung/properties/Item.java diff --git a/spring-boot/src/main/java/org/baeldung/properties/ConfigProperties.java b/spring-boot/src/main/java/org/baeldung/properties/ConfigProperties.java index 3698d8ef30..1a3c985fe4 100644 --- a/spring-boot/src/main/java/org/baeldung/properties/ConfigProperties.java +++ b/spring-boot/src/main/java/org/baeldung/properties/ConfigProperties.java @@ -9,6 +9,7 @@ import javax.validation.constraints.NotBlank; import javax.validation.constraints.Pattern; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.validation.annotation.Validated; @@ -80,4 +81,10 @@ public class ConfigProperties { public void setCredentials(Credentials credentials) { this.credentials = credentials; } + + @Bean + @ConfigurationProperties(prefix = "item") + public Item item(){ + return new Item(); + } } diff --git a/spring-boot/src/main/java/org/baeldung/properties/Item.java b/spring-boot/src/main/java/org/baeldung/properties/Item.java new file mode 100644 index 0000000000..0314654ada --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/properties/Item.java @@ -0,0 +1,31 @@ +package org.baeldung.properties; + +public class Item { + + private String name; + private int size; + + public Item() { + } + + public Item(String name, int size) { + this.name = name; + this.size = size; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getSize() { + return size; + } + + public void setSize(int size) { + this.size = size; + } +} diff --git a/spring-boot/src/main/resources/configprops.properties b/spring-boot/src/main/resources/configprops.properties index 2dad11f9cc..424b3632f9 100644 --- a/spring-boot/src/main/resources/configprops.properties +++ b/spring-boot/src/main/resources/configprops.properties @@ -17,4 +17,8 @@ mail.credentials.username=john mail.credentials.password=password mail.credentials.authMethod=SHA1 +#Bean method properties +item.name=Item name +item.size=42 + diff --git a/spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java index 4ba6bf29d8..f864fd4f8c 100644 --- a/spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/properties/ConfigPropertiesIntegrationTest.java @@ -53,4 +53,11 @@ public class ConfigPropertiesIntegrationTest { Assert.assertEquals("Incorrectly bound object property, username", "john", credentials.getUsername()); Assert.assertEquals("Incorrectly bound object property, password", "password", credentials.getPassword()); } + + @Test + public void whenBeanMethodAnnotatedThenPropertiesCorrectlyBound(){ + Item item = properties.item(); + Assert.assertEquals("Incorrectly bound object property, item.name","Test item name", item.getName()); + Assert.assertEquals("Incorrectly bound object property, item.size", 21, item.getSize()); + } } diff --git a/spring-boot/src/test/resources/configprops-test.properties b/spring-boot/src/test/resources/configprops-test.properties index 697771ae6e..ea11f2159e 100644 --- a/spring-boot/src/test/resources/configprops-test.properties +++ b/spring-boot/src/test/resources/configprops-test.properties @@ -17,3 +17,6 @@ mail.credentials.username=john mail.credentials.password=password mail.credentials.authMethod=SHA1 +#Bean method properties +item.name=Test item name +item.size=21 From 786fa105559831e6777234a331dd23720c23ec64 Mon Sep 17 00:00:00 2001 From: macroscopic64 Date: Thu, 25 Apr 2019 06:53:50 +0530 Subject: [PATCH 43/53] [BAEL-2073] Java 9 Migration Issues and Resolution --- core-java-modules/pom.xml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 core-java-modules/pom.xml diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml new file mode 100644 index 0000000000..ad49cceb9d --- /dev/null +++ b/core-java-modules/pom.xml @@ -0,0 +1,19 @@ + + + 4.0.0 + core-java-modules + core-java-modules + pom + + + parent-modules + com.baeldung + 1.0.0-SNAPSHOT + + + + pre-jpms + + + \ No newline at end of file From 156f9b69067a00de1ca67ba2cfae4b357e073f4f Mon Sep 17 00:00:00 2001 From: eric-martin Date: Wed, 24 Apr 2019 22:53:09 -0500 Subject: [PATCH 44/53] BAEL-2800: Moved core-java-collections-map to java-collections-maps-2 --- core-java-collections-map/README.md | 6 -- core-java-collections-map/pom.xml | 78 ------------------- java-collections-maps-2/pom.xml | 13 ++++ .../java/com/baeldung/map}/CopyHashMap.java | 2 +- .../baeldung/map}/CopyHashMapUnitTest.java | 2 +- .../test/java/com/baeldung/map}/Employee.java | 2 +- pom.xml | 2 - 7 files changed, 16 insertions(+), 89 deletions(-) delete mode 100644 core-java-collections-map/README.md delete mode 100644 core-java-collections-map/pom.xml rename {core-java-collections-map/src/main/java/com/baeldung/copyinghashmap => java-collections-maps-2/src/main/java/com/baeldung/map}/CopyHashMap.java (98%) rename {core-java-collections-map/src/test/java/com/baeldung/copyinghashmap => java-collections-maps-2/src/test/java/com/baeldung/map}/CopyHashMapUnitTest.java (98%) rename {core-java-collections-map/src/test/java/com/baeldung/copyinghashmap => java-collections-maps-2/src/test/java/com/baeldung/map}/Employee.java (91%) diff --git a/core-java-collections-map/README.md b/core-java-collections-map/README.md deleted file mode 100644 index da02928118..0000000000 --- a/core-java-collections-map/README.md +++ /dev/null @@ -1,6 +0,0 @@ -========= - -## Core Java Collections 2 - -### Relevant Articles: -- Java - Copying a HashMap diff --git a/core-java-collections-map/pom.xml b/core-java-collections-map/pom.xml deleted file mode 100644 index 8c0aef54bf..0000000000 --- a/core-java-collections-map/pom.xml +++ /dev/null @@ -1,78 +0,0 @@ - - 4.0.0 - core-java-collections-map - 0.1.0-SNAPSHOT - core-java-collections-map - jar - - - com.baeldung - parent-java - 0.0.1-SNAPSHOT - ../parent-java - - - - - org.apache.commons - commons-collections4 - ${commons-collections4.version} - - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - - - org.eclipse.collections - eclipse-collections - ${eclipse.collections.version} - - - org.assertj - assertj-core - ${assertj.version} - test - - - org.junit.platform - junit-platform-runner - ${junit.platform.version} - test - - - org.openjdk.jmh - jmh-core - ${openjdk.jmh.version} - - - org.openjdk.jmh - jmh-generator-annprocess - ${openjdk.jmh.version} - - - org.apache.commons - commons-exec - ${commons-exec.version} - - - org.projectlombok - lombok - ${lombok.version} - provided - - - - - 1.19 - 1.2.0 - 3.8.1 - 4.1 - 4.01 - 1.7.0 - 3.11.1 - 7.1.0 - 1.3 - - diff --git a/java-collections-maps-2/pom.xml b/java-collections-maps-2/pom.xml index 4ab94a7ae3..5f27eaa2d8 100644 --- a/java-collections-maps-2/pom.xml +++ b/java-collections-maps-2/pom.xml @@ -36,6 +36,17 @@ colt ${colt.version} + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + + + org.assertj + assertj-core + ${assertj.version} + test + @@ -43,6 +54,8 @@ 3.0.2 8.1.0 1.2.0 + 3.8.1 + 3.11.1 \ No newline at end of file diff --git a/core-java-collections-map/src/main/java/com/baeldung/copyinghashmap/CopyHashMap.java b/java-collections-maps-2/src/main/java/com/baeldung/map/CopyHashMap.java similarity index 98% rename from core-java-collections-map/src/main/java/com/baeldung/copyinghashmap/CopyHashMap.java rename to java-collections-maps-2/src/main/java/com/baeldung/map/CopyHashMap.java index e1649f593c..2ebc9413c8 100644 --- a/core-java-collections-map/src/main/java/com/baeldung/copyinghashmap/CopyHashMap.java +++ b/java-collections-maps-2/src/main/java/com/baeldung/map/CopyHashMap.java @@ -1,4 +1,4 @@ -package com.baeldung.copyinghashmap; +package com.baeldung.map; import java.util.HashMap; import java.util.Map; diff --git a/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/CopyHashMapUnitTest.java b/java-collections-maps-2/src/test/java/com/baeldung/map/CopyHashMapUnitTest.java similarity index 98% rename from core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/CopyHashMapUnitTest.java rename to java-collections-maps-2/src/test/java/com/baeldung/map/CopyHashMapUnitTest.java index 400696d97a..c400eea153 100644 --- a/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/CopyHashMapUnitTest.java +++ b/java-collections-maps-2/src/test/java/com/baeldung/map/CopyHashMapUnitTest.java @@ -1,4 +1,4 @@ -package com.baeldung.copyinghashmap; +package com.baeldung.map; import static org.assertj.core.api.Assertions.assertThat; diff --git a/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/Employee.java b/java-collections-maps-2/src/test/java/com/baeldung/map/Employee.java similarity index 91% rename from core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/Employee.java rename to java-collections-maps-2/src/test/java/com/baeldung/map/Employee.java index b47fdc768e..7963fa811c 100644 --- a/core-java-collections-map/src/test/java/com/baeldung/copyinghashmap/Employee.java +++ b/java-collections-maps-2/src/test/java/com/baeldung/map/Employee.java @@ -1,4 +1,4 @@ -package com.baeldung.copyinghashmap; +package com.baeldung.map; import java.io.Serializable; diff --git a/pom.xml b/pom.xml index 745275488c..49313d9d2b 100644 --- a/pom.xml +++ b/pom.xml @@ -387,7 +387,6 @@ core-java-arrays core-java-collections - core-java-collections-map core-java-collections-list core-java-collections-set core-java-concurrency-basic @@ -1058,7 +1057,6 @@ core-java-arrays core-java-collections - core-java-collections-map core-java-collections-list core-java-collections-set core-java-concurrency-basic From db614845279fb83631f152b49e920d8fbf50954d Mon Sep 17 00:00:00 2001 From: Josephine Barboza Date: Thu, 25 Apr 2019 23:33:54 +0530 Subject: [PATCH 45/53] BAEL-2766 Added core-groovy-collections module --- core-groovy-collections/README.md | 6 + core-groovy-collections/pom.xml | 131 ++++++++++++++++ .../groovy/com/baeldung/map/MapTest.groovy | 148 ++++++++++++++++++ pom.xml | 2 + 4 files changed, 287 insertions(+) create mode 100644 core-groovy-collections/README.md create mode 100644 core-groovy-collections/pom.xml create mode 100644 core-groovy-collections/src/test/groovy/com/baeldung/map/MapTest.groovy diff --git a/core-groovy-collections/README.md b/core-groovy-collections/README.md new file mode 100644 index 0000000000..482e33bce1 --- /dev/null +++ b/core-groovy-collections/README.md @@ -0,0 +1,6 @@ +# Groovy + +## Relevant articles: + +- [Maps in Groovy](http://www.baeldung.com/) + diff --git a/core-groovy-collections/pom.xml b/core-groovy-collections/pom.xml new file mode 100644 index 0000000000..bf3ae26592 --- /dev/null +++ b/core-groovy-collections/pom.xml @@ -0,0 +1,131 @@ + + + 4.0.0 + core-groovy-collections + 1.0-SNAPSHOT + core-groovy-collections + jar + + + com.baeldung + parent-modules + 1.0.0-SNAPSHOT + + + + + org.codehaus.groovy + groovy + ${groovy.version} + + + org.codehaus.groovy + groovy-all + ${groovy-all.version} + pom + + + org.codehaus.groovy + groovy-dateutil + ${groovy.version} + + + org.codehaus.groovy + groovy-sql + ${groovy-sql.version} + + + org.junit.platform + junit-platform-runner + ${junit.platform.version} + test + + + org.hsqldb + hsqldb + ${hsqldb.version} + test + + + org.spockframework + spock-core + ${spock-core.version} + test + + + + + + + org.codehaus.gmavenplus + gmavenplus-plugin + ${gmavenplus-plugin.version} + + + + addSources + addTestSources + compile + compileTests + + + + + + maven-failsafe-plugin + ${maven-failsafe-plugin.version} + + + org.junit.platform + junit-platform-surefire-provider + ${junit.platform.version} + + + + + junit5 + + integration-test + verify + + + + **/*Test5.java + + + + + + + maven-surefire-plugin + 2.20.1 + + false + + **/*Test.java + **/*Spec.java + + + + + + + + + central + http://jcenter.bintray.com + + + + + 1.0.0 + 2.5.6 + 2.5.6 + 2.5.6 + 2.4.0 + 1.1-groovy-2.4 + 1.6 + + + diff --git a/core-groovy-collections/src/test/groovy/com/baeldung/map/MapTest.groovy b/core-groovy-collections/src/test/groovy/com/baeldung/map/MapTest.groovy new file mode 100644 index 0000000000..c6105eb1c4 --- /dev/null +++ b/core-groovy-collections/src/test/groovy/com/baeldung/map/MapTest.groovy @@ -0,0 +1,148 @@ +package com.baeldung.map; + +import static groovy.test.GroovyAssert.* +import org.junit.Test + +class MapTest{ + + @Test + void createMap() { + + def emptyMap = [:] + assertNotNull(emptyMap) + + assertTrue(emptyMap instanceof java.util.LinkedHashMap) + + def map = [name:"Jerry", age: 42, city: "New York"] + assertTrue(map.size() == 3) + } + + @Test + void addItemsToMap() { + + def map = [name:"Jerry"] + + map["age"] = 42 + + map.city = "New York" + + def hobbyLiteral = "hobby" + def hobbyMap = [(hobbyLiteral): "Singing"] + map.putAll(hobbyMap) + + assertTrue(map == [name:"Jerry", age: 42, city: "New York", hobby:"Singing"]) + assertTrue(hobbyMap.hobby == "Singing") + assertTrue(hobbyMap[hobbyLiteral] == "Singing") + + map.plus([1:20]) // returns new map + + map << [2:30] + + } + + @Test + void getItemsFromMap() { + + def map = [name:"Jerry", age: 42, city: "New York", hobby:"Singing"] + + assertTrue(map["name"] == "Jerry") + + assertTrue(map.name == "Jerry") + + def propertyAge = "age" + assertTrue(map[propertyAge] == 42) + } + + @Test + void removeItemsFromMap() { + + def map = [1:20, a:30, 2:42, 4:34, ba:67, 6:39, 7:49] + + def minusMap = map.minus([2:42, 4:34]); + assertTrue(minusMap == [1:20, a:30, ba:67, 6:39, 7:49]) + + minusMap.removeAll{it -> it.key instanceof String} + assertTrue( minusMap == [ 1:20, 6:39, 7:49]) + + minusMap.retainAll{it -> it.value %2 == 0} + assertTrue( minusMap == [1:20]) + } + + @Test + void iteratingOnMaps(){ + def map = [name:"Jerry", age: 42, city: "New York", hobby:"Singing"] + + map.each{ entry -> println "$entry.key: $entry.value" } + + map.eachWithIndex{ entry, i -> println "$i $entry.key: $entry.value" } + + map.eachWithIndex{ key, value, i -> println "$i $key: $value" } + } + + @Test + void filteringAndSearchingMaps(){ + def map = [name:"Jerry", age: 42, city: "New York", hobby:"Singing"] + + assertTrue(map.find{ it.value == "New York"}.key == "city") + + assertTrue(map.findAll{ it.value == "New York"} == [city : "New York"]) + + map.grep{it.value == "New York"}.each{ it -> assertTrue(it.key == "city" && it.value == "New York")} + + assertTrue(map.every{it -> it.value instanceof String} == false) + + assertTrue(map.any{it -> it.value instanceof String} == true) + } + + @Test + void collect(){ + + def map = [1: [name:"Jerry", age: 42, city: "New York"], + 2: [name:"Long", age: 25, city: "New York"], + 3: [name:"Dustin", age: 29, city: "New York"], + 4: [name:"Dustin", age: 34, city: "New York"]] + + def names = map.collect{entry -> entry.value.name} // returns only list + assertTrue(names == ["Jerry", "Long", "Dustin", "Dustin"]) + + def uniqueNames = map.collect([] as HashSet){entry -> entry.value.name} + assertTrue(uniqueNames == ["Jerry", "Long", "Dustin"] as Set) + + def idNames = map.collectEntries{key, value -> [key, value.name]} + assertTrue(idNames == [1:"Jerry", 2: "Long", 3:"Dustin", 4: "Dustin"]) + + def below30Names = map.findAll{it.value.age < 30}.collect{key, value -> value.name} + assertTrue(below30Names == ["Long", "Dustin"]) + + + } + + @Test + void group(){ + def map = [1:20, 2: 40, 3: 11, 4: 93] + + def subMap = map.groupBy{it.value % 2} + println subMap + assertTrue(subMap == [0:[1:20, 2:40 ], 1:[3:11, 4:93]]) + + def keySubMap = map.subMap([1, 2]) + assertTrue(keySubMap == [1:20, 2:40]) + + } + + @Test + void sorting(){ + def map = [ab:20, a: 40, cb: 11, ba: 93] + + def naturallyOrderedMap = map.sort() + assertTrue([a:40, ab:20, ba:93, cb:11] == naturallyOrderedMap) + + def compSortedMap = map.sort({ k1, k2 -> k1 <=> k2 } as Comparator) + assertTrue([a:40, ab:20, ba:93, cb:11] == compSortedMap) + + def cloSortedMap = map.sort({ it1, it2 -> it1.value <=> it1.value }) + assertTrue([cb:11, ab:20, a:40, ba:93] == cloSortedMap) + + } + +} diff --git a/pom.xml b/pom.xml index 64710a39a6..c67374e5d0 100644 --- a/pom.xml +++ b/pom.xml @@ -377,6 +377,7 @@ checker-plugin core-groovy core-groovy-2 + core-groovy-collections @@ -1051,6 +1052,7 @@ checker-plugin core-groovy core-groovy-2 + core-groovy-collections core-java-8 From 46f5e0dc939fe40326bc16fafa5e6b77d177e74f Mon Sep 17 00:00:00 2001 From: isaolmez Date: Fri, 26 Apr 2019 11:10:34 +0300 Subject: [PATCH 46/53] BAEL-2809: Added code samples --- .../JpaBatchInsertsIntegrationTest.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java index dd61b7b6df..9e81dbc04d 100644 --- a/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java +++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java @@ -9,6 +9,7 @@ import java.util.List; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.TypedQuery; +import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; @@ -27,16 +28,16 @@ public class JpaBatchInsertsIntegrationTest { private static final int BATCH_SIZE = 5; + @Transactional @Test public void whenInsertingSingleTypeOfEntity_thenCreatesSingleBatch() { for (int i = 0; i < 10; i++) { School school = createSchool(i); entityManager.persist(school); } - - entityManager.flush(); } + @Transactional @Test public void whenFlushingAfterBatch_ThenClearsMemory() { for (int i = 0; i < 10; i++) { @@ -48,10 +49,9 @@ public class JpaBatchInsertsIntegrationTest { School school = createSchool(i); entityManager.persist(school); } - - entityManager.flush(); } + @Transactional @Test public void whenThereAreMultipleEntities_ThenCreatesNewBatch() { for (int i = 0; i < 10; i++) { @@ -67,10 +67,9 @@ public class JpaBatchInsertsIntegrationTest { entityManager.persist(firstStudent); entityManager.persist(secondStudent); } - - entityManager.flush(); } + @Transactional @Test public void whenUpdatingEntities_thenCreatesBatch() { for (int i = 0; i < 10; i++) { @@ -86,7 +85,10 @@ public class JpaBatchInsertsIntegrationTest { for (School school : allSchools) { school.setName("Updated_" + school.getName()); } + } + @After + public void tearDown() { entityManager.flush(); } } From adb8759e3028b0858ac8982ac08bf7303f9e4e5e Mon Sep 17 00:00:00 2001 From: Loredana Date: Fri, 26 Apr 2019 14:30:12 +0300 Subject: [PATCH 47/53] refactor module spring-boot-ex --- pom.xml | 5 ++- .../.gitignore | 0 .../pom.xml | 43 ------------------- ...tionToClientJsonSpringBootApplication.java | 13 ------ .../MainControllerIntegrationTest.java | 16 ------- spring-boot-exceptions/pom.xml | 37 ++++++++++++++++ .../jsonexception}/CustomException.java | 2 +- .../baeldung/jsonexception}/ErrorHandler.java | 2 +- .../jsonexception/JsonErrorApplication.java | 13 ++++++ .../jsonexception}/MainController.java | 2 +- .../src/main/resources/application.properties | 0 .../src/main/resources/static/.gitignore | 0 .../src/main/resources/templates/.gitignore | 0 .../MainControllerIntegrationTest.java | 19 ++++++++ .../SpringContextIntegrationTest.java} | 10 ++--- 15 files changed, 81 insertions(+), 81 deletions(-) rename spring-boot-exceptions/{pass-exception-to-client-json-spring-boot => }/.gitignore (100%) delete mode 100644 spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml delete mode 100644 spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/PassExceptionToClientJsonSpringBootApplication.java delete mode 100644 spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/test/java/com/baeldung/passexceptiontoclientjsonspringboot/MainControllerIntegrationTest.java create mode 100644 spring-boot-exceptions/pom.xml rename spring-boot-exceptions/{pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot => src/main/java/com/baeldung/jsonexception}/CustomException.java (77%) rename spring-boot-exceptions/{pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot => src/main/java/com/baeldung/jsonexception}/ErrorHandler.java (90%) create mode 100644 spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/JsonErrorApplication.java rename spring-boot-exceptions/{pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot => src/main/java/com/baeldung/jsonexception}/MainController.java (82%) rename spring-boot-exceptions/{pass-exception-to-client-json-spring-boot => }/src/main/resources/application.properties (100%) rename spring-boot-exceptions/{pass-exception-to-client-json-spring-boot => }/src/main/resources/static/.gitignore (100%) rename spring-boot-exceptions/{pass-exception-to-client-json-spring-boot => }/src/main/resources/templates/.gitignore (100%) create mode 100644 spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/MainControllerIntegrationTest.java rename spring-boot-exceptions/{pass-exception-to-client-json-spring-boot/src/test/java/com/baeldung/passexceptiontoclientjsonspringboot/PassExceptionToClientJsonSpringBootApplicationTests.java => src/test/java/com/baeldung/jsonexception/SpringContextIntegrationTest.java} (58%) diff --git a/pom.xml b/pom.xml index 17ab605e7a..4344347d18 100644 --- a/pom.xml +++ b/pom.xml @@ -628,6 +628,7 @@ spring-boot-custom-starter spring-boot-disable-console-logging + spring-boot-exceptions spring-boot-jasypt spring-boot-keycloak spring-boot-logging-log4j2 @@ -825,7 +826,8 @@ spring-boot-client spring-boot-configuration spring-boot-custom-starter - greeter-spring-boot-autoconfigure + spring-boot-exceptions + greeter-spring-boot-autoconfigure greeter-spring-boot-sample-app persistence-modules/spring-boot-h2/spring-boot-h2-database spring-boot-jasypt @@ -1286,6 +1288,7 @@ spring-boot-ctx-fluent spring-boot-custom-starter spring-boot-disable-console-logging + spring-boot-exceptions spring-boot-jasypt spring-boot-keycloak diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/.gitignore b/spring-boot-exceptions/.gitignore similarity index 100% rename from spring-boot-exceptions/pass-exception-to-client-json-spring-boot/.gitignore rename to spring-boot-exceptions/.gitignore diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml deleted file mode 100644 index 8237955aef..0000000000 --- a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/pom.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - 4.0.0 - - org.springframework.boot - spring-boot-starter-parent - 2.1.4.RELEASE - - - com.baeldung - pass-exception-to-client-json-spring-boot - 0.0.4-SNAPSHOT - pass-exception-to-client-json-spring-boot - Baeldung article code on how to pass exceptions to client in JSON format using Spring Boot - - - 1.8 - - - - - org.springframework.boot - spring-boot-starter-web - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - - - org.springframework.boot - spring-boot-maven-plugin - - - - - diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/PassExceptionToClientJsonSpringBootApplication.java b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/PassExceptionToClientJsonSpringBootApplication.java deleted file mode 100644 index 77833c28fd..0000000000 --- a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/PassExceptionToClientJsonSpringBootApplication.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.baeldung.passexceptiontoclientjsonspringboot; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; - -@SpringBootApplication -public class PassExceptionToClientJsonSpringBootApplication { - - public static void main(String[] args) { - SpringApplication.run(PassExceptionToClientJsonSpringBootApplication.class, args); - } - -} \ No newline at end of file diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/test/java/com/baeldung/passexceptiontoclientjsonspringboot/MainControllerIntegrationTest.java b/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/test/java/com/baeldung/passexceptiontoclientjsonspringboot/MainControllerIntegrationTest.java deleted file mode 100644 index a615dc5096..0000000000 --- a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/test/java/com/baeldung/passexceptiontoclientjsonspringboot/MainControllerIntegrationTest.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.passexceptiontoclientjsonspringboot; - -import org.junit.Test; - -public class MainControllerIntegrationTest { - - @Test(expected = CustomException.class) - public void givenIndex_thenCustomException() throws CustomException { - - MainController mainController = new MainController(); - - mainController.index(); - - } - -} \ No newline at end of file diff --git a/spring-boot-exceptions/pom.xml b/spring-boot-exceptions/pom.xml new file mode 100644 index 0000000000..105f60e295 --- /dev/null +++ b/spring-boot-exceptions/pom.xml @@ -0,0 +1,37 @@ + + + 4.0.0 + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 + + + com.baeldung + spring-boot-exceptions + 0.0.4-SNAPSHOT + pass-exception-to-client-json-spring-boot + Baeldung article code on how to pass exceptions to client in JSON format using Spring Boot + + + 1.8 + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + + diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/CustomException.java b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/CustomException.java similarity index 77% rename from spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/CustomException.java rename to spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/CustomException.java index 56fe80cd9a..f1a1d94f54 100644 --- a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/CustomException.java +++ b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/CustomException.java @@ -1,4 +1,4 @@ -package com.baeldung.passexceptiontoclientjsonspringboot; +package com.baeldung.jsonexception; public class CustomException extends RuntimeException { diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/ErrorHandler.java b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/ErrorHandler.java similarity index 90% rename from spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/ErrorHandler.java rename to spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/ErrorHandler.java index b39d2811dd..a890dfa3a2 100644 --- a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/ErrorHandler.java +++ b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/ErrorHandler.java @@ -1,4 +1,4 @@ -package com.baeldung.passexceptiontoclientjsonspringboot; +package com.baeldung.jsonexception; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ControllerAdvice; diff --git a/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/JsonErrorApplication.java b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/JsonErrorApplication.java new file mode 100644 index 0000000000..188584bd7c --- /dev/null +++ b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/JsonErrorApplication.java @@ -0,0 +1,13 @@ +package com.baeldung.jsonexception; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class JsonErrorApplication { + + public static void main(String[] args) { + SpringApplication.run(JsonErrorApplication.class, args); + } + +} \ No newline at end of file diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/MainController.java b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/MainController.java similarity index 82% rename from spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/MainController.java rename to spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/MainController.java index 82c0c022a8..5d73c239a4 100644 --- a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/java/com/baeldung/passexceptiontoclientjsonspringboot/MainController.java +++ b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/MainController.java @@ -1,4 +1,4 @@ -package com.baeldung.passexceptiontoclientjsonspringboot; +package com.baeldung.jsonexception; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/resources/application.properties b/spring-boot-exceptions/src/main/resources/application.properties similarity index 100% rename from spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/resources/application.properties rename to spring-boot-exceptions/src/main/resources/application.properties diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/resources/static/.gitignore b/spring-boot-exceptions/src/main/resources/static/.gitignore similarity index 100% rename from spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/resources/static/.gitignore rename to spring-boot-exceptions/src/main/resources/static/.gitignore diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/resources/templates/.gitignore b/spring-boot-exceptions/src/main/resources/templates/.gitignore similarity index 100% rename from spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/main/resources/templates/.gitignore rename to spring-boot-exceptions/src/main/resources/templates/.gitignore diff --git a/spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/MainControllerIntegrationTest.java b/spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/MainControllerIntegrationTest.java new file mode 100644 index 0000000000..77e71b7d21 --- /dev/null +++ b/spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/MainControllerIntegrationTest.java @@ -0,0 +1,19 @@ +package com.baeldung.jsonexception; + +import org.junit.Test; + +import com.baeldung.jsonexception.CustomException; +import com.baeldung.jsonexception.MainController; + +public class MainControllerIntegrationTest { + + @Test(expected = CustomException.class) + public void givenIndex_thenCustomException() throws CustomException { + + MainController mainController = new MainController(); + + mainController.index(); + + } + +} \ No newline at end of file diff --git a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/test/java/com/baeldung/passexceptiontoclientjsonspringboot/PassExceptionToClientJsonSpringBootApplicationTests.java b/spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/SpringContextIntegrationTest.java similarity index 58% rename from spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/test/java/com/baeldung/passexceptiontoclientjsonspringboot/PassExceptionToClientJsonSpringBootApplicationTests.java rename to spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/SpringContextIntegrationTest.java index 5e35c21f4c..aa91e242ab 100644 --- a/spring-boot-exceptions/pass-exception-to-client-json-spring-boot/src/test/java/com/baeldung/passexceptiontoclientjsonspringboot/PassExceptionToClientJsonSpringBootApplicationTests.java +++ b/spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/SpringContextIntegrationTest.java @@ -1,4 +1,4 @@ -package com.baeldung.passexceptiontoclientjsonspringboot; +package com.baeldung.jsonexception; import org.junit.Test; import org.junit.runner.RunWith; @@ -7,10 +7,10 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest -public class PassExceptionToClientJsonSpringBootApplicationTests { +public class SpringContextIntegrationTest { - @Test - public void contextLoads() { - } + @Test + public void contextLoads() { + } } From 7c73610226936b6283bad8d8164b7f7410e8c1e2 Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 26 Apr 2019 22:57:17 +0300 Subject: [PATCH 48/53] Update SpringContextIntegrationTest.java --- .../springbootconfiguration/SpringContextIntegrationTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/spring-boot-ops-2/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java b/spring-boot-ops-2/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java index 8ae49f6696..24bef73ef9 100644 --- a/spring-boot-ops-2/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java +++ b/spring-boot-ops-2/src/test/java/com/baeldung/springbootconfiguration/SpringContextIntegrationTest.java @@ -12,5 +12,4 @@ public class SpringContextIntegrationTest { @Test public void contextLoads() { } - } From 7cca99a327cce4cb69bc053e1b2da85e999fe3ab Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Fri, 26 Apr 2019 22:58:57 +0300 Subject: [PATCH 49/53] Update README.md --- libraries-security/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/libraries-security/README.md b/libraries-security/README.md index 6923e0474e..b9bbf11cdf 100644 --- a/libraries-security/README.md +++ b/libraries-security/README.md @@ -2,3 +2,4 @@ - [Guide to ScribeJava](https://www.baeldung.com/scribejava) - [Guide to Passay](https://www.baeldung.com/java-passay) +- [Guide to Google Tink](https://www.baeldung.com/google-tink) From 1e65e6a7b8d68a6cbd6d6a1ba71b885713ec2a0a Mon Sep 17 00:00:00 2001 From: Loredana Crusoveanu Date: Sat, 27 Apr 2019 00:03:46 +0300 Subject: [PATCH 50/53] Update pom.xml --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 4344347d18..a43e2d65c4 100644 --- a/pom.xml +++ b/pom.xml @@ -1175,7 +1175,7 @@ mapstruct maven - maven-java-11 + maven-archetype maven-polyglot/maven-polyglot-json-extension From 5ef87d3a2d05285532825b88c00035665688de1d Mon Sep 17 00:00:00 2001 From: Alejandro Gervasio Date: Sat, 27 Apr 2019 02:42:17 -0300 Subject: [PATCH 51/53] Update pom.xml --- maven-java-11/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maven-java-11/pom.xml b/maven-java-11/pom.xml index 4342fa740f..ff95840523 100644 --- a/maven-java-11/pom.xml +++ b/maven-java-11/pom.xml @@ -12,7 +12,7 @@ 1.0.0-SNAPSHOT - multimodule-maven-project + multimodule-maven-project UTF-8 From 4de89f8a63f6d3249cc0f2aff96b577f095d723c Mon Sep 17 00:00:00 2001 From: dupirefr Date: Sat, 27 Apr 2019 08:02:14 +0200 Subject: [PATCH 52/53] [BAEL-2843] Fixed some tests to match articles updates --- .../com/baeldung/java8/optional/OptionalUnitTest.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/core-java-8/src/test/java/com/baeldung/java8/optional/OptionalUnitTest.java b/core-java-8/src/test/java/com/baeldung/java8/optional/OptionalUnitTest.java index 4cb2551fae..bd7943c77b 100644 --- a/core-java-8/src/test/java/com/baeldung/java8/optional/OptionalUnitTest.java +++ b/core-java-8/src/test/java/com/baeldung/java8/optional/OptionalUnitTest.java @@ -27,34 +27,35 @@ public class OptionalUnitTest { @Test public void givenNonNull_whenCreatesNonNullable_thenCorrect() { String name = "baeldung"; - Optional.of(name); + Optional opt = Optional.of(name); + assertTrue(opt.isPresent()); } @Test(expected = NullPointerException.class) public void givenNull_whenThrowsErrorOnCreate_thenCorrect() { String name = null; - Optional opt = Optional.of(name); + Optional.of(name); } @Test public void givenNonNull_whenCreatesOptional_thenCorrect() { String name = "baeldung"; Optional opt = Optional.of(name); - assertEquals("Optional[baeldung]", opt.toString()); + assertTrue(opt.isPresent()); } @Test public void givenNonNull_whenCreatesNullable_thenCorrect() { String name = "baeldung"; Optional opt = Optional.ofNullable(name); - assertEquals("Optional[baeldung]", opt.toString()); + assertTrue(opt.isPresent()); } @Test public void givenNull_whenCreatesNullable_thenCorrect() { String name = null; Optional opt = Optional.ofNullable(name); - assertEquals("Optional.empty", opt.toString()); + assertFalse(opt.isPresent()); } // Checking Value With isPresent() From e84255194b921a3e0c21422f30141534bbaeddea Mon Sep 17 00:00:00 2001 From: Johan Janssen Date: Sun, 28 Apr 2019 05:01:11 +0200 Subject: [PATCH 53/53] Added Maven profiles example. (#6833) --- maven/profiles/pom.xml | 88 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 maven/profiles/pom.xml diff --git a/maven/profiles/pom.xml b/maven/profiles/pom.xml new file mode 100644 index 0000000000..110016f3a2 --- /dev/null +++ b/maven/profiles/pom.xml @@ -0,0 +1,88 @@ + + 4.0.0 + com.baeldung + profiles + 0.0.1-SNAPSHOT + profiles + + + + no-tests + + true + + + + integration-tests + + true + + + + mutation-tests + + + active-on-jdk-11 + + 11 + + + + active-on-windows-10 + + + windows 10 + Windows + amd64 + 10.0 + + + + + active-on-property-environment + + + environment + !test + + + + + active-on-missing-file + + + target/testreport.html + + + + + active-on-present-file + + + target/artifact.jar + + + + + + + + + org.apache.maven.plugins + maven-help-plugin + 3.2.0 + + + show-profiles + compile + + active-profiles + + + + + + + \ No newline at end of file