diff --git a/algorithms/src/main/java/com/baeldung/algorithms/primechecker/BigIntegerPrimeChecker.java b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/BigIntegerPrimeChecker.java index bd4708b661..752e659fa3 100644 --- a/algorithms/src/main/java/com/baeldung/algorithms/primechecker/BigIntegerPrimeChecker.java +++ b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/BigIntegerPrimeChecker.java @@ -2,10 +2,10 @@ package com.baeldung.algorithms.primechecker; import java.math.BigInteger; -public class BigIntegerPrimeChecker implements PrimeChecker{ +public class BigIntegerPrimeChecker implements PrimeChecker{ @Override - public boolean isPrime(int number) { + public boolean isPrime(Long number) { BigInteger bigInt = BigInteger.valueOf(number); return bigInt.isProbablePrime(100); } diff --git a/algorithms/src/main/java/com/baeldung/algorithms/primechecker/BruteForcePrimeChecker.java b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/BruteForcePrimeChecker.java index 0dfcfa1505..47ffb3e224 100644 --- a/algorithms/src/main/java/com/baeldung/algorithms/primechecker/BruteForcePrimeChecker.java +++ b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/BruteForcePrimeChecker.java @@ -1,12 +1,15 @@ package com.baeldung.algorithms.primechecker; import java.util.stream.IntStream; +import java.util.stream.LongStream; -public class BruteForcePrimeChecker implements PrimeChecker{ +public class BruteForcePrimeChecker implements PrimeChecker{ @Override - public boolean isPrime(int number) { - return IntStream.range(2, number).noneMatch(n -> (number % n == 0)); + public boolean isPrime(Integer number) { + + return number > 2 ? IntStream.range(2, number) + .noneMatch(n -> (number % n == 0)) : false; } diff --git a/algorithms/src/main/java/com/baeldung/algorithms/primechecker/OptimisedPrimeChecker.java b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/OptimisedPrimeChecker.java index f7e3e09be0..06ae4acc7f 100644 --- a/algorithms/src/main/java/com/baeldung/algorithms/primechecker/OptimisedPrimeChecker.java +++ b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/OptimisedPrimeChecker.java @@ -1,13 +1,14 @@ package com.baeldung.algorithms.primechecker; import java.util.stream.IntStream; +import java.util.stream.LongStream; -public class OptimisedPrimeChecker implements PrimeChecker{ +public class OptimisedPrimeChecker implements PrimeChecker{ @Override - public boolean isPrime(int number) { - return IntStream.range(2, (int)Math.sqrt(number) + 1) - .noneMatch(n -> (number % n == 0)); + public boolean isPrime(Integer number) { + return number > 2 ? IntStream.rangeClosed(2, (int) Math.sqrt(number)) + .noneMatch(n -> (number % n == 0)) : false; } diff --git a/algorithms/src/main/java/com/baeldung/algorithms/primechecker/PrimeChecker.java b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/PrimeChecker.java index f31af1ca4f..5f7a15a939 100644 --- a/algorithms/src/main/java/com/baeldung/algorithms/primechecker/PrimeChecker.java +++ b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/PrimeChecker.java @@ -1,6 +1,6 @@ package com.baeldung.algorithms.primechecker; -public interface PrimeChecker { +public interface PrimeChecker { - public boolean isPrime( int number ); + public boolean isPrime( T number ); } diff --git a/algorithms/src/main/java/com/baeldung/algorithms/primechecker/PrimesPrimeChecker.java b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/PrimesPrimeChecker.java index ee66d5d2ab..08b095cb79 100644 --- a/algorithms/src/main/java/com/baeldung/algorithms/primechecker/PrimesPrimeChecker.java +++ b/algorithms/src/main/java/com/baeldung/algorithms/primechecker/PrimesPrimeChecker.java @@ -2,10 +2,10 @@ package com.baeldung.algorithms.primechecker; import org.apache.commons.math3.primes.Primes; -public class PrimesPrimeChecker implements PrimeChecker{ +public class PrimesPrimeChecker implements PrimeChecker{ @Override - public boolean isPrime(int number) { + public boolean isPrime(Integer number) { return Primes.isPrime(number); } diff --git a/algorithms/src/test/java/com/baeldung/algorithms/primechecker/BigIntegerPrimeCheckerTest.java b/algorithms/src/test/java/com/baeldung/algorithms/primechecker/BigIntegerPrimeCheckerTest.java index 95eb85749d..8980397c68 100644 --- a/algorithms/src/test/java/com/baeldung/algorithms/primechecker/BigIntegerPrimeCheckerTest.java +++ b/algorithms/src/test/java/com/baeldung/algorithms/primechecker/BigIntegerPrimeCheckerTest.java @@ -9,18 +9,20 @@ import com.baeldung.algorithms.primechecker.PrimeChecker; public class BigIntegerPrimeCheckerTest { - PrimeChecker primeChecker = new BigIntegerPrimeChecker(); + BigIntegerPrimeChecker primeChecker = new BigIntegerPrimeChecker(); @Test public void givenPrimeNumber_whenCheckIsPrime_thenTrue(){ - assertTrue(primeChecker.isPrime(13)); - assertTrue(primeChecker.isPrime(1009)); + assertTrue(primeChecker.isPrime(13l)); + assertTrue(primeChecker.isPrime(1009L)); + assertTrue(primeChecker.isPrime(74207281L)); } @Test public void givenNonPrimeNumber_whenCheckIsPrime_thenFalse(){ - assertTrue(!primeChecker.isPrime(50)); - assertTrue(!primeChecker.isPrime(1001)); + assertTrue(!primeChecker.isPrime(50L)); + assertTrue(!primeChecker.isPrime(1001L)); + assertTrue(!primeChecker.isPrime(74207282L)); } } diff --git a/algorithms/src/test/java/com/baeldung/algorithms/primechecker/OptimisedPrimeCheckerTest.java b/algorithms/src/test/java/com/baeldung/algorithms/primechecker/OptimisedPrimeCheckerTest.java index 21ad55467f..64ecae7cc3 100644 --- a/algorithms/src/test/java/com/baeldung/algorithms/primechecker/OptimisedPrimeCheckerTest.java +++ b/algorithms/src/test/java/com/baeldung/algorithms/primechecker/OptimisedPrimeCheckerTest.java @@ -9,7 +9,7 @@ import com.baeldung.algorithms.primechecker.PrimeChecker; public class OptimisedPrimeCheckerTest { - PrimeChecker primeChecker = new OptimisedPrimeChecker(); + OptimisedPrimeChecker primeChecker = new OptimisedPrimeChecker(); @Test public void givenPrimeNumber_whenCheckIsPrime_thenTrue(){ diff --git a/algorithms/src/test/java/com/baeldung/algorithms/primechecker/PrimesPrimeCheckerTest.java b/algorithms/src/test/java/com/baeldung/algorithms/primechecker/PrimesPrimeCheckerTest.java index 63de593b44..cb294d6643 100644 --- a/algorithms/src/test/java/com/baeldung/algorithms/primechecker/PrimesPrimeCheckerTest.java +++ b/algorithms/src/test/java/com/baeldung/algorithms/primechecker/PrimesPrimeCheckerTest.java @@ -8,7 +8,7 @@ import com.baeldung.algorithms.primechecker.PrimeChecker; import com.baeldung.algorithms.primechecker.PrimesPrimeChecker; public class PrimesPrimeCheckerTest { - PrimeChecker primeChecker = new PrimesPrimeChecker(); + PrimesPrimeChecker primeChecker = new PrimesPrimeChecker(); @Test public void givenPrimeNumber_whenCheckIsPrime_thenTrue() { diff --git a/apache-fop/pom.xml b/apache-fop/pom.xml index 6f89497a7d..6075c23d21 100644 --- a/apache-fop/pom.xml +++ b/apache-fop/pom.xml @@ -101,9 +101,7 @@ org.dbdoclet herold - 6.1.0 - system - ${basedir}/src/test/resources/jars/herold.jar + 8.0.4 @@ -140,6 +138,8 @@ maven-surefire-plugin ${maven-surefire-plugin.version} + 3 + true **/*IntegrationTest.java **/*LiveTest.java diff --git a/apache-fop/src/test/java/org/baeldung/java/ApacheFOPConvertHTMLIntegrationTest.java b/apache-fop/src/test/java/org/baeldung/java/ApacheFOPConvertHTMLIntegrationTest.java index 99487c8fdf..5e2da6fd1e 100644 --- a/apache-fop/src/test/java/org/baeldung/java/ApacheFOPConvertHTMLIntegrationTest.java +++ b/apache-fop/src/test/java/org/baeldung/java/ApacheFOPConvertHTMLIntegrationTest.java @@ -19,21 +19,21 @@ import javax.xml.transform.stream.StreamSource; import org.apache.fop.apps.Fop; import org.apache.fop.apps.FopFactory; import org.apache.xmlgraphics.util.MimeConstants; -import org.dbdoclet.trafo.html.docbook.DocBookTransformer; +import org.dbdoclet.trafo.html.docbook.HtmlDocBookTrafo; import org.dbdoclet.trafo.script.Script; import org.junit.Test; import org.w3c.dom.Document; import org.w3c.tidy.Tidy; public class ApacheFOPConvertHTMLIntegrationTest { - private String inputFile = "src/test/resources/input.html"; - private String style = "src/test/resources/xhtml2fo.xsl"; - private String style1 = "src/test/resources/docbook-xsl/fo/docbook.xsl"; - private String output_jtidy = "src/test/resources/output_jtidy.pdf"; - private String output_html2fo = "src/test/resources/output_html2fo.pdf"; - private String output_herold = "src/test/resources/output_herold.pdf"; - private String foFile = "src/test/resources/input.fo"; - private String xmlFile = "src/test/resources/input.xml"; + private final String inputFile = "src/test/resources/input.html"; + private final String style = "src/test/resources/xhtml2fo.xsl"; + private final String style1 = "src/test/resources/docbook-xsl/fo/docbook.xsl"; + private final String output_jtidy = "src/test/resources/output_jtidy.pdf"; + private final String output_html2fo = "src/test/resources/output_html2fo.pdf"; + private final String output_herold = "src/test/resources/output_herold.pdf"; + private final String foFile = "src/test/resources/input.fo"; + private final String xmlFile = "src/test/resources/input.xml"; @Test public void whenTransformHTMLToPDFUsingJTidy_thenCorrect() throws Exception { @@ -114,8 +114,9 @@ public class ApacheFOPConvertHTMLIntegrationTest { private void fromHTMLTOXMLUsingHerold() throws Exception { final Script script = new Script(); - final DocBookTransformer transformer = new DocBookTransformer(); - transformer.setScript(script); - transformer.convert(new FileInputStream(inputFile), new FileOutputStream(xmlFile)); + final HtmlDocBookTrafo transformer = new HtmlDocBookTrafo(); + transformer.setInputStream(new FileInputStream(inputFile)); + transformer.setOutputStream(new FileOutputStream(xmlFile)); + transformer.transform(script); } } diff --git a/apache-fop/src/test/java/org/baeldung/java/ApacheFOPHeroldLiveTest.java b/apache-fop/src/test/java/org/baeldung/java/ApacheFOPHeroldLiveTest.java index 9e71cd9c16..8496222394 100644 --- a/apache-fop/src/test/java/org/baeldung/java/ApacheFOPHeroldLiveTest.java +++ b/apache-fop/src/test/java/org/baeldung/java/ApacheFOPHeroldLiveTest.java @@ -10,6 +10,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.net.HttpURLConnection; import java.net.URL; import javax.xml.transform.Result; @@ -25,19 +26,15 @@ import org.apache.fop.apps.Fop; import org.apache.fop.apps.FopFactory; import org.apache.xmlgraphics.util.MimeConstants; import org.dbdoclet.trafo.TrafoScriptManager; -import org.dbdoclet.trafo.html.docbook.DocBookTransformer; +import org.dbdoclet.trafo.html.docbook.HtmlDocBookTrafo; import org.dbdoclet.trafo.script.Script; import org.junit.Test; import org.w3c.dom.Document; public class ApacheFOPHeroldLiveTest { - private String[] inputUrls = {// @formatter:off - "http://www.baeldung.com/2011/10/20/bootstraping-a-web-application-with-spring-3-1-and-java-based-configuration-part-1/", - "http://www.baeldung.com/2011/10/25/building-a-restful-web-service-with-spring-3-1-and-java-based-configuration-part-2/", - "http://www.baeldung.com/2011/10/31/securing-a-restful-web-service-with-spring-security-3-1-part-3/", - "http://www.baeldung.com/spring-security-basic-authentication", - "http://www.baeldung.com/spring-security-digest-authentication", - "http://www.baeldung.com/2011/11/20/basic-and-digest-authentication-for-a-restful-service-with-spring-security-3-1/", + private final String[] inputUrls = {// @formatter:off + // "http://www.baeldung.com/spring-security-basic-authentication", + "http://www.baeldung.com/spring-security-digest-authentication" //"http://www.baeldung.com/spring-httpmessageconverter-rest", //"http://www.baeldung.com/2011/11/06/restful-web-service-discoverability-part-4/", //"http://www.baeldung.com/2011/11/13/rest-service-discoverability-with-spring-part-5/", @@ -49,10 +46,10 @@ public class ApacheFOPHeroldLiveTest { //"http://www.baeldung.com/2013/01/18/testing-rest-with-multiple-mime-types/" }; // @formatter:on - private String style_file = "src/test/resources/docbook-xsl/fo/docbook.xsl"; - private String output_file = "src/test/resources/final_output.pdf"; - private String xmlInput = "src/test/resources/input.xml"; - private String xmlOutput = "src/test/resources/output.xml"; + private final String style_file = "src/test/resources/docbook-xsl/fo/docbook.xsl"; + private final String output_file = "src/test/resources/final_output.pdf"; + private final String xmlInput = "src/test/resources/input.xml"; + private final String xmlOutput = "src/test/resources/output.xml"; // tests @@ -75,10 +72,11 @@ public class ApacheFOPHeroldLiveTest { final TrafoScriptManager mgr = new TrafoScriptManager(); final File profileFile = new File("src/test/resources/default.her"); script = mgr.parseScript(profileFile); - final DocBookTransformer transformer = new DocBookTransformer(); - transformer.setScript(script); + final HtmlDocBookTrafo transformer = new HtmlDocBookTrafo(); + transformer.setInputStream(getInputStream(input)); + transformer.setOutputStream(new FileOutputStream(xmlInput, append)); - transformer.convert(getInputStream(input), new FileOutputStream(xmlInput, append)); + transformer.transform(script); } private Document fromXMLFileToFO() throws Exception { @@ -112,7 +110,9 @@ public class ApacheFOPHeroldLiveTest { private InputStream getInputStream(final String input) throws IOException { final URL url = new URL(input); - return url.openStream(); + final HttpURLConnection httpcon = (HttpURLConnection) url.openConnection(); + httpcon.addRequestProperty("User-Agent", "Mozilla/4.0"); + return httpcon.getInputStream(); } private void fixXML(final String input, final String output) throws IOException { @@ -127,7 +127,7 @@ public class ApacheFOPHeroldLiveTest { if (line.contains("info>")) { writer.write(line.replace("info>", "section>")); - } else if (!((line.startsWith(" 4)) { + } else if (!((line.startsWith(" 4))) { writer.write(line.replaceAll("xml:id=\"", "xml:id=\"" + count)); } writer.write("\n"); diff --git a/apache-fop/src/test/resources/jars/herold.jar b/apache-fop/src/test/resources/jars/herold.jar deleted file mode 100644 index ef5d052f36..0000000000 Binary files a/apache-fop/src/test/resources/jars/herold.jar and /dev/null differ diff --git a/core-java/README.md b/core-java/README.md index 0861ee7c5e..096ff51df6 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -11,6 +11,7 @@ - [Converting between a List and a Set in Java](http://www.baeldung.com/convert-list-to-set-and-set-to-list) - [Convert a Map to an Array, List or Set in Java](http://www.baeldung.com/convert-map-values-to-array-list-set) - [Java – Write to File](http://www.baeldung.com/java-write-to-file) +- [Java - Convert File to InputStream] (http://www.baeldung.com/convert-file-to-input-stream) - [Java Scanner](http://www.baeldung.com/java-scanner) - [Java Timer](http://www.baeldung.com/java-timer-and-timertask) - [Java – Byte Array to Writer](http://www.baeldung.com/java-convert-byte-array-to-writer) diff --git a/core-java/src/main/java/com/baeldung/stringtokenizer/Application.java b/core-java/src/main/java/com/baeldung/stringtokenizer/Application.java index caa7ef06da..4560e40697 100644 --- a/core-java/src/main/java/com/baeldung/stringtokenizer/Application.java +++ b/core-java/src/main/java/com/baeldung/stringtokenizer/Application.java @@ -1,21 +1,52 @@ package com.baeldung.stringtokenizer; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.StringTokenizer; +import java.util.stream.Collectors; public class Application { - public List getTokens(String str) { - List tokens = new ArrayList(); -// StringTokenizer tokenizer = new StringTokenizer( str ); - StringTokenizer tokenizer = new StringTokenizer( str , "," ); -// StringTokenizer tokenizer = new StringTokenizer( str , "," , true ); - while (tokenizer.hasMoreElements()) { - tokens.add( tokenizer.nextToken() ); -// tokens.add( tokenizer.nextToken( "," ) ); - } - return tokens; - } + public List getTokens(String str) { + List tokens = new ArrayList(); + // StringTokenizer tokenizer = new StringTokenizer( str ); + StringTokenizer tokenizer = new StringTokenizer(str, ","); + // StringTokenizer tokenizer = new StringTokenizer( str , "," , true ); + while (tokenizer.hasMoreElements()) { + tokens.add(tokenizer.nextToken()); + // tokens.add( tokenizer.nextToken("e") ); + } + int tokenLength = tokens.size(); + return tokens; + } + + public List getTokensWithCollection(String str) { + StringTokenizer tokenizer = new StringTokenizer(str, ","); + + return Collections.list(tokenizer).stream() + .map(token -> (String) token) + .collect(Collectors.toList()); + } + + public List getTokensFromFile(String path, String delim) { + List tokens = new ArrayList<>(); + String currLine = ""; + StringTokenizer tokenizer; + try (BufferedReader br = new BufferedReader(new InputStreamReader(Application.class.getResourceAsStream("/" + path)))) { + while ((currLine = br.readLine()) != null) { + tokenizer = new StringTokenizer(currLine, delim); + while (tokenizer.hasMoreElements()) { + tokens.add(tokenizer.nextToken()); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + return tokens; + } } diff --git a/core-java/src/main/resources/data.csv b/core-java/src/main/resources/data.csv new file mode 100644 index 0000000000..ec4ac10443 --- /dev/null +++ b/core-java/src/main/resources/data.csv @@ -0,0 +1,3 @@ +1|IND|India +2|MY|Malaysia +3|AU|Australia diff --git a/core-java/src/test/java/com/baeldung/stringtokenizer/ApplicationTest.java b/core-java/src/test/java/com/baeldung/stringtokenizer/ApplicationTest.java index 5e3df5b303..5d475d2fbb 100644 --- a/core-java/src/test/java/com/baeldung/stringtokenizer/ApplicationTest.java +++ b/core-java/src/test/java/com/baeldung/stringtokenizer/ApplicationTest.java @@ -11,20 +11,37 @@ import static org.junit.Assert.assertEquals; public class ApplicationTest { Application application = new Application(); - List expectedTokens = new ArrayList(); - + List expectedTokensForString = new ArrayList(); + List expectedTokensForFile = new ArrayList(); + @Before public void init() { - expectedTokens.add( "Welcome" ); - expectedTokens.add( "to" ); - expectedTokens.add( "baeldung.com" ); + expectedTokensForString.add("Welcome"); + expectedTokensForString.add("to"); + expectedTokensForString.add("baeldung.com"); + + expectedTokensForFile.add("1"); + expectedTokensForFile.add("IND"); + expectedTokensForFile.add("India"); + expectedTokensForFile.add("2"); + expectedTokensForFile.add("MY"); + expectedTokensForFile.add("Malaysia"); + expectedTokensForFile.add("3"); + expectedTokensForFile.add("AU"); + expectedTokensForFile.add("Australia"); } - + @Test public void givenString_thenGetListOfString() { String str = "Welcome,to,baeldung.com"; List actualTokens = application.getTokens(str); - assertEquals(expectedTokens, actualTokens); + assertEquals(expectedTokensForString, actualTokens); } - + + @Test + public void givenFile_thenGetListOfString() { + List actualTokens = application.getTokensFromFile("data.csv", "|"); + assertEquals(expectedTokensForFile, actualTokens); + } + } diff --git a/cucumber/pom.xml b/cucumber/pom.xml new file mode 100644 index 0000000000..77d04f96c2 --- /dev/null +++ b/cucumber/pom.xml @@ -0,0 +1,93 @@ + + 4.0.0 + com.baeldung + cucumber + 1.0.0-SNAPSHOT + jar + + + 1.8 + 1.8 + UTF-8 + 3.5.1 + 1.7.21 + 1.1.7 + 4.12 + 1.3 + 1.2.5 + 2.19.1 + + + + + + + + info.cukes + cucumber-junit + ${cucumber.version} + test + + + + info.cukes + cucumber-java + ${cucumber.version} + test + + + + org.hamcrest + hamcrest-library + ${hamcrest.library.version} + test + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + + ch.qos.logback + logback-classic + ${logback.version} + + + + ch.qos.logback + logback-core + ${logback.version} + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven.compiler.plugin.version} + + true + true + ${java.source.version} + ${java.target.version} + + + + org.apache.maven.plugins + maven-surefire-plugin + ${surefire.plugin.version} + + + **/CalculatorTest.java + + + + + + + \ No newline at end of file diff --git a/cucumber/src/main/java/com/baeldung/cucumber/calculator/Calculator.java b/cucumber/src/main/java/com/baeldung/cucumber/calculator/Calculator.java new file mode 100644 index 0000000000..fd4a3bad7b --- /dev/null +++ b/cucumber/src/main/java/com/baeldung/cucumber/calculator/Calculator.java @@ -0,0 +1,7 @@ +package com.baeldung.cucumber.calculator; + +public class Calculator { + public int add(int a, int b) { + return a + b; + } +} diff --git a/cucumber/src/test/java/com/baeldung/cucumber/calculator/CalculatorRunSteps.java b/cucumber/src/test/java/com/baeldung/cucumber/calculator/CalculatorRunSteps.java new file mode 100644 index 0000000000..9c0e920a8d --- /dev/null +++ b/cucumber/src/test/java/com/baeldung/cucumber/calculator/CalculatorRunSteps.java @@ -0,0 +1,38 @@ +package com.baeldung.cucumber.calculator; + +import org.hamcrest.Matchers; +import org.junit.Assert; + +import cucumber.api.java.Before; +import cucumber.api.java.en.Given; +import cucumber.api.java.en.Then; +import cucumber.api.java.en.When; + +public class CalculatorRunSteps { + + private int total; + + private Calculator calculator; + + @Before + private void init() { + total = -999; + + } + + @Given("^I have a calculator$") + public void initializeCalculator() throws Throwable { + calculator = new Calculator(); + } + + @When("^I add (-?\\d+) and (-?\\d+)$") + public void testAdd(int num1, int num2) throws Throwable { + total = calculator.add(num1, num2); + } + + @Then("^the result should be (-?\\d+)$") + public void validateResult(int result) throws Throwable { + Assert.assertThat(total, Matchers.equalTo(result)); + } + +} diff --git a/cucumber/src/test/java/com/baeldung/cucumber/calculator/CalculatorTest.java b/cucumber/src/test/java/com/baeldung/cucumber/calculator/CalculatorTest.java new file mode 100644 index 0000000000..6bbbca60d2 --- /dev/null +++ b/cucumber/src/test/java/com/baeldung/cucumber/calculator/CalculatorTest.java @@ -0,0 +1,15 @@ +package com.baeldung.cucumber.calculator; + +import org.junit.runner.RunWith; + +import cucumber.api.CucumberOptions; +import cucumber.api.junit.Cucumber; + +@RunWith(Cucumber.class) +@CucumberOptions( + features={"classpath:features/calculator.feature", "classpath:features/calculator-scenario-outline.feature"} + , plugin = { "pretty", "json:target/reports/json/calculator.json" } + , glue = {"com.baeldung.cucumber.calculator"} +) +public class CalculatorTest { +} diff --git a/cucumber/src/test/resources/features/calculator-scenario-outline.feature b/cucumber/src/test/resources/features/calculator-scenario-outline.feature new file mode 100644 index 0000000000..7437dbf5f9 --- /dev/null +++ b/cucumber/src/test/resources/features/calculator-scenario-outline.feature @@ -0,0 +1,16 @@ +Feature: Calculator + As a user + I want to use a calculator to add numbers + So that I don't need to add myself + + Scenario Outline: Add two numbers & + Given I have a calculator + When I add and + Then the result should be + + Examples: + | num1 | num2 | total | + | -2 | 3 | 1 | + | 10 | 15 | 25 | + | 99 | -99 | 0 | + | -1 | -10 | -11 | \ No newline at end of file diff --git a/cucumber/src/test/resources/features/calculator.feature b/cucumber/src/test/resources/features/calculator.feature new file mode 100644 index 0000000000..eaf05cb6ca --- /dev/null +++ b/cucumber/src/test/resources/features/calculator.feature @@ -0,0 +1,24 @@ +Feature: Calculator + As a user + I want to use a calculator to add numbers + So that I don't need to add myself + + Scenario: Add two numbers -2 & 3 + Given I have a calculator + When I add -2 and 3 + Then the result should be 1 + + Scenario: Add two numbers 10 & 15 + Given I have a calculator + When I add 10 and 15 + Then the result should be 25 + + Scenario: Add two numbers 99 & -99 + Given I have a calculator + When I add 99 and -99 + Then the result should be 0 + + Scenario: Add two numbers -1 & -10 + Given I have a calculator + When I add -1 and -10 + Then the result should be -11 \ No newline at end of file diff --git a/cucumber/src/test/resources/logback-test.xml b/cucumber/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..e980d88693 --- /dev/null +++ b/cucumber/src/test/resources/logback-test.xml @@ -0,0 +1,13 @@ + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n%ex + + + + + + + + + \ No newline at end of file diff --git a/jee7/src/main/java/com/baeldung/jaxws/exception/EmployeeAlreadyExists.java b/jee7/src/main/java/com/baeldung/jaxws/exception/EmployeeAlreadyExists.java index 4842fbf84c..8a96f8aec0 100644 --- a/jee7/src/main/java/com/baeldung/jaxws/exception/EmployeeAlreadyExists.java +++ b/jee7/src/main/java/com/baeldung/jaxws/exception/EmployeeAlreadyExists.java @@ -1,13 +1,9 @@ package com.baeldung.jaxws.exception; -import java.io.Serializable; - import javax.xml.ws.WebFault; @WebFault -public class EmployeeAlreadyExists extends Exception implements Serializable { - - private static final long serialVersionUID = 1L; +public class EmployeeAlreadyExists extends Exception { public EmployeeAlreadyExists() { super("This employee already exists"); diff --git a/jee7/src/main/java/com/baeldung/jaxws/exception/EmployeeNotFound.java b/jee7/src/main/java/com/baeldung/jaxws/exception/EmployeeNotFound.java index 667e3e0c72..3de2ca8db6 100644 --- a/jee7/src/main/java/com/baeldung/jaxws/exception/EmployeeNotFound.java +++ b/jee7/src/main/java/com/baeldung/jaxws/exception/EmployeeNotFound.java @@ -1,10 +1,9 @@ package com.baeldung.jaxws.exception; import javax.xml.ws.WebFault; -import java.io.Serializable; @WebFault -public class EmployeeNotFound extends Exception implements Serializable { +public class EmployeeNotFound extends Exception { public EmployeeNotFound() { super("The specified employee does not exist"); diff --git a/jee7/src/main/java/com/baeldung/jaxws/model/Employee.java b/jee7/src/main/java/com/baeldung/jaxws/model/Employee.java index 5b1673c1e4..dbbdc234cf 100644 --- a/jee7/src/main/java/com/baeldung/jaxws/model/Employee.java +++ b/jee7/src/main/java/com/baeldung/jaxws/model/Employee.java @@ -1,9 +1,6 @@ package com.baeldung.jaxws.model; -import java.io.Serializable; - -public class Employee implements Serializable { - private static final long serialVersionUID = 1L; +public class Employee { private int id; private String firstName; diff --git a/pom.xml b/pom.xml index a582ff3e70..b21d656772 100644 --- a/pom.xml +++ b/pom.xml @@ -215,6 +215,7 @@ rabbitmq vertx spring-data-gemfire + cucumber @@ -233,6 +234,8 @@ org.apache.maven.plugins maven-surefire-plugin + 3 + true **/*IntegrationTest.java **/*LongRunningUnitTest.java diff --git a/querydsl/pom.xml b/querydsl/pom.xml index b0a07fb3ff..1335d0f1fd 100644 --- a/querydsl/pom.xml +++ b/querydsl/pom.xml @@ -181,6 +181,8 @@ org.apache.maven.plugins maven-surefire-plugin + 3 + true **/*IntegrationTest.java **/*LiveTest.java diff --git a/resteasy/bin/pom.xml b/resteasy/bin/pom.xml index f0bd8298f5..1116c0f01a 100644 --- a/resteasy/bin/pom.xml +++ b/resteasy/bin/pom.xml @@ -32,6 +32,8 @@ maven-surefire-plugin ${maven-surefire-plugin.version} + 3 + true **/*IntegrationTest.java **/*LiveTest.java diff --git a/rxjava/pom.xml b/rxjava/pom.xml index 4172187b03..3313713b9b 100644 --- a/rxjava/pom.xml +++ b/rxjava/pom.xml @@ -21,6 +21,8 @@ org.apache.maven.plugins maven-surefire-plugin + 3 + true **/*IntegrationTest.java **/*LongRunningUnitTest.java diff --git a/spring-5/pom.xml b/spring-5/pom.xml index f116ed73c0..2c96bae9bc 100644 --- a/spring-5/pom.xml +++ b/spring-5/pom.xml @@ -80,6 +80,8 @@ org.apache.maven.plugins maven-surefire-plugin + 3 + true **/*IntegrationTest.java **/*LiveTest.java diff --git a/spring-akka/pom.xml b/spring-akka/pom.xml index 1a273b0fed..5965213e65 100644 --- a/spring-akka/pom.xml +++ b/spring-akka/pom.xml @@ -70,6 +70,8 @@ maven-surefire-plugin ${maven-surefire-plugin.version} + 3 + true **/*IntegrationTest.java **/*LiveTest.java diff --git a/spring-all/src/main/java/org/baeldung/sample/AppConfig.java b/spring-all/src/main/java/org/baeldung/sample/AppConfig.java index ffc792d9df..8a177d2611 100644 --- a/spring-all/src/main/java/org/baeldung/sample/AppConfig.java +++ b/spring-all/src/main/java/org/baeldung/sample/AppConfig.java @@ -4,7 +4,7 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @Configuration -@ComponentScan("com.baeldung.autowire.sample") +@ComponentScan("org.baeldung.sample") public class AppConfig { } diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml index f087617709..5f77be43e3 100644 --- a/spring-boot/pom.xml +++ b/spring-boot/pom.xml @@ -67,6 +67,7 @@ com.h2database h2 + ${h2.version} @@ -219,6 +220,7 @@ 3.3.7-1 3.1.7 8.5.11 + 1.4.194 diff --git a/spring-boot/src/main/java/org/baeldung/config/H2JpaConfig.java b/spring-boot/src/main/java/org/baeldung/config/H2JpaConfig.java new file mode 100644 index 0000000000..ace7bb5a6d --- /dev/null +++ b/spring-boot/src/main/java/org/baeldung/config/H2JpaConfig.java @@ -0,0 +1,67 @@ +package org.baeldung.config; + +import java.util.Properties; + +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; +import org.springframework.core.env.Environment; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@Configuration +@EnableJpaRepositories(basePackages = { "org.baeldung.repository", "org.baeldung.boot.repository" }) +@PropertySource("classpath:persistence-generic-entity.properties") +@EnableTransactionManagement +public class H2JpaConfig { + + @Autowired + private Environment env; + + @Bean + public DataSource dataSource() { + final DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName")); + dataSource.setUrl(env.getProperty("jdbc.url")); + dataSource.setUsername(env.getProperty("jdbc.user")); + dataSource.setPassword(env.getProperty("jdbc.pass")); + + return dataSource; + } + + @Bean + public LocalContainerEntityManagerFactoryBean entityManagerFactory() { + final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); + em.setDataSource(dataSource()); + em.setPackagesToScan(new String[] { "org.baeldung.domain", "org.baeldung.boot.model" }); + em.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); + em.setJpaProperties(additionalProperties()); + return em; + } + + @Bean + JpaTransactionManager transactionManager(final EntityManagerFactory entityManagerFactory) { + final JpaTransactionManager transactionManager = new JpaTransactionManager(); + transactionManager.setEntityManagerFactory(entityManagerFactory); + return transactionManager; + } + + final Properties additionalProperties() { + final Properties hibernateProperties = new Properties(); + + hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); + hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); + hibernateProperties.setProperty("hibernate.show_sql", env.getProperty("hibernate.show_sql")); + + return hibernateProperties; + } + +} diff --git a/spring-boot/src/test/java/org/baeldung/SpringBootH2IntegrationTest.java b/spring-boot/src/test/java/org/baeldung/SpringBootH2IntegrationTest.java new file mode 100644 index 0000000000..185a36e571 --- /dev/null +++ b/spring-boot/src/test/java/org/baeldung/SpringBootH2IntegrationTest.java @@ -0,0 +1,28 @@ +package org.baeldung; + +import org.baeldung.config.H2JpaConfig; +import org.baeldung.domain.GenericEntity; +import org.baeldung.repository.GenericEntityRepository; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = { Application.class, H2JpaConfig.class }) +public class SpringBootH2IntegrationTest { + @Autowired + private GenericEntityRepository genericEntityRepository; + + @Test + public void givenGenericEntityRepository_whenSaveAndRetreiveEntity_thenOK() { + GenericEntity genericEntity = genericEntityRepository.save(new GenericEntity("test")); + GenericEntity foundEntity = genericEntityRepository.findOne(genericEntity.getId()); + assertNotNull(foundEntity); + assertEquals(genericEntity.getValue(), foundEntity.getValue()); + } +} \ No newline at end of file diff --git a/spring-boot/src/test/java/org/baeldung/SpringBootJPAIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/SpringBootJPAIntegrationTest.java index d4b19e6a1d..202d24ffc7 100644 --- a/spring-boot/src/test/java/org/baeldung/SpringBootJPAIntegrationTest.java +++ b/spring-boot/src/test/java/org/baeldung/SpringBootJPAIntegrationTest.java @@ -20,8 +20,8 @@ public class SpringBootJPAIntegrationTest { @Test public void givenGenericEntityRepository_whenSaveAndRetreiveEntity_thenOK() { GenericEntity genericEntity = genericEntityRepository.save(new GenericEntity("test")); - GenericEntity foundedEntity = genericEntityRepository.findOne(genericEntity.getId()); - assertNotNull(foundedEntity); - assertEquals(genericEntity.getValue(), foundedEntity.getValue()); + GenericEntity foundEntity = genericEntityRepository.findOne(genericEntity.getId()); + assertNotNull(foundEntity); + assertEquals(genericEntity.getValue(), foundEntity.getValue()); } } diff --git a/spring-boot/src/test/java/org/baeldung/SpringBootProfileIntegrationTest.java b/spring-boot/src/test/java/org/baeldung/SpringBootProfileIntegrationTest.java new file mode 100644 index 0000000000..806b38a8ce --- /dev/null +++ b/spring-boot/src/test/java/org/baeldung/SpringBootProfileIntegrationTest.java @@ -0,0 +1,30 @@ +package org.baeldung; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.baeldung.config.H2TestProfileJPAConfig; +import org.baeldung.domain.GenericEntity; +import org.baeldung.repository.GenericEntityRepository; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@SpringBootTest(classes = { Application.class, H2TestProfileJPAConfig.class }) +@ActiveProfiles("test") +public class SpringBootProfileIntegrationTest { + @Autowired + private GenericEntityRepository genericEntityRepository; + + @Test + public void givenGenericEntityRepository_whenSaveAndRetreiveEntity_thenOK() { + GenericEntity genericEntity = genericEntityRepository.save(new GenericEntity("test")); + GenericEntity foundEntity = genericEntityRepository.findOne(genericEntity.getId()); + assertNotNull(foundEntity); + assertEquals(genericEntity.getValue(), foundEntity.getValue()); + } +} diff --git a/spring-boot/src/test/java/org/baeldung/config/H2TestProfileJPAConfig.java b/spring-boot/src/test/java/org/baeldung/config/H2TestProfileJPAConfig.java new file mode 100644 index 0000000000..1d696f4a5d --- /dev/null +++ b/spring-boot/src/test/java/org/baeldung/config/H2TestProfileJPAConfig.java @@ -0,0 +1,66 @@ +package org.baeldung.config; + +import java.util.Properties; + +import javax.persistence.EntityManagerFactory; +import javax.sql.DataSource; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; +import org.springframework.core.env.Environment; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; +import org.springframework.jdbc.datasource.DriverManagerDataSource; +import org.springframework.orm.jpa.JpaTransactionManager; +import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; +import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter; +import org.springframework.transaction.annotation.EnableTransactionManagement; + +@Configuration +@EnableJpaRepositories(basePackages = { "org.baeldung.repository", "org.baeldung.boot.repository" }) +@EnableTransactionManagement +public class H2TestProfileJPAConfig { + + @Autowired + private Environment env; + + @Bean + @Profile("test") + public DataSource dataSource() { + final DriverManagerDataSource dataSource = new DriverManagerDataSource(); + dataSource.setDriverClassName("org.h2.Driver"); + dataSource.setUrl("jdbc:h2:mem:db;DB_CLOSE_DELAY=-1"); + dataSource.setUsername("sa"); + dataSource.setPassword("sa"); + + return dataSource; + } + + @Bean + public LocalContainerEntityManagerFactoryBean entityManagerFactory() { + final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean(); + em.setDataSource(dataSource()); + em.setPackagesToScan(new String[] { "org.baeldung.domain", "org.baeldung.boot.model" }); + em.setJpaVendorAdapter(new HibernateJpaVendorAdapter()); + em.setJpaProperties(additionalProperties()); + return em; + } + + @Bean + JpaTransactionManager transactionManager(final EntityManagerFactory entityManagerFactory) { + final JpaTransactionManager transactionManager = new JpaTransactionManager(); + transactionManager.setEntityManagerFactory(entityManagerFactory); + return transactionManager; + } + + final Properties additionalProperties() { + final Properties hibernateProperties = new Properties(); + + hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto")); + hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect")); + hibernateProperties.setProperty("hibernate.show_sql", env.getProperty("hibernate.show_sql")); + + return hibernateProperties; + } +} diff --git a/spring-boot/src/test/resources/application.properties b/spring-boot/src/test/resources/application.properties index 0e6cb86bc5..85e4e6e66f 100644 --- a/spring-boot/src/test/resources/application.properties +++ b/spring-boot/src/test/resources/application.properties @@ -2,4 +2,18 @@ spring.mail.host=localhost spring.mail.port=8025 spring.mail.properties.mail.smtp.auth=false -security.basic.enabled=false \ No newline at end of file +security.basic.enabled=false + +# spring.datasource.x +spring.datasource.driver-class-name=org.h2.Driver +spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1 +spring.datasource.username=sa +spring.datasource.password=sa + +# hibernate.X +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create-drop +hibernate.cache.use_second_level_cache=true +hibernate.cache.use_query_cache=true +hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory \ No newline at end of file diff --git a/spring-boot/src/test/resources/persistence-generic-entity.properties b/spring-boot/src/test/resources/persistence-generic-entity.properties new file mode 100644 index 0000000000..c60e7488b6 --- /dev/null +++ b/spring-boot/src/test/resources/persistence-generic-entity.properties @@ -0,0 +1,8 @@ +jdbc.driverClassName=org.h2.Driver +jdbc.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1 +jdbc.username=sa +jdbc.password=sa + +hibernate.dialect=org.hibernate.dialect.H2Dialect +hibernate.show_sql=true +hibernate.hbm2ddl.auto=create-drop \ No newline at end of file diff --git a/spring-cloud-data-flow/data-flow-shell/pom.xml b/spring-cloud-data-flow/data-flow-shell/pom.xml index d3bd297152..350f199d4b 100644 --- a/spring-cloud-data-flow/data-flow-shell/pom.xml +++ b/spring-cloud-data-flow/data-flow-shell/pom.xml @@ -68,6 +68,8 @@ org.apache.maven.plugins maven-surefire-plugin + 3 + true **/*IntegrationTest.java **/*LiveTest.java diff --git a/spring-cloud/pom.xml b/spring-cloud/pom.xml index 5b5b006d01..6d53b24647 100644 --- a/spring-cloud/pom.xml +++ b/spring-cloud/pom.xml @@ -13,6 +13,7 @@ spring-cloud-bootstrap spring-cloud-ribbon-client spring-cloud-rest + spring-cloud-zookeeper pom diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/pom.xml b/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/pom.xml index d9d08079b7..d9ef26280b 100644 --- a/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/pom.xml +++ b/spring-cloud/spring-cloud-rest/spring-cloud-rest-discovery-server/pom.xml @@ -76,6 +76,8 @@ org.apache.maven.plugins maven-surefire-plugin + 3 + true **/*IntegrationTest.java **/*LiveTest.java diff --git a/spring-cloud/spring-cloud-zookeeper/Greeting/pom.xml b/spring-cloud/spring-cloud-zookeeper/Greeting/pom.xml new file mode 100644 index 0000000000..4d19741210 --- /dev/null +++ b/spring-cloud/spring-cloud-zookeeper/Greeting/pom.xml @@ -0,0 +1,78 @@ + + + 4.0.0 + + com.baeldung.spring.cloud + spring-cloud-zookeeper + 1.0.0-SNAPSHOT + + Greeting + jar + + + org.springframework.boot + spring-boot-starter + 1.5.2.RELEASE + + + org.springframework + spring-web + 4.3.7.RELEASE + + + org.springframework.cloud + spring-cloud-starter-zookeeper-discovery + 1.0.3.RELEASE + + + org.springframework.boot + spring-boot-starter-actuator + 1.5.2.RELEASE + + + org.springframework.cloud + spring-cloud-starter-feign + 1.2.5.RELEASE + + + org.springframework.boot + spring-boot-starter-thymeleaf + 1.5.2.RELEASE + + + junit + junit + 4.12 + test + + + org.hamcrest + hamcrest-core + 1.3 + test + + + + + + + org.springframework.cloud + spring-cloud-dependencies + Brixton.SR7 + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + Greeting + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-zookeeper/Greeting/src/main/java/com/baeldung/spring/cloud/greeting/GreetingApplication.java b/spring-cloud/spring-cloud-zookeeper/Greeting/src/main/java/com/baeldung/spring/cloud/greeting/GreetingApplication.java new file mode 100644 index 0000000000..e8beebeadf --- /dev/null +++ b/spring-cloud/spring-cloud-zookeeper/Greeting/src/main/java/com/baeldung/spring/cloud/greeting/GreetingApplication.java @@ -0,0 +1,27 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.spring.cloud.greeting; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.netflix.feign.EnableFeignClients; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +@SpringBootApplication +@EnableDiscoveryClient +public class GreetingApplication { + + public static void main(String[] args) { + SpringApplication.run(GreetingApplication.class, args); + } + +} diff --git a/spring-cloud/spring-cloud-zookeeper/Greeting/src/main/java/com/baeldung/spring/cloud/greeting/GreetingController.java b/spring-cloud/spring-cloud-zookeeper/Greeting/src/main/java/com/baeldung/spring/cloud/greeting/GreetingController.java new file mode 100644 index 0000000000..d701a2c762 --- /dev/null +++ b/spring-cloud/spring-cloud-zookeeper/Greeting/src/main/java/com/baeldung/spring/cloud/greeting/GreetingController.java @@ -0,0 +1,33 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.spring.cloud.greeting; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.netflix.feign.EnableFeignClients; +import org.springframework.stereotype.Controller; + +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +@Controller +public class GreetingController { + + @Autowired + private HelloWorldClient helloWorldClient; + + @RequestMapping(value = "/get-greeting", method = RequestMethod.GET) + + public String greeting(Model model) { + + model.addAttribute("greeting", helloWorldClient.HelloWorld()); + return "greeting-view"; + + } + +} diff --git a/spring-cloud/spring-cloud-zookeeper/Greeting/src/main/java/com/baeldung/spring/cloud/greeting/HelloWorldClient.java b/spring-cloud/spring-cloud-zookeeper/Greeting/src/main/java/com/baeldung/spring/cloud/greeting/HelloWorldClient.java new file mode 100644 index 0000000000..d2b91ca715 --- /dev/null +++ b/spring-cloud/spring-cloud-zookeeper/Greeting/src/main/java/com/baeldung/spring/cloud/greeting/HelloWorldClient.java @@ -0,0 +1,49 @@ +package com.baeldung.spring.cloud.greeting; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.netflix.feign.EnableFeignClients; +import org.springframework.cloud.netflix.feign.FeignClient; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +/** + * This class provides operations on the Validation service. + * + *

+ * When booting up, Spring will try and find a service named "Validation" (see + * the FeignClient below) under the available ZooKeeper instance. + *

+ * + */ +@Configuration +@EnableFeignClients +@EnableDiscoveryClient +public class HelloWorldClient { + + @Autowired + private TheClient theClient; + + @FeignClient(name = "HelloWorld") + interface TheClient { + + @RequestMapping(path = "/helloworld", method = RequestMethod.GET) + @ResponseBody + String HelloWorld(); + } + + /** + * Initiate call to Validation. + * + * @param name + * @return the response + */ + public String HelloWorld() { + return theClient.HelloWorld(); + } + +} diff --git a/spring-cloud/spring-cloud-zookeeper/Greeting/src/main/resources/application.yml b/spring-cloud/spring-cloud-zookeeper/Greeting/src/main/resources/application.yml new file mode 100644 index 0000000000..6140f6ab2f --- /dev/null +++ b/spring-cloud/spring-cloud-zookeeper/Greeting/src/main/resources/application.yml @@ -0,0 +1,11 @@ +spring: + application: + name: Greeting + cloud: + zookeeper: + connect-string: localhost:2181 +server: + port: 8083 +logging: + level: + org.apache.zookeeper.ClientCnxn: WARN \ No newline at end of file diff --git a/spring-cloud/spring-cloud-zookeeper/Greeting/src/main/resources/templates/greeting-view.html b/spring-cloud/spring-cloud-zookeeper/Greeting/src/main/resources/templates/greeting-view.html new file mode 100644 index 0000000000..42cdadb487 --- /dev/null +++ b/spring-cloud/spring-cloud-zookeeper/Greeting/src/main/resources/templates/greeting-view.html @@ -0,0 +1,9 @@ + + + + Greeting Page + + +

+ + \ 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 new file mode 100644 index 0000000000..1c829a50df --- /dev/null +++ b/spring-cloud/spring-cloud-zookeeper/HelloWorld/pom.xml @@ -0,0 +1,51 @@ + + + 4.0.0 + + com.baeldung.spring.cloud + spring-cloud-zookeeper + 1.0.0-SNAPSHOT + + HelloWorld + jar + + + org.springframework.boot + spring-boot-starter + 1.5.2.RELEASE + + + org.springframework + spring-web + 4.3.7.RELEASE + + + org.springframework.cloud + spring-cloud-starter-zookeeper-discovery + 1.0.3.RELEASE + + + + + + + org.springframework.cloud + spring-cloud-dependencies + Brixton.SR7 + pom + import + + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + HelloWorld + \ No newline at end of file diff --git a/spring-cloud/spring-cloud-zookeeper/HelloWorld/src/main/java/com/baeldung/spring/cloud/helloworld/HelloWorldApplication.java b/spring-cloud/spring-cloud-zookeeper/HelloWorld/src/main/java/com/baeldung/spring/cloud/helloworld/HelloWorldApplication.java new file mode 100644 index 0000000000..8b35071516 --- /dev/null +++ b/spring-cloud/spring-cloud-zookeeper/HelloWorld/src/main/java/com/baeldung/spring/cloud/helloworld/HelloWorldApplication.java @@ -0,0 +1,18 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.spring.cloud.helloworld; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; + +@SpringBootApplication +@EnableDiscoveryClient +public class HelloWorldApplication { + public static void main(String[] args) { + SpringApplication.run(HelloWorldApplication.class, args); + } +} diff --git a/spring-cloud/spring-cloud-zookeeper/HelloWorld/src/main/java/com/baeldung/spring/cloud/helloworld/HelloWorldController.java b/spring-cloud/spring-cloud-zookeeper/HelloWorld/src/main/java/com/baeldung/spring/cloud/helloworld/HelloWorldController.java new file mode 100644 index 0000000000..d5ea84de19 --- /dev/null +++ b/spring-cloud/spring-cloud-zookeeper/HelloWorld/src/main/java/com/baeldung/spring/cloud/helloworld/HelloWorldController.java @@ -0,0 +1,21 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package com.baeldung.spring.cloud.helloworld; + +import org.springframework.http.MediaType; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HelloWorldController { + + @RequestMapping(path = "/helloworld", method = RequestMethod.GET) + public String HelloWorld() { + return "Hello World!"; + } + +} diff --git a/spring-cloud/spring-cloud-zookeeper/HelloWorld/src/main/resources/application.yml b/spring-cloud/spring-cloud-zookeeper/HelloWorld/src/main/resources/application.yml new file mode 100644 index 0000000000..550165a762 --- /dev/null +++ b/spring-cloud/spring-cloud-zookeeper/HelloWorld/src/main/resources/application.yml @@ -0,0 +1,16 @@ +spring: + application: + name: HelloWorld + cloud: + zookeeper: + connect-string: localhost:2181 + discovery: + enabled: true +server: + port: 8081 +endpoints: + restart: + enabled: true +logging: + level: + org.apache.zookeeper.ClientCnxn: WARN \ No newline at end of file diff --git a/spring-cloud/spring-cloud-zookeeper/pom.xml b/spring-cloud/spring-cloud-zookeeper/pom.xml new file mode 100644 index 0000000000..8406813161 --- /dev/null +++ b/spring-cloud/spring-cloud-zookeeper/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + + com.baeldung.spring.cloud + spring-cloud + 1.0.0-SNAPSHOT + + spring-cloud-zookeeper + pom + + Greeting + HelloWorld + + \ No newline at end of file diff --git a/spring-data-neo4j/pom.xml b/spring-data-neo4j/pom.xml index 96606d597b..7df48498e5 100644 --- a/spring-data-neo4j/pom.xml +++ b/spring-data-neo4j/pom.xml @@ -10,31 +10,31 @@ org.neo4j neo4j - 3.1.0 + ${neo4j.version} org.neo4j neo4j-ogm-core - 2.1.1 + ${neo4j-ogm.version} org.neo4j neo4j-ogm-embedded-driver - 2.1.1 + ${neo4j-ogm.version} org.neo4j.driver neo4j-java-driver - 1.1.1 + ${neo4j-java-driver.version} org.springframework.data spring-data-neo4j - 4.2.0.RELEASE + ${spring-data-neo4j.version} @@ -75,7 +75,7 @@ org.neo4j neo4j-ogm-test - ${neo4j-ogm-test.version} + ${neo4j-ogm.version} test @@ -160,12 +160,13 @@ UTF-8 UTF-8 + 1.1.1 3.1.0 4.1.6.RELEASE 1.1 1.4.3.RELEASE 4.3.5.RELEASE - 2.1.1 + 2.1.1 4.12 diff --git a/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/config/MovieDatabaseNeo4jTestConfiguration.java b/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/config/MovieDatabaseNeo4jTestConfiguration.java index 7bb1b78a09..fda478e5be 100644 --- a/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/config/MovieDatabaseNeo4jTestConfiguration.java +++ b/spring-data-neo4j/src/main/java/com/baeldung/spring/data/neo4j/config/MovieDatabaseNeo4jTestConfiguration.java @@ -5,20 +5,22 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; +import org.springframework.data.neo4j.config.Neo4jConfiguration; import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories; import org.springframework.transaction.annotation.EnableTransactionManagement; +@Configuration @EnableTransactionManagement @ComponentScan(basePackages = { "com.baeldung.spring.data.neo4j.services" }) -@Configuration @EnableNeo4jRepositories(basePackages = "com.baeldung.spring.data.neo4j.repostory") @Profile({ "embedded", "test" }) -public class MovieDatabaseNeo4jTestConfiguration { +public class MovieDatabaseNeo4jTestConfiguration extends Neo4jConfiguration { @Bean public org.neo4j.ogm.config.Configuration getConfiguration() { - org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration(); - config.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver"); + final org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration(); + config.driverConfiguration() + .setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver"); return config; } @@ -26,4 +28,5 @@ public class MovieDatabaseNeo4jTestConfiguration { public SessionFactory getSessionFactory() { return new SessionFactory(getConfiguration(), "com.baeldung.spring.data.neo4j.domain"); } + } diff --git a/spring-hibernate4/README.md b/spring-hibernate4/README.md index 02888c4ad0..08cfe2b538 100644 --- a/spring-hibernate4/README.md +++ b/spring-hibernate4/README.md @@ -13,6 +13,7 @@ - [Eager/Lazy Loading In Hibernate](http://www.baeldung.com/hibernate-lazy-eager-loading) - [Hibernate Criteria Queries](http://www.baeldung.com/hibernate-criteria-queries) - [Hibernate One to Many Annotation Tutorial](http://www.baeldung.com/hibernate-one-to-many) +- [Guide to @Immutable Annotation in Hibernate](http://www.baeldung.com/hibernate-immutable) ### Quick Start diff --git a/spring-jersey/pom.xml b/spring-jersey/pom.xml index 41ebb9a6b5..e6c8ea6ef5 100644 --- a/spring-jersey/pom.xml +++ b/spring-jersey/pom.xml @@ -45,6 +45,8 @@ maven-surefire-plugin ${maven-surefire-plugin.version} + 3 + true **/*IntegrationTest.java **/*LiveTest.java diff --git a/spring-mvc-velocity/pom.xml b/spring-mvc-velocity/pom.xml index 31f2d19375..0a9b3a016e 100644 --- a/spring-mvc-velocity/pom.xml +++ b/spring-mvc-velocity/pom.xml @@ -136,8 +136,9 @@ org.apache.maven.plugins maven-surefire-plugin - ${maven-surefire-plugin.version} + 3 + true **/*IntegrationTest.java diff --git a/spring-thymeleaf/pom.xml b/spring-thymeleaf/pom.xml index f5dfc9931e..be443e15df 100644 --- a/spring-thymeleaf/pom.xml +++ b/spring-thymeleaf/pom.xml @@ -176,6 +176,8 @@ maven-surefire-plugin ${maven-surefire-plugin.version} + 3 + true **/*IntegrationTest.java **/*LiveTest.java diff --git a/spring-userservice/pom.xml b/spring-userservice/pom.xml index c0099173ee..0f3ed96c4e 100644 --- a/spring-userservice/pom.xml +++ b/spring-userservice/pom.xml @@ -239,6 +239,9 @@ maven-surefire-plugin ${maven-surefire-plugin.version} + 3 + true + **/*IntegrationTest.java