Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.objectclass;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Borrower extends User {
|
||||
|
||||
private double totalLoanAmount;
|
||||
|
||||
public double requestLoan(double amount) {
|
||||
totalLoanAmount = amount;
|
||||
return totalLoanAmount;
|
||||
}
|
||||
|
||||
public double increaseLoan(double increaseBy) {
|
||||
return totalLoanAmount + increaseBy;
|
||||
}
|
||||
|
||||
public double payLoan(double amount) {
|
||||
return totalLoanAmount - amount;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.baeldung.objectclass;
|
||||
|
||||
public class Lender extends User {
|
||||
|
||||
private double totalInvestmentAmount;
|
||||
|
||||
public double invest(double amount) {
|
||||
totalInvestmentAmount = amount;
|
||||
return totalInvestmentAmount;
|
||||
}
|
||||
|
||||
public double increaseInvestment(double increaseBy) {
|
||||
return totalInvestmentAmount + increaseBy;
|
||||
}
|
||||
|
||||
public double collectDividends() {
|
||||
return totalInvestmentAmount * 0.07;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.baeldung.objectclass;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class User {
|
||||
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
|
||||
|
||||
}
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
package com.baeldung.objectclass;
|
||||
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class CreditAppUnitTest {
|
||||
|
||||
@Test
|
||||
public void givenLender_whenInstanceOf_thenReturnTrue() {
|
||||
User lender = new Lender();
|
||||
assertTrue(lender instanceof Lender);
|
||||
assertTrue(lender instanceof User);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenUser_whenInstanceOfLender_thenDowncast() {
|
||||
User user = new Lender();
|
||||
Lender lender = null;
|
||||
|
||||
if(user instanceof Lender) {
|
||||
lender = (Lender) user;
|
||||
}
|
||||
|
||||
assertNotNull(lender);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenUser_whenIsInstanceOfLender_thenDowncast() {
|
||||
User user = new Lender();
|
||||
Lender lender = null;
|
||||
|
||||
if(Lender.class.isInstance(user)) {
|
||||
lender = (Lender) user;
|
||||
}
|
||||
|
||||
assertNotNull(lender);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBorrower_whenLoanAmountIsDouble_thenRequestLoan() {
|
||||
Borrower borrower = new Borrower();
|
||||
double amount = 100.0;
|
||||
|
||||
//if(amount instanceof Double) // Compilation error, no autoboxing
|
||||
if(Double.class.isInstance(amount)) {
|
||||
borrower.requestLoan(amount);
|
||||
}
|
||||
assertEquals(100, borrower.getTotalLoanAmount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBorrower_whenLoanAmountIsNotString_thenRequestLoan() {
|
||||
Borrower borrower = new Borrower();
|
||||
Double amount = 100.0;
|
||||
|
||||
//if(amount instanceof String) // Compilation error, incompatible operands
|
||||
if(!String.class.isInstance(amount)) {
|
||||
borrower.requestLoan(amount);
|
||||
}
|
||||
assertEquals(100, borrower.getTotalLoanAmount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenLender_whenGetClass_thenEqualsLenderType() {
|
||||
User lender = new Lender();
|
||||
assertEquals(Lender.class, lender.getClass());
|
||||
assertNotEquals(User.class, lender.getClass());
|
||||
}
|
||||
|
||||
}
|
||||
+3
-4
@@ -256,10 +256,9 @@
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<wsdlDirectory>src/main/resources</wsdlDirectory>
|
||||
<wsdlFiles>
|
||||
<wsdlFile>country.wsdl</wsdlFile>
|
||||
</wsdlFiles>
|
||||
<wsdlUrls>
|
||||
<wsdlUrl>http://localhost:8888/ws/country?wsdl</wsdlUrl>
|
||||
</wsdlUrls>
|
||||
<keep>true</keep>
|
||||
<packageName>com.baeldung.soap.ws.client.generated</packageName>
|
||||
<sourceDestDir>src/main/java</sourceDestDir>
|
||||
|
||||
+3
-3
@@ -12,11 +12,11 @@ import javax.xml.ws.WebServiceFeature;
|
||||
|
||||
/**
|
||||
* This class was generated by the JAX-WS RI.
|
||||
* JAX-WS RI 2.3.2
|
||||
* JAX-WS RI 2.2.9-b130926.1035
|
||||
* Generated source version: 2.2
|
||||
*
|
||||
*/
|
||||
@WebServiceClient(name = "CountryServiceImplService", targetNamespace = "http://server.ws.soap.baeldung.com/", wsdlLocation = "file:src/main/resources/country.wsdl")
|
||||
@WebServiceClient(name = "CountryServiceImplService", targetNamespace = "http://server.ws.soap.baeldung.com/", wsdlLocation = "http://localhost:8888/ws/country?wsdl")
|
||||
public class CountryServiceImplService extends Service {
|
||||
|
||||
private final static URL COUNTRYSERVICEIMPLSERVICE_WSDL_LOCATION;
|
||||
@@ -27,7 +27,7 @@ public class CountryServiceImplService extends Service {
|
||||
URL url = null;
|
||||
WebServiceException e = null;
|
||||
try {
|
||||
url = new URL("file:src/main/resources/country.wsdl");
|
||||
url = new URL("http://localhost:8888/ws/country?wsdl");
|
||||
} catch (MalformedURLException ex) {
|
||||
e = new WebServiceException(ex);
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?><!-- Published by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. --><!-- Generated by JAX-WS RI (http://jax-ws.java.net). RI's version is JAX-WS RI 2.2.9-b130926.1035 svn-revision#5f6196f2b90e9460065a4c2f4e30e065b245e51e. -->
|
||||
<definitions xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsp="http://www.w3.org/ns/ws-policy"
|
||||
xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
|
||||
xmlns:tns="http://server.ws.soap.baeldung.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/"
|
||||
targetNamespace="http://server.ws.soap.baeldung.com/" name="CountryServiceImplService">
|
||||
<types>
|
||||
<xsd:schema>
|
||||
<xsd:import namespace="http://server.ws.soap.baeldung.com/" schemaLocation="http://localhost:8888/ws/country?xsd=1"></xsd:import>
|
||||
</xsd:schema>
|
||||
</types>
|
||||
<message name="findByName">
|
||||
<part name="arg0" type="xsd:string"></part>
|
||||
</message>
|
||||
<message name="findByNameResponse">
|
||||
<part name="return" type="tns:country"></part>
|
||||
</message>
|
||||
<portType name="CountryService">
|
||||
<operation name="findByName">
|
||||
<input wsam:Action="http://server.ws.soap.baeldung.com/CountryService/findByNameRequest" message="tns:findByName"></input>
|
||||
<output wsam:Action="http://server.ws.soap.baeldung.com/CountryService/findByNameResponse" message="tns:findByNameResponse"></output>
|
||||
</operation>
|
||||
</portType>
|
||||
<binding name="CountryServiceImplPortBinding" type="tns:CountryService">
|
||||
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="rpc"></soap:binding>
|
||||
<operation name="findByName">
|
||||
<soap:operation soapAction=""></soap:operation>
|
||||
<input>
|
||||
<soap:body use="literal" namespace="http://server.ws.soap.baeldung.com/"></soap:body>
|
||||
</input>
|
||||
<output>
|
||||
<soap:body use="literal" namespace="http://server.ws.soap.baeldung.com/"></soap:body>
|
||||
</output>
|
||||
</operation>
|
||||
</binding>
|
||||
<service name="CountryServiceImplService">
|
||||
<port name="CountryServiceImplPort" binding="tns:CountryServiceImplPortBinding">
|
||||
<soap:address location="http://localhost:8888/ws/country"></soap:address>
|
||||
</port>
|
||||
</service>
|
||||
</definitions>
|
||||
@@ -128,6 +128,21 @@
|
||||
<version>${awaitility.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.rosuda.REngine</groupId>
|
||||
<artifactId>Rserve</artifactId>
|
||||
<version>${rserve.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.jbytecode</groupId>
|
||||
<artifactId>RCaller</artifactId>
|
||||
<version>${rcaller.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.renjin</groupId>
|
||||
<artifactId>renjin-script-engine</artifactId>
|
||||
<version>${renjin.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<repositories>
|
||||
@@ -137,6 +152,13 @@
|
||||
<url>http://repo.numericalmethod.com/maven/</url>
|
||||
<layout>default</layout>
|
||||
</repository>
|
||||
|
||||
<!-- Needed for Renjin -->
|
||||
<repository>
|
||||
<id>bedatadriven</id>
|
||||
<name>bedatadriven public repo</name>
|
||||
<url>https://nexus.bedatadriven.com/content/groups/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<properties>
|
||||
@@ -153,6 +175,27 @@
|
||||
<assertj.version>3.6.2</assertj.version>
|
||||
<slf4j.version>1.7.25</slf4j.version>
|
||||
<awaitility.version>3.0.0</awaitility.version>
|
||||
<renjin.version>RELEASE</renjin.version>
|
||||
<rcaller.version>3.0</rcaller.version>
|
||||
<rserve.version>1.8.1</rserve.version>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<!-- Excludes FastR classes from compilations since they require GraalVM -->
|
||||
<excludes>
|
||||
<exclude>com/baeldung/r/FastRMean.java</exclude>
|
||||
</excludes>
|
||||
<testExcludes>
|
||||
<exclude>com/baeldung/r/FastRMeanUnitTest.java</exclude>
|
||||
</testExcludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.baeldung.r;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
/**
|
||||
* FastR showcase.
|
||||
*
|
||||
* @author Donato Rimenti
|
||||
*/
|
||||
public class FastRMean {
|
||||
|
||||
/**
|
||||
* Invokes the customMean R function passing the given values as arguments.
|
||||
*
|
||||
* @param values the input to the mean script
|
||||
* @return the result of the R script
|
||||
*/
|
||||
public double mean(int[] values) {
|
||||
Context polyglot = Context.newBuilder()
|
||||
.allowAllAccess(true)
|
||||
.build();
|
||||
String meanScriptContent = RUtils.getMeanScriptContent();
|
||||
polyglot.eval("R", meanScriptContent);
|
||||
Value rBindings = polyglot.getBindings("R");
|
||||
Value rInput = rBindings.getMember("c")
|
||||
.execute(values);
|
||||
return rBindings.getMember("customMean")
|
||||
.execute(rInput)
|
||||
.asDouble();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.baeldung.r;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import com.github.rcaller.rstuff.RCaller;
|
||||
import com.github.rcaller.rstuff.RCallerOptions;
|
||||
import com.github.rcaller.rstuff.RCode;
|
||||
|
||||
/**
|
||||
* RCaller showcase.
|
||||
*
|
||||
* @author Donato Rimenti
|
||||
*/
|
||||
public class RCallerMean {
|
||||
|
||||
/**
|
||||
* Invokes the customMean R function passing the given values as arguments.
|
||||
*
|
||||
* @param values the input to the mean script
|
||||
* @return the result of the R script
|
||||
* @throws IOException if any error occurs
|
||||
* @throws URISyntaxException if any error occurs
|
||||
*/
|
||||
public double mean(int[] values) throws IOException, URISyntaxException {
|
||||
String fileContent = RUtils.getMeanScriptContent();
|
||||
RCode code = RCode.create();
|
||||
code.addRCode(fileContent);
|
||||
code.addIntArray("input", values);
|
||||
code.addRCode("result <- customMean(input)");
|
||||
RCaller caller = RCaller.create(code, RCallerOptions.create());
|
||||
caller.runAndReturnResult("result");
|
||||
return caller.getParser()
|
||||
.getAsDoubleArray("result")[0];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.baeldung.r;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Utility class for loading the script.R content.
|
||||
*
|
||||
* @author Donato Rimenti
|
||||
*/
|
||||
public class RUtils {
|
||||
|
||||
/**
|
||||
* Loads the script.R and returns its content as a string.
|
||||
*
|
||||
* @return the script.R content as a string
|
||||
* @throws IOException if any error occurs
|
||||
* @throws URISyntaxException if any error occurs
|
||||
*/
|
||||
static String getMeanScriptContent() throws IOException, URISyntaxException {
|
||||
URI rScriptUri = RUtils.class.getClassLoader()
|
||||
.getResource("script.R")
|
||||
.toURI();
|
||||
Path inputScript = Paths.get(rScriptUri);
|
||||
return Files.lines(inputScript)
|
||||
.collect(Collectors.joining());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.baeldung.r;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import org.renjin.script.RenjinScriptEngine;
|
||||
import org.renjin.sexp.DoubleArrayVector;
|
||||
|
||||
/**
|
||||
* Renjin showcase.
|
||||
*
|
||||
* @author Donato Rimenti
|
||||
*/
|
||||
public class RenjinMean {
|
||||
|
||||
/**
|
||||
* Invokes the customMean R function passing the given values as arguments.
|
||||
*
|
||||
* @param values the input to the mean script
|
||||
* @return the result of the R script
|
||||
* @throws IOException if any error occurs
|
||||
* @throws URISyntaxException if any error occurs
|
||||
* @throws ScriptException if any error occurs
|
||||
*/
|
||||
public double mean(int[] values) throws IOException, URISyntaxException, ScriptException {
|
||||
RenjinScriptEngine engine = new RenjinScriptEngine();
|
||||
String meanScriptContent = RUtils.getMeanScriptContent();
|
||||
engine.put("input", values);
|
||||
engine.eval(meanScriptContent);
|
||||
DoubleArrayVector result = (DoubleArrayVector) engine.eval("customMean(input)");
|
||||
return result.asReal();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.baeldung.r;
|
||||
|
||||
import org.rosuda.REngine.REXPMismatchException;
|
||||
import org.rosuda.REngine.REngineException;
|
||||
import org.rosuda.REngine.Rserve.RConnection;
|
||||
|
||||
/**
|
||||
* Rserve showcase.
|
||||
*
|
||||
* @author Donato Rimenti
|
||||
*/
|
||||
public class RserveMean {
|
||||
|
||||
/**
|
||||
* Connects to the Rserve istance listening on 127.0.0.1:6311 and invokes the
|
||||
* customMean R function passing the given values as arguments.
|
||||
*
|
||||
* @param values the input to the mean script
|
||||
* @return the result of the R script
|
||||
* @throws REngineException if any error occurs
|
||||
* @throws REXPMismatchException if any error occurs
|
||||
*/
|
||||
public double mean(int[] values) throws REngineException, REXPMismatchException {
|
||||
RConnection c = new RConnection();
|
||||
c.assign("input", values);
|
||||
return c.eval("customMean(input)")
|
||||
.asDouble();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.baeldung.r;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test for {@link FastRMean}.
|
||||
*
|
||||
* @author Donato Rimenti
|
||||
*/
|
||||
@Ignore
|
||||
public class FastRMeanUnitTest {
|
||||
|
||||
/**
|
||||
* Object to test.
|
||||
*/
|
||||
private FastRMean fastrMean = new FastRMean();
|
||||
|
||||
/**
|
||||
* Test for {@link FastRMeanUnitTest#mean(int[])}.
|
||||
*/
|
||||
@Test
|
||||
public void givenValues_whenMean_thenCorrect() {
|
||||
int[] input = { 1, 2, 3, 4, 5 };
|
||||
double result = fastrMean.mean(input);
|
||||
Assert.assertEquals(3.0, result, 0.000001);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.baeldung.r;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Test for {@link RCallerMean}.
|
||||
*
|
||||
* @author Donato Rimenti
|
||||
*/
|
||||
@Ignore
|
||||
public class RCallerMeanIntegrationTest {
|
||||
|
||||
/**
|
||||
* Object to test.
|
||||
*/
|
||||
private RCallerMean rcallerMean = new RCallerMean();
|
||||
|
||||
/**
|
||||
* Test for {@link RCallerMeanIntegrationTest#mean(int[])}.
|
||||
*
|
||||
* @throws ScriptException if an error occurs
|
||||
* @throws URISyntaxException if an error occurs
|
||||
*/
|
||||
@Test
|
||||
public void givenValues_whenMean_thenCorrect() throws IOException, URISyntaxException {
|
||||
int[] input = { 1, 2, 3, 4, 5 };
|
||||
double result = rcallerMean.mean(input);
|
||||
Assert.assertEquals(3.0, result, 0.000001);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.baeldung.r;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.Assert;
|
||||
|
||||
/**
|
||||
* Test for {@link RenjinMean}.
|
||||
*
|
||||
* @author Donato Rimenti
|
||||
*/
|
||||
public class RenjinMeanUnitTest {
|
||||
|
||||
/**
|
||||
* Object to test.
|
||||
*/
|
||||
private RenjinMean renjinMean = new RenjinMean();
|
||||
|
||||
/**
|
||||
* Test for {@link RenjinMeanUnitTest#mean(int[])}.
|
||||
*
|
||||
* @throws ScriptException if an error occurs
|
||||
* @throws URISyntaxException if an error occurs
|
||||
* @throws IOException if an error occurs
|
||||
*/
|
||||
@Test
|
||||
public void givenValues_whenMean_thenCorrect() throws IOException, URISyntaxException, ScriptException {
|
||||
int[] input = { 1, 2, 3, 4, 5 };
|
||||
double result = renjinMean.mean(input);
|
||||
Assert.assertEquals(3.0, result, 0.000001);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.baeldung.r;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.rosuda.REngine.REXPMismatchException;
|
||||
import org.rosuda.REngine.REngineException;
|
||||
|
||||
/**
|
||||
* Test for {@link RserveMean}.
|
||||
*
|
||||
* @author Donato Rimenti
|
||||
*/
|
||||
@Ignore
|
||||
public class RserveMeanIntegrationTest {
|
||||
|
||||
/**
|
||||
* Object to test.
|
||||
*/
|
||||
private RserveMean rserveMean = new RserveMean();
|
||||
|
||||
/**
|
||||
* Test for {@link RserveMeanIntegrationTest#mean(int[])}.
|
||||
*
|
||||
* @throws REXPMismatchException if an error occurs
|
||||
* @throws REngineException if an error occurs
|
||||
*/
|
||||
@Test
|
||||
public void givenValues_whenMean_thenCorrect() throws REngineException, REXPMismatchException {
|
||||
int[] input = { 1, 2, 3, 4, 5 };
|
||||
double result = rserveMean.mean(input);
|
||||
Assert.assertEquals(3.0, result, 0.000001);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
customMean <- function(vector) {
|
||||
mean(vector)
|
||||
}
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-boot-1</artifactId>
|
||||
<artifactId>parent-boot-2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<relativePath>../../parent-boot-1</relativePath>
|
||||
<relativePath>../../parent-boot-2</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencyManagement>
|
||||
@@ -19,7 +19,7 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-releasetrain</artifactId>
|
||||
<version>Hopper-SR10</version>
|
||||
<version>Lovelace-SR16</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
@@ -174,7 +174,7 @@
|
||||
<start-class>com.baeldung.Application</start-class>
|
||||
<spring.version>4.3.4.RELEASE</spring.version>
|
||||
<httpclient.version>4.5.2</httpclient.version>
|
||||
<spring-data-dynamodb.version>4.4.1</spring-data-dynamodb.version>
|
||||
<spring-data-dynamodb.version>5.1.0</spring-data-dynamodb.version>
|
||||
<aws-java-sdk-dynamodb.version>1.11.64</aws-java-sdk-dynamodb.version>
|
||||
<bootstrap.version>3.3.7-1</bootstrap.version>
|
||||
<sqlite4java.version>1.0.392</sqlite4java.version>
|
||||
|
||||
+2
-2
@@ -44,8 +44,8 @@ public class DynamoDBConfig {
|
||||
return new BasicAWSCredentials(amazonAWSAccessKey, amazonAWSSecretKey);
|
||||
}
|
||||
|
||||
@Bean(name = "mvcHandlerMappingIntrospector")
|
||||
public HandlerMappingIntrospector mvcHandlerMappingIntrospector() {
|
||||
@Bean(name = "mvcHandlerMappingIntrospectorCustom")
|
||||
public HandlerMappingIntrospector mvcHandlerMappingIntrospectorCustom() {
|
||||
return new HandlerMappingIntrospector(context);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -1,12 +1,13 @@
|
||||
package com.baeldung.spring.data.dynamodb.repositories;
|
||||
|
||||
import com.baeldung.spring.data.dynamodb.model.ProductInfo;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.socialsignin.spring.data.dynamodb.repository.EnableScan;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
import java.util.List;
|
||||
import com.baeldung.spring.data.dynamodb.model.ProductInfo;
|
||||
|
||||
@EnableScan
|
||||
public interface ProductInfoRepository extends CrudRepository<ProductInfo, String> {
|
||||
List<ProductInfo> findById(String id);
|
||||
Optional<ProductInfo> findById(String id);
|
||||
}
|
||||
|
||||
@@ -652,6 +652,7 @@
|
||||
<module>spring-core</module>
|
||||
<module>spring-core-2</module>
|
||||
<module>spring-core-3</module>
|
||||
<module>spring-core-4</module>
|
||||
<module>spring-cucumber</module>
|
||||
|
||||
<module>spring-data-rest</module>
|
||||
@@ -1157,6 +1158,7 @@
|
||||
<module>spring-core</module>
|
||||
<module>spring-core-2</module>
|
||||
<module>spring-core-3</module>
|
||||
<module>spring-core-4</module>
|
||||
<module>spring-cucumber</module>
|
||||
|
||||
<module>spring-data-rest</module>
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.springwithgroovy
|
||||
|
||||
import org.springframework.boot.SpringApplication
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||
|
||||
import com.baeldung.springwithgroovy.SpringBootGroovyApplication
|
||||
|
||||
@SpringBootApplication
|
||||
class SpringBootGroovyApplication {
|
||||
static void main(String[] args) {
|
||||
SpringApplication.run SpringBootGroovyApplication, args
|
||||
}
|
||||
}
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
package com.baeldung.springwithgroovy.controller
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.web.bind.annotation.DeleteMapping
|
||||
import org.springframework.web.bind.annotation.GetMapping
|
||||
import org.springframework.web.bind.annotation.PathVariable
|
||||
import org.springframework.web.bind.annotation.PostMapping
|
||||
import org.springframework.web.bind.annotation.PutMapping
|
||||
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.RestController
|
||||
|
||||
import com.baeldung.springwithgroovy.entity.Todo
|
||||
import com.baeldung.springwithgroovy.service.TodoService
|
||||
|
||||
@RestController
|
||||
@RequestMapping('todo')
|
||||
public class TodoController {
|
||||
|
||||
@Autowired
|
||||
TodoService todoService
|
||||
|
||||
@GetMapping
|
||||
List<Todo> getAllTodoList(){
|
||||
todoService.findAll()
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
Todo saveTodo(@RequestBody Todo todo){
|
||||
todoService.saveTodo todo
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
Todo updateTodo(@RequestBody Todo todo){
|
||||
todoService.updateTodo todo
|
||||
}
|
||||
|
||||
@DeleteMapping('/{todoId}')
|
||||
deleteTodo(@PathVariable Integer todoId){
|
||||
todoService.deleteTodo todoId
|
||||
}
|
||||
|
||||
@GetMapping('/{todoId}')
|
||||
Todo getTodoById(@PathVariable Integer todoId){
|
||||
todoService.findById todoId
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.baeldung.springwithgroovy.entity
|
||||
|
||||
import javax.persistence.Column
|
||||
import javax.persistence.Entity
|
||||
import javax.persistence.GeneratedValue
|
||||
import javax.persistence.GenerationType
|
||||
import javax.persistence.Id
|
||||
import javax.persistence.Table
|
||||
|
||||
@Entity
|
||||
@Table(name = 'todo')
|
||||
class Todo {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
Integer id
|
||||
|
||||
@Column
|
||||
String task
|
||||
|
||||
@Column
|
||||
Boolean isCompleted
|
||||
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package com.baeldung.springwithgroovy.repository
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
import org.springframework.stereotype.Repository
|
||||
|
||||
import com.baeldung.springwithgroovy.entity.Todo
|
||||
|
||||
@Repository
|
||||
interface TodoRepository extends JpaRepository<Todo, Integer> {}
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
package com.baeldung.springwithgroovy.service
|
||||
|
||||
import com.baeldung.springwithgroovy.entity.Todo
|
||||
|
||||
interface TodoService {
|
||||
|
||||
List<Todo> findAll()
|
||||
|
||||
Todo findById(Integer todoId)
|
||||
|
||||
Todo saveTodo(Todo todo)
|
||||
|
||||
Todo updateTodo(Todo todo)
|
||||
|
||||
Todo deleteTodo(Integer todoId)
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
package com.baeldung.springwithgroovy.service.impl
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
import com.baeldung.springwithgroovy.entity.Todo
|
||||
import com.baeldung.springwithgroovy.repository.TodoRepository
|
||||
import com.baeldung.springwithgroovy.service.TodoService
|
||||
|
||||
@Service
|
||||
class TodoServiceImpl implements TodoService {
|
||||
|
||||
@Autowired
|
||||
TodoRepository todoRepository
|
||||
|
||||
@Override
|
||||
List<Todo> findAll() {
|
||||
todoRepository.findAll()
|
||||
}
|
||||
|
||||
@Override
|
||||
Todo findById(Integer todoId) {
|
||||
todoRepository.findById todoId get()
|
||||
}
|
||||
|
||||
@Override
|
||||
Todo saveTodo(Todo todo){
|
||||
todoRepository.save todo
|
||||
}
|
||||
|
||||
@Override
|
||||
Todo updateTodo(Todo todo){
|
||||
todoRepository.save todo
|
||||
}
|
||||
|
||||
@Override
|
||||
Todo deleteTodo(Integer todoId){
|
||||
todoRepository.deleteById todoId
|
||||
}
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package com.baeldung.springwithgroovy
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue
|
||||
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.test.context.event.annotation.BeforeTestClass
|
||||
import org.springframework.test.context.junit4.SpringRunner
|
||||
|
||||
import com.baeldung.springwithgroovy.entity.Todo
|
||||
|
||||
import io.restassured.RestAssured
|
||||
import io.restassured.response.Response
|
||||
|
||||
class TodoAppUnitTest {
|
||||
static API_ROOT = 'http://localhost:8081/todo'
|
||||
static readingTodoId
|
||||
static writingTodoId
|
||||
|
||||
@BeforeClass
|
||||
static void populateDummyData() {
|
||||
Todo readingTodo = new Todo(task: 'Reading', isCompleted: false)
|
||||
Todo writingTodo = new Todo(task: 'Writing', isCompleted: false)
|
||||
|
||||
final Response readingResponse =
|
||||
RestAssured.given()
|
||||
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
||||
.body(readingTodo).post(API_ROOT)
|
||||
|
||||
Todo cookingTodoResponse = readingResponse.as Todo.class
|
||||
readingTodoId = cookingTodoResponse.getId()
|
||||
|
||||
final Response writingResponse =
|
||||
RestAssured.given()
|
||||
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
||||
.body(writingTodo).post(API_ROOT)
|
||||
|
||||
Todo writingTodoResponse = writingResponse.as Todo.class
|
||||
writingTodoId = writingTodoResponse.getId()
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenGetAllTodoList_thenOk(){
|
||||
final Response response = RestAssured.get(API_ROOT)
|
||||
|
||||
assertEquals HttpStatus.OK.value(),response.getStatusCode()
|
||||
assertTrue response.as(List.class).size() > 0
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenGetTodoById_thenOk(){
|
||||
final Response response =
|
||||
RestAssured.get("$API_ROOT/$readingTodoId")
|
||||
|
||||
assertEquals HttpStatus.OK.value(),response.getStatusCode()
|
||||
Todo todoResponse = response.as Todo.class
|
||||
assertEquals readingTodoId,todoResponse.getId()
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenUpdateTodoById_thenOk(){
|
||||
Todo todo = new Todo(id:readingTodoId, isCompleted: true)
|
||||
final Response response =
|
||||
RestAssured.given()
|
||||
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
||||
.body(todo).put(API_ROOT)
|
||||
|
||||
assertEquals HttpStatus.OK.value(),response.getStatusCode()
|
||||
Todo todoResponse = response.as Todo.class
|
||||
assertTrue todoResponse.getIsCompleted()
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenDeleteTodoById_thenOk(){
|
||||
final Response response =
|
||||
RestAssured.given()
|
||||
.delete("$API_ROOT/$writingTodoId")
|
||||
|
||||
assertEquals HttpStatus.OK.value(),response.getStatusCode()
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenSaveTodo_thenOk(){
|
||||
Todo todo = new Todo(task: 'Blogging', isCompleted: false)
|
||||
final Response response =
|
||||
RestAssured.given()
|
||||
.contentType(MediaType.APPLICATION_JSON_VALUE)
|
||||
.body(todo).post(API_ROOT)
|
||||
|
||||
assertEquals HttpStatus.OK.value(),response.getStatusCode()
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user