Merge branch 'master' into pr/720-tim-bootstrap-security

This commit is contained in:
slavisa-baeldung 2016-10-22 07:37:10 +02:00
commit 63c6da7d9f
110 changed files with 1261 additions and 463 deletions

View File

@ -37,26 +37,36 @@ public class Baeldung {
} }
@GET @GET
@Path("courses/{courseOrder}") @Path("courses/{courseId}")
public Course getCourse(@PathParam("courseOrder") int courseOrder) { public Course getCourse(@PathParam("courseId") int courseId) {
return courses.get(courseOrder); return findById(courseId);
} }
@PUT @PUT
@Path("courses/{courseOrder}") @Path("courses/{courseId}")
public Response putCourse(@PathParam("courseOrder") int courseOrder, Course course) { public Response updateCourse(@PathParam("courseId") int courseId, Course course) {
Course existingCourse = courses.get(courseOrder); Course existingCourse = findById(courseId);
if (existingCourse == null) {
if (existingCourse == null || existingCourse.getId() != course.getId() || !(existingCourse.getName().equals(course.getName()))) { return Response.status(Response.Status.NOT_FOUND).build();
courses.put(courseOrder, course);
return Response.ok().build();
} }
if (existingCourse.equals(course)) {
return Response.notModified().build(); return Response.notModified().build();
}
courses.put(courseId, course);
return Response.ok().build();
} }
@Path("courses/{courseOrder}/students") @Path("courses/{courseId}/students")
public Course pathToStudent(@PathParam("courseOrder") int courseOrder) { public Course pathToStudent(@PathParam("courseId") int courseId) {
return courses.get(courseOrder); return findById(courseId);
}
private Course findById(int id) {
for (Map.Entry<Integer, Course> course : courses.entrySet()) {
if (course.getKey() == id) {
return course.getValue();
}
}
return null;
} }
} }

View File

