Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
ba7433e489
|
@ -2,10 +2,10 @@ package com.baeldung.algorithms.primechecker;
|
|||
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class BigIntegerPrimeChecker implements PrimeChecker{
|
||||
public class BigIntegerPrimeChecker implements PrimeChecker<Long>{
|
||||
|
||||
@Override
|
||||
public boolean isPrime(int number) {
|
||||
public boolean isPrime(Long number) {
|
||||
BigInteger bigInt = BigInteger.valueOf(number);
|
||||
return bigInt.isProbablePrime(100);
|
||||
}
|
||||
|
|
|
@ -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<Integer>{
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<Integer>{
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package com.baeldung.algorithms.primechecker;
|
||||
|
||||
public interface PrimeChecker {
|
||||
public interface PrimeChecker <T> {
|
||||
|
||||
public boolean isPrime( int number );
|
||||
public boolean isPrime( T number );
|
||||
}
|
||||
|
|
|
@ -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<Integer>{
|
||||
|
||||
@Override
|
||||
public boolean isPrime(int number) {
|
||||
public boolean isPrime(Integer number) {
|
||||
return Primes.isPrime(number);
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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(){
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -101,9 +101,7 @@
|
|||
<dependency>
|
||||
<groupId>org.dbdoclet</groupId>
|
||||
<artifactId>herold</artifactId>
|
||||
<version>6.1.0</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/src/test/resources/jars/herold.jar</systemPath>
|
||||
<version>8.0.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -140,6 +138,8 @@
|
|||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<forkCount>3</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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("<?xml") || line.startsWith("<article") || line.startsWith("</article")) && count > 4)) {
|
||||
} else if (!((line.startsWith("<?xml") || line.startsWith("<article") || line.startsWith("</article")) && (count > 4))) {
|
||||
writer.write(line.replaceAll("xml:id=\"", "xml:id=\"" + count));
|
||||
}
|
||||
writer.write("\n");
|
||||
|
|
Binary file not shown.
|
@ -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)
|
||||
|
|
|
@ -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<String> getTokens(String str) {
|
||||
List<String> tokens = new ArrayList<String>();
|
||||
// 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<String> getTokens(String str) {
|
||||
List<String> tokens = new ArrayList<String>();
|
||||
// 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<String> getTokensWithCollection(String str) {
|
||||
StringTokenizer tokenizer = new StringTokenizer(str, ",");
|
||||
|
||||
return Collections.list(tokenizer).stream()
|
||||
.map(token -> (String) token)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<String> getTokensFromFile(String path, String delim) {
|
||||
List<String> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
1|IND|India
|
||||
2|MY|Malaysia
|
||||
3|AU|Australia
|
|
|
@ -11,20 +11,37 @@ import static org.junit.Assert.assertEquals;
|
|||
public class ApplicationTest {
|
||||
|
||||
Application application = new Application();
|
||||
List<String> expectedTokens = new ArrayList<String>();
|
||||
|
||||
List<String> expectedTokensForString = new ArrayList<String>();
|
||||
List<String> expectedTokensForFile = new ArrayList<String>();
|
||||
|
||||
@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<String> actualTokens = application.getTokens(str);
|
||||
assertEquals(expectedTokens, actualTokens);
|
||||
assertEquals(expectedTokensForString, actualTokens);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void givenFile_thenGetListOfString() {
|
||||
List<String> actualTokens = application.getTokensFromFile("data.csv", "|");
|
||||
assertEquals(expectedTokensForFile, actualTokens);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>cucumber</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
<java.source.version>1.8</java.source.version>
|
||||
<java.target.version>1.8</java.target.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.plugin.version>3.5.1</maven.compiler.plugin.version>
|
||||
<slf4j.version>1.7.21</slf4j.version>
|
||||
<logback.version>1.1.7</logback.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<hamcrest.library.version>1.3</hamcrest.library.version>
|
||||
<cucumber.version>1.2.5</cucumber.version>
|
||||
<surefire.plugin.version>2.19.1</surefire.plugin.version>
|
||||
</properties>
|
||||
|
||||
<modules>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>info.cukes</groupId>
|
||||
<artifactId>cucumber-junit</artifactId>
|
||||
<version>${cucumber.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>info.cukes</groupId>
|
||||
<artifactId>cucumber-java</artifactId>
|
||||
<version>${cucumber.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<version>${hamcrest.library.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${slf4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>${logback.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-core</artifactId>
|
||||
<version>${logback.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>${maven.compiler.plugin.version}</version>
|
||||
<configuration>
|
||||
<verbose>true</verbose>
|
||||
<fork>true</fork>
|
||||
<source>${java.source.version}</source>
|
||||
<target>${java.target.version}</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${surefire.plugin.version}</version>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>**/CalculatorTest.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
|
@ -0,0 +1,7 @@
|
|||
package com.baeldung.cucumber.calculator;
|
||||
|
||||
public class Calculator {
|
||||
public int add(int a, int b) {
|
||||
return a + b;
|
||||
}
|
||||
}
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
|
@ -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 {
|
||||
}
|
|
@ -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 <num1> & <num2>
|
||||
Given I have a calculator
|
||||
When I add <num1> and <num2>
|
||||
Then the result should be <total>
|
||||
|
||||
Examples:
|
||||
| num1 | num2 | total |
|
||||
| -2 | 3 | 1 |
|
||||
| 10 | 15 | 25 |
|
||||
| 99 | -99 | 0 |
|
||||
| -1 | -10 | -11 |
|
|
@ -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
|
|
@ -0,0 +1,13 @@
|
|||
<configuration scan="true">
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n%ex
|
||||
</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
|
@ -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");
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
3
pom.xml
3
pom.xml
|
@ -215,6 +215,7 @@
|
|||
<module>rabbitmq</module>
|
||||
<module>vertx</module>
|
||||
<module>spring-data-gemfire</module>
|
||||
<module>cucumber</module>
|
||||
</modules>
|
||||
|
||||
<build>
|
||||
|
@ -233,6 +234,8 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<forkCount>3</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LongRunningUnitTest.java</exclude>
|
||||
|
|
|
@ -181,6 +181,8 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<forkCount>3</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
|
|
|
@ -32,6 +32,8 @@
|
|||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<forkCount>3</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
|
|
|
@ -21,6 +21,8 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<forkCount>3</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LongRunningUnitTest.java</exclude>
|
||||
|
|
|
@ -80,6 +80,8 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<forkCount>3</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
|
|
|
@ -70,6 +70,8 @@
|
|||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<forkCount>3</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
|
|
|
@ -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 {
|
||||
|
||||
}
|
||||
|
|
|
@ -67,6 +67,7 @@
|
|||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<version>${h2.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -219,6 +220,7 @@
|
|||
<bootstrap.version>3.3.7-1</bootstrap.version>
|
||||
<subethasmtp.version>3.1.7</subethasmtp.version>
|
||||
<tomee-servlet-api.version>8.5.11</tomee-servlet-api.version>
|
||||
<h2.version>1.4.194</h2.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -2,4 +2,18 @@ spring.mail.host=localhost
|
|||
spring.mail.port=8025
|
||||
spring.mail.properties.mail.smtp.auth=false
|
||||
|
||||
security.basic.enabled=false
|
||||
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
|
|
@ -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
|
|
@ -68,6 +68,8 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<forkCount>3</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<module>spring-cloud-bootstrap</module>
|
||||
<module>spring-cloud-ribbon-client</module>
|
||||
<module>spring-cloud-rest</module>
|
||||
<module>spring-cloud-zookeeper</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
|
|
|
@ -76,6 +76,8 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<forkCount>3</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.baeldung.spring.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>Greeting</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>1.5.2.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>4.3.7.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
|
||||
<version>1.0.3.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
<version>1.5.2.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-feign</artifactId>
|
||||
<version>1.2.5.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||
<version>1.5.2.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<version>1.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId> <!--changed -->
|
||||
<version>Brixton.SR7</version> <!--changed -->
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<name>Greeting</name>
|
||||
</project>
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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";
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -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.
|
||||
*
|
||||
* <p>
|
||||
* When booting up, Spring will try and find a service named "Validation" (see
|
||||
* the FeignClient below) under the available ZooKeeper instance.
|
||||
* </p>
|
||||
*
|
||||
*/
|
||||
@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();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
spring:
|
||||
application:
|
||||
name: Greeting
|
||||
cloud:
|
||||
zookeeper:
|
||||
connect-string: localhost:2181
|
||||
server:
|
||||
port: 8083
|
||||
logging:
|
||||
level:
|
||||
org.apache.zookeeper.ClientCnxn: WARN
|
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<title>Greeting Page</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2 th:text="${greeting}"/>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,51 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.baeldung.spring.cloud</groupId>
|
||||
<artifactId>spring-cloud-zookeeper</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>HelloWorld</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>1.5.2.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
<version>4.3.7.RELEASE</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
|
||||
<version>1.0.3.RELEASE</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId> <!--changed -->
|
||||
<version>Brixton.SR7</version> <!--changed -->
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<name>HelloWorld</name>
|
||||
</project>
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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!";
|
||||
}
|
||||
|
||||
}
|
|
@ -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
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>com.baeldung.spring.cloud</groupId>
|
||||
<artifactId>spring-cloud</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>spring-cloud-zookeeper</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>Greeting</module>
|
||||
<module>HelloWorld</module>
|
||||
</modules>
|
||||
</project>
|
|
@ -10,31 +10,31 @@
|
|||
<dependency>
|
||||
<groupId>org.neo4j</groupId>
|
||||
<artifactId>neo4j</artifactId>
|
||||
<version>3.1.0</version>
|
||||
<version>${neo4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.neo4j</groupId>
|
||||
<artifactId>neo4j-ogm-core</artifactId>
|
||||
<version>2.1.1</version>
|
||||
<version>${neo4j-ogm.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.neo4j</groupId>
|
||||
<artifactId>neo4j-ogm-embedded-driver</artifactId>
|
||||
<version>2.1.1</version>
|
||||
<version>${neo4j-ogm.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.neo4j.driver</groupId>
|
||||
<artifactId>neo4j-java-driver</artifactId>
|
||||
<version>1.1.1</version>
|
||||
<version>${neo4j-java-driver.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-neo4j</artifactId>
|
||||
<version>4.2.0.RELEASE</version>
|
||||
<version>${spring-data-neo4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -75,7 +75,7 @@
|
|||
<dependency>
|
||||
<groupId>org.neo4j</groupId>
|
||||
<artifactId>neo4j-ogm-test</artifactId>
|
||||
<version>${neo4j-ogm-test.version}</version>
|
||||
<version>${neo4j-ogm.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
|
@ -160,12 +160,13 @@
|
|||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
<neo4j-java-driver.version>1.1.1</neo4j-java-driver.version>
|
||||
<neo4j.version>3.1.0</neo4j.version>
|
||||
<spring-data-neo4j.version>4.1.6.RELEASE</spring-data-neo4j.version>
|
||||
<jackson-jsog.version>1.1</jackson-jsog.version>
|
||||
<spring-boot.version>1.4.3.RELEASE</spring-boot.version>
|
||||
<spring-test.version>4.3.5.RELEASE</spring-test.version>
|
||||
<neo4j-ogm-test.version>2.1.1</neo4j-ogm-test.version>
|
||||
<neo4j-ogm.version>2.1.1</neo4j-ogm.version>
|
||||
|
||||
<junit.version>4.12</junit.version>
|
||||
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<forkCount>3</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
|
|
|
@ -136,8 +136,9 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<forkCount>3</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
</excludes>
|
||||
|
|
|
@ -176,6 +176,8 @@
|
|||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<forkCount>3</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
<exclude>**/*LiveTest.java</exclude>
|
||||
|
|
|
@ -239,6 +239,9 @@
|
|||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<forkCount>3</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
|
||||
<excludes>
|
||||
<exclude>**/*IntegrationTest.java</exclude>
|
||||
</excludes>
|
||||
|
|
Loading…
Reference in New Issue