Merge branch 'master' of https://github.com/eugenp/tutorials
This commit is contained in:
commit
64d13813a4
@ -1,17 +1,12 @@
|
||||
package com.baeldung.cxf.jaxrs.implementation;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Response;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
@Path("baeldung")
|
||||
@Produces("text/xml")
|
||||
public class Baeldung {
|
||||
@ -51,14 +46,13 @@ public class Baeldung {
|
||||
@Path("courses/{courseOrder}")
|
||||
public Response putCourse(@PathParam("courseOrder") int courseOrder, Course course) {
|
||||
Course existingCourse = courses.get(courseOrder);
|
||||
Response response;
|
||||
|
||||
if (existingCourse == null || existingCourse.getId() != course.getId() || !(existingCourse.getName().equals(course.getName()))) {
|
||||
courses.put(courseOrder, course);
|
||||
response = Response.ok().build();
|
||||
} else {
|
||||
response = Response.notModified().build();
|
||||
return Response.ok().build();
|
||||
}
|
||||
return response;
|
||||
|
||||
return Response.notModified().build();
|
||||
}
|
||||
|
||||
@Path("courses/{courseOrder}/students")
|
||||
|
@ -1,17 +1,11 @@
|
||||
package com.baeldung.cxf.jaxrs.implementation;
|
||||
|
||||
import javax.ws.rs.*;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name = "Course")
|
||||
public class Course {
|
||||
private int id;
|
||||
@ -51,7 +45,7 @@ public class Course {
|
||||
@POST
|
||||
public Response postStudent(Student student) {
|
||||
if (students == null) {
|
||||
students = new ArrayList<Student>();
|
||||
students = new ArrayList<>();
|
||||
}
|
||||
students.add(student);
|
||||
return Response.ok(student).build();
|
||||
|
@ -1,18 +1,5 @@
|
||||
package com.baeldung.cxf.jaxrs.implementation;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
|
||||
import javax.xml.bind.JAXB;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpDelete;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
@ -20,6 +7,17 @@ import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.entity.InputStreamEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.xml.bind.JAXB;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class ServiceTest {
|
||||
private static final String BASE_URL = "http://localhost:8080/baeldung/courses/";
|
||||
@ -80,14 +78,12 @@ public class ServiceTest {
|
||||
private Course getCourse(int courseOrder) throws IOException {
|
||||
URL url = new URL(BASE_URL + courseOrder);
|
||||
InputStream input = url.openStream();
|
||||
Course course = JAXB.unmarshal(new InputStreamReader(input), Course.class);
|
||||
return course;
|
||||
return JAXB.unmarshal(new InputStreamReader(input), Course.class);
|
||||
}
|
||||
|
||||
private Student getStudent(int courseOrder, int studentOrder) throws IOException {
|
||||
URL url = new URL(BASE_URL + courseOrder + "/students/" + studentOrder);
|
||||
InputStream input = url.openStream();
|
||||
Student student = JAXB.unmarshal(new InputStreamReader(input), Student.class);
|
||||
return student;
|
||||
return JAXB.unmarshal(new InputStreamReader(input), Student.class);
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
<?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">
|
||||
<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>
|
||||
@ -9,11 +8,18 @@
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>19.0</version>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-guava</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
@ -26,11 +32,7 @@
|
||||
<version>3.5.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-guava</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@ -46,4 +48,9 @@
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<guava.version>19.0</guava.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -15,7 +15,7 @@
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.4</version>
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
@ -0,0 +1,38 @@
|
||||
package com.baeldung.encoderdecoder;
|
||||
|
||||
import org.hamcrest.CoreMatchers;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class EncoderDecoder {
|
||||
|
||||
@Test
|
||||
public void givenPlainURL_whenUsingUTF8EncodingScheme_thenEncodeURL() throws UnsupportedEncodingException {
|
||||
String plainURL = "http://www.baeldung.com" ;
|
||||
String encodedURL = URLEncoder.encode(plainURL, StandardCharsets.UTF_8.toString());
|
||||
|
||||
Assert.assertThat("http%3A%2F%2Fwww.baeldung.com", CoreMatchers.is(encodedURL));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEncodedURL_whenUsingUTF8EncodingScheme_thenDecodeURL() throws UnsupportedEncodingException {
|
||||
String encodedURL = "http%3A%2F%2Fwww.baeldung.com" ;
|
||||
String decodedURL = URLDecoder.decode(encodedURL, StandardCharsets.UTF_8.toString());
|
||||
|
||||
Assert.assertThat("http://www.baeldung.com", CoreMatchers.is(decodedURL));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenEncodedURL_whenUsingWrongEncodingScheme_thenDecodeInvalidURL() throws UnsupportedEncodingException {
|
||||
String encodedURL = "http%3A%2F%2Fwww.baeldung.com";
|
||||
|
||||
String decodedURL = URLDecoder.decode(encodedURL, StandardCharsets.UTF_16.toString());
|
||||
|
||||
Assert.assertFalse("http://www.baeldung.com".equals(decodedURL));
|
||||
}
|
||||
}
|
@ -102,22 +102,20 @@ public class FileOperationsTest {
|
||||
StringBuilder data = new StringBuilder();
|
||||
Stream<String> lines = Files.lines(path);
|
||||
lines.forEach(line -> data.append(line).append("\n"));
|
||||
lines.close();
|
||||
|
||||
Assert.assertEquals(expectedData, data.toString().trim());
|
||||
}
|
||||
|
||||
private String readFromInputStream(InputStream inputStream) throws IOException {
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
|
||||
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
|
||||
StringBuilder resultStringBuilder = new StringBuilder();
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
resultStringBuilder.append(line);
|
||||
resultStringBuilder.append("\n");
|
||||
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
String line;
|
||||
while ((line = bufferedReader.readLine()) != null) {
|
||||
resultStringBuilder.append(line).append("\n");
|
||||
}
|
||||
}
|
||||
bufferedReader.close();
|
||||
inputStreamReader.close();
|
||||
inputStream.close();
|
||||
|
||||
return resultStringBuilder.toString();
|
||||
}
|
||||
}
|
@ -1,47 +1,41 @@
|
||||
package com.baeldung.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.time.temporal.ChronoField;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.time.*;
|
||||
import java.time.temporal.ChronoField;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class CurrentDateTimeTest {
|
||||
|
||||
private static final Clock clock = Clock.fixed(Instant.parse("2016-10-09T15:10:30.00Z"), ZoneId.of("UTC"));
|
||||
|
||||
@Test
|
||||
public void shouldReturnCurrentDate() {
|
||||
|
||||
final LocalDate now = LocalDate.now();
|
||||
final Calendar calendar = GregorianCalendar.getInstance();
|
||||
final LocalDate now = LocalDate.now(clock);
|
||||
|
||||
assertEquals("10-10-2010".length(), now.toString().length());
|
||||
assertEquals(calendar.get(Calendar.DATE), now.get(ChronoField.DAY_OF_MONTH));
|
||||
assertEquals(calendar.get(Calendar.MONTH), now.get(ChronoField.MONTH_OF_YEAR) - 1);
|
||||
assertEquals(calendar.get(Calendar.YEAR), now.get(ChronoField.YEAR));
|
||||
assertEquals(9, now.get(ChronoField.DAY_OF_MONTH));
|
||||
assertEquals(10, now.get(ChronoField.MONTH_OF_YEAR));
|
||||
assertEquals(2016, now.get(ChronoField.YEAR));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnCurrentTime() {
|
||||
|
||||
final LocalTime now = LocalTime.now();
|
||||
final Calendar calendar = GregorianCalendar.getInstance();
|
||||
final LocalTime now = LocalTime.now(clock);
|
||||
|
||||
assertEquals(calendar.get(Calendar.HOUR_OF_DAY), now.get(ChronoField.HOUR_OF_DAY));
|
||||
assertEquals(calendar.get(Calendar.MINUTE), now.get(ChronoField.MINUTE_OF_HOUR));
|
||||
assertEquals(calendar.get(Calendar.SECOND), now.get(ChronoField.SECOND_OF_MINUTE));
|
||||
assertEquals(15, now.get(ChronoField.HOUR_OF_DAY));
|
||||
assertEquals(10, now.get(ChronoField.MINUTE_OF_HOUR));
|
||||
assertEquals(30, now.get(ChronoField.SECOND_OF_MINUTE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnCurrentTimestamp() {
|
||||
|
||||
final Instant now = Instant.now();
|
||||
final Calendar calendar = GregorianCalendar.getInstance();
|
||||
final Instant now = Instant.now(clock);
|
||||
|
||||
assertEquals(calendar.getTimeInMillis() / 1000, now.getEpochSecond());
|
||||
assertEquals(clock.instant().getEpochSecond(), now.getEpochSecond());
|
||||
}
|
||||
}
|
||||
|
@ -174,7 +174,7 @@
|
||||
<mysql-connector-java.version>5.1.38</mysql-connector-java.version>
|
||||
|
||||
<!-- marshalling -->
|
||||
<jackson.version>2.7.2</jackson.version>
|
||||
<jackson.version>2.7.8</jackson.version>
|
||||
|
||||
<!-- logging -->
|
||||
<org.slf4j.version>1.7.13</org.slf4j.version>
|
||||
|
@ -0,0 +1,46 @@
|
||||
package com.baeldung.java.nio.selector;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.SocketChannel;
|
||||
|
||||
public class EchoClient {
|
||||
private static SocketChannel client;
|
||||
private static ByteBuffer buffer;
|
||||
private static EchoClient instance;
|
||||
|
||||
public static EchoClient start() {
|
||||
if (instance == null)
|
||||
instance = new EchoClient();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
private EchoClient() {
|
||||
try {
|
||||
client = SocketChannel.open(new InetSocketAddress("localhost", 5454));
|
||||
buffer = ByteBuffer.allocate(256);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public String sendMessage(String msg) {
|
||||
buffer = ByteBuffer.wrap(msg.getBytes());
|
||||
String response = null;
|
||||
try {
|
||||
client.write(buffer);
|
||||
buffer.clear();
|
||||
client.read(buffer);
|
||||
response = new String(buffer.array()).trim();
|
||||
System.out.println("response=" + response);
|
||||
buffer.clear();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return response;
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package com.baeldung.java.nio.selector;
|
||||
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
import java.nio.channels.SocketChannel;
|
||||
import java.nio.channels.Selector;
|
||||
import java.nio.channels.SelectionKey;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.io.IOException;
|
||||
import java.util.Set;
|
||||
import java.util.Iterator;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
public class EchoServer {
|
||||
|
||||
public static void main(String[] args)
|
||||
|
||||
throws IOException {
|
||||
Selector selector = Selector.open();
|
||||
ServerSocketChannel serverSocket = ServerSocketChannel.open();
|
||||
serverSocket.bind(new InetSocketAddress("localhost", 5454));
|
||||
serverSocket.configureBlocking(false);
|
||||
serverSocket.register(selector, SelectionKey.OP_ACCEPT);
|
||||
ByteBuffer buffer = ByteBuffer.allocate(256);
|
||||
|
||||
while (true) {
|
||||
selector.select();
|
||||
Set<SelectionKey> selectedKeys = selector.selectedKeys();
|
||||
Iterator<SelectionKey> iter = selectedKeys.iterator();
|
||||
while (iter.hasNext()) {
|
||||
|
||||
SelectionKey key = iter.next();
|
||||
|
||||
if (key.isAcceptable()) {
|
||||
SocketChannel client = serverSocket.accept();
|
||||
client.configureBlocking(false);
|
||||
client.register(selector, SelectionKey.OP_READ);
|
||||
}
|
||||
|
||||
if (key.isReadable()) {
|
||||
SocketChannel client = (SocketChannel) key.channel();
|
||||
client.read(buffer);
|
||||
buffer.flip();
|
||||
client.write(buffer);
|
||||
buffer.clear();
|
||||
}
|
||||
iter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.baeldung.java.nio.selector;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class EchoTest {
|
||||
|
||||
@Test
|
||||
public void givenClient_whenServerEchosMessage_thenCorrect() {
|
||||
EchoClient client = EchoClient.start();
|
||||
String resp1 = client.sendMessage("hello");
|
||||
String resp2 = client.sendMessage("world");
|
||||
assertEquals("hello", resp1);
|
||||
assertEquals("world", resp2);
|
||||
}
|
||||
|
||||
}
|
1
core-java/src/test/resources/test_md5.txt
Normal file
1
core-java/src/test/resources/test_md5.txt
Normal file
@ -0,0 +1 @@
|
||||
hello world
|
@ -1,3 +0,0 @@
|
||||
## Performance of Gson and Jackson
|
||||
|
||||
Standalone java programs to measure the performance of both JSON APIs based on file size and object graph complexity.
|
@ -1,72 +0,0 @@
|
||||
<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>gson-jackson-performance</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>gson-jackson-performance</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
<finalName>gson-jackson-performance</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.7.1-1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -1,63 +0,0 @@
|
||||
package com.baeldung.data.complex;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.baeldung.data.utility.Utility;
|
||||
import com.baeldung.pojo.complex.AddressDetails;
|
||||
import com.baeldung.pojo.complex.ContactDetails;
|
||||
import com.baeldung.pojo.complex.CustomerAddressDetails;
|
||||
import com.baeldung.pojo.complex.CustomerPortfolioComplex;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class is responsible for generating data for complex type object
|
||||
*/
|
||||
|
||||
public class ComplexDataGeneration {
|
||||
|
||||
public static CustomerPortfolioComplex generateData() {
|
||||
List<CustomerAddressDetails> customerAddressDetailsList = new ArrayList<CustomerAddressDetails>();
|
||||
for (int i = 0; i < 600000; i++) {
|
||||
CustomerAddressDetails customerAddressDetails = new CustomerAddressDetails();
|
||||
customerAddressDetails.setAge(20);
|
||||
customerAddressDetails.setFirstName(Utility.generateRandomName());
|
||||
customerAddressDetails.setLastName(Utility.generateRandomName());
|
||||
|
||||
List<AddressDetails> addressDetailsList = new ArrayList<AddressDetails>();
|
||||
customerAddressDetails.setAddressDetails(addressDetailsList);
|
||||
|
||||
for (int j = 0; j < 2; j++) {
|
||||
AddressDetails addressDetails = new AddressDetails();
|
||||
addressDetails.setZipcode(Utility.generateRandomZip());
|
||||
addressDetails.setAddress(Utility.generateRandomAddress());
|
||||
|
||||
List<ContactDetails> contactDetailsList = new ArrayList<ContactDetails>();
|
||||
addressDetails.setContactDetails(contactDetailsList);
|
||||
|
||||
for (int k = 0; k < 2; k++) {
|
||||
ContactDetails contactDetails = new ContactDetails();
|
||||
contactDetails.setLandline(Utility.generateRandomPhone());
|
||||
contactDetails.setMobile(Utility.generateRandomPhone());
|
||||
contactDetailsList.add(contactDetails);
|
||||
contactDetails = null;
|
||||
}
|
||||
|
||||
addressDetailsList.add(addressDetails);
|
||||
addressDetails = null;
|
||||
contactDetailsList = null;
|
||||
}
|
||||
customerAddressDetailsList.add(customerAddressDetails);
|
||||
customerAddressDetails = null;
|
||||
|
||||
if (i % 6000 == 0) {
|
||||
Runtime.getRuntime().gc();
|
||||
}
|
||||
}
|
||||
|
||||
CustomerPortfolioComplex customerPortfolioComplex = new CustomerPortfolioComplex();
|
||||
customerPortfolioComplex.setCustomerAddressDetailsList(customerAddressDetailsList);
|
||||
customerAddressDetailsList = null;
|
||||
return customerPortfolioComplex;
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
package com.baeldung.data.complex;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import com.baeldung.data.utility.Utility;
|
||||
import com.baeldung.pojo.complex.CustomerPortfolioComplex;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class is responsible for performing functions for Complex type
|
||||
* GSON like
|
||||
* Java to Json
|
||||
* Json to Map
|
||||
* Json to Java Object
|
||||
*/
|
||||
|
||||
public class ComplexDataGson {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(ComplexDataGson.class);
|
||||
|
||||
static Gson gson = new Gson();
|
||||
|
||||
static long generateJsonAvgTime = 0L;
|
||||
|
||||
static long parseJsonToMapAvgTime = 0L;
|
||||
|
||||
static long parseJsonToActualObjectAvgTime = 0L;
|
||||
|
||||
public static void main(String[] args) {
|
||||
CustomerPortfolioComplex customerPortfolioComplex = ComplexDataGeneration.generateData();
|
||||
int j = 50;
|
||||
for (int i = 0; i < j; i++) {
|
||||
logger.info("-------Round " + (i + 1));
|
||||
String jsonStr = generateJson(customerPortfolioComplex);
|
||||
logger.info("Size of Complex content Jackson :: " + Utility.bytesIntoMB(jsonStr.getBytes().length));
|
||||
logger.info("--------------------------------------------------------------------------");
|
||||
parseJsonToMap(jsonStr);
|
||||
parseJsonToActualObject(jsonStr);
|
||||
jsonStr = null;
|
||||
}
|
||||
|
||||
generateJsonAvgTime = generateJsonAvgTime / j;
|
||||
parseJsonToMapAvgTime = parseJsonToMapAvgTime / j;
|
||||
parseJsonToActualObjectAvgTime = parseJsonToActualObjectAvgTime / j;
|
||||
|
||||
logger.info("--------------------------------------------------------------------------");
|
||||
logger.info("Average Time to Generate JSON : " + generateJsonAvgTime);
|
||||
logger.info("Average Time to Parse JSON To Map : " + parseJsonToMapAvgTime);
|
||||
logger.info("Average Time to Parse JSON To Actual Object : " + parseJsonToActualObjectAvgTime);
|
||||
logger.info("--------------------------------------------------------------------------");
|
||||
}
|
||||
|
||||
private static String generateJson(CustomerPortfolioComplex customerPortfolioComplex) {
|
||||
Runtime.getRuntime().gc();
|
||||
long startParsTime = System.nanoTime();
|
||||
String json = gson.toJson(customerPortfolioComplex);
|
||||
long endParsTime = System.nanoTime();
|
||||
long elapsedTime = endParsTime - startParsTime;
|
||||
generateJsonAvgTime = generateJsonAvgTime + elapsedTime;
|
||||
logger.info("Json Generation Time(ms):: " + elapsedTime);
|
||||
return json;
|
||||
}
|
||||
|
||||
private static void parseJsonToMap(String jsonStr) {
|
||||
long startParsTime = System.nanoTime();
|
||||
Map parsedMap = gson.fromJson(jsonStr , Map.class);
|
||||
long endParsTime = System.nanoTime();
|
||||
long elapsedTime = endParsTime - startParsTime;
|
||||
parseJsonToMapAvgTime = parseJsonToMapAvgTime + elapsedTime;
|
||||
logger.info("Generating Map from json Time(ms):: " + elapsedTime);
|
||||
logger.info("--------------------------------------------------------------------------");
|
||||
parsedMap = null;
|
||||
Runtime.getRuntime().gc();
|
||||
}
|
||||
|
||||
private static void parseJsonToActualObject(String jsonStr) {
|
||||
long startParsTime = System.nanoTime();
|
||||
CustomerPortfolioComplex customerPortfolioComplex = gson.fromJson(jsonStr , CustomerPortfolioComplex.class);
|
||||
long endParsTime = System.nanoTime();
|
||||
long elapsedTime = endParsTime - startParsTime;
|
||||
parseJsonToActualObjectAvgTime = parseJsonToActualObjectAvgTime + elapsedTime;
|
||||
logger.info("Generating Actual Object from json Time(ms):: " + elapsedTime);
|
||||
logger.info("--------------------------------------------------------------------------");
|
||||
customerPortfolioComplex = null;
|
||||
Runtime.getRuntime().gc();
|
||||
|
||||
}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
package com.baeldung.data.complex;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baeldung.data.utility.Utility;
|
||||
import org.apache.log4j.Logger;
|
||||
import com.baeldung.pojo.complex.CustomerPortfolioComplex;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class is responsible for performing functions for Complex type
|
||||
* Jackson like
|
||||
* Java to Json
|
||||
* Json to Map
|
||||
* Json to Java Object
|
||||
*/
|
||||
|
||||
public class ComplexDataJackson {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(ComplexDataJackson.class);
|
||||
|
||||
static ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
static long generateJsonAvgTime = 0L;
|
||||
|
||||
static long parseJsonToMapAvgTime = 0L;
|
||||
|
||||
static long parseJsonToActualObjectAvgTime = 0L;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
CustomerPortfolioComplex customerPortfolioComplex = ComplexDataGeneration.generateData();
|
||||
int j = 50;
|
||||
for (int i = 0; i < j; i++) {
|
||||
logger.info("-------Round " + (i + 1));
|
||||
String jsonStr = generateJson(customerPortfolioComplex);
|
||||
logger.info("Size of Complex content Jackson :: " + Utility.bytesIntoMB(jsonStr.getBytes().length));
|
||||
logger.info("--------------------------------------------------------------------------");
|
||||
parseJsonToMap(jsonStr);
|
||||
parseJsonToActualObject(jsonStr);
|
||||
jsonStr = null;
|
||||
}
|
||||
|
||||
generateJsonAvgTime = generateJsonAvgTime / j;
|
||||
parseJsonToMapAvgTime = parseJsonToMapAvgTime / j;
|
||||
parseJsonToActualObjectAvgTime = parseJsonToActualObjectAvgTime / j;
|
||||
|
||||
logger.info("--------------------------------------------------------------------------");
|
||||
logger.info("Average Time to Generate JSON : " + generateJsonAvgTime);
|
||||
logger.info("Average Time to Parse JSON To Map : " + parseJsonToMapAvgTime);
|
||||
logger.info("Average Time to Parse JSON To Actual Object : " + parseJsonToActualObjectAvgTime);
|
||||
logger.info("--------------------------------------------------------------------------");
|
||||
}
|
||||
|
||||
private static String generateJson(CustomerPortfolioComplex customerPortfolioComplex)
|
||||
throws JsonProcessingException {
|
||||
Runtime.getRuntime().gc();
|
||||
long startParsTime = System.nanoTime();
|
||||
String json = mapper.writeValueAsString(customerPortfolioComplex);
|
||||
long endParsTime = System.nanoTime();
|
||||
long elapsedTime = endParsTime - startParsTime;
|
||||
generateJsonAvgTime = generateJsonAvgTime + elapsedTime;
|
||||
logger.info("Json Generation Time(ms):: " + elapsedTime);
|
||||
return json;
|
||||
}
|
||||
|
||||
private static void parseJsonToMap(String jsonStr) throws JsonParseException , JsonMappingException , IOException {
|
||||
long startParsTime = System.nanoTime();
|
||||
Map parsedMap = mapper.readValue(jsonStr , Map.class);
|
||||
long endParsTime = System.nanoTime();
|
||||
long elapsedTime = endParsTime - startParsTime;
|
||||
parseJsonToMapAvgTime = parseJsonToMapAvgTime + elapsedTime;
|
||||
logger.info("Generating Map from json Time(ms):: " + elapsedTime);
|
||||
parsedMap = null;
|
||||
Runtime.getRuntime().gc();
|
||||
|
||||
}
|
||||
|
||||
private static void parseJsonToActualObject(String jsonStr) throws JsonParseException , JsonMappingException ,
|
||||
IOException {
|
||||
long startParsTime = System.nanoTime();
|
||||
CustomerPortfolioComplex customerPortfolioComplex = mapper.readValue(jsonStr , CustomerPortfolioComplex.class);
|
||||
long endParsTime = System.nanoTime();
|
||||
long elapsedTime = endParsTime - startParsTime;
|
||||
parseJsonToActualObjectAvgTime = parseJsonToActualObjectAvgTime + elapsedTime;
|
||||
logger.info("Generating Actual Object from json Time(ms):: " + elapsedTime);
|
||||
customerPortfolioComplex = null;
|
||||
Runtime.getRuntime().gc();
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
package com.baeldung.data.simple;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.baeldung.data.utility.Utility;
|
||||
import com.baeldung.pojo.simple.Customer;
|
||||
import com.baeldung.pojo.simple.CustomerPortfolioSimple;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class is responsible for generating data for simple type object
|
||||
*/
|
||||
|
||||
public class SimpleDataGeneration {
|
||||
|
||||
public static CustomerPortfolioSimple generateData() {
|
||||
List<Customer> customerList = new ArrayList<Customer>();
|
||||
for (int i = 0; i < 1; i++) {
|
||||
Customer customer = new Customer();
|
||||
customer.setAge(20);
|
||||
customer.setFirstName(Utility.generateRandomName());
|
||||
customer.setLastName(Utility.generateRandomName());
|
||||
|
||||
customerList.add(customer);
|
||||
customer = null;
|
||||
|
||||
}
|
||||
|
||||
CustomerPortfolioSimple customerPortfolioSimple = new CustomerPortfolioSimple();
|
||||
customerPortfolioSimple.setCustomerLists(customerList);
|
||||
customerList = null;
|
||||
return customerPortfolioSimple;
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
package com.baeldung.data.simple;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import com.baeldung.data.utility.Utility;
|
||||
import com.baeldung.pojo.simple.CustomerPortfolioSimple;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class is responsible for performing functions for Simple type
|
||||
* GSON like
|
||||
* Java to Json
|
||||
* Json to Map
|
||||
* Json to Java Object
|
||||
*/
|
||||
|
||||
public class SimpleDataGson {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(SimpleDataGson.class);
|
||||
|
||||
static Gson gson = new Gson();
|
||||
|
||||
static long generateJsonAvgTime = 0L;
|
||||
|
||||
static long parseJsonToMapAvgTime = 0L;
|
||||
|
||||
static long parseJsonToActualObjectAvgTime = 0L;
|
||||
|
||||
public static void main(String[] args) {
|
||||
CustomerPortfolioSimple customerPortfolioSimple = SimpleDataGeneration.generateData();
|
||||
String jsonStr = null;
|
||||
int j = 5;
|
||||
for (int i = 0; i < j; i++) {
|
||||
logger.info("-------Round " + (i + 1));
|
||||
jsonStr = generateJson(customerPortfolioSimple);
|
||||
logger.info("Size of Simple content Gson :: " + Utility.bytesIntoMB(jsonStr.getBytes().length));
|
||||
logger.info("--------------------------------------------------------------------------");
|
||||
parseJsonToMap(jsonStr);
|
||||
parseJsonToActualObject(jsonStr);
|
||||
jsonStr = null;
|
||||
}
|
||||
generateJsonAvgTime = generateJsonAvgTime / j;
|
||||
parseJsonToMapAvgTime = parseJsonToMapAvgTime / j;
|
||||
parseJsonToActualObjectAvgTime = parseJsonToActualObjectAvgTime / j;
|
||||
|
||||
logger.info("--------------------------------------------------------------------------");
|
||||
logger.info("Average Time to Generate JSON : " + generateJsonAvgTime);
|
||||
logger.info("Average Time to Parse JSON To Map : " + parseJsonToMapAvgTime);
|
||||
logger.info("Average Time to Parse JSON To Actual Object : " + parseJsonToActualObjectAvgTime);
|
||||
logger.info("--------------------------------------------------------------------------");
|
||||
}
|
||||
|
||||
private static String generateJson(CustomerPortfolioSimple customerPortfolioSimple) {
|
||||
Runtime.getRuntime().gc();
|
||||
long startParsTime = System.nanoTime();
|
||||
String json = gson.toJson(customerPortfolioSimple);
|
||||
long endParsTime = System.nanoTime();
|
||||
long elapsedTime = endParsTime - startParsTime;
|
||||
generateJsonAvgTime = generateJsonAvgTime + elapsedTime;
|
||||
logger.info("Json Generation Time(ms):: " + elapsedTime);
|
||||
return json;
|
||||
}
|
||||
|
||||
private static void parseJsonToMap(String jsonStr) {
|
||||
long startParsTime = System.nanoTime();
|
||||
Map parsedMap = gson.fromJson(jsonStr , Map.class);
|
||||
long endParsTime = System.nanoTime();
|
||||
long elapsedTime = endParsTime - startParsTime;
|
||||
parseJsonToMapAvgTime = parseJsonToMapAvgTime + elapsedTime;
|
||||
logger.info("Generating Map from json Time(ms):: " + elapsedTime);
|
||||
logger.info("--------------------------------------------------------------------------");
|
||||
parsedMap = null;
|
||||
Runtime.getRuntime().gc();
|
||||
|
||||
}
|
||||
|
||||
private static void parseJsonToActualObject(String jsonStr) {
|
||||
long startParsTime = System.nanoTime();
|
||||
CustomerPortfolioSimple customerPortfolioSimple = gson.fromJson(jsonStr , CustomerPortfolioSimple.class);
|
||||
long endParsTime = System.nanoTime();
|
||||
long elapsedTime = endParsTime - startParsTime;
|
||||
parseJsonToActualObjectAvgTime = parseJsonToActualObjectAvgTime + elapsedTime;
|
||||
logger.info("Generating Actual Object from json Time(ms):: " + elapsedTime);
|
||||
logger.info("--------------------------------------------------------------------------");
|
||||
customerPortfolioSimple = null;
|
||||
Runtime.getRuntime().gc();
|
||||
}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
package com.baeldung.data.simple;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
import com.baeldung.data.utility.Utility;
|
||||
import org.apache.log4j.Logger;
|
||||
import com.baeldung.pojo.simple.CustomerPortfolioSimple;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class is responsible for performing functions for Simple type
|
||||
* Jackson like
|
||||
* Java to Json
|
||||
* Json to Map
|
||||
* Json to Java Object
|
||||
*/
|
||||
|
||||
public class SimpleDataJackson {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(SimpleDataJackson.class);
|
||||
|
||||
static ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
static long generateJsonAvgTime = 0L;
|
||||
|
||||
static long parseJsonToMapAvgTime = 0L;
|
||||
|
||||
static long parseJsonToActualObjectAvgTime = 0L;
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
CustomerPortfolioSimple customerPortfolioSimple = SimpleDataGeneration.generateData();
|
||||
int j = 50;
|
||||
for (int i = 0; i < j; i++) {
|
||||
logger.info("-------Round " + (i + 1));
|
||||
String jsonStr = generateJson(customerPortfolioSimple);
|
||||
logger.info("Size of Simple content Jackson :: " + Utility.bytesIntoMB(jsonStr.getBytes().length));
|
||||
logger.info("--------------------------------------------------------------------------");
|
||||
|
||||
parseJsonToMap(jsonStr);
|
||||
parseJsonToActualObject(jsonStr);
|
||||
jsonStr = null;
|
||||
}
|
||||
|
||||
generateJsonAvgTime = generateJsonAvgTime / j;
|
||||
parseJsonToMapAvgTime = parseJsonToMapAvgTime / j;
|
||||
parseJsonToActualObjectAvgTime = parseJsonToActualObjectAvgTime / j;
|
||||
|
||||
logger.info("--------------------------------------------------------------------------");
|
||||
logger.info("Average Time to Generate JSON : " + generateJsonAvgTime);
|
||||
logger.info("Average Time to Parse JSON To Map : " + parseJsonToMapAvgTime);
|
||||
logger.info("Average Time to Parse JSON To Actual Object : " + parseJsonToActualObjectAvgTime);
|
||||
logger.info("--------------------------------------------------------------------------");
|
||||
}
|
||||
|
||||
private static String generateJson(CustomerPortfolioSimple customerPortfolioSimple) throws JsonProcessingException {
|
||||
Runtime.getRuntime().gc();
|
||||
long startParsTime = System.nanoTime();
|
||||
String json = mapper.writeValueAsString(customerPortfolioSimple);
|
||||
long endParsTime = System.nanoTime();
|
||||
long elapsedTime = endParsTime - startParsTime;
|
||||
generateJsonAvgTime = generateJsonAvgTime + elapsedTime;
|
||||
logger.info("Json Generation Time(ms):: " + elapsedTime);
|
||||
return json;
|
||||
}
|
||||
|
||||
private static void parseJsonToMap(String jsonStr) throws JsonParseException , JsonMappingException , IOException {
|
||||
long startParsTime = System.nanoTime();
|
||||
Map parsedMap = mapper.readValue(jsonStr , Map.class);
|
||||
long endParsTime = System.nanoTime();
|
||||
long elapsedTime = endParsTime - startParsTime;
|
||||
parseJsonToMapAvgTime = parseJsonToMapAvgTime + elapsedTime;
|
||||
logger.info("Generating Map from json Time(ms):: " + elapsedTime);
|
||||
logger.info("--------------------------------------------------------------------------");
|
||||
parsedMap = null;
|
||||
Runtime.getRuntime().gc();
|
||||
}
|
||||
|
||||
private static void parseJsonToActualObject(String jsonStr) throws JsonParseException , JsonMappingException ,
|
||||
IOException {
|
||||
long startParsTime = System.nanoTime();
|
||||
CustomerPortfolioSimple customerPortfolioSimple = mapper.readValue(jsonStr , CustomerPortfolioSimple.class);
|
||||
long endParsTime = System.nanoTime();
|
||||
long elapsedTime = endParsTime - startParsTime;
|
||||
parseJsonToActualObjectAvgTime = parseJsonToActualObjectAvgTime + elapsedTime;
|
||||
logger.info("Generating Actual Object from json Time(ms):: " + elapsedTime);
|
||||
customerPortfolioSimple = null;
|
||||
Runtime.getRuntime().gc();
|
||||
}
|
||||
}
|
@ -1,90 +0,0 @@
|
||||
package com.baeldung.data.utility;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
public class Utility {
|
||||
|
||||
public static String generateRandomName() {
|
||||
char[] chars = "abcdefghijklmnopqrstuvwxyz ".toCharArray();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 8; i++) {
|
||||
char c = chars[random.nextInt(chars.length)];
|
||||
sb.append(c);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String generateRandomAddress() {
|
||||
char[] chars = "abcdefghijklmnopqrstuvwxyz ".toCharArray();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 30; i++) {
|
||||
char c = chars[random.nextInt(chars.length)];
|
||||
sb.append(c);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String generateRandomZip() {
|
||||
char[] chars = "1234567890".toCharArray();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 8; i++) {
|
||||
char c = chars[random.nextInt(chars.length)];
|
||||
sb.append(c);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String generateRandomPhone() {
|
||||
char[] chars = "1234567890".toCharArray();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Random random = new Random();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
char c = chars[random.nextInt(chars.length)];
|
||||
sb.append(c);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String readFile(String fileName , Class clazz) throws IOException {
|
||||
String dir = clazz.getResource("/").getFile();
|
||||
dir = dir + "/" + fileName;
|
||||
|
||||
BufferedReader br = new BufferedReader(new FileReader(dir));
|
||||
try {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line = br.readLine();
|
||||
|
||||
while (line != null) {
|
||||
sb.append(line);
|
||||
sb.append(System.lineSeparator());
|
||||
line = br.readLine();
|
||||
}
|
||||
return sb.toString();
|
||||
} finally {
|
||||
br.close();
|
||||
}
|
||||
}
|
||||
|
||||
public static String bytesIntoMB(long bytes) {
|
||||
long kilobyte = 1024;
|
||||
long megabyte = kilobyte * 1024;
|
||||
|
||||
if ((bytes >= 0) && (bytes < kilobyte)) {
|
||||
return bytes + " B";
|
||||
|
||||
} else if ((bytes >= kilobyte) && (bytes < megabyte)) {
|
||||
return (bytes / kilobyte) + " KB";
|
||||
|
||||
} else if ((bytes >= megabyte)) {
|
||||
return (bytes / megabyte) + " MB";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package com.baeldung.pojo.complex;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AddressDetails {
|
||||
|
||||
private String address;
|
||||
|
||||
private String zipcode;
|
||||
|
||||
private List<ContactDetails> contactDetails;
|
||||
|
||||
public String getZipcode() {
|
||||
return zipcode;
|
||||
}
|
||||
|
||||
public void setZipcode(String zipcode) {
|
||||
this.zipcode = zipcode;
|
||||
}
|
||||
|
||||
public List<ContactDetails> getContactDetails() {
|
||||
return contactDetails;
|
||||
}
|
||||
|
||||
public void setContactDetails(List<ContactDetails> contactDetails) {
|
||||
this.contactDetails = contactDetails;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
public void setAddress(String address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.baeldung.pojo.complex;
|
||||
|
||||
public class ContactDetails {
|
||||
|
||||
private String mobile;
|
||||
|
||||
private String landline;
|
||||
|
||||
public String getMobile() {
|
||||
return mobile;
|
||||
}
|
||||
|
||||
public void setMobile(String mobile) {
|
||||
this.mobile = mobile;
|
||||
}
|
||||
|
||||
public String getLandline() {
|
||||
return landline;
|
||||
}
|
||||
|
||||
public void setLandline(String landline) {
|
||||
this.landline = landline;
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package com.baeldung.pojo.complex;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.baeldung.pojo.simple.Customer;
|
||||
|
||||
public class CustomerAddressDetails extends Customer {
|
||||
|
||||
private List<AddressDetails> addressDetails;
|
||||
|
||||
public List<AddressDetails> getAddressDetails() {
|
||||
return addressDetails;
|
||||
}
|
||||
|
||||
public void setAddressDetails(List<AddressDetails> addressDetails) {
|
||||
this.addressDetails = addressDetails;
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
package com.baeldung.pojo.complex;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CustomerPortfolioComplex {
|
||||
|
||||
private List<CustomerAddressDetails> customerAddressDetailsList;
|
||||
|
||||
public List<CustomerAddressDetails> getCustomerAddressDetailsList() {
|
||||
return customerAddressDetailsList;
|
||||
}
|
||||
|
||||
public void setCustomerAddressDetailsList(List<CustomerAddressDetails> customerAddressDetailsList) {
|
||||
this.customerAddressDetailsList = customerAddressDetailsList;
|
||||
}
|
||||
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package com.baeldung.pojo.simple;
|
||||
|
||||
|
||||
public class Customer {
|
||||
|
||||
private String firstName;
|
||||
|
||||
private String lastName;
|
||||
|
||||
private int age;
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package com.baeldung.pojo.simple;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CustomerPortfolioSimple {
|
||||
|
||||
private List<Customer> customerLists;
|
||||
|
||||
public List<Customer> getCustomerLists() {
|
||||
return customerLists;
|
||||
}
|
||||
|
||||
public void setCustomerLists(List<Customer> customerLists) {
|
||||
this.customerLists = customerLists;
|
||||
}
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
# Root logger option
|
||||
log4j.rootLogger=DEBUG, file
|
||||
|
||||
# Redirect log messages to console
|
||||
# log4j.appender.stdout=org.apache.log4j.ConsoleAppender
|
||||
# log4j.appender.stdout.Target=System.out
|
||||
# log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
|
||||
# log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
|
||||
|
||||
# Redirect log messages to a log file, support file rolling.
|
||||
log4j.appender.file=org.apache.log4j.RollingFileAppender
|
||||
log4j.appender.file.File=log4j-application.log
|
||||
log4j.appender.file.MaxFileSize=5MB
|
||||
log4j.appender.file.MaxBackupIndex=10
|
||||
log4j.appender.file.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
|
@ -19,7 +19,7 @@
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>18.0</version>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
|
@ -1,7 +1,6 @@
|
||||
<?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">
|
||||
<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>
|
||||
@ -14,12 +13,15 @@
|
||||
<artifactId>guava</artifactId>
|
||||
<version>18.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?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">
|
||||
<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>
|
||||
@ -10,20 +11,23 @@
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>19.0</version>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<version>1.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
@ -42,4 +46,8 @@
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<guava.version>19.0</guava.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -115,6 +115,7 @@
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
@ -221,8 +222,7 @@
|
||||
<spring-data-jpa.version>1.9.2.RELEASE</spring-data-jpa.version>
|
||||
|
||||
<!-- marshalling -->
|
||||
|
||||
<jackson.version>2.7.2</jackson.version>
|
||||
<jackson.version>2.7.8</jackson.version>
|
||||
|
||||
<!-- logging -->
|
||||
<org.slf4j.version>1.7.13</org.slf4j.version>
|
||||
|
@ -174,7 +174,7 @@
|
||||
<mysql-connector-java.version>5.1.38</mysql-connector-java.version>
|
||||
|
||||
<!-- marshalling -->
|
||||
<jackson.version>2.7.2</jackson.version>
|
||||
<jackson.version>2.7.8</jackson.version>
|
||||
|
||||
<!-- logging -->
|
||||
<org.slf4j.version>1.7.13</org.slf4j.version>
|
||||
|
@ -1,56 +1,36 @@
|
||||
<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">
|
||||
<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>cassandra-java-client</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
|
||||
<name>cassandra-java-client</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<!-- logging -->
|
||||
<org.slf4j.version>1.7.21</org.slf4j.version>
|
||||
<logback.version>1.1.7</logback.version>
|
||||
|
||||
<!-- testing -->
|
||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<mockito.version>1.10.19</mockito.version>
|
||||
<testng.version>6.8</testng.version>
|
||||
<assertj.version>3.5.1</assertj.version>
|
||||
|
||||
<!-- maven plugins -->
|
||||
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
|
||||
|
||||
|
||||
<name>cassandra-java-client</name>
|
||||
|
||||
<dependencies>
|
||||
<!-- Cassandra -->
|
||||
<cassandra-driver-core.version>3.1.0</cassandra-driver-core.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<!-- Cassandra -->
|
||||
<dependency>
|
||||
<dependency>
|
||||
<groupId>com.datastax.cassandra</groupId>
|
||||
<artifactId>cassandra-driver-core</artifactId>
|
||||
<version>${cassandra-driver-core.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.cassandraunit/cassandra-unit -->
|
||||
<dependency>
|
||||
<groupId>org.cassandraunit</groupId>
|
||||
<artifactId>cassandra-unit</artifactId>
|
||||
<version>3.0.0.1</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- This guava version is required for cassandra-unit 3.0.0.1 -->
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>19.0</version>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- logging -->
|
||||
|
||||
<!-- logging -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
@ -74,16 +54,16 @@
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
<version>${org.slf4j.version}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>${junit.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<finalName>java-cassandra</finalName>
|
||||
|
||||
<plugins>
|
||||
@ -97,6 +77,29 @@
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
|
||||
</build>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<guava.version>19.0</guava.version>
|
||||
|
||||
<!-- logging -->
|
||||
<org.slf4j.version>1.7.21</org.slf4j.version>
|
||||
<logback.version>1.1.7</logback.version>
|
||||
|
||||
<!-- testing -->
|
||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<mockito.version>1.10.19</mockito.version>
|
||||
<testng.version>6.8</testng.version>
|
||||
<assertj.version>3.5.1</assertj.version>
|
||||
|
||||
<!-- maven plugins -->
|
||||
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
|
||||
|
||||
<!-- Cassandra -->
|
||||
<cassandra-driver-core.version>3.1.0</cassandra-driver-core.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -20,12 +20,12 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.6</version>
|
||||
<version>2.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.6</version>
|
||||
<version>2.7</version>
|
||||
</dependency>
|
||||
<!--disruptor for log4j2 async logging-->
|
||||
<dependency>
|
||||
|
@ -1,45 +1,172 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.junit.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import play.mvc.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import model.Student;
|
||||
import play.test.*;
|
||||
import play.data.DynamicForm;
|
||||
import play.data.validation.ValidationError;
|
||||
import play.data.validation.Constraints.RequiredValidator;
|
||||
import play.i18n.Lang;
|
||||
import play.libs.F;
|
||||
import play.libs.F.*;
|
||||
import play.twirl.api.Content;
|
||||
|
||||
import static play.test.Helpers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Simple (JUnit) tests that can call all parts of a play app.
|
||||
* If you are interested in mocking a whole application, see the wiki for more details.
|
||||
*
|
||||
*/
|
||||
public class ApplicationTest {
|
||||
|
||||
@Test
|
||||
public void simpleCheck() {
|
||||
int a = 1 + 1;
|
||||
assertEquals(2, a);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void renderTemplate() {
|
||||
Content html = views.html.index.render("Your new application is ready.");
|
||||
assertEquals("text/html", html.contentType());
|
||||
assertTrue(html.body().contains("Your new application is ready."));
|
||||
}
|
||||
|
||||
public class ApplicationTest{
|
||||
private static final String BASE_URL = "http://localhost:9000";
|
||||
|
||||
@Test
|
||||
public void testInServer() throws Exception {
|
||||
TestServer server = testServer(3333);
|
||||
running(server, () -> {
|
||||
try {
|
||||
WSClient ws = play.libs.ws.WS.newClient(3333);
|
||||
CompletionStage<WSResponse> completionStage = ws.url("/").get();
|
||||
WSResponse response = completionStage.toCompletableFuture().get();
|
||||
ws.close();
|
||||
assertEquals(OK, response.getStatus());
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
@Test
|
||||
public void whenCreatesRecord_thenCorrect() {
|
||||
Student student = new Student("jody", "west", 50);
|
||||
JSONObject obj = new JSONObject(makeRequest(BASE_URL, "POST", new JSONObject(student)));
|
||||
assertTrue(obj.getBoolean("isSuccessfull"));
|
||||
JSONObject body = obj.getJSONObject("body");
|
||||
assertEquals(student.getAge(), body.getInt("age"));
|
||||
assertEquals(student.getFirstName(), body.getString("firstName"));
|
||||
assertEquals(student.getLastName(), body.getString("lastName"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeletesCreatedRecord_thenCorrect() {
|
||||
Student student = new Student("Usain", "Bolt", 25);
|
||||
JSONObject ob1 = new JSONObject(makeRequest(BASE_URL, "POST", new JSONObject(student))).getJSONObject("body");
|
||||
int id = ob1.getInt("id");
|
||||
JSONObject obj1 = new JSONObject(makeRequest(BASE_URL + "/" + id, "POST", new JSONObject()));
|
||||
assertTrue(obj1.getBoolean("isSuccessfull"));
|
||||
makeRequest(BASE_URL + "/" + id, "DELETE", null);
|
||||
JSONObject obj2 = new JSONObject(makeRequest(BASE_URL + "/" + id, "POST", new JSONObject()));
|
||||
assertFalse(obj2.getBoolean("isSuccessfull"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenUpdatesCreatedRecord_thenCorrect() {
|
||||
Student student = new Student("john", "doe", 50);
|
||||
JSONObject body1 = new JSONObject(makeRequest(BASE_URL, "POST", new JSONObject(student))).getJSONObject("body");
|
||||
assertEquals(student.getAge(), body1.getInt("age"));
|
||||
int newAge = 60;
|
||||
body1.put("age", newAge);
|
||||
JSONObject body2 = new JSONObject(makeRequest(BASE_URL, "PUT", body1)).getJSONObject("body");
|
||||
assertFalse(student.getAge() == body2.getInt("age"));
|
||||
assertTrue(newAge == body2.getInt("age"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGetsAllRecords_thenCorrect() {
|
||||
Student student1 = new Student("jane", "daisy", 50);
|
||||
Student student2 = new Student("john", "daniel", 60);
|
||||
Student student3 = new Student("don", "mason", 55);
|
||||
Student student4 = new Student("scarlet", "ohara", 90);
|
||||
|
||||
makeRequest(BASE_URL, "POST", new JSONObject(student1));
|
||||
makeRequest(BASE_URL, "POST", new JSONObject(student2));
|
||||
makeRequest(BASE_URL, "POST", new JSONObject(student3));
|
||||
makeRequest(BASE_URL, "POST", new JSONObject(student4));
|
||||
|
||||
JSONObject objects = new JSONObject(makeRequest(BASE_URL, "GET", null));
|
||||
assertTrue(objects.getBoolean("isSuccessfull"));
|
||||
JSONArray array = objects.getJSONArray("body");
|
||||
assertTrue(array.length() >= 4);
|
||||
}
|
||||
|
||||
public static String makeRequest(String myUrl, String httpMethod, JSONObject parameters) {
|
||||
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URL(myUrl);
|
||||
} catch (MalformedURLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
HttpURLConnection conn = null;
|
||||
try {
|
||||
|
||||
conn = (HttpURLConnection) url.openConnection();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
conn.setDoInput(true);
|
||||
|
||||
conn.setReadTimeout(10000);
|
||||
|
||||
conn.setRequestProperty("Content-Type", "application/json");
|
||||
DataOutputStream dos = null;
|
||||
int respCode = 0;
|
||||
String inputString = null;
|
||||
try {
|
||||
conn.setRequestMethod(httpMethod);
|
||||
|
||||
if (Arrays.asList("POST", "PUT").contains(httpMethod)) {
|
||||
String params = parameters.toString();
|
||||
|
||||
conn.setDoOutput(true);
|
||||
|
||||
dos = new DataOutputStream(conn.getOutputStream());
|
||||
dos.writeBytes(params);
|
||||
dos.flush();
|
||||
dos.close();
|
||||
}
|
||||
respCode = conn.getResponseCode();
|
||||
if (respCode != 200 && respCode != 201) {
|
||||
String error = inputStreamToString(conn.getErrorStream());
|
||||
return error;
|
||||
}
|
||||
inputString = inputStreamToString(conn.getInputStream());
|
||||
|
||||
} catch (IOException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
}
|
||||
return inputString;
|
||||
}
|
||||
|
||||
public static String inputStreamToString(InputStream is) {
|
||||
BufferedReader br = null;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
String line;
|
||||
try {
|
||||
|
||||
br = new BufferedReader(new InputStreamReader(is));
|
||||
while ((line = br.readLine()) != null) {
|
||||
sb.append(line);
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (br != null) {
|
||||
try {
|
||||
br.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +0,0 @@
|
||||
import org.junit.*;
|
||||
|
||||
import play.mvc.*;
|
||||
import play.test.*;
|
||||
|
||||
import static play.test.Helpers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import static org.fluentlenium.core.filter.FilterConstructor.*;
|
||||
|
||||
public class IntegrationTest {
|
||||
|
||||
/**
|
||||
* add your integration test here
|
||||
* in this example we just check if the welcome page is being shown
|
||||
*/
|
||||
@Test
|
||||
public void test() {
|
||||
running(testServer(3333, fakeApplication(inMemoryDatabase())), HTMLUNIT, browser -> {
|
||||
browser.goTo("http://localhost:3333");
|
||||
assertTrue(browser.pageSource().contains("Your new application is ready."));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
1
pom.xml
1
pom.xml
@ -34,7 +34,6 @@
|
||||
<!-- <module>gatling</module> --> <!-- not meant to run as part of the standard build -->
|
||||
|
||||
<module>gson</module>
|
||||
<module>gson-jackson-performance</module>
|
||||
<module>guava</module>
|
||||
<module>guava18</module>
|
||||
<module>guava19</module>
|
||||
|
@ -1,257 +1,226 @@
|
||||
<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/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>rest-assured</name>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.1-b06</version>
|
||||
</dependency>
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
<version>1.0</version>
|
||||
<name>rest-assured</name>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.1-b06</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>servlet-api</artifactId>
|
||||
<version>2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-security</artifactId>
|
||||
<version>9.2.0.M1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-servlet</artifactId>
|
||||
<version>9.2.0.M1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-servlets</artifactId>
|
||||
<version>9.2.0.M1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-io</artifactId>
|
||||
<version>9.2.0.M1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-http</artifactId>
|
||||
<version>9.2.0.M1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>9.2.0.M1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-util</artifactId>
|
||||
<version>9.2.0.M1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-security -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-security</artifactId>
|
||||
<version>9.2.0.M1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.21</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-servlet -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-servlet</artifactId>
|
||||
<version>9.2.0.M1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.7.21</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-servlets -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-servlets</artifactId>
|
||||
<version>9.2.0.M1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-io -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-io</artifactId>
|
||||
<version>9.2.0.M1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
<version>4.4.5</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-http -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-http</artifactId>
|
||||
<version>9.2.0.M1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.fge</groupId>
|
||||
<artifactId>uri-template</artifactId>
|
||||
<version>0.9</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.googlecode.libphonenumber</groupId>
|
||||
<artifactId>libphonenumber</artifactId>
|
||||
<version>7.4.5</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-server -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-server</artifactId>
|
||||
<version>9.2.0.M1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
<version>1.4.7</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-util -->
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-util</artifactId>
|
||||
<version>9.2.0.M1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>2.9.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>1.7.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.fge</groupId>
|
||||
<artifactId>msg-simple</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>1.7.21</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.fge</groupId>
|
||||
<artifactId>jackson-coreutils</artifactId>
|
||||
<version>1.8</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.jayway.restassured/rest-assured-common -->
|
||||
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.fge</groupId>
|
||||
<artifactId>btf</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpcore</artifactId>
|
||||
<version>4.4.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-all</artifactId>
|
||||
<version>2.4.7</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.github.fge/uri-template -->
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.fge</groupId>
|
||||
<artifactId>uri-template</artifactId>
|
||||
<version>0.9</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.tomakehurst</groupId>
|
||||
<artifactId>wiremock</artifactId>
|
||||
<version>2.1.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>json-schema-validator</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.fge</groupId>
|
||||
<artifactId>json-schema-validator</artifactId>
|
||||
<version>2.2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.fge</groupId>
|
||||
<artifactId>json-schema-core</artifactId>
|
||||
<version>1.2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.googlecode.libphonenumber/libphonenumber -->
|
||||
<dependency>
|
||||
<groupId>com.googlecode.libphonenumber</groupId>
|
||||
<artifactId>libphonenumber</artifactId>
|
||||
<version>7.4.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-collections</groupId>
|
||||
<artifactId>commons-collections</artifactId>
|
||||
<version>3.2.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
<version>1.4.7</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>joda-time</groupId>
|
||||
<artifactId>joda-time</artifactId>
|
||||
<version>2.9.4</version>
|
||||
</dependency>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.3</version>
|
||||
<configuration>
|
||||
<source>8</source>
|
||||
<target>8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>2.8.0</version>
|
||||
</dependency>
|
||||
<properties>
|
||||
<jackson.version>2.8.3</jackson.version>
|
||||
<guava.version>19.0</guava.version>
|
||||
</properties>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.8.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>2.8.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.fge</groupId>
|
||||
<artifactId>msg-simple</artifactId>
|
||||
<version>1.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.fge</groupId>
|
||||
<artifactId>jackson-coreutils</artifactId>
|
||||
<version>1.8</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>18.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.fge</groupId>
|
||||
<artifactId>btf</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>4.5.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.codehaus.groovy</groupId>
|
||||
<artifactId>groovy-all</artifactId>
|
||||
<version>2.4.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.github.tomakehurst</groupId>
|
||||
<artifactId>wiremock</artifactId>
|
||||
<version>2.1.7</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>rest-assured</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>json-schema-validator</artifactId>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.fge</groupId>
|
||||
<artifactId>json-schema-validator</artifactId>
|
||||
<version>2.2.6</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.fge</groupId>
|
||||
<artifactId>json-schema-core</artifactId>
|
||||
<version>1.2.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.3</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-all</artifactId>
|
||||
<version>1.3</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/commons-collections/commons-collections -->
|
||||
<dependency>
|
||||
<groupId>commons-collections</groupId>
|
||||
<artifactId>commons-collections</artifactId>
|
||||
<version>3.2.2</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
|
@ -156,7 +156,7 @@
|
||||
|
||||
<properties>
|
||||
<!-- marshalling -->
|
||||
<jackson.version>2.7.2</jackson.version>
|
||||
<jackson.version>2.7.8</jackson.version>
|
||||
|
||||
<!-- logging -->
|
||||
<org.slf4j.version>1.7.13</org.slf4j.version>
|
||||
|
@ -29,5 +29,4 @@ public class SpringExtension extends AbstractExtensionId<SpringExtension.SpringE
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -27,9 +27,7 @@ public class SpringAkkaTest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Test
|
||||
public void whenCallingGreetingActor_thenActorGreetsTheCaller() throws Exception {
|
||||
ActorRef greeter = system.actorOf(
|
||||
SPRING_EXTENSION_PROVIDER.get(system)
|
||||
.props("greetingActor"), "greeter");
|
||||
ActorRef greeter = system.actorOf(SPRING_EXTENSION_PROVIDER.get(system).props("greetingActor"), "greeter");
|
||||
|
||||
FiniteDuration duration = FiniteDuration.create(1, TimeUnit.SECONDS);
|
||||
Timeout timeout = Timeout.durationToTimeout(duration);
|
||||
|
@ -1,295 +1,301 @@
|
||||
<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>spring-all</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
<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>spring-all</artifactId>
|
||||
<version>0.1-SNAPSHOT</version>
|
||||
|
||||
<name>spring-all</name>
|
||||
<packaging>war</packaging>
|
||||
<name>spring-all</name>
|
||||
<packaging>war</packaging>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>1.3.6.RELEASE</version>
|
||||
</parent>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>1.3.6.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- Spring -->
|
||||
<!-- Spring -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-orm</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-webmvc</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-orm</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- aspectj -->
|
||||
<!-- aspectj -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aspects</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-aspects</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- persistence -->
|
||||
<!-- persistence -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>${hibernate.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hsqldb</groupId>
|
||||
<artifactId>hsqldb</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- validation -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-core</artifactId>
|
||||
<version>${hibernate.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hsqldb</groupId>
|
||||
<artifactId>hsqldb</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
<!-- validation -->
|
||||
|
||||
<!-- web -->
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- web -->
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- util -->
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- logging -->
|
||||
<!-- util -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<!-- <scope>runtime</scope> -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||
</dependency>
|
||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>${guava.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- test scoped -->
|
||||
<!-- logging -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<!-- <scope>runtime</scope> -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>jcl-over-slf4j</artifactId>
|
||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||
</dependency>
|
||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>log4j-over-slf4j</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<!-- test scoped -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<version>3.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-library</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependency>
|
||||
<groupId>org.easymock</groupId>
|
||||
<artifactId>easymock</artifactId>
|
||||
<version>3.4</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ehcache</groupId>
|
||||
<artifactId>ehcache</artifactId>
|
||||
<version>3.1.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependencies>
|
||||
</dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>${org.springframework.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependencyManagement>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>${org.springframework.version}</version>
|
||||
</dependency>
|
||||
<dependencies>
|
||||
|
||||
</dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-framework-bom</artifactId>
|
||||
<version>${org.springframework.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencyManagement>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-core</artifactId>
|
||||
<version>${org.springframework.version}</version>
|
||||
</dependency>
|
||||
|
||||
<build>
|
||||
<finalName>spring-all</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
</dependencies>
|
||||
|
||||
<plugins>
|
||||
</dependencyManagement>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<build>
|
||||
<finalName>spring-all</finalName>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
</resource>
|
||||
</resources>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<configuration>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugins>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<!-- <exclude>**/*ProductionTest.java</exclude> -->
|
||||
</excludes>
|
||||
<systemPropertyVariables>
|
||||
<!-- <provPersistenceTarget>h2</provPersistenceTarget> -->
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.codehaus.cargo</groupId>
|
||||
<artifactId>cargo-maven2-plugin</artifactId>
|
||||
<version>${cargo-maven2-plugin.version}</version>
|
||||
<configuration>
|
||||
<wait>true</wait>
|
||||
<container>
|
||||
<containerId>jetty8x</containerId>
|
||||
<type>embedded</type>
|
||||
<systemProperties>
|
||||
<!-- <provPersistenceTarget>cargo</provPersistenceTarget> -->
|
||||
</systemProperties>
|
||||
</container>
|
||||
<configuration>
|
||||
<properties>
|
||||
<cargo.servlet.port>8082</cargo.servlet.port>
|
||||
</properties>
|
||||
</configuration>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-war-plugin</artifactId>
|
||||
<configuration>
|
||||
<failOnMissingWebXml>false</failOnMissingWebXml>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<!-- <exclude>**/*ProductionTest.java</exclude> -->
|
||||
</excludes>
|
||||
<systemPropertyVariables>
|
||||
<!-- <provPersistenceTarget>h2</provPersistenceTarget> -->
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
</build>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.cargo</groupId>
|
||||
<artifactId>cargo-maven2-plugin</artifactId>
|
||||
<version>${cargo-maven2-plugin.version}</version>
|
||||
<configuration>
|
||||
<wait>true</wait>
|
||||
<container>
|
||||
<containerId>jetty8x</containerId>
|
||||
<type>embedded</type>
|
||||
<systemProperties>
|
||||
<!-- <provPersistenceTarget>cargo</provPersistenceTarget> -->
|
||||
</systemProperties>
|
||||
</container>
|
||||
<configuration>
|
||||
<properties>
|
||||
<cargo.servlet.port>8082</cargo.servlet.port>
|
||||
</properties>
|
||||
</configuration>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<properties>
|
||||
<!-- Spring -->
|
||||
<org.springframework.version>4.3.1.RELEASE</org.springframework.version>
|
||||
<org.springframework.security.version>4.0.4.RELEASE</org.springframework.security.version>
|
||||
<javassist.version>3.20.0-GA</javassist.version>
|
||||
<jstl.version>1.2</jstl.version>
|
||||
</plugins>
|
||||
|
||||
<!-- persistence -->
|
||||
<hibernate.version>4.3.11.Final</hibernate.version>
|
||||
<mysql-connector-java.version>5.1.38</mysql-connector-java.version>
|
||||
</build>
|
||||
|
||||
<!-- logging -->
|
||||
<org.slf4j.version>1.7.13</org.slf4j.version>
|
||||
<logback.version>1.1.3</logback.version>
|
||||
<properties>
|
||||
<!-- Spring -->
|
||||
<org.springframework.version>4.3.1.RELEASE</org.springframework.version>
|
||||
<org.springframework.security.version>4.0.4.RELEASE</org.springframework.security.version>
|
||||
<javassist.version>3.20.0-GA</javassist.version>
|
||||
<jstl.version>1.2</jstl.version>
|
||||
|
||||
<!-- various -->
|
||||
<hibernate-validator.version>5.2.2.Final</hibernate-validator.version>
|
||||
<!-- persistence -->
|
||||
<hibernate.version>4.3.11.Final</hibernate.version>
|
||||
<mysql-connector-java.version>5.1.38</mysql-connector-java.version>
|
||||
|
||||
<!-- util -->
|
||||
<guava.version>19.0</guava.version>
|
||||
<commons-lang3.version>3.4</commons-lang3.version>
|
||||
<!-- logging -->
|
||||
<org.slf4j.version>1.7.13</org.slf4j.version>
|
||||
<logback.version>1.1.3</logback.version>
|
||||
|
||||
<!-- testing -->
|
||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<mockito.version>1.10.19</mockito.version>
|
||||
<!-- various -->
|
||||
<hibernate-validator.version>5.2.2.Final</hibernate-validator.version>
|
||||
|
||||
<httpcore.version>4.4.1</httpcore.version>
|
||||
<httpclient.version>4.5</httpclient.version>
|
||||
<!-- util -->
|
||||
<guava.version>19.0</guava.version>
|
||||
<commons-lang3.version>3.4</commons-lang3.version>
|
||||
|
||||
<rest-assured.version>2.9.0</rest-assured.version>
|
||||
<!-- testing -->
|
||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
||||
<junit.version>4.12</junit.version>
|
||||
<mockito.version>1.10.19</mockito.version>
|
||||
|
||||
<!-- maven plugins -->
|
||||
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
|
||||
<maven-war-plugin.version>2.6</maven-war-plugin.version>
|
||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||
<maven-resources-plugin.version>2.7</maven-resources-plugin.version>
|
||||
<cargo-maven2-plugin.version>1.4.18</cargo-maven2-plugin.version>
|
||||
<httpcore.version>4.4.1</httpcore.version>
|
||||
<httpclient.version>4.5</httpclient.version>
|
||||
|
||||
</properties>
|
||||
<rest-assured.version>2.9.0</rest-assured.version>
|
||||
|
||||
<!-- maven plugins -->
|
||||
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
|
||||
<maven-war-plugin.version>2.6</maven-war-plugin.version>
|
||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
||||
<maven-resources-plugin.version>2.7</maven-resources-plugin.version>
|
||||
<cargo-maven2-plugin.version>1.4.18</cargo-maven2-plugin.version>
|
||||
|
||||
</properties>
|
||||
|
||||
</project>
|
@ -72,5 +72,5 @@ public abstract class AbstractService {
|
||||
public String getAddress5(final Customer customer) {
|
||||
return customer.getAddress();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -11,21 +11,21 @@ import org.springframework.web.context.support.GenericWebApplicationContext;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
|
||||
public class StudentControllerConfig implements WebApplicationInitializer {
|
||||
|
||||
@Override
|
||||
public void onStartup(ServletContext sc) throws ServletException {
|
||||
AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
|
||||
root.register(WebConfig.class);
|
||||
|
||||
root.setServletContext(sc);
|
||||
@Override
|
||||
public void onStartup(ServletContext sc) throws ServletException {
|
||||
AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
|
||||
root.register(WebConfig.class);
|
||||
|
||||
// Manages the lifecycle of the root application context
|
||||
sc.addListener(new ContextLoaderListener(root));
|
||||
root.setServletContext(sc);
|
||||
|
||||
DispatcherServlet dv = new DispatcherServlet(new GenericWebApplicationContext());
|
||||
// Manages the lifecycle of the root application context
|
||||
sc.addListener(new ContextLoaderListener(root));
|
||||
|
||||
ServletRegistration.Dynamic appServlet = sc.addServlet("test-mvc", dv);
|
||||
appServlet.setLoadOnStartup(1);
|
||||
appServlet.addMapping("/test/*");
|
||||
}
|
||||
DispatcherServlet dv = new DispatcherServlet(new GenericWebApplicationContext());
|
||||
|
||||
ServletRegistration.Dynamic appServlet = sc.addServlet("test-mvc", dv);
|
||||
appServlet.setLoadOnStartup(1);
|
||||
appServlet.addMapping("/test/*");
|
||||
}
|
||||
}
|
||||
|
@ -11,13 +11,13 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||
|
||||
@Configuration
|
||||
@EnableWebMvc
|
||||
@ComponentScan(basePackages= {"org.baeldung.controller.controller","org.baeldung.controller.config" })
|
||||
@ComponentScan(basePackages = { "org.baeldung.controller.controller", "org.baeldung.controller.config" })
|
||||
public class WebConfig extends WebMvcConfigurerAdapter {
|
||||
@Override
|
||||
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
|
||||
configurer.enable();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public ViewResolver viewResolver() {
|
||||
InternalResourceViewResolver bean = new InternalResourceViewResolver();
|
||||
|
@ -7,15 +7,15 @@ import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
public class RestController{
|
||||
public class RestController {
|
||||
|
||||
@GetMapping(value="/student/{studentId}")
|
||||
public @ResponseBody Student getTestData(@PathVariable Integer studentId) {
|
||||
Student student = new Student();
|
||||
student.setName("Peter");
|
||||
student.setId(studentId);
|
||||
@GetMapping(value = "/student/{studentId}")
|
||||
public @ResponseBody Student getTestData(@PathVariable Integer studentId) {
|
||||
Student student = new Student();
|
||||
student.setName("Peter");
|
||||
student.setId(studentId);
|
||||
|
||||
return student;
|
||||
return student;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +1,33 @@
|
||||
package org.baeldung.controller.student;
|
||||
|
||||
public class Student {
|
||||
private String name;
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
private int id;
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode(){
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj){
|
||||
return this.name.equals(((Student)obj).getName());
|
||||
}
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return this.name.equals(((Student) obj).getName());
|
||||
}
|
||||
}
|
24
spring-all/src/main/java/org/baeldung/ehcache/app/App.java
Executable file
24
spring-all/src/main/java/org/baeldung/ehcache/app/App.java
Executable file
@ -0,0 +1,24 @@
|
||||
package org.baeldung.ehcache.app;
|
||||
|
||||
import org.baeldung.ehcache.calculator.SquaredCalculator;
|
||||
import org.baeldung.ehcache.config.CacheHelper;
|
||||
|
||||
public class App {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
SquaredCalculator squaredCalculator = new SquaredCalculator();
|
||||
CacheHelper cacheHelper = new CacheHelper();
|
||||
|
||||
squaredCalculator.setCache(cacheHelper);
|
||||
|
||||
calculate(squaredCalculator);
|
||||
calculate(squaredCalculator);
|
||||
}
|
||||
|
||||
private static void calculate(SquaredCalculator squaredCalculator) {
|
||||
for (int i = 10; i < 15; i++) {
|
||||
System.out.println("Square value of " + i + " is: " + squaredCalculator.getSquareValueOfNumber(i) + "\n");
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package org.baeldung.ehcache.calculator;
|
||||
|
||||
import org.baeldung.ehcache.config.CacheHelper;
|
||||
|
||||
public class SquaredCalculator {
|
||||
private CacheHelper cache;
|
||||
|
||||
public int getSquareValueOfNumber(int input) {
|
||||
if (cache.getSquareNumberCache().containsKey(input)) {
|
||||
return cache.getSquareNumberCache().get(input);
|
||||
}
|
||||
|
||||
System.out.println("Calculating square value of " + input + " and caching result.");
|
||||
|
||||
int squaredValue = (int) Math.pow(input, 2);
|
||||
cache.getSquareNumberCache().put(input, squaredValue);
|
||||
|
||||
return squaredValue;
|
||||
}
|
||||
|
||||
public void setCache(CacheHelper cache) {
|
||||
this.cache = cache;
|
||||
}
|
||||
}
|
25
spring-all/src/main/java/org/baeldung/ehcache/config/CacheHelper.java
Executable file
25
spring-all/src/main/java/org/baeldung/ehcache/config/CacheHelper.java
Executable file
@ -0,0 +1,25 @@
|
||||
package org.baeldung.ehcache.config;
|
||||
|
||||
import org.ehcache.Cache;
|
||||
import org.ehcache.CacheManager;
|
||||
import org.ehcache.config.builders.CacheConfigurationBuilder;
|
||||
import org.ehcache.config.builders.CacheManagerBuilder;
|
||||
import org.ehcache.config.builders.ResourcePoolsBuilder;
|
||||
|
||||
public class CacheHelper {
|
||||
|
||||
private CacheManager cacheManager;
|
||||
private Cache<Integer, Integer> squareNumberCache;
|
||||
|
||||
public CacheHelper() {
|
||||
cacheManager = CacheManagerBuilder.newCacheManagerBuilder().withCache("squaredNumber", CacheConfigurationBuilder.newCacheConfigurationBuilder(Integer.class, Integer.class, ResourcePoolsBuilder.heap(10))).build();
|
||||
cacheManager.init();
|
||||
|
||||
squareNumberCache = cacheManager.getCache("squaredNumber", Integer.class, Integer.class);
|
||||
}
|
||||
|
||||
public Cache<Integer, Integer> getSquareNumberCache() {
|
||||
return squareNumberCache;
|
||||
}
|
||||
|
||||
}
|
@ -11,7 +11,6 @@ public class PropertiesWithPlaceHolderConfigurer {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public PropertyPlaceholderConfigurer propertyConfigurer() {
|
||||
final PropertyPlaceholderConfigurer props = new PropertyPlaceholderConfigurer();
|
||||
|
@ -2,14 +2,14 @@ package org.baeldung.scopes;
|
||||
|
||||
public class HelloMessageGenerator {
|
||||
|
||||
private String message;
|
||||
private String message;
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(final String message) {
|
||||
this.message = message;
|
||||
}
|
||||
public void setMessage(final String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,27 +1,27 @@
|
||||
package org.baeldung.scopes;
|
||||
|
||||
public class Person {
|
||||
private String name;
|
||||
private int age;
|
||||
private String name;
|
||||
private int age;
|
||||
|
||||
public Person() {
|
||||
}
|
||||
public Person() {
|
||||
}
|
||||
|
||||
public Person(final String name, final int age) {
|
||||
this.name = name;
|
||||
}
|
||||
public Person(final String name, final int age) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public void setName(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Person [name=" + name + "]";
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Person [name=" + name + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,23 +9,23 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Controller
|
||||
public class ScopesController {
|
||||
public static final Logger LOG = Logger.getLogger(ScopesController.class);
|
||||
public static final Logger LOG = Logger.getLogger(ScopesController.class);
|
||||
|
||||
@Resource(name = "requestMessage")
|
||||
HelloMessageGenerator requestMessage;
|
||||
@Resource(name = "requestMessage")
|
||||
HelloMessageGenerator requestMessage;
|
||||
|
||||
@Resource(name = "sessionMessage")
|
||||
HelloMessageGenerator sessionMessage;
|
||||
@Resource(name = "sessionMessage")
|
||||
HelloMessageGenerator sessionMessage;
|
||||
|
||||
@RequestMapping("/scopes")
|
||||
public String getScopes(final Model model) {
|
||||
LOG.info("Request Message:" + requestMessage.getMessage());
|
||||
LOG.info("Session Message" + sessionMessage.getMessage());
|
||||
requestMessage.setMessage("Good morning!");
|
||||
sessionMessage.setMessage("Good afternoon!");
|
||||
model.addAttribute("requestMessage", requestMessage.getMessage());
|
||||
model.addAttribute("sessionMessage", sessionMessage.getMessage());
|
||||
return "scopesExample";
|
||||
}
|
||||
@RequestMapping("/scopes")
|
||||
public String getScopes(final Model model) {
|
||||
LOG.info("Request Message:" + requestMessage.getMessage());
|
||||
LOG.info("Session Message" + sessionMessage.getMessage());
|
||||
requestMessage.setMessage("Good morning!");
|
||||
sessionMessage.setMessage("Good afternoon!");
|
||||
model.addAttribute("requestMessage", requestMessage.getMessage());
|
||||
model.addAttribute("sessionMessage", sessionMessage.getMessage());
|
||||
return "scopesExample";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,42 +16,42 @@ import org.springframework.web.servlet.view.UrlBasedViewResolver;
|
||||
@ComponentScan("org.baeldung.scopes")
|
||||
@EnableWebMvc
|
||||
public class ScopesConfig {
|
||||
@Bean
|
||||
public UrlBasedViewResolver setupViewResolver() {
|
||||
final UrlBasedViewResolver resolver = new UrlBasedViewResolver();
|
||||
resolver.setPrefix("/WEB-INF/view/");
|
||||
resolver.setSuffix(".jsp");
|
||||
resolver.setViewClass(JstlView.class);
|
||||
return resolver;
|
||||
}
|
||||
@Bean
|
||||
public UrlBasedViewResolver setupViewResolver() {
|
||||
final UrlBasedViewResolver resolver = new UrlBasedViewResolver();
|
||||
resolver.setPrefix("/WEB-INF/view/");
|
||||
resolver.setSuffix(".jsp");
|
||||
resolver.setViewClass(JstlView.class);
|
||||
return resolver;
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
public HelloMessageGenerator requestMessage() {
|
||||
return new HelloMessageGenerator();
|
||||
}
|
||||
@Bean
|
||||
@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
public HelloMessageGenerator requestMessage() {
|
||||
return new HelloMessageGenerator();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
public HelloMessageGenerator sessionMessage() {
|
||||
return new HelloMessageGenerator();
|
||||
}
|
||||
@Bean
|
||||
@Scope(value = WebApplicationContext.SCOPE_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
public HelloMessageGenerator sessionMessage() {
|
||||
return new HelloMessageGenerator();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Scope(value = WebApplicationContext.SCOPE_GLOBAL_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
public HelloMessageGenerator globalSessionMessage() {
|
||||
return new HelloMessageGenerator();
|
||||
}
|
||||
@Bean
|
||||
@Scope(value = WebApplicationContext.SCOPE_GLOBAL_SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS)
|
||||
public HelloMessageGenerator globalSessionMessage() {
|
||||
return new HelloMessageGenerator();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Scope("prototype")
|
||||
public Person personPrototype() {
|
||||
return new Person();
|
||||
}
|
||||
@Bean
|
||||
@Scope("prototype")
|
||||
public Person personPrototype() {
|
||||
return new Person();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@Scope("singleton")
|
||||
public Person personSingleton() {
|
||||
return new Person();
|
||||
}
|
||||
@Bean
|
||||
@Scope("singleton")
|
||||
public Person personSingleton() {
|
||||
return new Person();
|
||||
}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ public class Foo {
|
||||
|
||||
private static final AtomicInteger instanceCount = new AtomicInteger(0);
|
||||
|
||||
|
||||
private final int instanceNum;
|
||||
|
||||
public Foo() {
|
||||
|
@ -18,17 +18,16 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@WebAppConfiguration
|
||||
@ContextConfiguration(classes={WebConfig.class}, loader=AnnotationConfigWebContextLoader.class )
|
||||
@ContextConfiguration(classes = { WebConfig.class }, loader = AnnotationConfigWebContextLoader.class)
|
||||
public class ControllerAnnotationTest {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Autowired
|
||||
private WebApplicationContext wac;
|
||||
|
||||
|
||||
private Student selectedStudent;
|
||||
|
||||
@Before
|
||||
@ -43,9 +42,7 @@ public class ControllerAnnotationTest {
|
||||
@Test
|
||||
public void testTestController() throws Exception {
|
||||
|
||||
ModelAndView mv = this.mockMvc.perform(MockMvcRequestBuilders.get("/test/"))
|
||||
.andReturn()
|
||||
.getModelAndView();
|
||||
ModelAndView mv = this.mockMvc.perform(MockMvcRequestBuilders.get("/test/")).andReturn().getModelAndView();
|
||||
|
||||
// validate modal data
|
||||
Assert.assertSame(mv.getModelMap().get("data").toString(), "Welcome home man");
|
||||
@ -57,9 +54,7 @@ public class ControllerAnnotationTest {
|
||||
@Test
|
||||
public void testRestController() throws Exception {
|
||||
|
||||
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/student/{studentId}", 1))
|
||||
.andReturn().getResponse()
|
||||
.getContentAsString();
|
||||
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/student/{studentId}", 1)).andReturn().getResponse().getContentAsString();
|
||||
|
||||
ObjectMapper reader = new ObjectMapper();
|
||||
|
||||
@ -72,9 +67,7 @@ public class ControllerAnnotationTest {
|
||||
@Test
|
||||
public void testRestAnnotatedController() throws Exception {
|
||||
|
||||
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/annotated/student/{studentId}", 1))
|
||||
.andReturn().getResponse()
|
||||
.getContentAsString();
|
||||
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/annotated/student/{studentId}", 1)).andReturn().getResponse().getContentAsString();
|
||||
|
||||
ObjectMapper reader = new ObjectMapper();
|
||||
|
||||
|
@ -19,7 +19,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@WebAppConfiguration
|
||||
@ContextConfiguration({"classpath:test-mvc.xml"})
|
||||
@ContextConfiguration({ "classpath:test-mvc.xml" })
|
||||
public class ControllerTest {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
@ -41,9 +41,7 @@ public class ControllerTest {
|
||||
@Test
|
||||
public void testTestController() throws Exception {
|
||||
|
||||
ModelAndView mv = this.mockMvc.perform(MockMvcRequestBuilders.get("/test/"))
|
||||
.andReturn()
|
||||
.getModelAndView();
|
||||
ModelAndView mv = this.mockMvc.perform(MockMvcRequestBuilders.get("/test/")).andReturn().getModelAndView();
|
||||
|
||||
// validate modal data
|
||||
Assert.assertSame(mv.getModelMap().get("data").toString(), "Welcome home man");
|
||||
@ -55,9 +53,7 @@ public class ControllerTest {
|
||||
@Test
|
||||
public void testRestController() throws Exception {
|
||||
|
||||
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/student/{studentId}", 1))
|
||||
.andReturn().getResponse()
|
||||
.getContentAsString();
|
||||
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/student/{studentId}", 1)).andReturn().getResponse().getContentAsString();
|
||||
|
||||
ObjectMapper reader = new ObjectMapper();
|
||||
|
||||
@ -70,9 +66,7 @@ public class ControllerTest {
|
||||
@Test
|
||||
public void testRestAnnotatedController() throws Exception {
|
||||
|
||||
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/annotated/student/{studentId}", 1))
|
||||
.andReturn().getResponse()
|
||||
.getContentAsString();
|
||||
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/annotated/student/{studentId}", 1)).andReturn().getResponse().getContentAsString();
|
||||
|
||||
ObjectMapper reader = new ObjectMapper();
|
||||
|
||||
|
@ -8,36 +8,36 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class ScopesTest {
|
||||
|
||||
private static final String NAME = "John Smith";
|
||||
private static final String NAME_OTHER = "Anna Jones";
|
||||
private static final String NAME = "John Smith";
|
||||
private static final String NAME_OTHER = "Anna Jones";
|
||||
|
||||
@Test
|
||||
public void testScopeSingleton() {
|
||||
final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("scopes.xml");
|
||||
@Test
|
||||
public void testScopeSingleton() {
|
||||
final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("scopes.xml");
|
||||
|
||||
final Person personSingletonA = (Person) applicationContext.getBean("personSingleton");
|
||||
final Person personSingletonB = (Person) applicationContext.getBean("personSingleton");
|
||||
final Person personSingletonA = (Person) applicationContext.getBean("personSingleton");
|
||||
final Person personSingletonB = (Person) applicationContext.getBean("personSingleton");
|
||||
|
||||
personSingletonA.setName(NAME);
|
||||
Assert.assertEquals(NAME, personSingletonB.getName());
|
||||
personSingletonA.setName(NAME);
|
||||
Assert.assertEquals(NAME, personSingletonB.getName());
|
||||
|
||||
((AbstractApplicationContext) applicationContext).close();
|
||||
}
|
||||
((AbstractApplicationContext) applicationContext).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testScopePrototype() {
|
||||
final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("scopes.xml");
|
||||
@Test
|
||||
public void testScopePrototype() {
|
||||
final ApplicationContext applicationContext = new ClassPathXmlApplicationContext("scopes.xml");
|
||||
|
||||
final Person personPrototypeA = (Person) applicationContext.getBean("personPrototype");
|
||||
final Person personPrototypeB = (Person) applicationContext.getBean("personPrototype");
|
||||
final Person personPrototypeA = (Person) applicationContext.getBean("personPrototype");
|
||||
final Person personPrototypeB = (Person) applicationContext.getBean("personPrototype");
|
||||
|
||||
personPrototypeA.setName(NAME);
|
||||
personPrototypeB.setName(NAME_OTHER);
|
||||
personPrototypeA.setName(NAME);
|
||||
personPrototypeB.setName(NAME_OTHER);
|
||||
|
||||
Assert.assertEquals(NAME, personPrototypeA.getName());
|
||||
Assert.assertEquals(NAME_OTHER, personPrototypeB.getName());
|
||||
Assert.assertEquals(NAME, personPrototypeA.getName());
|
||||
Assert.assertEquals(NAME_OTHER, personPrototypeB.getName());
|
||||
|
||||
((AbstractApplicationContext) applicationContext).close();
|
||||
}
|
||||
((AbstractApplicationContext) applicationContext).close();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -26,18 +26,12 @@ public class AttributeAnnotationTest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac)
|
||||
.build();
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInterceptorAddsRequestAndSessionParams_thenParamsInjectedWithAttributesAnnotations() throws Exception {
|
||||
String result = this.mockMvc.perform(get("/test")
|
||||
.accept(MediaType.ALL))
|
||||
.andExpect(status().isOk())
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
String result = this.mockMvc.perform(get("/test").accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
|
||||
|
||||
Assert.assertEquals("login = john, query = invoices", result);
|
||||
}
|
||||
|
@ -29,15 +29,12 @@ public class ComposedMappingTest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac)
|
||||
.build();
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRequestingMethodWithGetMapping_thenReceiving200Answer() throws Exception {
|
||||
this.mockMvc.perform(get("/appointments")
|
||||
.accept(MediaType.ALL))
|
||||
.andExpect(status().isOk());
|
||||
this.mockMvc.perform(get("/appointments").accept(MediaType.ALL)).andExpect(status().isOk());
|
||||
verify(appointmentService);
|
||||
}
|
||||
|
||||
|
@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@ContextConfiguration(classes = {FooRepositoryConfiguration.class, FooServiceConfiguration.class})
|
||||
@ContextConfiguration(classes = { FooRepositoryConfiguration.class, FooServiceConfiguration.class })
|
||||
public class ConfigurationConstructorInjectionTest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Autowired
|
||||
|
@ -1,6 +1,5 @@
|
||||
package org.baeldung.spring43.defaultmethods;
|
||||
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
@ -28,27 +28,16 @@ public class ScopeAnnotationsTest extends AbstractJUnit4SpringContextTests {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac)
|
||||
.build();
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDifferentRequests_thenDifferentInstancesOfRequestScopedBeans() throws Exception {
|
||||
MockHttpSession session = new MockHttpSession();
|
||||
|
||||
String requestScopedServiceInstanceNumber1 = this.mockMvc.perform(get("/appointments/request")
|
||||
.session(session)
|
||||
.accept(MediaType.ALL)).andExpect(status().isOk())
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
String requestScopedServiceInstanceNumber1 = this.mockMvc.perform(get("/appointments/request").session(session).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
|
||||
|
||||
String requestScopedServiceInstanceNumber2 = this.mockMvc.perform(get("/appointments/request")
|
||||
.session(session)
|
||||
.accept(MediaType.ALL)).andExpect(status().isOk())
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
String requestScopedServiceInstanceNumber2 = this.mockMvc.perform(get("/appointments/request").session(session).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
|
||||
|
||||
assertNotEquals(requestScopedServiceInstanceNumber1, requestScopedServiceInstanceNumber2);
|
||||
}
|
||||
@ -59,24 +48,9 @@ public class ScopeAnnotationsTest extends AbstractJUnit4SpringContextTests {
|
||||
MockHttpSession session1 = new MockHttpSession();
|
||||
MockHttpSession session2 = new MockHttpSession();
|
||||
|
||||
String sessionScopedServiceInstanceNumber1 = this.mockMvc.perform(get("/appointments/session")
|
||||
.session(session1)
|
||||
.accept(MediaType.ALL)).andExpect(status().isOk())
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
String sessionScopedServiceInstanceNumber2 = this.mockMvc.perform(get("/appointments/session")
|
||||
.session(session1)
|
||||
.accept(MediaType.ALL)).andExpect(status().isOk())
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
String sessionScopedServiceInstanceNumber3 = this.mockMvc.perform(get("/appointments/session")
|
||||
.session(session2)
|
||||
.accept(MediaType.ALL)).andExpect(status().isOk())
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
String sessionScopedServiceInstanceNumber1 = this.mockMvc.perform(get("/appointments/session").session(session1).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
|
||||
String sessionScopedServiceInstanceNumber2 = this.mockMvc.perform(get("/appointments/session").session(session1).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
|
||||
String sessionScopedServiceInstanceNumber3 = this.mockMvc.perform(get("/appointments/session").session(session2).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
|
||||
|
||||
assertEquals(sessionScopedServiceInstanceNumber1, sessionScopedServiceInstanceNumber2);
|
||||
|
||||
@ -90,18 +64,8 @@ public class ScopeAnnotationsTest extends AbstractJUnit4SpringContextTests {
|
||||
MockHttpSession session1 = new MockHttpSession();
|
||||
MockHttpSession session2 = new MockHttpSession();
|
||||
|
||||
String applicationScopedServiceInstanceNumber1 = this.mockMvc.perform(get("/appointments/application")
|
||||
.session(session1)
|
||||
.accept(MediaType.ALL)).andExpect(status().isOk())
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
String applicationScopedServiceInstanceNumber2 = this.mockMvc.perform(get("/appointments/application")
|
||||
.session(session2)
|
||||
.accept(MediaType.ALL)).andExpect(status().isOk())
|
||||
.andReturn()
|
||||
.getResponse()
|
||||
.getContentAsString();
|
||||
String applicationScopedServiceInstanceNumber1 = this.mockMvc.perform(get("/appointments/application").session(session1).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
|
||||
String applicationScopedServiceInstanceNumber2 = this.mockMvc.perform(get("/appointments/application").session(session2).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
|
||||
|
||||
assertEquals(applicationScopedServiceInstanceNumber1, applicationScopedServiceInstanceNumber2);
|
||||
|
||||
|
@ -3,9 +3,9 @@ package com.baeldung.autowire.sample;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
|
||||
FooService fooService = ctx.getBean(FooService.class);
|
||||
fooService.doStuff();
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
|
||||
FooService fooService = ctx.getBean(FooService.class);
|
||||
fooService.doStuff();
|
||||
}
|
||||
}
|
||||
|
@ -9,5 +9,5 @@ public class BarFormatter implements Formatter {
|
||||
public String format() {
|
||||
return "bar";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -9,5 +9,5 @@ public class FooFormatter implements Formatter {
|
||||
public String format() {
|
||||
return "foo";
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -5,13 +5,13 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class FooService {
|
||||
|
||||
|
||||
@Autowired
|
||||
@FormatterType("Foo")
|
||||
private Formatter formatter;
|
||||
|
||||
public String doStuff(){
|
||||
|
||||
public String doStuff() {
|
||||
return formatter.format();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,6 @@ package com.baeldung.autowire.sample;
|
||||
|
||||
public interface Formatter {
|
||||
|
||||
String format();
|
||||
String format();
|
||||
|
||||
}
|
||||
|
@ -8,10 +8,10 @@ import java.lang.annotation.Target;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
||||
@Qualifier
|
||||
@Target({ElementType.FIELD, ElementType.METHOD,ElementType.TYPE, ElementType.PARAMETER})
|
||||
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.TYPE, ElementType.PARAMETER })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface FormatterType {
|
||||
|
||||
|
||||
String value();
|
||||
|
||||
}
|
||||
|
@ -9,14 +9,14 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes=AppConfig.class, loader=AnnotationConfigContextLoader.class)
|
||||
@ContextConfiguration(classes = AppConfig.class, loader = AnnotationConfigContextLoader.class)
|
||||
public class FooServiceTest {
|
||||
|
||||
|
||||
@Autowired
|
||||
FooService fooService;
|
||||
|
||||
|
||||
@Test
|
||||
public void whenFooFormatterType_thenReturnFoo(){
|
||||
public void whenFooFormatterType_thenReturnFoo() {
|
||||
Assert.assertEquals("foo", fooService.doStuff());
|
||||
}
|
||||
}
|
||||
|
@ -88,12 +88,12 @@
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>bootstrap</artifactId>
|
||||
<version>3.3.4</version>
|
||||
<version>3.3.7-1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>jquery</artifactId>
|
||||
<version>2.1.4</version>
|
||||
<version>3.1.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
|
@ -6,10 +6,10 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
@Controller
|
||||
public class TestController {
|
||||
|
||||
@RequestMapping(value="/")
|
||||
public String welcome(Model model){
|
||||
return "index";
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/")
|
||||
public String welcome(Model model) {
|
||||
return "index";
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
@SpringBootApplication
|
||||
public class WebjarsdemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(WebjarsdemoApplication.class, args);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(WebjarsdemoApplication.class, args);
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
@SpringBootApplication(scanBasePackages = { "com.baeldung.git"})
|
||||
@SpringBootApplication(scanBasePackages = { "com.baeldung.git" })
|
||||
public class CommitIdApplication {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CommitIdApplication.class, args);
|
||||
@ -21,6 +21,3 @@ public class CommitIdApplication {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -22,7 +22,7 @@ public class CommitInfoController {
|
||||
@RequestMapping("/commitId")
|
||||
public Map<String, String> getCommitId() {
|
||||
Map<String, String> result = new HashMap<>();
|
||||
result.put("Commit message",commitMessage);
|
||||
result.put("Commit message", commitMessage);
|
||||
result.put("Commit branch", branch);
|
||||
result.put("Commit id", commitId);
|
||||
return result;
|
||||
|
@ -1,19 +1,19 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>WebJars Demo</title>
|
||||
<link rel="stylesheet" href="/webjars/bootstrap/3.3.4/css/bootstrap.min.css" />
|
||||
<link rel="stylesheet" href="/webjars/bootstrap/3.3.7-1/css/bootstrap.min.css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div class="container"><br/>
|
||||
<div class="alert alert-success">
|
||||
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
|
||||
<a href="#" class="close" data-dismiss="alert" aria-label="close">×</a>
|
||||
<strong>Success!</strong> It is working as we expected.
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="/webjars/jquery/2.1.4/jquery.min.js"></script>
|
||||
<script src="/webjars/bootstrap/3.3.4/js/bootstrap.min.js"></script>
|
||||
<script src="/webjars/jquery/3.1.1/jquery.min.js"></script>
|
||||
<script src="/webjars/bootstrap/3.3.7-1/js/bootstrap.min.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
@ -11,8 +11,8 @@ import org.springframework.test.context.web.WebAppConfiguration;
|
||||
@WebAppConfiguration
|
||||
public class WebjarsdemoApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,13 +32,10 @@ public class CommitIdTest {
|
||||
LOG.info(commitMessage);
|
||||
LOG.info(branch);
|
||||
|
||||
assertThat(commitMessage)
|
||||
.isNotEqualTo("UNKNOWN");
|
||||
assertThat(commitMessage).isNotEqualTo("UNKNOWN");
|
||||
|
||||
assertThat(branch)
|
||||
.isNotEqualTo("UNKNOWN");
|
||||
assertThat(branch).isNotEqualTo("UNKNOWN");
|
||||
|
||||
assertThat(commitId)
|
||||
.isNotEqualTo("UNKNOWN");
|
||||
assertThat(commitId).isNotEqualTo("UNKNOWN");
|
||||
}
|
||||
}
|
@ -31,22 +31,15 @@ public class SpringBootApplicationTest {
|
||||
private WebApplicationContext webApplicationContext;
|
||||
private MockMvc mockMvc;
|
||||
|
||||
|
||||
@Before
|
||||
public void setupMockMvc() {
|
||||
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
|
||||
.build();
|
||||
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenRequestHasBeenMade_whenMeetsAllOfGivenConditions_thenCorrect() throws Exception {
|
||||
MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(),
|
||||
MediaType.APPLICATION_JSON.getSubtype(),
|
||||
Charset.forName("utf8"));
|
||||
MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
|
||||
|
||||
mockMvc.perform(MockMvcRequestBuilders.get("/entity/all")).
|
||||
andExpect(MockMvcResultMatchers.status().isOk()).
|
||||
andExpect(MockMvcResultMatchers.content().contentType(contentType)).
|
||||
andExpect(jsonPath("$", hasSize(4)));
|
||||
mockMvc.perform(MockMvcRequestBuilders.get("/entity/all")).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.content().contentType(contentType)).andExpect(jsonPath("$", hasSize(4)));
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,6 @@ public class SpringBootMailTest {
|
||||
return wiserMessage.getMimeMessage().getSubject();
|
||||
}
|
||||
|
||||
|
||||
private SimpleMailMessage composeEmailMessage() {
|
||||
SimpleMailMessage mailMessage = new SimpleMailMessage();
|
||||
mailMessage.setTo(userTo);
|
||||
|
@ -30,8 +30,7 @@ public class DetailsServiceClientTest {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
String detailsString = objectMapper.writeValueAsString(new Details("John Smith", "john"));
|
||||
this.server.expect(requestTo("/john/details"))
|
||||
.andRespond(withSuccess(detailsString, MediaType.APPLICATION_JSON));
|
||||
this.server.expect(requestTo("/john/details")).andRespond(withSuccess(detailsString, MediaType.APPLICATION_JSON));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -1,27 +0,0 @@
|
||||
## Spring Cloud Config ##
|
||||
|
||||
To get this example working, you have to initialize a new *Git* repository in
|
||||
the ```client-config``` directory first *and* you have to set the environment variable
|
||||
```CONFIG_REPO``` to an absolute path of that directory.
|
||||
|
||||
```
|
||||
$> cd client-config
|
||||
$> git init
|
||||
$> git add .
|
||||
$> git commit -m 'Initial commit'
|
||||
$> export CONFIG_REPO=$(pwd)
|
||||
```
|
||||
|
||||
Then you're able to run the examples with ```mvn install spring-boot:run```.
|
||||
|
||||
### Docker ###
|
||||
|
||||
To get the *Docker* examples working, you have to repackage the ```spring-cloud-config-server```
|
||||
and ```spring-cloud-config-client``` modules first:
|
||||
|
||||
```
|
||||
$> mvn install spring-boot:repackage
|
||||
```
|
||||
|
||||
Don't forget to download the *Java JCE* package from
|
||||
(Oracle)[http://www.oracle.com/technetwork/java/javase/downloads/jce8-download-2133166.html].
|
@ -1,6 +0,0 @@
|
||||
FROM alpine-java:base
|
||||
MAINTAINER baeldung.com
|
||||
RUN apk --no-cache add netcat-openbsd
|
||||
COPY files/spring-cloud-config-client-1.0.0-SNAPSHOT.jar /opt/spring-cloud/lib/config-client.jar
|
||||
COPY files/config-client-entrypoint.sh /opt/spring-cloud/bin/
|
||||
RUN chmod 755 /opt/spring-cloud/bin/config-client-entrypoint.sh
|
@ -1,9 +0,0 @@
|
||||
FROM alpine-java:base
|
||||
MAINTAINER baeldung.com
|
||||
COPY files/spring-cloud-config-server-1.0.0-SNAPSHOT.jar /opt/spring-cloud/lib/config-server.jar
|
||||
ENV SPRING_APPLICATION_JSON='{"spring": {"cloud": {"config": {"server": \
|
||||
{"git": {"uri": "/var/lib/spring-cloud/config-repo", "clone-on-start": true}}}}}}'
|
||||
ENTRYPOINT ["/usr/bin/java"]
|
||||
CMD ["-jar", "/opt/spring-cloud/lib/config-server.jar"]
|
||||
VOLUME /var/lib/spring-cloud/config-repo
|
||||
EXPOSE 8888
|
2
spring-cloud-config/docker/files/.gitignore
vendored
2
spring-cloud-config/docker/files/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
/UnlimitedJCEPolicyJDK8
|
||||
/*.jar
|
@ -1,8 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
while ! nc -z config-server 8888 ; do
|
||||
echo "Waiting for upcoming Config Server"
|
||||
sleep 2
|
||||
done
|
||||
|
||||
java -jar /opt/spring-cloud/lib/config-client.jar
|
@ -1,52 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
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.spring.cloud</groupId>
|
||||
<artifactId>spring-cloud-config</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>spring-cloud-config-server</module>
|
||||
<module>spring-cloud-config-client</module>
|
||||
</modules>
|
||||
|
||||
<parent>
|
||||
<groupId>com.baeldung</groupId>
|
||||
<artifactId>parent-modules</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-parent</artifactId>
|
||||
<version>1.4.0.RELEASE</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>Brixton.SR4</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>1.4.0.RELEASE</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
</project>
|
@ -18,9 +18,9 @@ public class SpringDemoApplication extends SpringBootServletInitializer {
|
||||
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
|
||||
return application.sources(SpringDemoApplication.class);
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public RestTemplate getRestTemplate(){
|
||||
return new RestTemplate();
|
||||
public RestTemplate getRestTemplate() {
|
||||
return new RestTemplate();
|
||||
}
|
||||
}
|
||||
|
@ -19,22 +19,27 @@ public class Campus {
|
||||
@Field
|
||||
@NotNull
|
||||
private Point location;
|
||||
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public Point getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public void setLocation(Point location) {
|
||||
this.location = location;
|
||||
}
|
||||
@ -42,13 +47,13 @@ public class Campus {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 1;
|
||||
if(id != null) {
|
||||
if (id != null) {
|
||||
hash = hash * 31 + id.hashCode();
|
||||
}
|
||||
if(name != null) {
|
||||
if (name != null) {
|
||||
hash = hash * 31 + name.hashCode();
|
||||
}
|
||||
if(location != null) {
|
||||
if (location != null) {
|
||||
hash = hash * 31 + location.hashCode();
|
||||
}
|
||||
return hash;
|
||||
@ -56,30 +61,33 @@ public class Campus {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if((obj == null) || (obj.getClass() != this.getClass())) return false;
|
||||
if(obj == this) return true;
|
||||
if ((obj == null) || (obj.getClass() != this.getClass()))
|
||||
return false;
|
||||
if (obj == this)
|
||||
return true;
|
||||
Campus other = (Campus) obj;
|
||||
return this.hashCode() == other.hashCode();
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private Campus() {}
|
||||
|
||||
private Campus() {
|
||||
}
|
||||
|
||||
public Campus(Builder b) {
|
||||
this.id = b.id;
|
||||
this.name = b.name;
|
||||
this.location = b.location;
|
||||
}
|
||||
|
||||
|
||||
public static class Builder {
|
||||
private String id;
|
||||
private String name;
|
||||
private Point location;
|
||||
|
||||
|
||||
public static Builder newInstance() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
|
||||
public Campus build() {
|
||||
return new Campus(this);
|
||||
}
|
||||
@ -93,7 +101,7 @@ public class Campus {
|
||||
this.name = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Builder location(Point location) {
|
||||
this.location = location;
|
||||
return this;
|
||||
|
@ -24,7 +24,7 @@ public class Person {
|
||||
private DateTime created;
|
||||
@Field
|
||||
private DateTime updated;
|
||||
|
||||
|
||||
public Person(String id, String firstName, String lastName) {
|
||||
this.id = id;
|
||||
this.firstName = firstName;
|
||||
@ -34,44 +34,53 @@ public class Person {
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public DateTime getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(DateTime created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public DateTime getUpdated() {
|
||||
return updated;
|
||||
}
|
||||
|
||||
public void setUpdated(DateTime updated) {
|
||||
this.updated = updated;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 1;
|
||||
if(id != null) {
|
||||
if (id != null) {
|
||||
hash = hash * 31 + id.hashCode();
|
||||
}
|
||||
if(firstName != null) {
|
||||
if (firstName != null) {
|
||||
hash = hash * 31 + firstName.hashCode();
|
||||
}
|
||||
if(lastName != null) {
|
||||
if (lastName != null) {
|
||||
hash = hash * 31 + lastName.hashCode();
|
||||
}
|
||||
return hash;
|
||||
@ -79,8 +88,10 @@ public class Person {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if((obj == null) || (obj.getClass() != this.getClass())) return false;
|
||||
if(obj == this) return true;
|
||||
if ((obj == null) || (obj.getClass() != this.getClass()))
|
||||
return false;
|
||||
if (obj == this)
|
||||
return true;
|
||||
Person other = (Person) obj;
|
||||
return this.hashCode() == other.hashCode();
|
||||
}
|
||||
|
@ -20,13 +20,13 @@ public class Student {
|
||||
private String id;
|
||||
@Field
|
||||
@NotNull
|
||||
@Size(min=1, max=20)
|
||||
@Pattern(regexp=NAME_REGEX)
|
||||
@Size(min = 1, max = 20)
|
||||
@Pattern(regexp = NAME_REGEX)
|
||||
private String firstName;
|
||||
@Field
|
||||
@NotNull
|
||||
@Size(min=1, max=20)
|
||||
@Pattern(regexp=NAME_REGEX)
|
||||
@Size(min = 1, max = 20)
|
||||
@Pattern(regexp = NAME_REGEX)
|
||||
private String lastName;
|
||||
@Field
|
||||
@Past
|
||||
@ -38,8 +38,9 @@ public class Student {
|
||||
private DateTime updated;
|
||||
@Version
|
||||
private long version;
|
||||
|
||||
public Student() {}
|
||||
|
||||
public Student() {
|
||||
}
|
||||
|
||||
public Student(String id, String firstName, String lastName, DateTime dateOfBirth) {
|
||||
this.id = id;
|
||||
@ -51,36 +52,47 @@ public class Student {
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public DateTime getDateOfBirth() {
|
||||
return dateOfBirth;
|
||||
}
|
||||
|
||||
public void setDateOfBirth(DateTime dateOfBirth) {
|
||||
this.dateOfBirth = dateOfBirth;
|
||||
}
|
||||
|
||||
public DateTime getCreated() {
|
||||
return created;
|
||||
}
|
||||
|
||||
public void setCreated(DateTime created) {
|
||||
this.created = created;
|
||||
}
|
||||
|
||||
public DateTime getUpdated() {
|
||||
return updated;
|
||||
}
|
||||
|
||||
public void setUpdated(DateTime updated) {
|
||||
this.updated = updated;
|
||||
}
|
||||
@ -88,16 +100,16 @@ public class Student {
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 1;
|
||||
if(id != null) {
|
||||
if (id != null) {
|
||||
hash = hash * 31 + id.hashCode();
|
||||
}
|
||||
if(firstName != null) {
|
||||
if (firstName != null) {
|
||||
hash = hash * 31 + firstName.hashCode();
|
||||
}
|
||||
if(lastName != null) {
|
||||
if (lastName != null) {
|
||||
hash = hash * 31 + lastName.hashCode();
|
||||
}
|
||||
if(dateOfBirth != null) {
|
||||
if (dateOfBirth != null) {
|
||||
hash = hash * 31 + dateOfBirth.hashCode();
|
||||
}
|
||||
return hash;
|
||||
@ -105,8 +117,10 @@ public class Student {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if((obj == null) || (obj.getClass() != this.getClass())) return false;
|
||||
if(obj == this) return true;
|
||||
if ((obj == null) || (obj.getClass() != this.getClass()))
|
||||
return false;
|
||||
if (obj == this)
|
||||
return true;
|
||||
Student other = (Student) obj;
|
||||
return this.hashCode() == other.hashCode();
|
||||
}
|
||||
|
@ -17,9 +17,6 @@ public class CustomStudentRepositoryImpl implements CustomStudentRepository {
|
||||
private CouchbaseTemplate template;
|
||||
|
||||
public List<Student> findByFirstNameStartsWith(String s) {
|
||||
return template.findByView(ViewQuery.from(DESIGN_DOC, "byFirstName")
|
||||
.startKey(s)
|
||||
.stale(Stale.FALSE),
|
||||
Student.class);
|
||||
return template.findByView(ViewQuery.from(DESIGN_DOC, "byFirstName").startKey(s).stale(Stale.FALSE), Student.class);
|
||||
}
|
||||
}
|
||||
|
@ -7,5 +7,6 @@ import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface PersonRepository extends CrudRepository<Person, String> {
|
||||
List<Person> findByFirstName(String firstName);
|
||||
|
||||
List<Person> findByLastName(String lastName);
|
||||
}
|
||||
|
@ -7,5 +7,6 @@ import org.springframework.data.repository.CrudRepository;
|
||||
|
||||
public interface StudentRepository extends CrudRepository<Student, String>, CustomStudentRepository {
|
||||
List<Student> findByFirstName(String firstName);
|
||||
|
||||
List<Student> findByLastName(String lastName);
|
||||
}
|
||||
|
@ -14,8 +14,9 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
@Qualifier("PersonRepositoryService")
|
||||
public class PersonRepositoryService implements PersonService {
|
||||
|
||||
|
||||
private PersonRepository repo;
|
||||
|
||||
@Autowired
|
||||
public void setPersonRepository(PersonRepository repo) {
|
||||
this.repo = repo;
|
||||
@ -28,7 +29,7 @@ public class PersonRepositoryService implements PersonService {
|
||||
public List<Person> findAll() {
|
||||
List<Person> people = new ArrayList<Person>();
|
||||
Iterator<Person> it = repo.findAll().iterator();
|
||||
while(it.hasNext()) {
|
||||
while (it.hasNext()) {
|
||||
people.add(it.next());
|
||||
}
|
||||
return people;
|
||||
|
@ -14,17 +14,18 @@ import com.couchbase.client.java.view.ViewQuery;
|
||||
@Service
|
||||
@Qualifier("PersonTemplateService")
|
||||
public class PersonTemplateService implements PersonService {
|
||||
|
||||
|
||||
private static final String DESIGN_DOC = "person";
|
||||
|
||||
private CouchbaseTemplate template;
|
||||
|
||||
@Autowired
|
||||
public void setCouchbaseTemplate(CouchbaseTemplate template) {
|
||||
this.template = template;
|
||||
}
|
||||
|
||||
public Person findOne(String id) {
|
||||
return template.findById(id, Person.class);
|
||||
public Person findOne(String id) {
|
||||
return template.findById(id, Person.class);
|
||||
}
|
||||
|
||||
public List<Person> findAll() {
|
||||
|
@ -14,8 +14,9 @@ import org.springframework.stereotype.Service;
|
||||
@Service
|
||||
@Qualifier("StudentRepositoryService")
|
||||
public class StudentRepositoryService implements StudentService {
|
||||
|
||||
|
||||
private StudentRepository repo;
|
||||
|
||||
@Autowired
|
||||
public void setStudentRepository(StudentRepository repo) {
|
||||
this.repo = repo;
|
||||
@ -28,7 +29,7 @@ public class StudentRepositoryService implements StudentService {
|
||||
public List<Student> findAll() {
|
||||
List<Student> people = new ArrayList<Student>();
|
||||
Iterator<Student> it = repo.findAll().iterator();
|
||||
while(it.hasNext()) {
|
||||
while (it.hasNext()) {
|
||||
people.add(it.next());
|
||||
}
|
||||
return people;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user