@ -3,6 +3,7 @@ package com.baeldung.cxf.jaxrs.implementation;
import javax.ws.rs.*; import javax.ws.rs.*;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -10,7 +11,7 @@ import java.util.List;
public class Course { public class Course {
private int id; private int id;
private String name; private String name;
private List<Student> students; private List<Student> students = new ArrayList<>();
public int getId() { public int getId() {
return id; return id;
@ -35,31 +36,51 @@ public class Course {
public void setStudents(List<Student> students) { public void setStudents(List<Student> students) {
this.students = students; this.students = students;
} }
@GET @GET
@Path("{studentOrder}") @Path("{studentId}")
public Student getStudent(@PathParam("studentOrder")int studentOrder) { public Student getStudent(@PathParam("studentId") int studentId) {
return students.get(studentOrder); return findById(studentId);
} }
@POST @POST
public Response postStudent(Student student) { public Response createStudent(Student student) {
if (students == null) { for (Student element : students) {
students = new ArrayList<>(); if (element.getId() == student.getId()) {
return Response.status(Response.Status.CONFLICT).build();
}
} }
students.add(student); students.add(student);
return Response.ok(student).build(); return Response.ok(student).build();
} }
@DELETE @DELETE
@Path("{studentOrder}") @Path("{studentId}")
public Response deleteStudent(@PathParam("studentOrder") int studentOrder) { public Response deleteStudent(@PathParam("studentId") int studentId) {
Student student = students.get(studentOrder); Student student = findById(studentId);
if (student != null) { if (student == null) {
students.remove(studentOrder); return Response.status(Response.Status.NOT_FOUND).build();
return Response.ok().build();
} else {
return Response.notModified().build();
} }
students.remove(student);
return Response.ok().build();
}
private Student findById(int id) {
for (Student student : students) {
if (student.getId() == id) {
return student;
}
}
return null;
}
@Override
public int hashCode() {
return id + name.hashCode();
}
@Override
public boolean equals(Object obj) {
return (obj instanceof Course) && (id == ((Course) obj).getId()) && (name.equals(((Course) obj).getName()));
} }
} }

View File

@ -22,4 +22,14 @@ public class Student {
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
@Override
public int hashCode() {
return id + name.hashCode();
}
@Override
public boolean equals(Object obj) {
return (obj instanceof Student) && (id == ((Student) obj).getId()) && (name.equals(((Student) obj).getName()));
}
} }

View File

@ -0,0 +1,4 @@
<Course>
<id>2</id>
<name>Apache CXF Support for RESTful</name>
</Course>

View File

@ -0,0 +1,4 @@
<Student>
<id>2</id>
<name>Student B</name>
</Student>

View File

@ -1,4 +1,3 @@
<Student> <Student>
<id>3</id> <id>3</id>
<name>Student C</name> <name>Student C</name>

View File

@ -0,0 +1,4 @@
<Course>
<id>1</id>
<name>REST with Spring</name>
</Course>

View File

@ -34,38 +34,78 @@ public class ServiceTest {
} }
@Test @Test
public void whenPutCourse_thenCorrect() throws IOException { public void whenUpdateNonExistentCourse_thenReceiveNotFoundResponse() throws IOException {
HttpPut httpPut = new HttpPut(BASE_URL + "3"); HttpPut httpPut = new HttpPut(BASE_URL + "3");
InputStream resourceStream = this.getClass().getClassLoader().getResourceAsStream("course.xml"); InputStream resourceStream = this.getClass().getClassLoader().getResourceAsStream("non_existent_course.xml");
httpPut.setEntity(new InputStreamEntity(resourceStream));
httpPut.setHeader("Content-Type", "text/xml");
HttpResponse response = client.execute(httpPut);
assertEquals(404, response.getStatusLine().getStatusCode());
}
@Test
public void whenUpdateUnchangedCourse_thenReceiveNotModifiedResponse() throws IOException {
HttpPut httpPut = new HttpPut(BASE_URL + "1");
InputStream resourceStream = this.getClass().getClassLoader().getResourceAsStream("unchanged_course.xml");
httpPut.setEntity(new InputStreamEntity(resourceStream));
httpPut.setHeader("Content-Type", "text/xml");
HttpResponse response = client.execute(httpPut);
assertEquals(304, response.getStatusLine().getStatusCode());
}
@Test
public void whenUpdateValidCourse_thenReceiveOKResponse() throws IOException {
HttpPut httpPut = new HttpPut(BASE_URL + "2");
InputStream resourceStream = this.getClass().getClassLoader().getResourceAsStream("changed_course.xml");
httpPut.setEntity(new InputStreamEntity(resourceStream)); httpPut.setEntity(new InputStreamEntity(resourceStream));
httpPut.setHeader("Content-Type", "text/xml"); httpPut.setHeader("Content-Type", "text/xml");
HttpResponse response = client.execute(httpPut); HttpResponse response = client.execute(httpPut);
assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals(200, response.getStatusLine().getStatusCode());
Course course = getCourse(3); Course course = getCourse(2);
assertEquals(3, course.getId()); assertEquals(2, course.getId());
assertEquals("Apache CXF Support for RESTful", course.getName()); assertEquals("Apache CXF Support for RESTful", course.getName());
} }
@Test
public void whenCreateConflictStudent_thenReceiveConflictResponse() throws IOException {
HttpPost httpPost = new HttpPost(BASE_URL + "1/students");
InputStream resourceStream = this.getClass().getClassLoader().getResourceAsStream("conflict_student.xml");
httpPost.setEntity(new InputStreamEntity(resourceStream));
httpPost.setHeader("Content-Type", "text/xml");
HttpResponse response = client.execute(httpPost);
assertEquals(409, response.getStatusLine().getStatusCode());
}
@Test @Test
public void whenPostStudent_thenCorrect() throws IOException { public void whenCreateValidStudent_thenReceiveOKResponse() throws IOException {
HttpPost httpPost = new HttpPost(BASE_URL + "2/students"); HttpPost httpPost = new HttpPost(BASE_URL + "2/students");
InputStream resourceStream = this.getClass().getClassLoader().getResourceAsStream("student.xml"); InputStream resourceStream = this.getClass().getClassLoader().getResourceAsStream("created_student.xml");
httpPost.setEntity(new InputStreamEntity(resourceStream)); httpPost.setEntity(new InputStreamEntity(resourceStream));
httpPost.setHeader("Content-Type", "text/xml"); httpPost.setHeader("Content-Type", "text/xml");
HttpResponse response = client.execute(httpPost); HttpResponse response = client.execute(httpPost);
assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals(200, response.getStatusLine().getStatusCode());
Student student = getStudent(2, 0); Student student = getStudent(2, 3);
assertEquals(3, student.getId()); assertEquals(3, student.getId());
assertEquals("Student C", student.getName()); assertEquals("Student C", student.getName());
} }
@Test @Test
public void whenDeleteStudent_thenCorrect() throws IOException { public void whenDeleteInvalidStudent_thenReceiveNotFoundResponse() throws IOException {
HttpDelete httpDelete = new HttpDelete(BASE_URL + "1/students/0"); HttpDelete httpDelete = new HttpDelete(BASE_URL + "1/students/3");
HttpResponse response = client.execute(httpDelete);
assertEquals(404, response.getStatusLine().getStatusCode());
}
@Test
public void whenDeleteValidStudent_thenReceiveOKResponse() throws IOException {
HttpDelete httpDelete = new HttpDelete(BASE_URL + "1/students/1");
HttpResponse response = client.execute(httpDelete); HttpResponse response = client.execute(httpDelete);
assertEquals(200, response.getStatusLine().getStatusCode()); assertEquals(200, response.getStatusLine().getStatusCode());

View File

@ -3,36 +3,82 @@ package com.baeldung.encoderdecoder;
import org.hamcrest.CoreMatchers; import org.hamcrest.CoreMatchers;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLDecoder; import java.net.URLDecoder;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
public class EncoderDecoder { public class EncoderDecoder {
@Test private static final String URL = "http://www.baeldung.com?key1=value+1&key2=value%40%21%242&key3=value%253";
public void givenPlainURL_whenUsingUTF8EncodingScheme_thenEncodeURL() throws UnsupportedEncodingException { private static final Logger LOGGER = LoggerFactory.getLogger(EncoderDecoder.class);
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)); private String encodeValue(String value) {
String encoded = null;
try {
encoded = URLEncoder.encode(value, StandardCharsets.UTF_8.toString());
} catch (UnsupportedEncodingException e) {
LOGGER.error("Error encoding parameter {}", e.getMessage(), e);
}
return encoded;
}
private String decode(String value) {
String decoded = null;
try {
decoded = URLDecoder.decode(value, StandardCharsets.UTF_8.toString());
} catch (UnsupportedEncodingException e) {
LOGGER.error("Error encoding parameter {}", e.getMessage(), e);
}
return decoded;
} }
@Test @Test
public void givenEncodedURL_whenUsingUTF8EncodingScheme_thenDecodeURL() throws UnsupportedEncodingException { public void givenURL_whenAnalyze_thenCorrect() throws Exception {
String encodedURL = "http%3A%2F%2Fwww.baeldung.com" ; URL url = new URL(URL);
String decodedURL = URLDecoder.decode(encodedURL, StandardCharsets.UTF_8.toString());
Assert.assertThat("http://www.baeldung.com", CoreMatchers.is(decodedURL)); Assert.assertThat(url.getProtocol(), CoreMatchers.is("http"));
Assert.assertThat(url.getHost(), CoreMatchers.is("www.baeldung.com"));
Assert.assertThat(url.getQuery(), CoreMatchers.is("key1=value+1&key2=value%40%21%242&key3=value%253"));
} }
@Test @Test
public void givenEncodedURL_whenUsingWrongEncodingScheme_thenDecodeInvalidURL() throws UnsupportedEncodingException { public void givenRequestParam_whenUTF8Scheme_thenEncode() throws Exception {
String encodedURL = "http%3A%2F%2Fwww.baeldung.com"; Map<String, String> requestParams = new HashMap<>();
requestParams.put("key1", "value 1");
requestParams.put("key2", "value@!$2");
requestParams.put("key3", "value%3");
String decodedURL = URLDecoder.decode(encodedURL, StandardCharsets.UTF_16.toString()); String encodedQuery = requestParams.keySet().stream()
.map(key -> key + "=" + encodeValue(requestParams.get(key)))
.collect(Collectors.joining("&"));
String encodedURL = "http://www.baeldung.com?" + encodedQuery;
Assert.assertFalse("http://www.baeldung.com".equals(decodedURL)); Assert.assertThat(URL, CoreMatchers.is(encodedURL));
} }
@Test
public void givenRequestParam_whenUTF8Scheme_thenDecodeRequestParams() throws Exception {
URL url = new URL(URL);
String query = url.getQuery();
String decodedQuery = Arrays.stream(query.split("&"))
.map(param -> param.split("=")[0] + "=" + decode(param.split("=")[1]))
.collect(Collectors.joining("&"));
Assert.assertEquals(
"http://www.baeldung.com?key1=value 1&key2=value@!$2&key3=value%3", url.getProtocol() + "://" + url.getHost() + "?" + decodedQuery);
}
} }

View File

@ -1,14 +1,15 @@
package com.baeldung.java.nio.selector; package com.baeldung.java.nio.selector;
import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel; import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel; 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.util.Iterator;
import java.net.InetSocketAddress; import java.util.Set;
public class EchoServer { public class EchoServer {
@ -47,4 +48,15 @@ public class EchoServer {
} }
} }
} }
}
public static Process start() throws IOException, InterruptedException {
String javaHome = System.getProperty("java.home");
String javaBin = javaHome + File.separator + "bin" + File.separator + "java";
String classpath = System.getProperty("java.class.path");
String className = EchoServer.class.getCanonicalName();
ProcessBuilder builder = new ProcessBuilder(javaBin, "-cp", classpath, className);
return builder.start();
}
}

View File

@ -0,0 +1,23 @@
package com.baeldung.printscreen;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
public class Screenshot {
private final String path;
public Screenshot(String path) {
this.path = path;
}
public void getScreenshot(int timeToWait) throws Exception {
Thread.sleep(timeToWait);
Rectangle rectangle = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
Robot robot = new Robot();
BufferedImage img = robot.createScreenCapture(rectangle);
ImageIO.write(img, "jpg", new File(path));
}
}

View File

@ -2,17 +2,20 @@ package com.baeldung.java.nio.selector;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.io.IOException;
import org.junit.Test; import org.junit.Test;
public class EchoTest { public class EchoTest {
@Test @Test
public void givenClient_whenServerEchosMessage_thenCorrect() { public void givenClient_whenServerEchosMessage_thenCorrect() throws IOException, InterruptedException {
Process process = EchoServer.start();
EchoClient client = EchoClient.start(); EchoClient client = EchoClient.start();
String resp1 = client.sendMessage("hello"); String resp1 = client.sendMessage("hello");
String resp2 = client.sendMessage("world"); String resp2 = client.sendMessage("world");
assertEquals("hello", resp1); assertEquals("hello", resp1);
assertEquals("world", resp2); assertEquals("world", resp2);
process.destroy();
} }
} }

View File

