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; diff --git a/cloud-foundry-uaa/README.md b/cloud-foundry-uaa/README.md new file mode 100644 index 0000000000..b2f382cad1 --- /dev/null +++ b/cloud-foundry-uaa/README.md @@ -0,0 +1,3 @@ +### Revelant Articles + +- [A Quick Guide To Using Cloud Foundry UAA](https://www.baeldung.com/cloud-foundry-uaa) 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/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..f1d528207f --- /dev/null +++ b/core-groovy/src/test/groovy/com/baeldung/map/MapTest.groovy @@ -0,0 +1,148 @@ +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"]) + 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/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() diff --git a/core-java-8/src/test/java/com/baeldung/reduceIfelse/CalculatorUnitTest.java b/core-java-8/src/test/java/com/baeldung/reduceIfelse/CalculatorUnitTest.java index fa351930d8..1ff34bee89 100644 --- a/core-java-8/src/test/java/com/baeldung/reduceIfelse/CalculatorUnitTest.java +++ b/core-java-8/src/test/java/com/baeldung/reduceIfelse/CalculatorUnitTest.java @@ -29,4 +29,11 @@ public class CalculatorUnitTest { int result = calculator.calculate(new AddCommand(3, 7)); assertEquals(10, result); } + + @Test + public void whenCalculateUsingFactory_thenReturnCorrectResult() { + Calculator calculator = new Calculator(); + int result = calculator.calculateUsingFactory(3, 4, "add"); + assertEquals(7, result); + } } 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..dcd61cdfa7 --- /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; + } + +} 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..f6f1f954f6 --- /dev/null +++ b/core-java-arrays/src/test/java/com/baeldung/array/AddElementToEndOfArrayUnitTest.java @@ -0,0 +1,49 @@ +package com.baeldung.array; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; + +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); + + Integer[] expectedArray = {1, 2, 3, 4, 5}; + assertArrayEquals(expectedArray, destArray); + } + + @Test + public void givenSourceArrayAndElement_whenAddElementUsingArrayListIsInvoked_thenNewElementMustBeAdded() { + Integer[] sourceArray = {1, 2, 3, 4}; + int elementToAdd = 5; + + Integer[] destArray = addElementToEndOfArray.addElementUsingArrayList(sourceArray, elementToAdd); + + Integer[] expectedArray = {1, 2, 3, 4, 5}; + assertArrayEquals(expectedArray, destArray); + } + + @Test + public void givenSourceArrayAndElement_whenAddElementUsingSystemArrayCopyIsInvoked_thenNewElementMustBeAdded() { + Integer[] sourceArray = {1, 2, 3, 4}; + int elementToAdd = 5; + + Integer[] destArray = addElementToEndOfArray.addElementUsingSystemArrayCopy(sourceArray, elementToAdd); + + Integer[] expectedArray = {1, 2, 3, 4, 5}; + assertArrayEquals(expectedArray, destArray); + } +} 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/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/core-java-lang-oop-2/README.md b/core-java-lang-oop-2/README.md index e309810ba2..af0aed5af3 100644 --- a/core-java-lang-oop-2/README.md +++ b/core-java-lang-oop-2/README.md @@ -3,3 +3,4 @@ ## Core Java Lang OOP 2 Cookbooks and Examples ### Relevant Articles: +- [Generic Constructors in Java](https://www.baeldung.com/java-generic-constructors) 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 diff --git a/core-java-modules/pre-jpms/pom.xml b/core-java-modules/pre-jpms/pom.xml new file mode 100644 index 0000000000..169cd21f3e --- /dev/null +++ b/core-java-modules/pre-jpms/pom.xml @@ -0,0 +1,74 @@ + + 4.0.0 + pre-jpms + 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/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/App.java b/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/App.java new file mode 100644 index 0000000000..1afaae30e4 --- /dev/null +++ b/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/App.java @@ -0,0 +1,77 @@ +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. JCE Provider Name: {}\n", new SunJCE().getName()); + } catch (Throwable e) { + LOGGER.error(e.toString()); + } + } + + private static void getCallStackClassNames() { + try { + StringBuffer sbStack = new StringBuffer(); + 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()); + } + } + + 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/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/Book.java b/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/Book.java new file mode 100644 index 0000000000..6780c73738 --- /dev/null +++ b/core-java-modules/pre-jpms/src/main/java/com/baeldung/prejpms/Book.java @@ -0,0 +1,37 @@ +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/core-java-modules/pre-jpms/src/main/resources/logback.xml b/core-java-modules/pre-jpms/src/main/resources/logback.xml new file mode 100644 index 0000000000..7c5914e58e --- /dev/null +++ b/core-java-modules/pre-jpms/src/main/resources/logback.xml @@ -0,0 +1,10 @@ + + + + [%level] %msg%n + + + + + + \ No newline at end of file diff --git a/core-java-networking/src/main/java/com/baeldung/networking/cookies/ProxyAcceptCookiePolicy.java b/core-java-networking/src/main/java/com/baeldung/networking/cookies/ProxyAcceptCookiePolicy.java index 0b5f6d7714..9fbbee8501 100644 --- a/core-java-networking/src/main/java/com/baeldung/networking/cookies/ProxyAcceptCookiePolicy.java +++ b/core-java-networking/src/main/java/com/baeldung/networking/cookies/ProxyAcceptCookiePolicy.java @@ -17,8 +17,8 @@ public class ProxyAcceptCookiePolicy implements CookiePolicy { host = uri.getHost(); } - if (!HttpCookie.domainMatches(acceptedProxy, host)) { - return false; + if (HttpCookie.domainMatches(acceptedProxy, host)) { + return true; } return CookiePolicy.ACCEPT_ORIGINAL_SERVER.shouldAccept(uri, cookie); 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 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) { +} 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)); + } + +} diff --git a/httpclient-simple/README.md b/httpclient-simple/README.md index d1224359e0..e2d000fb91 100644 --- a/httpclient-simple/README.md +++ b/httpclient-simple/README.md @@ -8,4 +8,8 @@ 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) +- [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) +- [Posting with HttpClient](https://www.baeldung.com/httpclient-post-http-request) 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/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 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/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..a5fc29b089 100644 --- a/httpclient/README.md +++ b/httpclient/README.md @@ -7,13 +7,10 @@ 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) - [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) 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)); } /** 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/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 diff --git a/libraries-apache-commons/src/main/java/com/baeldung/commons/beanutils/CourseService.java b/libraries-apache-commons/src/main/java/com/baeldung/commons/beanutils/CourseService.java index 538fa3accb..2c7644fd64 100644 --- a/libraries-apache-commons/src/main/java/com/baeldung/commons/beanutils/CourseService.java +++ b/libraries-apache-commons/src/main/java/com/baeldung/commons/beanutils/CourseService.java @@ -29,6 +29,6 @@ public class CourseService { } public static void copyProperties(Course course, CourseEntity courseEntity) throws IllegalAccessException, InvocationTargetException { - BeanUtils.copyProperties(course, courseEntity); + BeanUtils.copyProperties(courseEntity, course); } } diff --git a/libraries-apache-commons/src/test/java/com/baeldung/commons/beanutils/CourseServiceUnitTest.java b/libraries-apache-commons/src/test/java/com/baeldung/commons/beanutils/CourseServiceUnitTest.java index 833d91b2c4..224ee8404c 100644 --- a/libraries-apache-commons/src/test/java/com/baeldung/commons/beanutils/CourseServiceUnitTest.java +++ b/libraries-apache-commons/src/test/java/com/baeldung/commons/beanutils/CourseServiceUnitTest.java @@ -44,6 +44,8 @@ public class CourseServiceUnitTest { CourseEntity courseEntity = new CourseEntity(); CourseService.copyProperties(course, courseEntity); + Assert.assertNotNull(course.getName()); + Assert.assertNotNull(courseEntity.getName()); Assert.assertEquals(course.getName(), courseEntity.getName()); Assert.assertEquals(course.getCodes(), courseEntity.getCodes()); Assert.assertNull(courseEntity.getStudent("ST-1")); 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) 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..ff95840523 --- /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/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 diff --git a/patterns/design-patterns-2/README.md b/patterns/design-patterns-2/README.md new file mode 100644 index 0000000000..c2a75d4680 --- /dev/null +++ b/patterns/design-patterns-2/README.md @@ -0,0 +1,3 @@ +### Relevant Articles + +- [The Mediator Pattern in Java](https://www.baeldung.com/java-mediator-pattern) 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); + } +} 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 diff --git a/persistence-modules/spring-data-jpa-2/pom.xml b/persistence-modules/spring-data-jpa-2/pom.xml index 251007ba6d..fbc19810ef 100644 --- a/persistence-modules/spring-data-jpa-2/pom.xml +++ b/persistence-modules/spring-data-jpa-2/pom.xml @@ -26,6 +26,12 @@ h2 + + net.ttddyy + datasource-proxy + 1.4.1 + + com.fasterxml.jackson.core jackson-databind @@ -35,7 +41,5 @@ org.springframework spring-oxm - - \ 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..4141f5668e --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/main/resources/application-batchinserts.properties @@ -0,0 +1,6 @@ +spring.jpa.show-sql=false + +spring.jpa.properties.hibernate.jdbc.batch_size=5 +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 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..9e81dbc04d --- /dev/null +++ b/persistence-modules/spring-data-jpa-2/src/test/java/com/baeldung/batchinserts/JpaBatchInsertsIntegrationTest.java @@ -0,0 +1,94 @@ +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.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.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; + + @Transactional + @Test + public void whenInsertingSingleTypeOfEntity_thenCreatesSingleBatch() { + for (int i = 0; i < 10; i++) { + School school = createSchool(i); + entityManager.persist(school); + } + } + + @Transactional + @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); + } + } + + @Transactional + @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); + } + } + + @Transactional + @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()); + } + } + + @After + public void tearDown() { + 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; + } +} 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..de6f47d71d 100644 --- a/pom.xml +++ b/pom.xml @@ -12,6 +12,7 @@ lombok-custom + picocli @@ -377,6 +378,7 @@ checker-plugin core-groovy core-groovy-2 + core-groovy-collections @@ -387,8 +389,8 @@ core-java-arrays 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 @@ -397,6 +399,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 @@ -619,18 +622,20 @@ spring-boot-camel spring-boot-client - spring-boot-configuration + spring-boot-crud spring-boot-ctx-fluent spring-boot-custom-starter spring-boot-disable-console-logging + spring-boot-exceptions spring-boot-jasypt spring-boot-keycloak spring-boot-logging-log4j2 spring-boot-mvc spring-boot-mvc-birt spring-boot-ops + spring-boot-ops-2 spring-boot-rest spring-boot-data spring-boot-property-exp @@ -820,9 +825,9 @@ spring-boot-bootstrap spring-boot-camel 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 @@ -1049,6 +1054,7 @@ checker-plugin core-groovy core-groovy-2 + core-groovy-collections core-java-8 @@ -1057,8 +1063,8 @@ core-java-arrays 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 @@ -1067,6 +1073,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 @@ -1168,6 +1175,7 @@ mapstruct maven + maven-archetype maven-polyglot/maven-polyglot-json-extension @@ -1275,11 +1283,11 @@ spring-boot-camel spring-boot-client - spring-boot-configuration spring-boot-crud spring-boot-ctx-fluent spring-boot-custom-starter spring-boot-disable-console-logging + spring-boot-exceptions spring-boot-jasypt spring-boot-keycloak @@ -1287,6 +1295,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 @@ -1495,8 +1504,9 @@ UTF-8 UTF-8 - refs/remotes/origin/master - true + refs/remotes/origin/master + true + false false false false @@ -1537,7 +1547,7 @@ 0.3.1 2.5.1 0.0.1 - 3.4 + 3.8 2.3 3.8 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; +} 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-exceptions/.gitignore similarity index 100% rename from spring-boot-configuration/.gitignore rename to spring-boot-exceptions/.gitignore 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/src/main/java/com/baeldung/jsonexception/CustomException.java b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/CustomException.java new file mode 100644 index 0000000000..f1a1d94f54 --- /dev/null +++ b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/CustomException.java @@ -0,0 +1,11 @@ +package com.baeldung.jsonexception; + +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/src/main/java/com/baeldung/jsonexception/ErrorHandler.java b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/ErrorHandler.java new file mode 100644 index 0000000000..a890dfa3a2 --- /dev/null +++ b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/ErrorHandler.java @@ -0,0 +1,19 @@ +package com.baeldung.jsonexception; + +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 +@ResponseBody +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/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/src/main/java/com/baeldung/jsonexception/MainController.java b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/MainController.java new file mode 100644 index 0000000000..5d73c239a4 --- /dev/null +++ b/spring-boot-exceptions/src/main/java/com/baeldung/jsonexception/MainController.java @@ -0,0 +1,14 @@ +package com.baeldung.jsonexception; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class MainController { + + @GetMapping("/") + public void index() throws CustomException { + throw new CustomException(); + } + +} \ No newline at end of file diff --git a/spring-boot-configuration/src/main/resources/application.properties b/spring-boot-exceptions/src/main/resources/application.properties similarity index 100% rename from spring-boot-configuration/src/main/resources/application.properties rename to spring-boot-exceptions/src/main/resources/application.properties diff --git a/spring-boot-exceptions/src/main/resources/static/.gitignore b/spring-boot-exceptions/src/main/resources/static/.gitignore new file mode 100644 index 0000000000..5e7d2734cf --- /dev/null +++ b/spring-boot-exceptions/src/main/resources/static/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/spring-boot-exceptions/src/main/resources/templates/.gitignore b/spring-boot-exceptions/src/main/resources/templates/.gitignore new file mode 100644 index 0000000000..5e7d2734cf --- /dev/null +++ b/spring-boot-exceptions/src/main/resources/templates/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.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/src/test/java/com/baeldung/jsonexception/SpringContextIntegrationTest.java b/spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/SpringContextIntegrationTest.java new file mode 100644 index 0000000000..aa91e242ab --- /dev/null +++ b/spring-boot-exceptions/src/test/java/com/baeldung/jsonexception/SpringContextIntegrationTest.java @@ -0,0 +1,16 @@ +package com.baeldung.jsonexception; + +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 SpringContextIntegrationTest { + + @Test + public void contextLoads() { + } + +} diff --git a/spring-boot-mvc-birt/README.md b/spring-boot-mvc-birt/README.md new file mode 100644 index 0000000000..9fe3d94e2a --- /dev/null +++ b/spring-boot-mvc-birt/README.md @@ -0,0 +1,3 @@ +### Relevant Articles + +- [BIRT Reporting with Spring Boot](https://www.baeldung.com/birt-reports-spring-boot) diff --git a/spring-boot-ops-2/.gitignore b/spring-boot-ops-2/.gitignore new file mode 100644 index 0000000000..153c9335eb --- /dev/null +++ b/spring-boot-ops-2/.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-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-ops-2/src/main/resources/application.properties b/spring-boot-ops-2/src/main/resources/application.properties new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/spring-boot-ops-2/src/main/resources/application.properties @@ -0,0 +1 @@ + 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..24bef73ef9 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,7 @@ import org.springframework.test.context.junit4.SpringRunner; @SpringBootTest public class SpringContextIntegrationTest { - @Test - public void contextLoads() { - } - + @Test + public void contextLoads() { + } } diff --git a/spring-boot-rest/README.md b/spring-boot-rest/README.md index 5abac75452..b28192cf62 100644 --- a/spring-boot-rest/README.md +++ b/spring-boot-rest/README.md @@ -7,10 +7,12 @@ Module for the articles that are part of the Spring REST E-book: 5. [Entity To DTO Conversion for a Spring REST API](https://www.baeldung.com/entity-to-and-from-dto-for-a-java-spring-application) 6. [Error Handling for REST with Spring](http://www.baeldung.com/exception-handling-for-rest-with-spring) 7. [REST API Discoverability and HATEOAS](http://www.baeldung.com/restful-web-service-discoverability) -8. [REST Pagination in Spring](http://www.baeldung.com/rest-api-pagination-in-spring) -9. [Test a REST API with Java](http://www.baeldung.com/integration-testing-a-rest-api) -10. [HATEOAS for a Spring REST Service](http://www.baeldung.com/rest-api-discoverability-with-spring) -11. [Versioning a REST API](http://www.baeldung.com/rest-versioning) -12. [ETags for REST with Spring](http://www.baeldung.com/etags-for-rest-with-spring) -13. [Testing REST with multiple MIME types](http://www.baeldung.com/testing-rest-api-with-multiple-media-types) -14. [Testing Web APIs with Postman Collections](https://www.baeldung.com/postman-testing-collections) +8. [An Intro to Spring HATEOAS](http://www.baeldung.com/spring-hateoas-tutorial) +9. [REST Pagination in Spring](http://www.baeldung.com/rest-api-pagination-in-spring) +10. [Test a REST API with Java](http://www.baeldung.com/integration-testing-a-rest-api) + +- [HATEOAS for a Spring REST Service](http://www.baeldung.com/rest-api-discoverability-with-spring) +- [Versioning a REST API](http://www.baeldung.com/rest-versioning) +- [ETags for REST with Spring](http://www.baeldung.com/etags-for-rest-with-spring) +- [Testing REST with multiple MIME types](http://www.baeldung.com/testing-rest-api-with-multiple-media-types) +- [Testing Web APIs with Postman Collections](https://www.baeldung.com/postman-testing-collections) diff --git a/spring-boot-rest/pom.xml b/spring-boot-rest/pom.xml index 2bf7c0181f..598b589ea0 100644 --- a/spring-boot-rest/pom.xml +++ b/spring-boot-rest/pom.xml @@ -44,6 +44,12 @@ org.springframework.boot spring-boot-starter-data-jpa + + + + org.springframework.boot + spring-boot-starter-hateoas + 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 diff --git a/spring-security-rest/src/main/java/org/baeldung/persistence/model/Customer.java b/spring-boot-rest/src/main/java/com/baeldung/persistence/model/Customer.java similarity index 97% rename from spring-security-rest/src/main/java/org/baeldung/persistence/model/Customer.java rename to spring-boot-rest/src/main/java/com/baeldung/persistence/model/Customer.java index b302ec057a..10da2e10f0 100644 --- a/spring-security-rest/src/main/java/org/baeldung/persistence/model/Customer.java +++ b/spring-boot-rest/src/main/java/com/baeldung/persistence/model/Customer.java @@ -1,4 +1,4 @@ -package org.baeldung.persistence.model; +package com.baeldung.persistence.model; import java.util.Map; diff --git a/spring-security-rest/src/main/java/org/baeldung/persistence/model/Order.java b/spring-boot-rest/src/main/java/com/baeldung/persistence/model/Order.java similarity index 96% rename from spring-security-rest/src/main/java/org/baeldung/persistence/model/Order.java rename to spring-boot-rest/src/main/java/com/baeldung/persistence/model/Order.java index ca551423e8..7aea9bce5c 100644 --- a/spring-security-rest/src/main/java/org/baeldung/persistence/model/Order.java +++ b/spring-boot-rest/src/main/java/com/baeldung/persistence/model/Order.java @@ -1,4 +1,4 @@ -package org.baeldung.persistence.model; +package com.baeldung.persistence.model; import org.springframework.hateoas.ResourceSupport; diff --git a/spring-security-rest/src/main/java/org/baeldung/web/service/CustomerService.java b/spring-boot-rest/src/main/java/com/baeldung/services/CustomerService.java similarity index 64% rename from spring-security-rest/src/main/java/org/baeldung/web/service/CustomerService.java rename to spring-boot-rest/src/main/java/com/baeldung/services/CustomerService.java index da016af2d5..a5e95e693b 100644 --- a/spring-security-rest/src/main/java/org/baeldung/web/service/CustomerService.java +++ b/spring-boot-rest/src/main/java/com/baeldung/services/CustomerService.java @@ -1,8 +1,8 @@ -package org.baeldung.web.service; +package com.baeldung.services; import java.util.List; -import org.baeldung.persistence.model.Customer; +import com.baeldung.persistence.model.Customer; public interface CustomerService { diff --git a/spring-security-rest/src/main/java/org/baeldung/web/service/CustomerServiceImpl.java b/spring-boot-rest/src/main/java/com/baeldung/services/CustomerServiceImpl.java similarity index 92% rename from spring-security-rest/src/main/java/org/baeldung/web/service/CustomerServiceImpl.java rename to spring-boot-rest/src/main/java/com/baeldung/services/CustomerServiceImpl.java index e179de2554..58030483ec 100644 --- a/spring-security-rest/src/main/java/org/baeldung/web/service/CustomerServiceImpl.java +++ b/spring-boot-rest/src/main/java/com/baeldung/services/CustomerServiceImpl.java @@ -1,12 +1,13 @@ -package org.baeldung.web.service; +package com.baeldung.services; import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import org.baeldung.persistence.model.Customer; import org.springframework.stereotype.Service; +import com.baeldung.persistence.model.Customer; + @Service public class CustomerServiceImpl implements CustomerService { diff --git a/spring-security-rest/src/main/java/org/baeldung/web/service/OrderService.java b/spring-boot-rest/src/main/java/com/baeldung/services/OrderService.java similarity index 70% rename from spring-security-rest/src/main/java/org/baeldung/web/service/OrderService.java rename to spring-boot-rest/src/main/java/com/baeldung/services/OrderService.java index 9a23488c50..775701e042 100644 --- a/spring-security-rest/src/main/java/org/baeldung/web/service/OrderService.java +++ b/spring-boot-rest/src/main/java/com/baeldung/services/OrderService.java @@ -1,8 +1,8 @@ -package org.baeldung.web.service; +package com.baeldung.services; import java.util.List; -import org.baeldung.persistence.model.Order; +import com.baeldung.persistence.model.Order; public interface OrderService { diff --git a/spring-security-rest/src/main/java/org/baeldung/web/service/OrderServiceImpl.java b/spring-boot-rest/src/main/java/com/baeldung/services/OrderServiceImpl.java similarity index 93% rename from spring-security-rest/src/main/java/org/baeldung/web/service/OrderServiceImpl.java rename to spring-boot-rest/src/main/java/com/baeldung/services/OrderServiceImpl.java index 0a6d4708a1..fffdf88969 100644 --- a/spring-security-rest/src/main/java/org/baeldung/web/service/OrderServiceImpl.java +++ b/spring-boot-rest/src/main/java/com/baeldung/services/OrderServiceImpl.java @@ -1,14 +1,15 @@ -package org.baeldung.web.service; +package com.baeldung.services; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.baeldung.persistence.model.Customer; -import org.baeldung.persistence.model.Order; import org.springframework.stereotype.Service; +import com.baeldung.persistence.model.Customer; +import com.baeldung.persistence.model.Order; + @Service public class OrderServiceImpl implements OrderService { diff --git a/spring-security-rest/src/main/java/org/baeldung/web/controller/CustomerController.java b/spring-boot-rest/src/main/java/com/baeldung/web/controller/CustomerController.java similarity index 64% rename from spring-security-rest/src/main/java/org/baeldung/web/controller/CustomerController.java rename to spring-boot-rest/src/main/java/com/baeldung/web/controller/CustomerController.java index e1db105d18..91aa9f2144 100644 --- a/spring-security-rest/src/main/java/org/baeldung/web/controller/CustomerController.java +++ b/spring-boot-rest/src/main/java/com/baeldung/web/controller/CustomerController.java @@ -1,24 +1,25 @@ -package org.baeldung.web.controller; +package com.baeldung.web.controller; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; import java.util.List; -import org.baeldung.persistence.model.Customer; -import org.baeldung.persistence.model.Order; -import org.baeldung.web.service.CustomerService; -import org.baeldung.web.service.OrderService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.hateoas.Link; import org.springframework.hateoas.Resources; import org.springframework.hateoas.config.EnableHypermediaSupport; import org.springframework.hateoas.config.EnableHypermediaSupport.HypermediaType; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import com.baeldung.persistence.model.Customer; +import com.baeldung.persistence.model.Order; +import com.baeldung.services.CustomerService; +import com.baeldung.services.OrderService; + @RestController @RequestMapping(value = "/customers") @EnableHypermediaSupport(type = HypermediaType.HAL) @@ -29,45 +30,49 @@ public class CustomerController { @Autowired private OrderService orderService; - @RequestMapping(value = "/{customerId}", method = RequestMethod.GET) + @GetMapping("/{customerId}") public Customer getCustomerById(@PathVariable final String customerId) { return customerService.getCustomerDetail(customerId); } - @RequestMapping(value = "/{customerId}/{orderId}", method = RequestMethod.GET) + @GetMapping("/{customerId}/{orderId}") public Order getOrderById(@PathVariable final String customerId, @PathVariable final String orderId) { return orderService.getOrderByIdForCustomer(customerId, orderId); } - @RequestMapping(value = "/{customerId}/orders", method = RequestMethod.GET , produces = {"application/hal+json"}) + @GetMapping(value = "/{customerId}/orders", produces = { "application/hal+json" }) public Resources getOrdersForCustomer(@PathVariable final String customerId) { final List orders = orderService.getAllOrdersForCustomer(customerId); for (final Order order : orders) { - final Link selfLink = linkTo(methodOn(CustomerController.class).getOrderById(customerId, order.getOrderId())).withSelfRel(); + final Link selfLink = linkTo( + methodOn(CustomerController.class).getOrderById(customerId, order.getOrderId())).withSelfRel(); order.add(selfLink); } - - Link link =linkTo(methodOn(CustomerController.class).getOrdersForCustomer(customerId)).withSelfRel(); - Resources result = new Resources<>(orders,link); + + Link link = linkTo(methodOn(CustomerController.class).getOrdersForCustomer(customerId)).withSelfRel(); + Resources result = new Resources<>(orders, link); return result; } - @RequestMapping(method = RequestMethod.GET, produces = {"application/hal+json"}) + @GetMapping(produces = { "application/hal+json" }) public Resources getAllCustomers() { final List allCustomers = customerService.allCustomers(); - + for (final Customer customer : allCustomers) { String customerId = customer.getCustomerId(); - Link selfLink = linkTo(CustomerController.class).slash(customerId).withSelfRel(); + Link selfLink = linkTo(CustomerController.class).slash(customerId) + .withSelfRel(); customer.add(selfLink); - if (orderService.getAllOrdersForCustomer(customerId).size() > 0) { - final Link ordersLink = linkTo(methodOn(CustomerController.class).getOrdersForCustomer(customerId)).withRel("allOrders"); + if (orderService.getAllOrdersForCustomer(customerId) + .size() > 0) { + final Link ordersLink = linkTo(methodOn(CustomerController.class).getOrdersForCustomer(customerId)) + .withRel("allOrders"); customer.add(ordersLink); } } - - Link link =linkTo(CustomerController.class).withSelfRel(); - Resources result = new Resources<>(allCustomers,link); + + Link link = linkTo(CustomerController.class).withSelfRel(); + Resources result = new Resources<>(allCustomers, link); return result; } diff --git a/spring-boot-rest/src/test/java/com/baeldung/springhateoas/CustomerControllerIntegrationTest.java b/spring-boot-rest/src/test/java/com/baeldung/springhateoas/CustomerControllerIntegrationTest.java new file mode 100644 index 0000000000..b08da6d2cd --- /dev/null +++ b/spring-boot-rest/src/test/java/com/baeldung/springhateoas/CustomerControllerIntegrationTest.java @@ -0,0 +1,98 @@ +package com.baeldung.springhateoas; + +import static org.hamcrest.Matchers.is; +import static org.mockito.BDDMockito.given; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +import java.util.Collections; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.hateoas.MediaTypes; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; + +import com.baeldung.persistence.model.Customer; +import com.baeldung.persistence.model.Order; +import com.baeldung.services.CustomerService; +import com.baeldung.services.OrderService; +import com.baeldung.web.controller.CustomerController; + +@RunWith(SpringRunner.class) +@WebMvcTest(CustomerController.class) +public class CustomerControllerIntegrationTest { + + @Autowired + private MockMvc mvc; + + @MockBean + private CustomerService customerService; + + @MockBean + private OrderService orderService; + + private static final String DEFAULT_CUSTOMER_ID = "customer1"; + private static final String DEFAULT_ORDER_ID = "order1"; + + @Test + public void givenExistingCustomer_whenCustomerRequested_thenResourceRetrieved() throws Exception { + given(this.customerService.getCustomerDetail(DEFAULT_CUSTOMER_ID)) + .willReturn(new Customer(DEFAULT_CUSTOMER_ID, "customerJohn", "companyOne")); + + this.mvc.perform(get("/customers/" + DEFAULT_CUSTOMER_ID)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$._links").doesNotExist()) + .andExpect(jsonPath("$.customerId", is(DEFAULT_CUSTOMER_ID))); + } + + @Test + public void givenExistingOrder_whenOrderRequested_thenResourceRetrieved() throws Exception { + given(this.orderService.getOrderByIdForCustomer(DEFAULT_CUSTOMER_ID, DEFAULT_ORDER_ID)) + .willReturn(new Order(DEFAULT_ORDER_ID, 1., 1)); + + this.mvc.perform(get("/customers/" + DEFAULT_CUSTOMER_ID + "/" + DEFAULT_ORDER_ID)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$._links").doesNotExist()) + .andExpect(jsonPath("$.orderId", is(DEFAULT_ORDER_ID))); + } + + @Test + public void givenExistingCustomerWithOrders_whenOrdersRequested_thenHalResourceRetrieved() throws Exception { + Order order1 = new Order(DEFAULT_ORDER_ID, 1., 1); + List orders = Collections.singletonList(order1); + given(this.orderService.getAllOrdersForCustomer(DEFAULT_CUSTOMER_ID)).willReturn(orders); + + this.mvc.perform(get("/customers/" + DEFAULT_CUSTOMER_ID + "/orders").accept(MediaTypes.HAL_JSON_VALUE)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$._embedded.orderList[0]._links.self.href", + is("http://localhost/customers/customer1/order1"))) + .andExpect(jsonPath("$._links.self.href", is("http://localhost/customers/customer1/orders"))); + } + + @Test + public void givenExistingCustomer_whenAllCustomersRequested_thenHalResourceRetrieved() throws Exception { + // customers + Customer retrievedCustomer = new Customer(DEFAULT_CUSTOMER_ID, "customerJohn", "companyOne"); + List customers = Collections.singletonList(retrievedCustomer); + given(this.customerService.allCustomers()).willReturn(customers); + // orders + Order order1 = new Order(DEFAULT_ORDER_ID, 1., 1); + List orders = Collections.singletonList(order1); + given(this.orderService.getAllOrdersForCustomer(DEFAULT_CUSTOMER_ID)).willReturn(orders); + + this.mvc.perform(get("/customers/").accept(MediaTypes.HAL_JSON_VALUE)) + .andExpect(status().isOk()) + .andExpect( + jsonPath("$._embedded.customerList[0]._links.self.href", is("http://localhost/customers/customer1"))) + .andExpect(jsonPath("$._embedded.customerList[0]._links.allOrders.href", + is("http://localhost/customers/customer1/orders"))) + .andExpect(jsonPath("$._links.self.href", is("http://localhost/customers"))); + } + +} 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 diff --git a/spring-cloud/spring-cloud-archaius/basic-config/src/test/java/com/baeldung/spring/cloud/archaius/basic/ArchaiusBasicConfigurationIntegrationTest.java b/spring-cloud/spring-cloud-archaius/basic-config/src/test/java/com/baeldung/spring/cloud/archaius/basic/ArchaiusBasicConfigurationIntegrationTest.java index 2948606c0b..d49a8dfa7e 100644 --- a/spring-cloud/spring-cloud-archaius/basic-config/src/test/java/com/baeldung/spring/cloud/archaius/basic/ArchaiusBasicConfigurationIntegrationTest.java +++ b/spring-cloud/spring-cloud-archaius/basic-config/src/test/java/com/baeldung/spring/cloud/archaius/basic/ArchaiusBasicConfigurationIntegrationTest.java @@ -5,21 +5,18 @@ import static org.assertj.core.api.Assertions.assertThat; import java.util.Collections; import org.junit.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.platform.runner.JUnitPlatform; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.util.TestPropertyValues; import org.springframework.cloud.context.environment.EnvironmentChangeEvent; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.springframework.test.context.junit4.SpringRunner; import com.netflix.config.DynamicPropertyFactory; import com.netflix.config.DynamicStringProperty; -@RunWith(JUnitPlatform.class) -@ExtendWith(SpringExtension.class) +@RunWith(SpringRunner.class) @SpringBootTest public class ArchaiusBasicConfigurationIntegrationTest { diff --git a/spring-cloud/spring-cloud-archaius/dynamodb-config/src/test/java/com/baeldung/spring/cloud/archaius/dynamosources/SpringContextLiveTest.java b/spring-cloud/spring-cloud-archaius/dynamodb-config/src/test/java/com/baeldung/spring/cloud/archaius/dynamosources/SpringContextLiveTest.java new file mode 100644 index 0000000000..a1a6c46c60 --- /dev/null +++ b/spring-cloud/spring-cloud-archaius/dynamodb-config/src/test/java/com/baeldung/spring/cloud/archaius/dynamosources/SpringContextLiveTest.java @@ -0,0 +1,20 @@ +package com.baeldung.spring.cloud.archaius.dynamosources; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * To run this Live Test we need to: + * * start a dynamodb instance locally on port 8000(e.g. with the following command `docker run -p 8000:8000 --name bael-dynamodb amazon/dynamodb-local`) + * + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = DynamoSourcesApplication.class) +public class SpringContextLiveTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/discovery/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-archaius/jdbc-config/src/test/java/com/baeldung/spring/cloud/archaius/jdbconfig/SpringContextIntegrationTest.java similarity index 70% rename from spring-cloud/spring-cloud-bootstrap/discovery/java/org/baeldung/SpringContextIntegrationTest.java rename to spring-cloud/spring-cloud-archaius/jdbc-config/src/test/java/com/baeldung/spring/cloud/archaius/jdbconfig/SpringContextIntegrationTest.java index 6016788eab..b3cd01e684 100644 --- a/spring-cloud/spring-cloud-bootstrap/discovery/java/org/baeldung/SpringContextIntegrationTest.java +++ b/spring-cloud/spring-cloud-archaius/jdbc-config/src/test/java/com/baeldung/spring/cloud/archaius/jdbconfig/SpringContextIntegrationTest.java @@ -1,17 +1,15 @@ -package org.baeldung; +package com.baeldung.spring.cloud.archaius.jdbconfig; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; -import com.baeldung.spring.cloud.bootstrap.config.ConfigApplication; - @RunWith(SpringRunner.class) -@SpringBootTest(classes = ConfigApplication.class) +@SpringBootTest(classes = JdbcSourcesApplication.class) public class SpringContextIntegrationTest { @Test public void whenSpringContextIsBootstrapped_thenNoExceptions() { } -} +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-archaius/zookeeper-config/src/test/java/com/baeldung/spring/cloud/archaius/zookeeperconfig/SpringContextLiveTest.java b/spring-cloud/spring-cloud-archaius/zookeeper-config/src/test/java/com/baeldung/spring/cloud/archaius/zookeeperconfig/SpringContextLiveTest.java new file mode 100644 index 0000000000..a827b8e27d --- /dev/null +++ b/spring-cloud/spring-cloud-archaius/zookeeper-config/src/test/java/com/baeldung/spring/cloud/archaius/zookeeperconfig/SpringContextLiveTest.java @@ -0,0 +1,20 @@ +package com.baeldung.spring.cloud.archaius.zookeeperconfig; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * This Live tTest requires: + * * A Zookeeper instance running locally on port 2181 (e.g. using `docker run --name bael-zookeeper -p 2181:2181 --restart always zookeeper`) + * + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = ZookeeperConfigApplication.class) +public class SpringContextLiveTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-aws/README.md b/spring-cloud/spring-cloud-aws/README.md index 36d0c7080e..3b7b4dbcd7 100644 --- a/spring-cloud/spring-cloud-aws/README.md +++ b/spring-cloud/spring-cloud-aws/README.md @@ -8,7 +8,7 @@ #### Running the Integration Tests -To run the Integration Tests, we need to have an AWS account and have API keys generated for programmatic access. Edit +To run the Live Tests, we need to have an AWS account and have API keys generated for programmatic access. Edit the `application.properties` file to add the following properties: ``` diff --git a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/SpringContextLiveTest.java b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/SpringContextLiveTest.java new file mode 100644 index 0000000000..90ad9c518c --- /dev/null +++ b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/SpringContextLiveTest.java @@ -0,0 +1,22 @@ +package com.baeldung.spring.cloud.aws; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +/** + * + * To run this Live Test, we need to have an AWS account and have API keys generated for programmatic access. + * + * Check the README file in this module for more information. + * + */ +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SpringCloudAwsApplication.class) +public class SpringContextLiveTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/ec2/EC2MetadataIntegrationTest.java b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/ec2/EC2MetadataLiveTest.java similarity index 86% rename from spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/ec2/EC2MetadataIntegrationTest.java rename to spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/ec2/EC2MetadataLiveTest.java index 1e75134194..853777ed25 100644 --- a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/ec2/EC2MetadataIntegrationTest.java +++ b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/ec2/EC2MetadataLiveTest.java @@ -16,12 +16,19 @@ import org.springframework.test.context.junit4.SpringRunner; import com.amazonaws.regions.Regions; import com.amazonaws.services.ec2.AmazonEC2; +/** + * + * To run this Live Test, we need to have an AWS account and have API keys generated for programmatic access. + * + * Check the README file in this module for more information. + * + */ @SpringBootTest @RunWith(SpringRunner.class) @TestPropertySource("classpath:application-test.properties") -public class EC2MetadataIntegrationTest { +public class EC2MetadataLiveTest { - private static final Logger logger = LoggerFactory.getLogger(EC2MetadataIntegrationTest.class); + private static final Logger logger = LoggerFactory.getLogger(EC2MetadataLiveTest.class); private boolean serverEc2; diff --git a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/rds/SpringCloudRDSIntegrationTest.java b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/rds/SpringCloudRDSLiveTest.java similarity index 85% rename from spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/rds/SpringCloudRDSIntegrationTest.java rename to spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/rds/SpringCloudRDSLiveTest.java index 9e163d6dc4..e7004c6b9f 100644 --- a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/rds/SpringCloudRDSIntegrationTest.java +++ b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/rds/SpringCloudRDSLiveTest.java @@ -14,9 +14,16 @@ import java.sql.Statement; import static org.assertj.core.api.Assertions.assertThat; +/** + * + * To run this Live Test, we need to have an AWS account and have API keys generated for programmatic access. + * + * Check the README file in this module for more information. + * + */ @SpringBootTest @RunWith(SpringRunner.class) -public class SpringCloudRDSIntegrationTest { +public class SpringCloudRDSLiveTest { @Autowired DataSource dataSource; diff --git a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/s3/SpringCloudS3IntegrationTest.java b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/s3/SpringCloudS3LiveTest.java similarity index 94% rename from spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/s3/SpringCloudS3IntegrationTest.java rename to spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/s3/SpringCloudS3LiveTest.java index a866287dec..dff3a06fe0 100644 --- a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/s3/SpringCloudS3IntegrationTest.java +++ b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/s3/SpringCloudS3LiveTest.java @@ -23,10 +23,17 @@ import java.util.UUID; import static org.assertj.core.api.Assertions.assertThat; +/** + * + * To run this Live Test, we need to have an AWS account and have API keys generated for programmatic access. + * + * Check the README file in this module for more information. + * + */ @SpringBootTest @RunWith(SpringRunner.class) @TestPropertySource("classpath:application-test.properties") -public class SpringCloudS3IntegrationTest { +public class SpringCloudS3LiveTest { @Autowired private SpringCloudS3 springCloudS3; diff --git a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sns/SpringCloudSNSIntegrationTest.java b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sns/SpringCloudSNSLiveTest.java similarity index 88% rename from spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sns/SpringCloudSNSIntegrationTest.java rename to spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sns/SpringCloudSNSLiveTest.java index e1f23d5c76..b773520089 100644 --- a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sns/SpringCloudSNSIntegrationTest.java +++ b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sns/SpringCloudSNSLiveTest.java @@ -16,10 +16,17 @@ import com.amazonaws.services.sns.model.CreateTopicResult; import com.baeldung.spring.cloud.aws.SpringCloudAwsTestUtil; import com.baeldung.spring.cloud.aws.sqs.Greeting; +/** + * + * To run this Live Test, we need to have an AWS account and have API keys generated for programmatic access. + * + * Check the README file in this module for more information. + * + */ @SpringBootTest @RunWith(SpringRunner.class) @TestPropertySource("classpath:application-test.properties") -public class SpringCloudSNSIntegrationTest { +public class SpringCloudSNSLiveTest { @Autowired private SNSMessageSender snsMessageSender; diff --git a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sqs/SpringCloudSQSIntegrationTest.java b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sqs/SpringCloudSQSLiveTest.java similarity index 95% rename from spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sqs/SpringCloudSQSIntegrationTest.java rename to spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sqs/SpringCloudSQSLiveTest.java index 76d2fd7c0d..24917e52f1 100644 --- a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sqs/SpringCloudSQSIntegrationTest.java +++ b/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/sqs/SpringCloudSQSLiveTest.java @@ -26,12 +26,19 @@ import java.util.concurrent.CountDownLatch; import static org.assertj.core.api.Assertions.assertThat; +/** + * + * To run this Live Test, we need to have an AWS account and have API keys generated for programmatic access. + * + * Check the README file in this module for more information. + * + */ @SpringBootTest @RunWith(SpringRunner.class) @TestPropertySource("classpath:application-test.properties") -public class SpringCloudSQSIntegrationTest { +public class SpringCloudSQSLiveTest { - private static final Logger logger = LoggerFactory.getLogger(SpringCloudSQSIntegrationTest.class); + private static final Logger logger = LoggerFactory.getLogger(SpringCloudSQSLiveTest.class); @Autowired @Lazy diff --git a/spring-cloud/spring-cloud-bootstrap/README.MD b/spring-cloud/spring-cloud-bootstrap/README.MD index 5185200469..7a3a94c8e3 100644 --- a/spring-cloud/spring-cloud-bootstrap/README.MD +++ b/spring-cloud/spring-cloud-bootstrap/README.MD @@ -6,7 +6,7 @@ - [Spring Cloud – Adding Angular 4](http://www.baeldung.com/spring-cloud-angular) - To run the project: - - copy the appliction-config folder to c:\Users\{username}\ on Windows or /Users/{username}/ on *nix. Then open a git bash terminal in application-config and run: + - copy the appliction-config folder to c:\Users\{username}\ on Windows or /home/{username}/ on *nix. Then open a git bash terminal in application-config and run: - git init - git add . - git commit -m "First commit" diff --git a/spring-cloud/spring-cloud-bootstrap/discovery/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-bootstrap/discovery/src/test/java/org/baeldung/SpringContextLiveTest.java similarity index 70% rename from spring-cloud/spring-cloud-bootstrap/discovery/src/test/java/org/baeldung/SpringContextIntegrationTest.java rename to spring-cloud/spring-cloud-bootstrap/discovery/src/test/java/org/baeldung/SpringContextLiveTest.java index 1e2db33395..e4e2e95e04 100644 --- a/spring-cloud/spring-cloud-bootstrap/discovery/src/test/java/org/baeldung/SpringContextIntegrationTest.java +++ b/spring-cloud/spring-cloud-bootstrap/discovery/src/test/java/org/baeldung/SpringContextLiveTest.java @@ -7,9 +7,15 @@ import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.spring.cloud.bootstrap.discovery.DiscoveryApplication; +/** + * + * This Live Test requires: + * * A Redis instance running in port 6379 (e.g. using `docker run --name some-redis -p 6379:6379 -d redis`) + * + */ @RunWith(SpringRunner.class) @SpringBootTest(classes = DiscoveryApplication.class) -public class SpringContextIntegrationTest { +public class SpringContextLiveTest { @Test public void whenSpringContextIsBootstrapped_thenNoExceptions() { diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml b/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml index 2efa926e3a..4f9c60a26a 100644 --- a/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/gateway/pom.xml @@ -98,6 +98,6 @@ - Brixton.SR7 + Dalston.RELEASE \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/GatewayApplication.java b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/GatewayApplication.java index 10ed66bfd4..79785a3f20 100644 --- a/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/GatewayApplication.java +++ b/spring-cloud/spring-cloud-bootstrap/gateway/src/main/java/com/baeldung/spring/cloud/bootstrap/gateway/GatewayApplication.java @@ -71,7 +71,7 @@ public class GatewayApplication { InstanceInfo instance = eurekaClient.getNextServerFromEureka("zipkin", false); if (!(baseUrl != null && instance.getHomePageUrl().equals(baseUrl))) { baseUrl = instance.getHomePageUrl(); - delegate = new HttpZipkinSpanReporter(baseUrl, zipkinProperties.getFlushInterval(), zipkinProperties.getCompression().isEnabled(), spanMetricReporter); + delegate = new HttpZipkinSpanReporter(new RestTemplate(), baseUrl, zipkinProperties.getFlushInterval(), spanMetricReporter); if (!span.name.matches(skipPattern)) delegate.report(span); } if (!span.name.matches(skipPattern)) delegate.report(span); diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-bootstrap/gateway/src/test/java/org/baeldung/SpringContextLiveTest.java similarity index 70% rename from spring-cloud/spring-cloud-bootstrap/gateway/src/test/java/org/baeldung/SpringContextIntegrationTest.java rename to spring-cloud/spring-cloud-bootstrap/gateway/src/test/java/org/baeldung/SpringContextLiveTest.java index ef3bb5ef95..e0342cf82c 100644 --- a/spring-cloud/spring-cloud-bootstrap/gateway/src/test/java/org/baeldung/SpringContextIntegrationTest.java +++ b/spring-cloud/spring-cloud-bootstrap/gateway/src/test/java/org/baeldung/SpringContextLiveTest.java @@ -7,9 +7,15 @@ import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.spring.cloud.bootstrap.gateway.GatewayApplication; +/** + * + * This Live Test requires: + * * A Redis instance running in port 6379 (e.g. using `docker run --name some-redis -p 6379:6379 -d redis`) + * + */ @RunWith(SpringRunner.class) @SpringBootTest(classes = GatewayApplication.class) -public class SpringContextIntegrationTest { +public class SpringContextLiveTest { @Test public void whenSpringContextIsBootstrapped_thenNoExceptions() { diff --git a/spring-cloud/spring-cloud-bootstrap/gateway/src/test/resources/bootstrap.properties b/spring-cloud/spring-cloud-bootstrap/gateway/src/test/resources/bootstrap.properties new file mode 100644 index 0000000000..c76df21ff1 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/gateway/src/test/resources/bootstrap.properties @@ -0,0 +1,2 @@ +# This property would be provided by the config service in a real-case scenario +spring.sleuth.web.skipPattern=(^cleanup.|.+favicon.) \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/svc-book/pom.xml b/spring-cloud/spring-cloud-bootstrap/svc-book/pom.xml index eb855a91e3..a88b77dda0 100644 --- a/spring-cloud/spring-cloud-bootstrap/svc-book/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/svc-book/pom.xml @@ -72,7 +72,7 @@ - Brixton.SR7 + Dalston.RELEASE \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/BookServiceApplication.java b/spring-cloud/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/BookServiceApplication.java index 3d55a59dbc..91fd23e32d 100644 --- a/spring-cloud/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/BookServiceApplication.java +++ b/spring-cloud/spring-cloud-bootstrap/svc-book/src/main/java/com/baeldung/spring/cloud/bootstrap/svcbook/BookServiceApplication.java @@ -12,6 +12,8 @@ import org.springframework.cloud.sleuth.zipkin.HttpZipkinSpanReporter; import org.springframework.cloud.sleuth.zipkin.ZipkinProperties; import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter; import org.springframework.context.annotation.Bean; +import org.springframework.web.client.RestTemplate; + import zipkin.Span; @SpringBootApplication @@ -42,7 +44,7 @@ public class BookServiceApplication { InstanceInfo instance = eurekaClient.getNextServerFromEureka("zipkin", false); if (!(baseUrl != null && instance.getHomePageUrl().equals(baseUrl))) { baseUrl = instance.getHomePageUrl(); - delegate = new HttpZipkinSpanReporter(baseUrl, zipkinProperties.getFlushInterval(), zipkinProperties.getCompression().isEnabled(), spanMetricReporter); + delegate = new HttpZipkinSpanReporter(new RestTemplate(), baseUrl, zipkinProperties.getFlushInterval(), spanMetricReporter); if (!span.name.matches(skipPattern)) delegate.report(span); } } diff --git a/spring-cloud/spring-cloud-bootstrap/svc-book/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-bootstrap/svc-book/src/test/java/org/baeldung/SpringContextLiveTest.java similarity index 70% rename from spring-cloud/spring-cloud-bootstrap/svc-book/src/test/java/org/baeldung/SpringContextIntegrationTest.java rename to spring-cloud/spring-cloud-bootstrap/svc-book/src/test/java/org/baeldung/SpringContextLiveTest.java index 0ffc2410e3..2e437aa3f7 100644 --- a/spring-cloud/spring-cloud-bootstrap/svc-book/src/test/java/org/baeldung/SpringContextIntegrationTest.java +++ b/spring-cloud/spring-cloud-bootstrap/svc-book/src/test/java/org/baeldung/SpringContextLiveTest.java @@ -7,9 +7,15 @@ import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.spring.cloud.bootstrap.svcbook.BookServiceApplication; +/** + * + * This Live Test requires: + * * A Redis instance running in port 6379 (e.g. using `docker run --name some-redis -p 6379:6379 -d redis`) + * + */ @RunWith(SpringRunner.class) @SpringBootTest(classes = BookServiceApplication.class) -public class SpringContextIntegrationTest { +public class SpringContextLiveTest { @Test public void whenSpringContextIsBootstrapped_thenNoExceptions() { diff --git a/spring-cloud/spring-cloud-bootstrap/svc-book/src/test/resources/bootstrap.properties b/spring-cloud/spring-cloud-bootstrap/svc-book/src/test/resources/bootstrap.properties new file mode 100644 index 0000000000..c76df21ff1 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/svc-book/src/test/resources/bootstrap.properties @@ -0,0 +1,2 @@ +# This property would be provided by the config service in a real-case scenario +spring.sleuth.web.skipPattern=(^cleanup.|.+favicon.) \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/svc-rating/pom.xml b/spring-cloud/spring-cloud-bootstrap/svc-rating/pom.xml index 7c1e93bad1..f0b19922d8 100644 --- a/spring-cloud/spring-cloud-bootstrap/svc-rating/pom.xml +++ b/spring-cloud/spring-cloud-bootstrap/svc-rating/pom.xml @@ -81,7 +81,7 @@ - Brixton.SR7 + Dalston.RELEASE \ No newline at end of file diff --git a/spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/RatingServiceApplication.java b/spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/RatingServiceApplication.java index 31ca69c139..8dacbaa79d 100644 --- a/spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/RatingServiceApplication.java +++ b/spring-cloud/spring-cloud-bootstrap/svc-rating/src/main/java/com/baeldung/spring/cloud/bootstrap/svcrating/RatingServiceApplication.java @@ -16,6 +16,7 @@ import org.springframework.context.annotation.Primary; import org.springframework.core.Ordered; import org.springframework.core.annotation.Order; import org.springframework.transaction.annotation.EnableTransactionManagement; +import org.springframework.web.client.RestTemplate; import com.netflix.appinfo.InstanceInfo; import com.netflix.discovery.EurekaClient; @@ -52,7 +53,7 @@ public class RatingServiceApplication { InstanceInfo instance = eurekaClient.getNextServerFromEureka("zipkin", false); if (!(baseUrl != null && instance.getHomePageUrl().equals(baseUrl))) { baseUrl = instance.getHomePageUrl(); - delegate = new HttpZipkinSpanReporter(baseUrl, zipkinProperties.getFlushInterval(), zipkinProperties.getCompression().isEnabled(), spanMetricReporter); + delegate = new HttpZipkinSpanReporter(new RestTemplate(), baseUrl, zipkinProperties.getFlushInterval(), spanMetricReporter); if (!span.name.matches(skipPattern)) delegate.report(span); } if (!span.name.matches(skipPattern)) delegate.report(span); diff --git a/spring-cloud/spring-cloud-bootstrap/svc-rating/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-bootstrap/svc-rating/src/test/java/org/baeldung/SpringContextLiveTest.java similarity index 70% rename from spring-cloud/spring-cloud-bootstrap/svc-rating/src/test/java/org/baeldung/SpringContextIntegrationTest.java rename to spring-cloud/spring-cloud-bootstrap/svc-rating/src/test/java/org/baeldung/SpringContextLiveTest.java index 3589666f17..e2921f0308 100644 --- a/spring-cloud/spring-cloud-bootstrap/svc-rating/src/test/java/org/baeldung/SpringContextIntegrationTest.java +++ b/spring-cloud/spring-cloud-bootstrap/svc-rating/src/test/java/org/baeldung/SpringContextLiveTest.java @@ -7,9 +7,16 @@ import org.springframework.test.context.junit4.SpringRunner; import com.baeldung.spring.cloud.bootstrap.svcrating.RatingServiceApplication; + +/** + * + * This Live Test requires: + * * A Redis instance running in port 6379 (e.g. using `docker run --name some-redis -p 6379:6379 -d redis`) + * + */ @RunWith(SpringRunner.class) @SpringBootTest(classes = RatingServiceApplication.class) -public class SpringContextIntegrationTest { +public class SpringContextLiveTest { @Test public void whenSpringContextIsBootstrapped_thenNoExceptions() { diff --git a/spring-cloud/spring-cloud-bootstrap/svc-rating/src/test/resources/bootstrap.properties b/spring-cloud/spring-cloud-bootstrap/svc-rating/src/test/resources/bootstrap.properties new file mode 100644 index 0000000000..c76df21ff1 --- /dev/null +++ b/spring-cloud/spring-cloud-bootstrap/svc-rating/src/test/resources/bootstrap.properties @@ -0,0 +1,2 @@ +# This property would be provided by the config service in a real-case scenario +spring.sleuth.web.skipPattern=(^cleanup.|.+favicon.) \ No newline at end of file diff --git a/spring-cloud/spring-cloud-functions/src/test/java/com/baeldung/spring/cloudfunction/aws/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-functions/src/test/java/com/baeldung/spring/cloudfunction/aws/SpringContextIntegrationTest.java new file mode 100644 index 0000000000..beee84246d --- /dev/null +++ b/spring-cloud/spring-cloud-functions/src/test/java/com/baeldung/spring/cloudfunction/aws/SpringContextIntegrationTest.java @@ -0,0 +1,15 @@ +package com.baeldung.spring.cloudfunction.aws; + +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(classes = CloudFunctionAwsApplication.class) +public class SpringContextIntegrationTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/test/java/com/baeldung/spring/cloud/kubernetes/travelagency/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/test/java/com/baeldung/spring/cloud/kubernetes/travelagency/SpringContextIntegrationTest.java new file mode 100644 index 0000000000..2f901d39f6 --- /dev/null +++ b/spring-cloud/spring-cloud-kubernetes/travel-agency-service/src/test/java/com/baeldung/spring/cloud/kubernetes/travelagency/SpringContextIntegrationTest.java @@ -0,0 +1,16 @@ +package com.baeldung.spring.cloud.kubernetes.travelagency; + + +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(classes = Application.class) +public class SpringContextIntegrationTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/SpringContextIntegrationTest.java similarity index 77% rename from spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/SpringContextIntegrationTest.java rename to spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/SpringContextIntegrationTest.java index e0026ce441..77d294093c 100644 --- a/spring-cloud/spring-cloud-aws/src/test/java/com/baeldung/spring/cloud/aws/SpringContextIntegrationTest.java +++ b/spring-cloud/spring-cloud-openfeign/src/test/java/com/baeldung/cloud/openfeign/SpringContextIntegrationTest.java @@ -1,4 +1,5 @@ -package com.baeldung.spring.cloud.aws; +package com.baeldung.cloud.openfeign; + import org.junit.Test; import org.junit.runner.RunWith; @@ -6,10 +7,10 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) -@SpringBootTest(classes = SpringCloudAwsApplication.class) +@SpringBootTest(classes = ExampleApplication.class) public class SpringContextIntegrationTest { - + @Test public void whenSpringContextIsBootstrapped_thenNoExceptions() { } -} +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/main/resources/application.yml b/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/main/resources/application.yml index 1187c12fe7..71275793ec 100644 --- a/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/main/resources/application.yml +++ b/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/main/resources/application.yml @@ -3,11 +3,11 @@ logging: org: springframework: cloud: - task=DEBUG + task: DEBUG spring: application: - name=helloWorld + name: helloWorld datasource: url: jdbc:mysql://localhost:3306/springcloud?useSSL=false username: root diff --git a/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/test/java/org/baeldung/SpringContextIntegrationTest.java deleted file mode 100644 index 4b5aff2db8..0000000000 --- a/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/test/java/org/baeldung/SpringContextIntegrationTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.baeldung; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import com.baeldung.task.JobConfiguration; - -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = JobConfiguration.class) -public class SpringContextIntegrationTest { - - @Test - public void whenSpringContextIsBootstrapped_thenNoExceptions() { - } -} diff --git a/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/test/java/org/baeldung/SpringContextLiveTest.java b/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/test/java/org/baeldung/SpringContextLiveTest.java new file mode 100644 index 0000000000..ddbcbf65ea --- /dev/null +++ b/spring-cloud/spring-cloud-task/springcloudtaskbatch/src/test/java/org/baeldung/SpringContextLiveTest.java @@ -0,0 +1,29 @@ +package org.baeldung; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.baeldung.task.JobConfiguration; +import com.baeldung.task.TaskDemo; + +/** + * This Live Test requires: + * * a MySql instance running, that allows a root user with no password, and with a database named + * + * (e.g. with the following command `docker run -p 3306:3306 --name bael-mysql -e MYSQL_ALLOW_EMPTY_PASSWORD=true -e MYSQL_DATABASE=springcloud mysql:latest`) + * + */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootApplication +@ContextConfiguration(classes = { JobConfiguration.class, TaskDemo.class }, initializers = { + ConfigFileApplicationContextInitializer.class }) +public class SpringContextLiveTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} diff --git a/spring-cloud/spring-cloud-vault/src/test/java/org/baeldung/spring/cloud/vaultsample/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-vault/src/test/java/org/baeldung/spring/cloud/vaultsample/SpringContextIntegrationTest.java new file mode 100644 index 0000000000..e1eb2f8e24 --- /dev/null +++ b/spring-cloud/spring-cloud-vault/src/test/java/org/baeldung/spring/cloud/vaultsample/SpringContextIntegrationTest.java @@ -0,0 +1,15 @@ +package org.baeldung.spring.cloud.vaultsample; + +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(classes = VaultSampleApplication.class) +public class SpringContextIntegrationTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-zookeeper/HelloWorld/pom.xml b/spring-cloud/spring-cloud-zookeeper/HelloWorld/pom.xml index 262b059544..0da0f7503e 100644 --- a/spring-cloud/spring-cloud-zookeeper/HelloWorld/pom.xml +++ b/spring-cloud/spring-cloud-zookeeper/HelloWorld/pom.xml @@ -34,6 +34,12 @@ + + org.springframework.boot + spring-boot-starter-test + ${spring-boot.version} + test +
diff --git a/spring-cloud/spring-cloud-zookeeper/HelloWorld/src/test/java/com/baeldung/spring/cloud/helloworld/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-zookeeper/HelloWorld/src/test/java/com/baeldung/spring/cloud/helloworld/SpringContextIntegrationTest.java new file mode 100644 index 0000000000..2770649aa3 --- /dev/null +++ b/spring-cloud/spring-cloud-zookeeper/HelloWorld/src/test/java/com/baeldung/spring/cloud/helloworld/SpringContextIntegrationTest.java @@ -0,0 +1,16 @@ +package com.baeldung.spring.cloud.helloworld; + + +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(classes = HelloWorldApplication.class) +public class SpringContextIntegrationTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} \ No newline at end of file diff --git a/spring-cloud/spring-cloud-zuul/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/SpringContextIntegrationTest.java b/spring-cloud/spring-cloud-zuul/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/SpringContextIntegrationTest.java new file mode 100644 index 0000000000..dbcdbdd434 --- /dev/null +++ b/spring-cloud/spring-cloud-zuul/src/test/java/com/baeldung/spring/cloud/zuulratelimitdemo/controller/SpringContextIntegrationTest.java @@ -0,0 +1,17 @@ +package com.baeldung.spring.cloud.zuulratelimitdemo.controller; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import com.baeldung.spring.cloud.zuulratelimitdemo.ZuulRatelimitDemoApplication; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = ZuulRatelimitDemoApplication.class) +public class SpringContextIntegrationTest { + + @Test + public void whenSpringContextIsBootstrapped_thenNoExceptions() { + } +} \ No newline at end of file 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) diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/controller/PersonAPI.java b/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/controller/PersonAPI.java new file mode 100644 index 0000000000..b1b56ec2f3 --- /dev/null +++ b/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/controller/PersonAPI.java @@ -0,0 +1,38 @@ +package org.baeldung.resttemplate.web.controller; + +import javax.servlet.http.HttpServletResponse; + +import org.baeldung.resttemplate.web.dto.Person; +import org.baeldung.resttemplate.web.service.PersonService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.servlet.support.ServletUriComponentsBuilder; + +@RestController +public class PersonAPI { + + @Autowired + private PersonService personService; + + @GetMapping("/") + public String home() { + return "Spring boot is working!"; + } + + @PostMapping(value = "/createPerson", consumes = "application/json", produces = "application/json") + public Person createPerson(@RequestBody Person person) { + return personService.saveUpdatePerson(person); + } + + @PostMapping(value = "/updatePerson", consumes = "application/json", produces = "application/json") + public Person updatePerson(@RequestBody Person person, HttpServletResponse response) { + response.setHeader("Location", ServletUriComponentsBuilder.fromCurrentContextPath() + .path("/findPerson/" + person.getId()) + .toUriString()); + return personService.saveUpdatePerson(person); + } + +} \ No newline at end of file diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/dto/Person.java b/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/dto/Person.java new file mode 100644 index 0000000000..4b7679638f --- /dev/null +++ b/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/dto/Person.java @@ -0,0 +1,32 @@ +package org.baeldung.resttemplate.web.dto; + +public class Person { + private Integer id; + private String name; + + public Person() { + + } + + public Person(Integer id, String name) { + this.id = id; + this.name = name; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/PersonService.java b/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/PersonService.java new file mode 100644 index 0000000000..c5ad39e101 --- /dev/null +++ b/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/PersonService.java @@ -0,0 +1,10 @@ +package org.baeldung.resttemplate.web.service; + +import org.baeldung.resttemplate.web.dto.Person; + +public interface PersonService { + + public Person saveUpdatePerson(Person person); + + public Person findPersonById(Integer id); +} \ No newline at end of file diff --git a/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/PersonServiceImpl.java b/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/PersonServiceImpl.java new file mode 100644 index 0000000000..658e0fade0 --- /dev/null +++ b/spring-resttemplate/src/main/java/org/baeldung/resttemplate/web/service/PersonServiceImpl.java @@ -0,0 +1,19 @@ +package org.baeldung.resttemplate.web.service; + +import org.baeldung.resttemplate.web.dto.Person; +import org.springframework.stereotype.Component; + +@Component +public class PersonServiceImpl implements PersonService { + + @Override + public Person saveUpdatePerson(Person person) { + return person; + } + + @Override + public Person findPersonById(Integer id) { + return new Person(id, "John"); + } + +} diff --git a/spring-resttemplate/src/test/java/org/baeldung/resttemplate/PersonAPILiveTest.java b/spring-resttemplate/src/test/java/org/baeldung/resttemplate/PersonAPILiveTest.java new file mode 100644 index 0000000000..de18f6db09 --- /dev/null +++ b/spring-resttemplate/src/test/java/org/baeldung/resttemplate/PersonAPILiveTest.java @@ -0,0 +1,96 @@ +package org.baeldung.resttemplate; + +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; +import java.net.URI; + +import org.baeldung.resttemplate.web.dto.Person; +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.web.client.RestTemplate; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = RestTemplateConfigurationApplication.class) +public class PersonAPILiveTest { + + private static String createPersonUrl; + private static String updatePersonUrl; + + private static RestTemplate restTemplate; + + private static HttpHeaders headers; + + private final ObjectMapper objectMapper = new ObjectMapper(); + + private static JSONObject personJsonObject; + + @BeforeClass + public static void runBeforeAllTestMethods() throws JSONException { + createPersonUrl = "http://localhost:8082/spring-rest/createPerson"; + updatePersonUrl = "http://localhost:8082/spring-rest/updatePerson"; + + restTemplate = new RestTemplate(); + + headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + personJsonObject = new JSONObject(); + personJsonObject.put("id", 1); + personJsonObject.put("name", "John"); + } + + @Test + public void givenDataIsJson_whenDataIsPostedByPostForObject_thenResponseBodyIsNotNull() throws IOException { + HttpEntity request = new HttpEntity(personJsonObject.toString(), headers); + String personResultAsJsonStr = restTemplate.postForObject(createPersonUrl, request, String.class); + JsonNode root = objectMapper.readTree(personResultAsJsonStr); + + Person person = restTemplate.postForObject(createPersonUrl, request, Person.class); + + assertNotNull(personResultAsJsonStr); + assertNotNull(root); + assertNotNull(root.path("name") + .asText()); + + assertNotNull(person); + assertNotNull(person.getName()); + } + + @Test + public void givenDataIsJson_whenDataIsPostedByPostForEntity_thenResponseBodyIsNotNull() throws IOException { + HttpEntity request = new HttpEntity(personJsonObject.toString(), headers); + ResponseEntity responseEntityStr = restTemplate.postForEntity(createPersonUrl, request, String.class); + JsonNode root = objectMapper.readTree(responseEntityStr.getBody()); + + ResponseEntity responseEntityPerson = restTemplate.postForEntity(createPersonUrl, request, Person.class); + + assertNotNull(responseEntityStr.getBody()); + assertNotNull(root.path("name") + .asText()); + + assertNotNull(responseEntityPerson.getBody()); + assertNotNull(responseEntityPerson.getBody() + .getName()); + } + + @Test + public void givenDataIsJson_whenDataIsPostedByPostForLocation_thenResponseBodyIsTheLocationHeader() throws JsonProcessingException { + HttpEntity request = new HttpEntity(personJsonObject.toString(), headers); + URI locationHeader = restTemplate.postForLocation(updatePersonUrl, request); + + assertNotNull(locationHeader); + } +} \ No newline at end of file diff --git a/spring-security-rest/README.md b/spring-security-rest/README.md index f71eead9ae..f450a514b2 100644 --- a/spring-security-rest/README.md +++ b/spring-security-rest/README.md @@ -11,7 +11,6 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com - [Spring REST Service Security](http://www.baeldung.com/2011/10/31/securing-a-restful-web-service-with-spring-security-3-1-part-3/) - [Setting Up Swagger 2 with a Spring REST API](http://www.baeldung.com/swagger-2-documentation-for-spring-rest-api) - [Custom Error Message Handling for REST API](http://www.baeldung.com/global-error-handler-in-a-spring-rest-api) -- [An Intro to Spring HATEOAS](http://www.baeldung.com/spring-hateoas-tutorial) - [Spring Security Context Propagation with @Async](http://www.baeldung.com/spring-security-async-principal-propagation) - [Servlet 3 Async Support with Spring MVC and Spring Security](http://www.baeldung.com/spring-mvc-async-security) - [Intro to Spring Security Expressions](http://www.baeldung.com/spring-security-expressions) diff --git a/spring-security-rest/pom.xml b/spring-security-rest/pom.xml index 24f1c5807a..b6039ce9d3 100644 --- a/spring-security-rest/pom.xml +++ b/spring-security-rest/pom.xml @@ -84,13 +84,6 @@ ${spring.version} - - - org.springframework.hateoas - spring-hateoas - ${org.springframework.hateoas.version} - - @@ -273,9 +266,6 @@ - - 0.25.0.RELEASE - 3.1.0 1.1.0.Final diff --git a/testing-modules/groovy-spock/README.md b/testing-modules/groovy-spock/README.md index a98df27172..e61c56d470 100644 --- a/testing-modules/groovy-spock/README.md +++ b/testing-modules/groovy-spock/README.md @@ -2,3 +2,4 @@ - [Introduction to Testing with Spock and Groovy](http://www.baeldung.com/groovy-spock) - [Difference Between Stub, Mock, and Spy in the Spock Framework](https://www.baeldung.com/spock-stub-mock-spy) +- [Guide to Spock Extensions](https://www.baeldung.com/spock-extensions) 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