@ -0,0 +1,26 @@
package com.baeldung.printscreen;
import org.junit.After;
import org.junit.Test;
import java.io.File;
import static org.junit.Assert.assertTrue;
public class ScreenshotTest {
private Screenshot screenshot = new Screenshot("", "Screenshot", "jpg");
private File file = new File("Screenshot.jpg");
@Test
public void testGetScreenshot() throws Exception {
screenshot.getScreenshot(2000);
assertTrue(file.exists());
}
@After
public void tearDown() throws Exception {
file.delete();
}
}

View File

@ -161,9 +161,55 @@
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<properties> <properties>
<org.jooq.version>3.7.3</org.jooq.version> <org.jooq.version>3.7.3</org.jooq.version>
<com.h2database.version>1.4.191</com.h2database.version> <com.h2database.version>1.4.191</com.h2database.version>
@ -173,6 +219,7 @@
<junit.version>4.12</junit.version> <junit.version>4.12</junit.version>
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version> <maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
</properties> </properties>
</project> </project>

View File

@ -22,7 +22,7 @@ import javax.sql.DataSource;
@ComponentScan({ "com.baeldung.jooq.introduction.db.public_.tables" }) @ComponentScan({ "com.baeldung.jooq.introduction.db.public_.tables" })
@EnableTransactionManagement @EnableTransactionManagement
@PropertySource("classpath:intro_config.properties") @PropertySource("classpath:intro_config.properties")
public class PersistenceContext { public class PersistenceContextIntegrationTest {
@Autowired @Autowired
private Environment environment; private Environment environment;

View File

@ -17,10 +17,10 @@ import static com.baeldung.jooq.introduction.db.public_.tables.AuthorBook.AUTHOR
import static com.baeldung.jooq.introduction.db.public_.tables.Book.BOOK; import static com.baeldung.jooq.introduction.db.public_.tables.Book.BOOK;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ContextConfiguration(classes = PersistenceContext.class) @ContextConfiguration(classes = PersistenceContextIntegrationTest.class)
@Transactional(transactionManager = "transactionManager") @Transactional(transactionManager = "transactionManager")
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
public class QueryTest { public class QueryIntegrationTest {
@Autowired @Autowired
private DSLContext dsl; private DSLContext dsl;

View File

@ -20,7 +20,7 @@ import static org.junit.Assert.assertEquals;
@SpringApplicationConfiguration(Application.class) @SpringApplicationConfiguration(Application.class)
@Transactional("transactionManager") @Transactional("transactionManager")
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
public class SpringBootTest { public class SpringBootIntegrationTest {
@Autowired @Autowired
private DSLContext dsl; private DSLContext dsl;

View File

@ -55,6 +55,54 @@
</annotationProcessorPaths> </annotationProcessorPaths>
</configuration> </configuration>
</plugin> </plugin>
</plugins>
</build> <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project> </project>

View File

@ -12,7 +12,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml") @ContextConfiguration("classpath:applicationContext.xml")
public class SimpleSourceDestinationMapperTest { public class SimpleSourceDestinationMapperIntegrationTest {
@Autowired @Autowired
SimpleSourceDestinationMapper simpleSourceDestinationMapper; SimpleSourceDestinationMapper simpleSourceDestinationMapper;

View File

@ -1,26 +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>corejava-printscreen</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>How to Print Screen in Java</name>
<url>https://github.com/eugenp/tutorials</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>4.12</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@ -1,38 +0,0 @@
package org.baeldung.corejava;;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
public class Screenshot {
private String filePath;
private String filenamePrefix;
private String fileType;
private int timeToWait;
public Screenshot(String filePath, String filenamePrefix,
String fileType, int timeToWait) {
this.filePath = filePath;
this.filenamePrefix = filenamePrefix;
this.fileType = fileType;
this.timeToWait = timeToWait;
}
public void getScreenshot() throws Exception {
Thread.sleep(timeToWait);
Rectangle rectangle = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
Robot robot = new Robot();
BufferedImage img = robot.createScreenCapture(rectangle);
ImageIO.write(img, fileType, setupFileNamePath());
}
private File setupFileNamePath() {
return new File(filePath + filenamePrefix + "." + fileType);
}
private Rectangle getScreenSizedRectangle(final Dimension d) {
return new Rectangle(0, 0, d.width, d.height);
}
}

View File

@ -1,39 +0,0 @@
package org.baeldung.corejava;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import static org.junit.Assert.*;
public class ScreenshotTest {
private Screenshot screenshot;
private String filePath;
private String fileName;
private String fileType;
private File file;
@Before
public void setUp() throws Exception {
filePath = "";
fileName = "Screenshot";
fileType = "jpg";
file = new File(filePath + fileName + "." + fileType);
screenshot = new Screenshot(filePath, fileName, fileType, 2000);
}
@Test
public void testGetScreenshot() throws Exception {
screenshot.getScreenshot();
assertTrue(file.exists());
}
@After
public void tearDown() throws Exception {
file.delete();
}
}

View File

@ -20,6 +20,7 @@
<hibernate.version>5.2.1.Final</hibernate.version> <hibernate.version>5.2.1.Final</hibernate.version>
<querydsl.version>4.1.3</querydsl.version> <querydsl.version>4.1.3</querydsl.version>
<slf4j.version>1.7.21</slf4j.version> <slf4j.version>1.7.21</slf4j.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
</properties> </properties>
<dependencies> <dependencies>
@ -166,7 +167,55 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project> </project>

View File

@ -17,7 +17,7 @@ import junit.framework.Assert;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@Transactional @Transactional
@TransactionConfiguration(defaultRollback = true) @TransactionConfiguration(defaultRollback = true)
public class PersonDaoTest { public class PersonDaoIntegrationTest {
@Autowired @Autowired
private PersonDao personDao; private PersonDao personDao;

View File

@ -1,28 +1,15 @@
package com.baeldung; package com.baeldung;
import org.junit.*;
import redis.clients.jedis.*;
import redis.embedded.RedisServer;
import java.io.IOException; import java.io.IOException;
import java.time.Duration; import java.time.Duration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.Pipeline;
import redis.clients.jedis.Response;
import redis.clients.jedis.Transaction;
import redis.embedded.RedisServer;
/**
* Unit test for Redis Java library - Jedis.
*/
public class JedisTest { public class JedisTest {
private Jedis jedis; private Jedis jedis;
@ -140,9 +127,9 @@ public class JedisTest {
scores.put("PlayerTwo", 1500.0); scores.put("PlayerTwo", 1500.0);
scores.put("PlayerThree", 8200.0); scores.put("PlayerThree", 8200.0);
for (String player : scores.keySet()) { scores.keySet().forEach(player -> {
jedis.zadd(key, scores.get(player), player); jedis.zadd(key, scores.get(player), player);
} });
Set<String> players = jedis.zrevrange(key, 0, 1); Set<String> players = jedis.zrevrange(key, 0, 1);
Assert.assertEquals("PlayerThree", players.iterator().next()); Assert.assertEquals("PlayerThree", players.iterator().next());

View File

@ -148,12 +148,54 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version> <version>${maven-surefire-plugin.version}</version>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*UnitTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
<exclude>**/*LiveTest.java</exclude>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<properties> <properties>
<!-- marshalling --> <!-- marshalling -->
<jackson.version>2.7.8</jackson.version> <jackson.version>2.7.8</jackson.version>

View File

@ -6,5 +6,5 @@ import cucumber.api.junit.Cucumber;
@RunWith(Cucumber.class) @RunWith(Cucumber.class)
@CucumberOptions(features = "classpath:Feature") @CucumberOptions(features = "classpath:Feature")
public class CucumberTest { public class CucumberIntegrationTest {
} }

View File

@ -20,14 +20,35 @@
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version> <version>2.19.1</version>
<configuration> <configuration>
<testSourceDirectory></testSourceDirectory> <testFailureIgnore>true</testFailureIgnore>
<includes> <includes>
<include>Test*.java</include> <include>**/*UnitTest.java</include>
</includes> </includes>
<systemPropertyVariables></systemPropertyVariables>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<profiles>
<profile>
<id>live</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<includes>
<include>**/*LiveTest.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.seleniumhq.selenium</groupId> <groupId>org.seleniumhq.selenium</groupId>
@ -37,12 +58,12 @@
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
<version>4.8.1</version> <version>4.12</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.testng</groupId> <groupId>org.testng</groupId>
<artifactId>testng</artifactId> <artifactId>testng</artifactId>
<version>6.9.10</version> <version>6.9.13.6</version>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -1,15 +1,22 @@
package main.java.com.baeldung.selenium; package main.java.com.baeldung.selenium;
import java.util.List;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxDriver;
public class SeleniumExample { public class SeleniumExample {
private WebDriver webDriver; private WebDriver webDriver;
private String url = "http://www.baeldung.com/"; private String url = "http://www.baeldung.com/";
public SeleniumExample() { public SeleniumExample() {
webDriver = new FirefoxDriver(); webDriver = new FirefoxDriver();
webDriver.manage().window().maximize();
webDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
webDriver.get(url); webDriver.get(url);
} }
@ -21,4 +28,30 @@ public class SeleniumExample {
return webDriver.getTitle(); return webDriver.getTitle();
} }
public void getAboutBaeldungPage() {
closeOverlay();
clickAboutLink();
clickAboutUsLink();
}
private void closeOverlay() {
List<WebElement> webElementList = webDriver.findElements(By.tagName("a"));
if (webElementList != null && !webElementList.isEmpty()) {
webElementList.stream().filter(webElement -> "Close".equalsIgnoreCase(webElement.getAttribute("title"))).findAny().get().click();
}
}
private void clickAboutLink() {
webDriver.findElement(By.partialLinkText("About")).click();
}
private void clickAboutUsLink() {
webDriver.findElement(By.partialLinkText("About Baeldung.")).click();
}
public boolean isAuthorInformationAvailable() {
return webDriver
.findElement(By.xpath("//*[contains(text(), 'Eugen an engineer')]"))
.isDisplayed();
}
} }

View File

@ -0,0 +1,41 @@
package test.java.com.baeldung.selenium.junit;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import main.java.com.baeldung.selenium.SeleniumExample;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class SeleniumWithJUnitLiveTest {
private static SeleniumExample seleniumExample;
private String expecteTilteAboutBaeldungPage = "About Baeldung | Baeldung";
@BeforeClass
public static void setUp() {
seleniumExample = new SeleniumExample();
}
@AfterClass
public static void tearDown() {
seleniumExample.closeWindow();
}
@Test
public void whenAboutBaeldungIsLoaded_thenAboutEugenIsMentionedOnPage() {
try {
seleniumExample.getAboutBaeldungPage();
String actualTitle = seleniumExample.getTitle();
assertNotNull(actualTitle);
assertEquals(actualTitle, expecteTilteAboutBaeldungPage);
assertTrue(seleniumExample.isAuthorInformationAvailable());
} catch (Exception exception) {
exception.printStackTrace();
seleniumExample.closeWindow();
}
}
}

View File

@ -1,32 +0,0 @@
package test.java.com.baeldung.selenium.junit;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import main.java.com.baeldung.selenium.SeleniumExample;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class TestSeleniumWithJUnit {
private SeleniumExample seleniumExample;
private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
@Before
public void setUp() {
seleniumExample = new SeleniumExample();
}
@After
public void tearDown() {
seleniumExample.closeWindow();
}
@Test
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
String actualTitle = seleniumExample.getTitle();
assertNotNull(actualTitle);
assertEquals(actualTitle, expectedTitle);
}
}

View File

@ -0,0 +1,40 @@
package test.java.com.baeldung.selenium.testng;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import main.java.com.baeldung.selenium.SeleniumExample;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
public class SeleniumWithTestNGLiveTest {
private SeleniumExample seleniumExample;
private String expecteTilteAboutBaeldungPage = "About Baeldung | Baeldung";
@BeforeSuite
public void setUp() {
seleniumExample = new SeleniumExample();
}
@AfterSuite
public void tearDown() {
seleniumExample.closeWindow();
}
@Test
public void whenAboutBaeldungIsLoaded_thenAboutEugenIsMentionedOnPage() {
try {
seleniumExample.getAboutBaeldungPage();
String actualTitle = seleniumExample.getTitle();
assertNotNull(actualTitle);
assertEquals(actualTitle, expecteTilteAboutBaeldungPage);
assertTrue(seleniumExample.isAuthorInformationAvailable());
} catch (Exception exception) {
exception.printStackTrace();
seleniumExample.closeWindow();
}
}
}

View File

@ -1,32 +0,0 @@
package test.java.com.baeldung.selenium.testng;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import main.java.com.baeldung.selenium.SeleniumExample;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
public class TestSeleniumWithTestNG {
private SeleniumExample seleniumExample;
private String expectedTitle = "Baeldung | Java, Spring and Web Development tutorials";
@BeforeSuite
public void setUp() {
seleniumExample = new SeleniumExample();
}
@AfterSuite
public void tearDown() {
seleniumExample.closeWindow();
}
@Test
public void whenPageIsLoaded_thenTitleIsAsPerExpectation() {
String actualTitle = seleniumExample.getTitle();
assertNotNull(actualTitle);
assertEquals(actualTitle, expectedTitle);
}
}

View File

@ -65,9 +65,54 @@
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins> </plugins>
</build>
</build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<properties> <properties>
<spring.version>4.3.2.RELEASE</spring.version> <spring.version>4.3.2.RELEASE</spring.version>
@ -75,6 +120,8 @@
<junit.version>4.12</junit.version> <junit.version>4.12</junit.version>
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version> <maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
</properties> </properties>
</project> </project>

View File

@ -20,7 +20,7 @@ import static akka.pattern.Patterns.ask;
import static org.baeldung.akka.SpringExtension.SPRING_EXTENSION_PROVIDER; import static org.baeldung.akka.SpringExtension.SPRING_EXTENSION_PROVIDER;
@ContextConfiguration(classes = AppConfiguration.class) @ContextConfiguration(classes = AppConfiguration.class)
public class SpringAkkaTest extends AbstractJUnit4SpringContextTests { public class SpringAkkaIntegrationTest extends AbstractJUnit4SpringContextTests {
@Autowired @Autowired
private ActorSystem system; private ActorSystem system;

View File

@ -15,3 +15,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring
- [Guide To Running Logic on Startup in Spring](http://www.baeldung.com/running-setup-logic-on-startup-in-spring) - [Guide To Running Logic on Startup in Spring](http://www.baeldung.com/running-setup-logic-on-startup-in-spring)
- [Quick Guide to Spring Controllers](http://www.baeldung.com/spring-controllers) - [Quick Guide to Spring Controllers](http://www.baeldung.com/spring-controllers)
- [Quick Guide to Spring Bean Scopes](http://www.baeldung.com/spring-bean-scopes) - [Quick Guide to Spring Bean Scopes](http://www.baeldung.com/spring-bean-scopes)
- [Introduction To Ehcache](http://www.baeldung.com/ehcache)

View File

@ -224,7 +224,7 @@
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<configuration> <configuration>
<excludes> <excludes>
<!-- <exclude>**/*ProductionTest.java</exclude> --> <exclude>**/*IntegrationTest.java</exclude>
</excludes> </excludes>
<systemPropertyVariables> <systemPropertyVariables>
<!-- <provPersistenceTarget>h2</provPersistenceTarget> --> <!-- <provPersistenceTarget>h2</provPersistenceTarget> -->
@ -232,31 +232,45 @@
</configuration> </configuration>
</plugin> </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>
</plugins> </plugins>
</build> </build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<properties> <properties>
<!-- Spring --> <!-- Spring -->
<org.springframework.version>4.3.1.RELEASE</org.springframework.version> <org.springframework.version>4.3.1.RELEASE</org.springframework.version>

View File

@ -13,7 +13,7 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { SpringAsyncConfig.class }, loader = AnnotationConfigContextLoader.class) @ContextConfiguration(classes = { SpringAsyncConfig.class }, loader = AnnotationConfigContextLoader.class)
public class AsyncAnnotationExampleTest { public class AsyncAnnotationExampleIntegrationTest {
@Autowired @Autowired
private AsyncComponent asyncAnnotationExample; private AsyncComponent asyncAnnotationExample;

View File

@ -8,7 +8,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:springAsync-config.xml") @ContextConfiguration("classpath:springAsync-config.xml")
public class AsyncWithXMLTest { public class AsyncWithXMLIntegrationTest {
@Autowired @Autowired
private AsyncComponent asyncAnnotationExample; private AsyncComponent asyncAnnotationExample;

View File

@ -21,7 +21,7 @@ import org.springframework.web.servlet.ModelAndView;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration @WebAppConfiguration
@ContextConfiguration(classes = { WebConfig.class }, loader = AnnotationConfigWebContextLoader.class) @ContextConfiguration(classes = { WebConfig.class }, loader = AnnotationConfigWebContextLoader.class)
public class ControllerAnnotationTest { public class ControllerAnnotationIntegrationTest {
private MockMvc mockMvc; private MockMvc mockMvc;

View File

@ -20,7 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration @WebAppConfiguration
@ContextConfiguration({ "classpath:test-mvc.xml" }) @ContextConfiguration({ "classpath:test-mvc.xml" })
public class ControllerTest { public class ControllerIntegrationTest {
private MockMvc mockMvc; private MockMvc mockMvc;

View File

@ -14,7 +14,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { CustomAnnotationConfiguration.class }) @ContextConfiguration(classes = { CustomAnnotationConfiguration.class })
public class DataAccessAnnotationTest { public class DataAccessAnnotationIntegrationTest {
@DataAccess(entity = Person.class) @DataAccess(entity = Person.class)
private GenericDAO<Person> personGenericDAO; private GenericDAO<Person> personGenericDAO;

View File

@ -17,7 +17,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { CustomAnnotationConfiguration.class }) @ContextConfiguration(classes = { CustomAnnotationConfiguration.class })
public class DataAccessFieldCallbackTest { public class DataAccessFieldCallbackIntegrationTest {
@Autowired @Autowired
private ConfigurableListableBeanFactory configurableListableBeanFactory; private ConfigurableListableBeanFactory configurableListableBeanFactory;

View File

@ -1,20 +1,20 @@
package org.baeldung.ehcache; package org.baeldung.ehcache;
import static org.junit.Assert.*;
import org.baeldung.ehcache.calculator.SquaredCalculator; import org.baeldung.ehcache.calculator.SquaredCalculator;
import org.baeldung.ehcache.config.CacheHelper; import org.baeldung.ehcache.config.CacheHelper;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
public class SquareCalculatorTest { public class SquareCalculatorTest {
SquaredCalculator squaredCalculator = new SquaredCalculator(); private SquaredCalculator squaredCalculator = new SquaredCalculator();
CacheHelper cacheHelper = new CacheHelper(); private CacheHelper cacheHelper = new CacheHelper();
@Before @Before
public void setup() { public void setup() {
squaredCalculator.setCache(cacheHelper); squaredCalculator.setCache(cacheHelper);
} }
@Test @Test
@ -22,7 +22,7 @@ public class SquareCalculatorTest {
for (int i = 10; i < 15; i++) { for (int i = 10; i < 15; i++) {
assertFalse(cacheHelper.getSquareNumberCache().containsKey(i)); assertFalse(cacheHelper.getSquareNumberCache().containsKey(i));
System.out.println("Square value of " + i + " is: " System.out.println("Square value of " + i + " is: "
+ squaredCalculator.getSquareValueOfNumber(i) + "\n"); + squaredCalculator.getSquareValueOfNumber(i) + "\n");
} }
} }
@ -31,13 +31,13 @@ public class SquareCalculatorTest {
for (int i = 10; i < 15; i++) { for (int i = 10; i < 15; i++) {
assertFalse(cacheHelper.getSquareNumberCache().containsKey(i)); assertFalse(cacheHelper.getSquareNumberCache().containsKey(i));
System.out.println("Square value of " + i + " is: " System.out.println("Square value of " + i + " is: "
+ squaredCalculator.getSquareValueOfNumber(i) + "\n"); + squaredCalculator.getSquareValueOfNumber(i) + "\n");
} }
for (int i = 10; i < 15; i++) { for (int i = 10; i < 15; i++) {
assertTrue(cacheHelper.getSquareNumberCache().containsKey(i)); assertTrue(cacheHelper.getSquareNumberCache().containsKey(i));
System.out.println("Square value of " + i + " is: " System.out.println("Square value of " + i + " is: "
+ squaredCalculator.getSquareValueOfNumber(i) + "\n"); + squaredCalculator.getSquareValueOfNumber(i) + "\n");
} }
} }
} }

View File

@ -15,7 +15,7 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { SpringJdbcConfig.class }, loader = AnnotationConfigContextLoader.class) @ContextConfiguration(classes = { SpringJdbcConfig.class }, loader = AnnotationConfigContextLoader.class)
public class EmployeeDAOTest { public class EmployeeDAOIntegrationTest {
@Autowired @Autowired
private EmployeeDAO employeeDao; private EmployeeDAO employeeDao;

View File

@ -12,7 +12,7 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("dev") @ActiveProfiles("dev")
@ContextConfiguration(classes = { SpringProfilesConfig.class }, loader = AnnotationConfigContextLoader.class) @ContextConfiguration(classes = { SpringProfilesConfig.class }, loader = AnnotationConfigContextLoader.class)
public class DevProfileWithAnnotationTest { public class DevProfileWithAnnotationIntegrationTest {
@Autowired @Autowired
DatasourceConfig datasourceConfig; DatasourceConfig datasourceConfig;

View File

@ -13,7 +13,7 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles("production") @ActiveProfiles("production")
@ContextConfiguration(classes = { SpringProfilesConfig.class }, loader = AnnotationConfigContextLoader.class) @ContextConfiguration(classes = { SpringProfilesConfig.class }, loader = AnnotationConfigContextLoader.class)
public class ProductionProfileWithAnnotationTest { public class ProductionProfileWithAnnotationIntegrationTest {
@Autowired @Autowired
DatasourceConfig datasourceConfig; DatasourceConfig datasourceConfig;

View File

@ -18,7 +18,7 @@ import org.springframework.web.context.WebApplicationContext;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration @WebAppConfiguration
@ContextHierarchy({ @ContextConfiguration(classes = ParentConfig2.class), @ContextConfiguration(classes = ChildConfig2.class) }) @ContextHierarchy({ @ContextConfiguration(classes = ParentConfig2.class), @ContextConfiguration(classes = ChildConfig2.class) })
public class ParentChildPropertyPlaceHolderPropertiesTest { public class ParentChildPropertyPlaceHolderPropertiesIntegrationTest {
@Autowired @Autowired
private WebApplicationContext wac; private WebApplicationContext wac;

View File

@ -18,7 +18,7 @@ import org.springframework.web.context.WebApplicationContext;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration @WebAppConfiguration
@ContextHierarchy({ @ContextConfiguration(classes = ParentConfig.class), @ContextConfiguration(classes = ChildConfig.class) }) @ContextHierarchy({ @ContextConfiguration(classes = ParentConfig.class), @ContextConfiguration(classes = ChildConfig.class) })
public class ParentChildPropertySourcePropertiesTest { public class ParentChildPropertySourcePropertiesIntegrationTest {
@Autowired @Autowired
private WebApplicationContext wac; private WebApplicationContext wac;

View File

@ -8,7 +8,7 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { SpringSchedulingConfig.class }, loader = AnnotationConfigContextLoader.class) @ContextConfiguration(classes = { SpringSchedulingConfig.class }, loader = AnnotationConfigContextLoader.class)
public class ScheduledAnnotationExampleTest { public class ScheduledAnnotationExampleIntegrationTest {
@Test @Test
public void testScheduledAnnotation() throws InterruptedException { public void testScheduledAnnotation() throws InterruptedException {

View File

@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:springScheduled-config.xml") @ContextConfiguration("classpath:springScheduled-config.xml")
public class SchedulingWithXmlConfigTest { public class SchedulingWithXmlConfigIntegrationTest {
@Test @Test
public void testXmlBasedScheduling() throws InterruptedException { public void testXmlBasedScheduling() throws InterruptedException {

View File

@ -17,7 +17,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@ContextConfiguration(classes = AttributeAnnotationConfiguration.class) @ContextConfiguration(classes = AttributeAnnotationConfiguration.class)
@WebAppConfiguration @WebAppConfiguration
public class AttributeAnnotationTest extends AbstractJUnit4SpringContextTests { public class AttributeAnnotationIntegrationTest extends AbstractJUnit4SpringContextTests {
private MockMvc mockMvc; private MockMvc mockMvc;

View File

@ -12,7 +12,7 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ContextConfiguration(classes = CacheRefinementsConfiguration.class) @ContextConfiguration(classes = CacheRefinementsConfiguration.class)
public class CacheRefinementsTest extends AbstractJUnit4SpringContextTests { public class CacheRefinementsIntegrationTest extends AbstractJUnit4SpringContextTests {
private ExecutorService executorService = Executors.newFixedThreadPool(10); private ExecutorService executorService = Executors.newFixedThreadPool(10);

View File

@ -17,7 +17,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@ContextConfiguration(classes = ComposedMappingConfiguration.class) @ContextConfiguration(classes = ComposedMappingConfiguration.class)
@WebAppConfiguration @WebAppConfiguration
public class ComposedMappingTest extends AbstractJUnit4SpringContextTests { public class ComposedMappingIntegrationTest extends AbstractJUnit4SpringContextTests {
@Autowired @Autowired
private AppointmentService appointmentService; private AppointmentService appointmentService;

View File

@ -8,7 +8,7 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@ContextConfiguration(classes = { FooRepositoryConfiguration.class, FooServiceConfiguration.class }) @ContextConfiguration(classes = { FooRepositoryConfiguration.class, FooServiceConfiguration.class })
public class ConfigurationConstructorInjectionTest extends AbstractJUnit4SpringContextTests { public class ConfigurationConstructorInjectionIntegrationTest extends AbstractJUnit4SpringContextTests {
@Autowired @Autowired
public FooService fooService; public FooService fooService;

View File

@ -8,7 +8,7 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@ContextConfiguration("classpath:implicit-ctor-context.xml") @ContextConfiguration("classpath:implicit-ctor-context.xml")
public class ImplicitConstructorTest extends AbstractJUnit4SpringContextTests { public class ImplicitConstructorIntegrationTest extends AbstractJUnit4SpringContextTests {
@Autowired @Autowired
private FooService fooService; private FooService fooService;

View File

@ -10,7 +10,7 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ContextConfiguration("classpath:defaultmethods-context.xml") @ContextConfiguration("classpath:defaultmethods-context.xml")
public class DefaultMethodsInjectionTest extends AbstractJUnit4SpringContextTests { public class DefaultMethodsInjectionIntegrationTest extends AbstractJUnit4SpringContextTests {
@Autowired @Autowired
private IDateHolder dateHolder; private IDateHolder dateHolder;

View File

@ -5,7 +5,7 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests;
@ContextConfiguration(classes = TransactionalTestConfiguration.class) @ContextConfiguration(classes = TransactionalTestConfiguration.class)
public class TransactionalTest extends AbstractTransactionalJUnit4SpringContextTests implements ITransactionalTest { public class TransactionalIntegrationTest extends AbstractTransactionalJUnit4SpringContextTests implements ITransactionalTest {
@Test @Test
public void whenDefaultMethodAnnotatedWithBeforeTransaction_thenDefaultMethodIsExecuted() { public void whenDefaultMethodAnnotatedWithBeforeTransaction_thenDefaultMethodIsExecuted() {

View File

@ -8,7 +8,7 @@ import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@ContextConfiguration(classes = ObjectProviderConfiguration.class) @ContextConfiguration(classes = ObjectProviderConfiguration.class)
public class ObjectProviderTest extends AbstractJUnit4SpringContextTests { public class ObjectProviderIntegrationTest extends AbstractJUnit4SpringContextTests {
@Autowired @Autowired
private FooService fooService; private FooService fooService;

View File

@ -19,7 +19,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@ContextConfiguration(classes = ScopeAnnotationsConfiguration.class) @ContextConfiguration(classes = ScopeAnnotationsConfiguration.class)
@WebAppConfiguration @WebAppConfiguration
public class ScopeAnnotationsTest extends AbstractJUnit4SpringContextTests { public class ScopeAnnotationsIntegrationTest extends AbstractJUnit4SpringContextTests {
private MockMvc mockMvc; private MockMvc mockMvc;

View File

@ -10,7 +10,7 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { AsynchronousSpringEventsConfig.class }, loader = AnnotationConfigContextLoader.class) @ContextConfiguration(classes = { AsynchronousSpringEventsConfig.class }, loader = AnnotationConfigContextLoader.class)
public class AsynchronousCustomSpringEventsTest { public class AsynchronousCustomSpringEventsIntegrationTest {
@Autowired @Autowired
private CustomSpringEventPublisher publisher; private CustomSpringEventPublisher publisher;

View File

@ -9,7 +9,7 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { SynchronousSpringEventsConfig.class }, loader = AnnotationConfigContextLoader.class) @ContextConfiguration(classes = { SynchronousSpringEventsConfig.class }, loader = AnnotationConfigContextLoader.class)
public class ContextRefreshedListenerTest { public class ContextRefreshedListenerIntegrationTest {
@Test @Test
public void testContextRefreshedListener() throws InterruptedException { public void testContextRefreshedListener() throws InterruptedException {

View File

@ -9,7 +9,7 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { SynchronousSpringEventsConfig.class }, loader = AnnotationConfigContextLoader.class) @ContextConfiguration(classes = { SynchronousSpringEventsConfig.class }, loader = AnnotationConfigContextLoader.class)
public class SynchronousCustomSpringEventsTest { public class SynchronousCustomSpringEventsIntegrationTest {
@Autowired @Autowired
private CustomSpringEventPublisher publisher; private CustomSpringEventPublisher publisher;

View File

@ -12,7 +12,7 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { SpringStartupConfig.class }, loader = AnnotationConfigContextLoader.class) @ContextConfiguration(classes = { SpringStartupConfig.class }, loader = AnnotationConfigContextLoader.class)
public class SpringStartupTest { public class SpringStartupIntegrationTest {
@Autowired @Autowired
private ApplicationContext ctx; private ApplicationContext ctx;

View File

@ -9,7 +9,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:startupConfig.xml") @ContextConfiguration("classpath:startupConfig.xml")
public class SpringStartupXMLConfigTest { public class SpringStartupXMLConfigIntegrationTest {
@Autowired @Autowired
private ApplicationContext ctx; private ApplicationContext ctx;

View File

@ -57,7 +57,48 @@
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version> <version>${maven-surefire-plugin.version}</version>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project> </project>

View File

@ -10,7 +10,7 @@ import org.springframework.test.context.support.AnnotationConfigContextLoader;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AppConfig.class, loader = AnnotationConfigContextLoader.class) @ContextConfiguration(classes = AppConfig.class, loader = AnnotationConfigContextLoader.class)
public class FooServiceTest { public class FooServiceIntegrationTest {
@Autowired @Autowired
FooService fooService; FooService fooService;

View File

@ -133,10 +133,56 @@
<version>2.2.1</version> <version>2.2.1</version>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<repositories> <repositories>
<repository> <repository>
<id>spring-snapshots</id> <id>spring-snapshots</id>

View File

@ -9,7 +9,7 @@ import org.springframework.test.context.web.WebAppConfiguration;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = WebjarsdemoApplication.class) @SpringApplicationConfiguration(classes = WebjarsdemoApplication.class)
@WebAppConfiguration @WebAppConfiguration
public class WebjarsdemoApplicationTests { public class WebjarsdemoApplicationIntegrationTest {
@Test @Test
public void contextLoads() { public void contextLoads() {

View File

@ -12,9 +12,9 @@ import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@ContextConfiguration(classes = CommitIdApplication.class) @ContextConfiguration(classes = CommitIdApplication.class)
public class CommitIdTest { public class CommitIdIntegrationTest {
private static final Logger LOG = LoggerFactory.getLogger(CommitIdTest.class); private static final Logger LOG = LoggerFactory.getLogger(CommitIdIntegrationTest.class);
@Value("${git.commit.message.short:UNKNOWN}") @Value("${git.commit.message.short:UNKNOWN}")
private String commitMessage; private String commitMessage;

View File

@ -26,7 +26,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class) @SpringApplicationConfiguration(classes = Application.class)
@WebAppConfiguration @WebAppConfiguration
public class SpringBootApplicationTest { public class SpringBootApplicationIntegrationTest {
@Autowired @Autowired
private WebApplicationContext webApplicationContext; private WebApplicationContext webApplicationContext;
private MockMvc mockMvc; private MockMvc mockMvc;

View File

@ -13,7 +13,7 @@ import static org.junit.Assert.assertNotNull;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class) @SpringApplicationConfiguration(classes = Application.class)
public class SpringBootJPATest { public class SpringBootJPAIntegrationTest {
@Autowired @Autowired
private GenericEntityRepository genericEntityRepository; private GenericEntityRepository genericEntityRepository;

View File

@ -24,7 +24,7 @@ import static org.junit.Assert.assertThat;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class) @SpringApplicationConfiguration(classes = Application.class)
public class SpringBootMailTest { public class SpringBootMailIntegrationTest {
@Autowired @Autowired
private JavaMailSender javaMailSender; private JavaMailSender javaMailSender;

View File

@ -10,7 +10,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = Application.class) @SpringBootTest(classes = Application.class)
@TestPropertySource("classpath:exception.properties") @TestPropertySource("classpath:exception.properties")
public class ApplicationTests { public class ApplicationIntegrationTest {
@Test @Test
public void contextLoads() { public void contextLoads() {
} }

View File

@ -9,7 +9,7 @@ import org.springframework.test.context.web.WebAppConfiguration;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = DemoApplication.class) @SpringBootTest(classes = DemoApplication.class)
@WebAppConfiguration @WebAppConfiguration
public class DemoApplicationTests { public class DemoApplicationIntegrationTest {
@Test @Test
public void contextLoads() { public void contextLoads() {

View File

@ -2,7 +2,7 @@ package org.baeldung.boot.repository;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import org.baeldung.boot.DemoApplicationTests; import org.baeldung.boot.DemoApplicationIntegrationTest;
import org.baeldung.boot.model.Foo; import org.baeldung.boot.model.Foo;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;
@ -14,7 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@Transactional @Transactional
public class FooRepositoryTest extends DemoApplicationTests { public class FooRepositoryIntegrationTest extends DemoApplicationIntegrationTest {
@Autowired @Autowired
private FooRepository fooRepository; private FooRepository fooRepository;

View File

@ -4,7 +4,7 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue; import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat; import static org.junit.Assert.assertThat;
import org.baeldung.boot.ApplicationTests; import org.baeldung.boot.ApplicationIntegrationTest;
import org.baeldung.boot.model.Foo; import org.baeldung.boot.model.Foo;
import org.baeldung.session.exception.repository.FooRepository; import org.baeldung.session.exception.repository.FooRepository;
import org.junit.Test; import org.junit.Test;
@ -14,7 +14,7 @@ import org.springframework.transaction.annotation.Transactional;
@Transactional @Transactional
@TestPropertySource("classpath:exception-hibernate.properties") @TestPropertySource("classpath:exception-hibernate.properties")
public class HibernateSessionTest extends ApplicationTests { public class HibernateSessionIntegrationTest extends ApplicationIntegrationTest {
@Autowired @Autowired
private FooRepository fooRepository; private FooRepository fooRepository;

View File

@ -1,6 +1,6 @@
package org.baeldung.boot.repository; package org.baeldung.boot.repository;
import org.baeldung.boot.ApplicationTests; import org.baeldung.boot.ApplicationIntegrationTest;
import org.baeldung.boot.model.Foo; import org.baeldung.boot.model.Foo;
import org.baeldung.session.exception.repository.FooRepository; import org.baeldung.session.exception.repository.FooRepository;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
@ -9,7 +9,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@Transactional @Transactional
public class NoHibernateSessionTest extends ApplicationTests { public class NoHibernateSessionIntegrationTest extends ApplicationIntegrationTest {
@Autowired @Autowired
private FooRepository fooRepository; private FooRepository fooRepository;

View File

@ -16,7 +16,7 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
@RunWith(SpringRunner.class) @RunWith(SpringRunner.class)
@RestClientTest(DetailsServiceClient.class) @RestClientTest(DetailsServiceClient.class)
public class DetailsServiceClientTest { public class DetailsServiceClientIntegrationTest {
@Autowired @Autowired
private DetailsServiceClient client; private DetailsServiceClient client;

View File

@ -0,0 +1 @@
// dataflow 1.2.0.RELEASE log opened at 2016-10-20 13:13:20

View File

@ -73,17 +73,63 @@
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project> </project>

View File

@ -6,5 +6,5 @@ import org.junit.runner.RunWith;
@RunWith(Cucumber.class) @RunWith(Cucumber.class)
@CucumberOptions(features = "src/test/resources") @CucumberOptions(features = "src/test/resources")
public class CucumberTest { public class CucumberIntegrationTest {
} }

View File

@ -3,7 +3,7 @@ package com.baeldung;
import cucumber.api.java.en.Given; import cucumber.api.java.en.Given;
import cucumber.api.java.en.When; import cucumber.api.java.en.When;
public class OtherDefs extends SpringIntegrationTest { public class OtherDefsIntegrationTest extends SpringIntegrationTest {
@When("^the client calls /baeldung$") @When("^the client calls /baeldung$")
public void the_client_issues_POST_hello() throws Throwable { public void the_client_issues_POST_hello() throws Throwable {
executePost("http://localhost:8080/baeldung"); executePost("http://localhost:8080/baeldung");

View File

@ -9,7 +9,7 @@ import cucumber.api.java.en.And;
import cucumber.api.java.en.Then; import cucumber.api.java.en.Then;
import cucumber.api.java.en.When; import cucumber.api.java.en.When;
public class StepDefs extends SpringIntegrationTest { public class StepDefsIntegrationTest extends SpringIntegrationTest {
@When("^the client calls /version$") @When("^the client calls /version$")
public void the_client_issues_GET_version() throws Throwable { public void the_client_issues_GET_version() throws Throwable {

View File

@ -23,6 +23,7 @@
<cassandra-unit-spring.version>2.1.9.2</cassandra-unit-spring.version> <cassandra-unit-spring.version>2.1.9.2</cassandra-unit-spring.version>
<cassandra-unit-shaded>2.1.9.2</cassandra-unit-shaded> <cassandra-unit-shaded>2.1.9.2</cassandra-unit-shaded>
<hector-core.version>2.0-0</hector-core.version> <hector-core.version>2.0-0</hector-core.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
</properties> </properties>
<dependencies> <dependencies>
@ -108,6 +109,52 @@
<target>1.7</target> <target>1.7</target>
</configuration> </configuration>
</plugin> </plugin>
</plugins> <plugin>
</build> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project> </project>

View File

@ -86,6 +86,17 @@
<target>1.7</target> <target>1.7</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
@ -99,7 +110,7 @@
<logback.version>1.1.3</logback.version> <logback.version>1.1.3</logback.version>
<org.slf4j.version>1.7.12</org.slf4j.version> <org.slf4j.version>1.7.12</org.slf4j.version>
<junit.version>4.11</junit.version> <junit.version>4.11</junit.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
</properties> </properties>
</project> </project>

View File

@ -3,7 +3,7 @@ package org.baeldung.spring.data.couchbase.service;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
public class PersonRepositoryServiceTest extends PersonServiceTest { public class PersonRepositoryServiceIntegrationTest extends PersonServiceIntegrationTest {
@Autowired @Autowired
@Qualifier("PersonRepositoryService") @Qualifier("PersonRepositoryService")

View File

@ -20,7 +20,7 @@ import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.document.JsonDocument; import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.document.json.JsonObject; import com.couchbase.client.java.document.json.JsonObject;
public abstract class PersonServiceTest extends IntegrationTest { public abstract class PersonServiceIntegrationTest extends IntegrationTest {
static final String typeField = "_class"; static final String typeField = "_class";
static final String john = "John"; static final String john = "John";

View File

@ -3,7 +3,7 @@ package org.baeldung.spring.data.couchbase.service;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
public class PersonTemplateServiceTest extends PersonServiceTest { public class PersonTemplateServiceIntegrationTest extends PersonServiceIntegrationTest {
@Autowired @Autowired
@Qualifier("PersonTemplateService") @Qualifier("PersonTemplateService")

View File

@ -3,7 +3,7 @@ package org.baeldung.spring.data.couchbase.service;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
public class StudentRepositoryServiceTest extends StudentServiceTest { public class StudentRepositoryServiceIntegrationTest extends StudentServiceIntegrationTest {
@Autowired @Autowired
@Qualifier("StudentRepositoryService") @Qualifier("StudentRepositoryService")

View File

@ -22,7 +22,7 @@ import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.document.JsonDocument; import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.document.json.JsonObject; import com.couchbase.client.java.document.json.JsonObject;
public abstract class StudentServiceTest extends IntegrationTest { public abstract class StudentServiceIntegrationTest extends IntegrationTest {
static final String typeField = "_class"; static final String typeField = "_class";
static final String joe = "Joe"; static final String joe = "Joe";

View File

@ -3,7 +3,7 @@ package org.baeldung.spring.data.couchbase.service;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Qualifier;
public class StudentTemplateServiceTest extends StudentServiceTest { public class StudentTemplateServiceIntegrationTest extends StudentServiceIntegrationTest {
@Autowired @Autowired
@Qualifier("StudentTemplateService") @Qualifier("StudentTemplateService")

View File

@ -18,7 +18,7 @@ import org.springframework.data.geo.Distance;
import org.springframework.data.geo.Metrics; import org.springframework.data.geo.Metrics;
import org.springframework.data.geo.Point; import org.springframework.data.geo.Point;
public class CampusServiceImplTest extends MultiBucketIntegationTest { public class CampusServiceImplIntegrationTest extends MultiBucketIntegationTest {
@Autowired @Autowired
private CampusServiceImpl campusService; private CampusServiceImpl campusService;

View File

@ -21,7 +21,7 @@ import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.document.JsonDocument; import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.document.json.JsonObject; import com.couchbase.client.java.document.json.JsonObject;
public class PersonServiceImplTest extends MultiBucketIntegationTest { public class PersonServiceImplIntegrationTest extends MultiBucketIntegationTest {
static final String typeField = "_class"; static final String typeField = "_class";
static final String john = "John"; static final String john = "John";

View File

@ -23,7 +23,7 @@ import com.couchbase.client.java.CouchbaseCluster;
import com.couchbase.client.java.document.JsonDocument; import com.couchbase.client.java.document.JsonDocument;
import com.couchbase.client.java.document.json.JsonObject; import com.couchbase.client.java.document.json.JsonObject;
public class StudentServiceImplTest extends MultiBucketIntegationTest { public class StudentServiceImplIntegrationTest extends MultiBucketIntegationTest {
static final String typeField = "_class"; static final String typeField = "_class";
static final String joe = "Joe"; static final String joe = "Joe";

View File

@ -20,6 +20,7 @@
<org.slf4j.version>1.7.12</org.slf4j.version> <org.slf4j.version>1.7.12</org.slf4j.version>
<logback.version>1.1.3</logback.version> <logback.version>1.1.3</logback.version>
<elasticsearch.version>2.0.1.RELEASE</elasticsearch.version> <elasticsearch.version>2.0.1.RELEASE</elasticsearch.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
</properties> </properties>
<dependencies> <dependencies>
@ -86,4 +87,54 @@
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project> </project>

View File

@ -29,7 +29,7 @@ import com.baeldung.spring.data.es.service.ArticleService;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = Config.class) @ContextConfiguration(classes = Config.class)
public class ElasticSearchTest { public class ElasticSearchIntegrationTest {
@Autowired @Autowired
private ElasticsearchTemplate elasticsearchTemplate; private ElasticsearchTemplate elasticsearchTemplate;

View File

@ -42,7 +42,7 @@ import com.baeldung.spring.data.es.service.ArticleService;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = Config.class) @ContextConfiguration(classes = Config.class)
public class ElasticSearchQueryTest { public class ElasticSearchQueryIntegrationTest {
@Autowired @Autowired
private ElasticsearchTemplate elasticsearchTemplate; private ElasticsearchTemplate elasticsearchTemplate;

View File

@ -112,9 +112,55 @@
<target>1.8</target> <target>1.8</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<excludes>
<exclude>**/*IntegrationTest.java</exclude>
<exclude>**/*LiveTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
<profiles>
<profile>
<id>integration</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*LiveTest.java</exclude>
</excludes>
<includes>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
<configuration>
<systemPropertyVariables>
<test.mime>json</test.mime>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@ -130,6 +176,7 @@
<org.slf4j.version>1.7.12</org.slf4j.version> <org.slf4j.version>1.7.12</org.slf4j.version>
<logback.version>1.1.3</logback.version> <logback.version>1.1.3</logback.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
</properties> </properties>
</project> </project>

Some files were not shown because too many files have changed in this diff Show More