From a8b3f44a2fd25918d25d0237c27d2c77080f67e5 Mon Sep 17 00:00:00 2001 From: Ivan Paolillo Date: Fri, 7 Oct 2016 17:31:28 +0200 Subject: [PATCH 01/58] Code improvement --- okhttp/pom.xml | 98 ++++++++++++------- .../okhttp/ProgressRequestWrapper.java | 10 +- .../okhttp/OkHttpFileUploadingTest.java | 4 +- .../org/baeldung/okhttp/OkHttpGetTest.java | 6 +- .../org/baeldung/okhttp/OkHttpHeaderTest.java | 4 +- .../org/baeldung/okhttp/OkHttpMiscTest.java | 54 +++++----- .../baeldung/okhttp/OkHttpPostingTest.java | 8 +- .../baeldung/okhttp/OkHttpRedirectTest.java | 2 +- 8 files changed, 111 insertions(+), 75 deletions(-) diff --git a/okhttp/pom.xml b/okhttp/pom.xml index ba5bcf9725..4d371f40b0 100644 --- a/okhttp/pom.xml +++ b/okhttp/pom.xml @@ -1,44 +1,76 @@ - - 4.0.0 - org.baeldung.okhttp - okhttp - 0.0.1-SNAPSHOT + + 4.0.0 + org.baeldung.okhttp + okhttp + 0.0.1-SNAPSHOT - + - - - com.squareup.okhttp3 - okhttp - ${com.squareup.okhttp3.version} - + - - - junit - junit - ${junit.version} - test - + + com.squareup.okhttp3 + okhttp + ${com.squareup.okhttp3.version} + - - org.hamcrest - hamcrest-library - ${org.hamcrest.version} - test - + - + + org.slf4j + slf4j-api + ${org.slf4j.version} + - + + ch.qos.logback + logback-classic + ${logback.version} + - - 3.4.1 + + org.slf4j + jcl-over-slf4j + ${org.slf4j.version} + - - 1.3 - 4.12 - + + org.slf4j + log4j-over-slf4j + ${org.slf4j.version} + + + + junit + junit + ${junit.version} + test + + + + org.hamcrest + hamcrest-library + ${org.hamcrest.version} + test + + + + + + + + 3.4.1 + + + 1.7.13 + 1.1.3 + + + 1.3 + 4.12 + + diff --git a/okhttp/src/main/java/org/baeldung/okhttp/ProgressRequestWrapper.java b/okhttp/src/main/java/org/baeldung/okhttp/ProgressRequestWrapper.java index 6a98f8d20a..255d10b98a 100644 --- a/okhttp/src/main/java/org/baeldung/okhttp/ProgressRequestWrapper.java +++ b/okhttp/src/main/java/org/baeldung/okhttp/ProgressRequestWrapper.java @@ -1,11 +1,16 @@ package org.baeldung.okhttp; -import okhttp3.MediaType; import okhttp3.RequestBody; -import okio.*; +import okhttp3.MediaType; import java.io.IOException; +import okio.Buffer; +import okio.BufferedSink; +import okio.ForwardingSink; +import okio.Okio; +import okio.Sink; + public class ProgressRequestWrapper extends RequestBody { protected RequestBody delegate; @@ -61,6 +66,7 @@ public class ProgressRequestWrapper extends RequestBody { } public interface ProgressListener { + void onRequestProgress(long bytesWritten, long contentLength); } diff --git a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingTest.java b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingTest.java index 32457fc11b..77219b8e22 100644 --- a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingTest.java +++ b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingTest.java @@ -23,7 +23,7 @@ public class OkHttpFileUploadingTest { private static final String BASE_URL = "http://localhost:8080/spring-rest"; @Test - public void whenUploadFileUsingOkHttp_thenCorrect() throws IOException { + public void whenUploadFile_thenCorrect() throws IOException { OkHttpClient client = new OkHttpClient(); @@ -45,7 +45,7 @@ public class OkHttpFileUploadingTest { } @Test - public void whenGetUploadFileProgressUsingOkHttp_thenCorrect() throws IOException { + public void whenGetUploadFileProgress_thenCorrect() throws IOException { OkHttpClient client = new OkHttpClient(); diff --git a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpGetTest.java b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpGetTest.java index e8edff92df..de954e3dd7 100644 --- a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpGetTest.java +++ b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpGetTest.java @@ -19,7 +19,7 @@ public class OkHttpGetTest { private static final String BASE_URL = "http://localhost:8080/spring-rest"; @Test - public void whenGetRequestUsingOkHttp_thenCorrect() throws IOException { + public void whenGetRequest_thenCorrect() throws IOException { OkHttpClient client = new OkHttpClient(); @@ -34,7 +34,7 @@ public class OkHttpGetTest { } @Test - public void whenGetRequestWithQueryParameterUsingOkHttp_thenCorrect() throws IOException { + public void whenGetRequestWithQueryParameter_thenCorrect() throws IOException { OkHttpClient client = new OkHttpClient(); @@ -54,7 +54,7 @@ public class OkHttpGetTest { } @Test - public void whenAsynchronousGetRequestUsingOkHttp_thenCorrect() { + public void whenAsynchronousGetRequest_thenCorrect() { OkHttpClient client = new OkHttpClient(); diff --git a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpHeaderTest.java b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpHeaderTest.java index 5b2e89eca8..958eeb51ce 100644 --- a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpHeaderTest.java +++ b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpHeaderTest.java @@ -14,7 +14,7 @@ public class OkHttpHeaderTest { private static final String SAMPLE_URL = "http://www.github.com"; @Test - public void whenSetHeaderUsingOkHttp_thenCorrect() throws IOException { + public void whenSetHeader_thenCorrect() throws IOException { OkHttpClient client = new OkHttpClient(); @@ -29,7 +29,7 @@ public class OkHttpHeaderTest { } @Test - public void whenSetDefaultHeaderUsingOkHttp_thenCorrect() throws IOException { + public void whenSetDefaultHeader_thenCorrect() throws IOException { OkHttpClient client = new OkHttpClient.Builder() .addInterceptor(new DefaultContentTypeInterceptor("application/json")) diff --git a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpMiscTest.java b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpMiscTest.java index 829bafe8ef..b72b461158 100644 --- a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpMiscTest.java +++ b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpMiscTest.java @@ -7,6 +7,8 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import okhttp3.Cache; import okhttp3.Call; @@ -17,13 +19,12 @@ import okhttp3.Response; public class OkHttpMiscTest { private static final String BASE_URL = "http://localhost:8080/spring-rest"; + private static Logger logger = LoggerFactory.getLogger(OkHttpMiscTest.class); //@Test - public void whenSetRequestTimeoutUsingOkHttp_thenFail() throws IOException { + public void whenSetRequestTimeout_thenFail() throws IOException { OkHttpClient client = new OkHttpClient.Builder() - //.connectTimeout(10, TimeUnit.SECONDS) - //.writeTimeout(10, TimeUnit.SECONDS) .readTimeout(1, TimeUnit.SECONDS) .build(); @@ -36,8 +37,8 @@ public class OkHttpMiscTest { response.close(); } - //@Test - public void whenCancelRequestUsingOkHttp_thenCorrect() throws IOException { + @Test + public void whenCancelRequest_thenCorrect() throws IOException { ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); @@ -48,7 +49,6 @@ public class OkHttpMiscTest { .build(); final int seconds = 1; - //final int seconds = 3; final long startNanos = System.nanoTime(); final Call call = client.newCall(request); @@ -57,57 +57,55 @@ public class OkHttpMiscTest { executor.schedule(new Runnable() { public void run() { - System.out.printf("%.2f Canceling call.%n", (System.nanoTime() - startNanos) / 1e9f); + logger.debug("Canceling call: " + (System.nanoTime() - startNanos) / 1e9f); call.cancel(); - System.out.printf("%.2f Canceled call.%n", (System.nanoTime() - startNanos) / 1e9f); + logger.debug("Canceled call: " + (System.nanoTime() - startNanos) / 1e9f); } }, seconds, TimeUnit.SECONDS); try { - System.out.printf("%.2f Executing call.%n", (System.nanoTime() - startNanos) / 1e9f); - Response response = call.execute(); - System.out.printf("%.2f Call was expected to fail, but completed: %s%n", (System.nanoTime() - startNanos) / 1e9f, response); + logger.debug("Executing call: " + (System.nanoTime() - startNanos) / 1e9f); + Response response = call.execute(); + logger.debug("Call was expected to fail, but completed: " + (System.nanoTime() - startNanos) / 1e9f, response); } catch (IOException e) { - System.out.printf("%.2f Call failed as expected: %s%n", (System.nanoTime() - startNanos) / 1e9f, e); + logger.debug("Call failed as expected: " + (System.nanoTime() - startNanos) / 1e9f, e); } } - @Test - public void whenSetResponseCacheUsingOkHttp_thenCorrect() throws IOException { + //@Test + public void whenSetResponseCache_thenCorrect() throws IOException { int cacheSize = 10 * 1024 * 1024; // 10 MiB File cacheDirectory = new File("src/test/resources/cache"); Cache cache = new Cache(cacheDirectory, cacheSize); OkHttpClient client = new OkHttpClient.Builder() - .cache(cache) - .build(); + .cache(cache) + .build(); Request request = new Request.Builder() - .url("http://publicobject.com/helloworld.txt") - //.cacheControl(CacheControl.FORCE_NETWORK) - //.cacheControl(CacheControl.FORCE_CACHE) - .build(); + .url("http://publicobject.com/helloworld.txt") + .build(); Response response1 = client.newCall(request).execute(); String responseBody1 = response1.body().string(); - System.out.println("Response 1 response: " + response1); - System.out.println("Response 1 cache response: " + response1.cacheResponse()); - System.out.println("Response 1 network response: " + response1.networkResponse()); - System.out.println("Response 1 responseBody: " + responseBody1); + logger.debug("Response 1 response: " + response1); + logger.debug("Response 1 cache response: " + response1.cacheResponse()); + logger.debug("Response 1 network response: " + response1.networkResponse()); + logger.debug("Response 1 responseBody: " + responseBody1); Response response2 = client.newCall(request).execute(); String responseBody2 = response2.body().string(); - System.out.println("Response 2 response: " + response2); - System.out.println("Response 2 cache response: " + response2.cacheResponse()); - System.out.println("Response 2 network response: " + response2.networkResponse()); - System.out.println("Response 2 responseBody: " + responseBody2); + logger.debug("Response 2 response: " + response2); + logger.debug("Response 2 cache response: " + response2.cacheResponse()); + logger.debug("Response 2 network response: " + response2.networkResponse()); + logger.debug("Response 2 responseBody: " + responseBody2); } } diff --git a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpPostingTest.java b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpPostingTest.java index 1ba2d517c5..41a024d2ee 100644 --- a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpPostingTest.java +++ b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpPostingTest.java @@ -24,7 +24,7 @@ public class OkHttpPostingTest { private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://browserspy.dk/password-ok.php"; @Test - public void whenSendPostRequestUsingOkHttp_thenCorrect() throws IOException { + public void whenSendPostRequest_thenCorrect() throws IOException { OkHttpClient client = new OkHttpClient(); @@ -45,7 +45,7 @@ public class OkHttpPostingTest { } @Test - public void whenSendPostRequestWithAuthorizationUsingOkHttp_thenCorrect() throws IOException { + public void whenSendPostRequestWithAuthorization_thenCorrect() throws IOException { String postBody = "test post"; @@ -64,7 +64,7 @@ public class OkHttpPostingTest { } @Test - public void whenPostJsonUsingOkHttp_thenCorrect() throws IOException { + public void whenPostJson_thenCorrect() throws IOException { OkHttpClient client = new OkHttpClient(); @@ -84,7 +84,7 @@ public class OkHttpPostingTest { } @Test - public void whenSendMultipartRequestUsingOkHttp_thenCorrect() throws IOException { + public void whenSendMultipartRequest_thenCorrect() throws IOException { OkHttpClient client = new OkHttpClient(); diff --git a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpRedirectTest.java b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpRedirectTest.java index 1582a5ff7f..c709253478 100644 --- a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpRedirectTest.java +++ b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpRedirectTest.java @@ -15,7 +15,7 @@ import okhttp3.Response; public class OkHttpRedirectTest { @Test - public void whenSetFollowRedirectsUsingOkHttp_thenNotRedirected() throws IOException { + public void whenSetFollowRedirects_thenNotRedirected() throws IOException { OkHttpClient client = new OkHttpClient().newBuilder() .followRedirects(false) From 8692cad3282d0d8e72170bfa8720bb57ea98dd95 Mon Sep 17 00:00:00 2001 From: Ivan Paolillo Date: Fri, 7 Oct 2016 17:47:58 +0200 Subject: [PATCH 02/58] Code improvement --- .../org/baeldung/okhttp/OkHttpMiscTest.java | 24 ++++++++----------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpMiscTest.java b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpMiscTest.java index b72b461158..fe15a76200 100644 --- a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpMiscTest.java +++ b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpMiscTest.java @@ -21,7 +21,7 @@ public class OkHttpMiscTest { private static final String BASE_URL = "http://localhost:8080/spring-rest"; private static Logger logger = LoggerFactory.getLogger(OkHttpMiscTest.class); - //@Test + @Test public void whenSetRequestTimeout_thenFail() throws IOException { OkHttpClient client = new OkHttpClient.Builder() @@ -75,7 +75,7 @@ public class OkHttpMiscTest { } } - //@Test + @Test public void whenSetResponseCache_thenCorrect() throws IOException { int cacheSize = 10 * 1024 * 1024; // 10 MiB @@ -91,21 +91,17 @@ public class OkHttpMiscTest { .build(); Response response1 = client.newCall(request).execute(); - - String responseBody1 = response1.body().string(); - - logger.debug("Response 1 response: " + response1); - logger.debug("Response 1 cache response: " + response1.cacheResponse()); - logger.debug("Response 1 network response: " + response1.networkResponse()); - logger.debug("Response 1 responseBody: " + responseBody1); + logResponse(response1); Response response2 = client.newCall(request).execute(); + logResponse(response2); + } - String responseBody2 = response2.body().string(); + private void logResponse(Response response) throws IOException { - logger.debug("Response 2 response: " + response2); - logger.debug("Response 2 cache response: " + response2.cacheResponse()); - logger.debug("Response 2 network response: " + response2.networkResponse()); - logger.debug("Response 2 responseBody: " + responseBody2); + logger.debug("Response response: " + response); + logger.debug("Response cache response: " + response.cacheResponse()); + logger.debug("Response network response: " + response.networkResponse()); + logger.debug("Response responseBody: " + response.body().string()); } } From 453b739f6c11cf7c28102f810ac734d956a02f2f Mon Sep 17 00:00:00 2001 From: Ivan Paolillo Date: Tue, 11 Oct 2016 10:38:51 +0200 Subject: [PATCH 03/58] Add OkHttp example --- spring-rest/pom.xml | 23 +++- .../okhttp/DefaultContentTypeInterceptor.java | 26 +++++ .../okhttp/OkHttpFileUploadingTest.java | 81 +++++++++++++ .../org/baeldung/okhttp/OkHttpGetTest.java | 78 +++++++++++++ .../org/baeldung/okhttp/OkHttpHeaderTest.java | 48 ++++++++ .../org/baeldung/okhttp/OkHttpMiscTest.java | 107 +++++++++++++++++ .../baeldung/okhttp/OkHttpPostingTest.java | 109 ++++++++++++++++++ .../baeldung/okhttp/OkHttpRedirectTest.java | 33 ++++++ .../okhttp/ProgressRequestWrapper.java | 74 ++++++++++++ spring-rest/src/test/resources/test.txt | 1 + 10 files changed, 574 insertions(+), 6 deletions(-) create mode 100644 spring-rest/src/test/java/org/baeldung/okhttp/DefaultContentTypeInterceptor.java create mode 100644 spring-rest/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingTest.java create mode 100644 spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetTest.java create mode 100644 spring-rest/src/test/java/org/baeldung/okhttp/OkHttpHeaderTest.java create mode 100644 spring-rest/src/test/java/org/baeldung/okhttp/OkHttpMiscTest.java create mode 100644 spring-rest/src/test/java/org/baeldung/okhttp/OkHttpPostingTest.java create mode 100644 spring-rest/src/test/java/org/baeldung/okhttp/OkHttpRedirectTest.java create mode 100644 spring-rest/src/test/java/org/baeldung/okhttp/ProgressRequestWrapper.java create mode 100644 spring-rest/src/test/resources/test.txt diff --git a/spring-rest/pom.xml b/spring-rest/pom.xml index 18cb1dc72a..69ab4ed361 100644 --- a/spring-rest/pom.xml +++ b/spring-rest/pom.xml @@ -15,7 +15,7 @@ - + org.springframework.boot spring-boot-starter-thymeleaf @@ -71,7 +71,7 @@ com.fasterxml.jackson.core jackson-databind - + com.fasterxml.jackson.dataformat jackson-dataformat-xml @@ -118,6 +118,14 @@ log4j-over-slf4j + + + + com.squareup.okhttp3 + okhttp + ${com.squareup.okhttp3.version} + + @@ -153,14 +161,14 @@ rest-assured ${rest-assured.version} - + com.google.protobuf protobuf-java 2.6.1 - + com.esotericsoftware kryo @@ -198,7 +206,7 @@ maven-surefire-plugin - **/*LiveTest.java + **/*LiveTest.java @@ -285,7 +293,7 @@ - + @@ -320,6 +328,9 @@ 2.19.1 1.6.0 + + 3.4.1 + diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/DefaultContentTypeInterceptor.java b/spring-rest/src/test/java/org/baeldung/okhttp/DefaultContentTypeInterceptor.java new file mode 100644 index 0000000000..2a33a1febd --- /dev/null +++ b/spring-rest/src/test/java/org/baeldung/okhttp/DefaultContentTypeInterceptor.java @@ -0,0 +1,26 @@ +package org.baeldung.okhttp; + +import java.io.IOException; + +import okhttp3.Interceptor; +import okhttp3.Request; +import okhttp3.Response; + +public class DefaultContentTypeInterceptor implements Interceptor { + + private final String contentType; + + public DefaultContentTypeInterceptor(String contentType) { + this.contentType = contentType; + } + + public Response intercept(Interceptor.Chain chain) throws IOException { + + Request originalRequest = chain.request(); + Request requestWithUserAgent = originalRequest.newBuilder() + .header("Content-Type", contentType) + .build(); + + return chain.proceed(requestWithUserAgent); + } +} diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingTest.java new file mode 100644 index 0000000000..77219b8e22 --- /dev/null +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingTest.java @@ -0,0 +1,81 @@ +package org.baeldung.okhttp; + +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertThat; + +import java.io.File; +import java.io.IOException; + +import org.baeldung.okhttp.ProgressRequestWrapper; +import org.junit.Test; + +import okhttp3.Call; +import okhttp3.MediaType; +import okhttp3.MultipartBody; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class OkHttpFileUploadingTest { + + private static final String BASE_URL = "http://localhost:8080/spring-rest"; + + @Test + public void whenUploadFile_thenCorrect() throws IOException { + + OkHttpClient client = new OkHttpClient(); + + RequestBody requestBody = new MultipartBody.Builder() + .setType(MultipartBody.FORM) + .addFormDataPart("file", "file.txt", + RequestBody.create(MediaType.parse("application/octet-stream"), new File("src/test/resources/test.txt"))) + .build(); + + Request request = new Request.Builder() + .url(BASE_URL + "/users/upload") + .post(requestBody) + .build(); + + Call call = client.newCall(request); + Response response = call.execute(); + + assertThat(response.code(), equalTo(200)); + } + + @Test + public void whenGetUploadFileProgress_thenCorrect() throws IOException { + + OkHttpClient client = new OkHttpClient(); + + RequestBody requestBody = new MultipartBody.Builder() + .setType(MultipartBody.FORM) + .addFormDataPart("file", "file.txt", + RequestBody.create(MediaType.parse("application/octet-stream"), new File("src/test/resources/test.txt"))) + .build(); + + + ProgressRequestWrapper.ProgressListener listener = new ProgressRequestWrapper.ProgressListener() { + + public void onRequestProgress(long bytesWritten, long contentLength) { + + float percentage = 100f * bytesWritten / contentLength; + assertFalse(Float.compare(percentage, 100) > 0); + } + }; + + ProgressRequestWrapper countingBody = new ProgressRequestWrapper(requestBody, listener); + + Request request = new Request.Builder() + .url(BASE_URL + "/users/upload") + .post(countingBody) + .build(); + + Call call = client.newCall(request); + Response response = call.execute(); + + assertThat(response.code(), equalTo(200)); + + } +} diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetTest.java new file mode 100644 index 0000000000..de954e3dd7 --- /dev/null +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetTest.java @@ -0,0 +1,78 @@ +package org.baeldung.okhttp; + +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; + +import java.io.IOException; + +import org.junit.Test; + +import okhttp3.Call; +import okhttp3.Callback; +import okhttp3.HttpUrl; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +public class OkHttpGetTest { + + private static final String BASE_URL = "http://localhost:8080/spring-rest"; + + @Test + public void whenGetRequest_thenCorrect() throws IOException { + + OkHttpClient client = new OkHttpClient(); + + Request request = new Request.Builder() + .url(BASE_URL + "/date") + .build(); + + Call call = client.newCall(request); + Response response = call.execute(); + + assertThat(response.code(), equalTo(200)); + } + + @Test + public void whenGetRequestWithQueryParameter_thenCorrect() throws IOException { + + OkHttpClient client = new OkHttpClient(); + + HttpUrl.Builder urlBuilder = HttpUrl.parse(BASE_URL + "/ex/bars").newBuilder(); + urlBuilder.addQueryParameter("id", "1"); + + String url = urlBuilder.build().toString(); + + Request request = new Request.Builder() + .url(url) + .build(); + + Call call = client.newCall(request); + Response response = call.execute(); + + assertThat(response.code(), equalTo(200)); + } + + @Test + public void whenAsynchronousGetRequest_thenCorrect() { + + OkHttpClient client = new OkHttpClient(); + + Request request = new Request.Builder() + .url(BASE_URL + "/date") + .build(); + + Call call = client.newCall(request); + + call.enqueue(new Callback() { + + public void onResponse(Call call, Response response) throws IOException { + assertThat(response.code(), equalTo(200)); + } + + public void onFailure(Call call, IOException e) { + + } + }); + } +} diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpHeaderTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpHeaderTest.java new file mode 100644 index 0000000000..958eeb51ce --- /dev/null +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpHeaderTest.java @@ -0,0 +1,48 @@ +package org.baeldung.okhttp; + +import java.io.IOException; + +import org.junit.Test; + +import okhttp3.Call; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +public class OkHttpHeaderTest { + + private static final String SAMPLE_URL = "http://www.github.com"; + + @Test + public void whenSetHeader_thenCorrect() throws IOException { + + OkHttpClient client = new OkHttpClient(); + + Request request = new Request.Builder() + .url(SAMPLE_URL) + .addHeader("Content-Type", "application/json") + .build(); + + Call call = client.newCall(request); + Response response = call.execute(); + response.close(); + } + + @Test + public void whenSetDefaultHeader_thenCorrect() throws IOException { + + OkHttpClient client = new OkHttpClient.Builder() + .addInterceptor(new DefaultContentTypeInterceptor("application/json")) + .build(); + + Request request = new Request.Builder() + .url(SAMPLE_URL) + .build(); + + Call call = client.newCall(request); + Response response = call.execute(); + response.close(); + } + + +} diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpMiscTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpMiscTest.java new file mode 100644 index 0000000000..fe15a76200 --- /dev/null +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpMiscTest.java @@ -0,0 +1,107 @@ +package org.baeldung.okhttp; + +import java.io.File; +import java.io.IOException; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import okhttp3.Cache; +import okhttp3.Call; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +public class OkHttpMiscTest { + + private static final String BASE_URL = "http://localhost:8080/spring-rest"; + private static Logger logger = LoggerFactory.getLogger(OkHttpMiscTest.class); + + @Test + public void whenSetRequestTimeout_thenFail() throws IOException { + + OkHttpClient client = new OkHttpClient.Builder() + .readTimeout(1, TimeUnit.SECONDS) + .build(); + + Request request = new Request.Builder() + .url(BASE_URL + "/delay/2") // This URL is served with a 2 second delay. + .build(); + + Call call = client.newCall(request); + Response response = call.execute(); + response.close(); + } + + @Test + public void whenCancelRequest_thenCorrect() throws IOException { + + ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); + + OkHttpClient client = new OkHttpClient(); + + Request request = new Request.Builder() + .url(BASE_URL + "/delay/2") // This URL is served with a 2 second delay. + .build(); + + final int seconds = 1; + + final long startNanos = System.nanoTime(); + final Call call = client.newCall(request); + + // Schedule a job to cancel the call in 1 second. + executor.schedule(new Runnable() { + public void run() { + + logger.debug("Canceling call: " + (System.nanoTime() - startNanos) / 1e9f); + call.cancel(); + logger.debug("Canceled call: " + (System.nanoTime() - startNanos) / 1e9f); + } + }, seconds, TimeUnit.SECONDS); + + try { + + logger.debug("Executing call: " + (System.nanoTime() - startNanos) / 1e9f); + Response response = call.execute(); + logger.debug("Call was expected to fail, but completed: " + (System.nanoTime() - startNanos) / 1e9f, response); + + } catch (IOException e) { + + logger.debug("Call failed as expected: " + (System.nanoTime() - startNanos) / 1e9f, e); + } + } + + @Test + public void whenSetResponseCache_thenCorrect() throws IOException { + + int cacheSize = 10 * 1024 * 1024; // 10 MiB + File cacheDirectory = new File("src/test/resources/cache"); + Cache cache = new Cache(cacheDirectory, cacheSize); + + OkHttpClient client = new OkHttpClient.Builder() + .cache(cache) + .build(); + + Request request = new Request.Builder() + .url("http://publicobject.com/helloworld.txt") + .build(); + + Response response1 = client.newCall(request).execute(); + logResponse(response1); + + Response response2 = client.newCall(request).execute(); + logResponse(response2); + } + + private void logResponse(Response response) throws IOException { + + logger.debug("Response response: " + response); + logger.debug("Response cache response: " + response.cacheResponse()); + logger.debug("Response network response: " + response.networkResponse()); + logger.debug("Response responseBody: " + response.body().string()); + } +} diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpPostingTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpPostingTest.java new file mode 100644 index 0000000000..41a024d2ee --- /dev/null +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpPostingTest.java @@ -0,0 +1,109 @@ +package org.baeldung.okhttp; + +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; + +import java.io.File; +import java.io.IOException; + +import org.junit.Test; + +import okhttp3.Call; +import okhttp3.Credentials; +import okhttp3.FormBody; +import okhttp3.MediaType; +import okhttp3.MultipartBody; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; + +public class OkHttpPostingTest { + + private static final String BASE_URL = "http://localhost:8080/spring-rest"; + private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://browserspy.dk/password-ok.php"; + + @Test + public void whenSendPostRequest_thenCorrect() throws IOException { + + OkHttpClient client = new OkHttpClient(); + + RequestBody formBody = new FormBody.Builder() + .add("username", "test") + .add("password", "test") + .build(); + + Request request = new Request.Builder() + .url(BASE_URL + "/users") + .post(formBody) + .build(); + + Call call = client.newCall(request); + Response response = call.execute(); + + assertThat(response.code(), equalTo(200)); + } + + @Test + public void whenSendPostRequestWithAuthorization_thenCorrect() throws IOException { + + String postBody = "test post"; + + OkHttpClient client = new OkHttpClient(); + + Request request = new Request.Builder() + .url(URL_SECURED_BY_BASIC_AUTHENTICATION) + .addHeader("Authorization", Credentials.basic("test", "test")) + .post(RequestBody.create(MediaType.parse("text/x-markdown; charset=utf-8"), postBody)) + .build(); + + Call call = client.newCall(request); + Response response = call.execute(); + + assertThat(response.code(), equalTo(200)); + } + + @Test + public void whenPostJson_thenCorrect() throws IOException { + + OkHttpClient client = new OkHttpClient(); + + String json = "{\"id\":1,\"name\":\"John\"}"; + + RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json); + + Request request = new Request.Builder() + .url(BASE_URL + "/users/detail") + .post(body) + .build(); + + Call call = client.newCall(request); + Response response = call.execute(); + + assertThat(response.code(), equalTo(200)); + } + + @Test + public void whenSendMultipartRequest_thenCorrect() throws IOException { + + OkHttpClient client = new OkHttpClient(); + + RequestBody requestBody = new MultipartBody.Builder() + .setType(MultipartBody.FORM) + .addFormDataPart("username", "test") + .addFormDataPart("password", "test") + .addFormDataPart("file", "file.txt", + RequestBody.create(MediaType.parse("application/octet-stream"), new File("src/test/resources/test.txt"))) + .build(); + + Request request = new Request.Builder() + .url(BASE_URL + "/users/multipart") + .post(requestBody) + .build(); + + Call call = client.newCall(request); + Response response = call.execute(); + + assertThat(response.code(), equalTo(200)); + } +} diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpRedirectTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpRedirectTest.java new file mode 100644 index 0000000000..c709253478 --- /dev/null +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpRedirectTest.java @@ -0,0 +1,33 @@ +package org.baeldung.okhttp; + +import static org.hamcrest.Matchers.equalTo; +import static org.junit.Assert.assertThat; + +import java.io.IOException; + +import org.junit.Test; + +import okhttp3.Call; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; + +public class OkHttpRedirectTest { + + @Test + public void whenSetFollowRedirects_thenNotRedirected() throws IOException { + + OkHttpClient client = new OkHttpClient().newBuilder() + .followRedirects(false) + .build(); + + Request request = new Request.Builder() + .url("http://t.co/I5YYd9tddw") + .build(); + + Call call = client.newCall(request); + Response response = call.execute(); + + assertThat(response.code(), equalTo(301)); + } +} diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/ProgressRequestWrapper.java b/spring-rest/src/test/java/org/baeldung/okhttp/ProgressRequestWrapper.java new file mode 100644 index 0000000000..255d10b98a --- /dev/null +++ b/spring-rest/src/test/java/org/baeldung/okhttp/ProgressRequestWrapper.java @@ -0,0 +1,74 @@ +package org.baeldung.okhttp; + +import okhttp3.RequestBody; +import okhttp3.MediaType; + +import java.io.IOException; + +import okio.Buffer; +import okio.BufferedSink; +import okio.ForwardingSink; +import okio.Okio; +import okio.Sink; + +public class ProgressRequestWrapper extends RequestBody { + + protected RequestBody delegate; + protected ProgressListener listener; + + protected CountingSink countingSink; + + public ProgressRequestWrapper(RequestBody delegate, ProgressListener listener) { + this.delegate = delegate; + this.listener = listener; + } + + @Override + public MediaType contentType() { + return delegate.contentType(); + } + + @Override + public long contentLength() throws IOException { + return delegate.contentLength(); + } + + @Override + public void writeTo(BufferedSink sink) throws IOException { + + BufferedSink bufferedSink; + + countingSink = new CountingSink(sink); + bufferedSink = Okio.buffer(countingSink); + + delegate.writeTo(bufferedSink); + + bufferedSink.flush(); + } + + protected final class CountingSink extends ForwardingSink { + + private long bytesWritten = 0; + + public CountingSink(Sink delegate) { + super(delegate); + } + + @Override + public void write(Buffer source, long byteCount) throws IOException { + + super.write(source, byteCount); + + bytesWritten += byteCount; + listener.onRequestProgress(bytesWritten, contentLength()); + } + + } + + public interface ProgressListener { + + void onRequestProgress(long bytesWritten, long contentLength); + + } +} + diff --git a/spring-rest/src/test/resources/test.txt b/spring-rest/src/test/resources/test.txt new file mode 100644 index 0000000000..95d09f2b10 --- /dev/null +++ b/spring-rest/src/test/resources/test.txt @@ -0,0 +1 @@ +hello world \ No newline at end of file From ebc1c54bea85af32ef238f1128a46ba6a84c85dc Mon Sep 17 00:00:00 2001 From: Ivan Paolillo Date: Tue, 11 Oct 2016 10:42:45 +0200 Subject: [PATCH 04/58] Add OkHttp example --- spring-rest/src/test/resources/.gitignore | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 spring-rest/src/test/resources/.gitignore diff --git a/spring-rest/src/test/resources/.gitignore b/spring-rest/src/test/resources/.gitignore deleted file mode 100644 index 83c05e60c8..0000000000 --- a/spring-rest/src/test/resources/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -*.class - -#folders# -/target -/neoDb* -/data -/src/main/webapp/WEB-INF/classes -*/META-INF/* - -# Packaged files # -*.jar -*.war -*.ear \ No newline at end of file From 774b2610504f7c74f6888c89f5687c94d6a94699 Mon Sep 17 00:00:00 2001 From: Ivan Paolillo Date: Tue, 11 Oct 2016 10:44:47 +0200 Subject: [PATCH 05/58] Add OkHttp example --- spring-rest/src/test/resources/.gitignore | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 spring-rest/src/test/resources/.gitignore diff --git a/spring-rest/src/test/resources/.gitignore b/spring-rest/src/test/resources/.gitignore new file mode 100644 index 0000000000..83c05e60c8 --- /dev/null +++ b/spring-rest/src/test/resources/.gitignore @@ -0,0 +1,13 @@ +*.class + +#folders# +/target +/neoDb* +/data +/src/main/webapp/WEB-INF/classes +*/META-INF/* + +# Packaged files # +*.jar +*.war +*.ear \ No newline at end of file From 70eb0501c651b13cc74f9fff1164e7d3aac9bd5b Mon Sep 17 00:00:00 2001 From: Ivan Paolillo Date: Thu, 13 Oct 2016 10:02:09 +0200 Subject: [PATCH 06/58] Delete okhttp project --- okhttp/pom.xml | 76 ------------ .../okhttp/DefaultContentTypeInterceptor.java | 26 ----- .../okhttp/ProgressRequestWrapper.java | 74 ------------ .../okhttp/OkHttpFileUploadingTest.java | 81 ------------- .../org/baeldung/okhttp/OkHttpGetTest.java | 78 ------------- .../org/baeldung/okhttp/OkHttpHeaderTest.java | 48 -------- .../org/baeldung/okhttp/OkHttpMiscTest.java | 107 ----------------- .../baeldung/okhttp/OkHttpPostingTest.java | 109 ------------------ .../baeldung/okhttp/OkHttpRedirectTest.java | 33 ------ okhttp/src/test/resources/test.txt | 1 - 10 files changed, 633 deletions(-) delete mode 100644 okhttp/pom.xml delete mode 100644 okhttp/src/main/java/org/baeldung/okhttp/DefaultContentTypeInterceptor.java delete mode 100644 okhttp/src/main/java/org/baeldung/okhttp/ProgressRequestWrapper.java delete mode 100644 okhttp/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingTest.java delete mode 100644 okhttp/src/test/java/org/baeldung/okhttp/OkHttpGetTest.java delete mode 100644 okhttp/src/test/java/org/baeldung/okhttp/OkHttpHeaderTest.java delete mode 100644 okhttp/src/test/java/org/baeldung/okhttp/OkHttpMiscTest.java delete mode 100644 okhttp/src/test/java/org/baeldung/okhttp/OkHttpPostingTest.java delete mode 100644 okhttp/src/test/java/org/baeldung/okhttp/OkHttpRedirectTest.java delete mode 100644 okhttp/src/test/resources/test.txt diff --git a/okhttp/pom.xml b/okhttp/pom.xml deleted file mode 100644 index 4d371f40b0..0000000000 --- a/okhttp/pom.xml +++ /dev/null @@ -1,76 +0,0 @@ - - 4.0.0 - org.baeldung.okhttp - okhttp - 0.0.1-SNAPSHOT - - - - - - - com.squareup.okhttp3 - okhttp - ${com.squareup.okhttp3.version} - - - - - - org.slf4j - slf4j-api - ${org.slf4j.version} - - - - ch.qos.logback - logback-classic - ${logback.version} - - - - org.slf4j - jcl-over-slf4j - ${org.slf4j.version} - - - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - - - - - junit - junit - ${junit.version} - test - - - - org.hamcrest - hamcrest-library - ${org.hamcrest.version} - test - - - - - - - - 3.4.1 - - - 1.7.13 - 1.1.3 - - - 1.3 - 4.12 - - - - diff --git a/okhttp/src/main/java/org/baeldung/okhttp/DefaultContentTypeInterceptor.java b/okhttp/src/main/java/org/baeldung/okhttp/DefaultContentTypeInterceptor.java deleted file mode 100644 index 2a33a1febd..0000000000 --- a/okhttp/src/main/java/org/baeldung/okhttp/DefaultContentTypeInterceptor.java +++ /dev/null @@ -1,26 +0,0 @@ -package org.baeldung.okhttp; - -import java.io.IOException; - -import okhttp3.Interceptor; -import okhttp3.Request; -import okhttp3.Response; - -public class DefaultContentTypeInterceptor implements Interceptor { - - private final String contentType; - - public DefaultContentTypeInterceptor(String contentType) { - this.contentType = contentType; - } - - public Response intercept(Interceptor.Chain chain) throws IOException { - - Request originalRequest = chain.request(); - Request requestWithUserAgent = originalRequest.newBuilder() - .header("Content-Type", contentType) - .build(); - - return chain.proceed(requestWithUserAgent); - } -} diff --git a/okhttp/src/main/java/org/baeldung/okhttp/ProgressRequestWrapper.java b/okhttp/src/main/java/org/baeldung/okhttp/ProgressRequestWrapper.java deleted file mode 100644 index 255d10b98a..0000000000 --- a/okhttp/src/main/java/org/baeldung/okhttp/ProgressRequestWrapper.java +++ /dev/null @@ -1,74 +0,0 @@ -package org.baeldung.okhttp; - -import okhttp3.RequestBody; -import okhttp3.MediaType; - -import java.io.IOException; - -import okio.Buffer; -import okio.BufferedSink; -import okio.ForwardingSink; -import okio.Okio; -import okio.Sink; - -public class ProgressRequestWrapper extends RequestBody { - - protected RequestBody delegate; - protected ProgressListener listener; - - protected CountingSink countingSink; - - public ProgressRequestWrapper(RequestBody delegate, ProgressListener listener) { - this.delegate = delegate; - this.listener = listener; - } - - @Override - public MediaType contentType() { - return delegate.contentType(); - } - - @Override - public long contentLength() throws IOException { - return delegate.contentLength(); - } - - @Override - public void writeTo(BufferedSink sink) throws IOException { - - BufferedSink bufferedSink; - - countingSink = new CountingSink(sink); - bufferedSink = Okio.buffer(countingSink); - - delegate.writeTo(bufferedSink); - - bufferedSink.flush(); - } - - protected final class CountingSink extends ForwardingSink { - - private long bytesWritten = 0; - - public CountingSink(Sink delegate) { - super(delegate); - } - - @Override - public void write(Buffer source, long byteCount) throws IOException { - - super.write(source, byteCount); - - bytesWritten += byteCount; - listener.onRequestProgress(bytesWritten, contentLength()); - } - - } - - public interface ProgressListener { - - void onRequestProgress(long bytesWritten, long contentLength); - - } -} - diff --git a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingTest.java b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingTest.java deleted file mode 100644 index 77219b8e22..0000000000 --- a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingTest.java +++ /dev/null @@ -1,81 +0,0 @@ -package org.baeldung.okhttp; - -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; - -import java.io.File; -import java.io.IOException; - -import org.baeldung.okhttp.ProgressRequestWrapper; -import org.junit.Test; - -import okhttp3.Call; -import okhttp3.MediaType; -import okhttp3.MultipartBody; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.RequestBody; -import okhttp3.Response; - -public class OkHttpFileUploadingTest { - - private static final String BASE_URL = "http://localhost:8080/spring-rest"; - - @Test - public void whenUploadFile_thenCorrect() throws IOException { - - OkHttpClient client = new OkHttpClient(); - - RequestBody requestBody = new MultipartBody.Builder() - .setType(MultipartBody.FORM) - .addFormDataPart("file", "file.txt", - RequestBody.create(MediaType.parse("application/octet-stream"), new File("src/test/resources/test.txt"))) - .build(); - - Request request = new Request.Builder() - .url(BASE_URL + "/users/upload") - .post(requestBody) - .build(); - - Call call = client.newCall(request); - Response response = call.execute(); - - assertThat(response.code(), equalTo(200)); - } - - @Test - public void whenGetUploadFileProgress_thenCorrect() throws IOException { - - OkHttpClient client = new OkHttpClient(); - - RequestBody requestBody = new MultipartBody.Builder() - .setType(MultipartBody.FORM) - .addFormDataPart("file", "file.txt", - RequestBody.create(MediaType.parse("application/octet-stream"), new File("src/test/resources/test.txt"))) - .build(); - - - ProgressRequestWrapper.ProgressListener listener = new ProgressRequestWrapper.ProgressListener() { - - public void onRequestProgress(long bytesWritten, long contentLength) { - - float percentage = 100f * bytesWritten / contentLength; - assertFalse(Float.compare(percentage, 100) > 0); - } - }; - - ProgressRequestWrapper countingBody = new ProgressRequestWrapper(requestBody, listener); - - Request request = new Request.Builder() - .url(BASE_URL + "/users/upload") - .post(countingBody) - .build(); - - Call call = client.newCall(request); - Response response = call.execute(); - - assertThat(response.code(), equalTo(200)); - - } -} diff --git a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpGetTest.java b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpGetTest.java deleted file mode 100644 index de954e3dd7..0000000000 --- a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpGetTest.java +++ /dev/null @@ -1,78 +0,0 @@ -package org.baeldung.okhttp; - -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; - -import java.io.IOException; - -import org.junit.Test; - -import okhttp3.Call; -import okhttp3.Callback; -import okhttp3.HttpUrl; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; - -public class OkHttpGetTest { - - private static final String BASE_URL = "http://localhost:8080/spring-rest"; - - @Test - public void whenGetRequest_thenCorrect() throws IOException { - - OkHttpClient client = new OkHttpClient(); - - Request request = new Request.Builder() - .url(BASE_URL + "/date") - .build(); - - Call call = client.newCall(request); - Response response = call.execute(); - - assertThat(response.code(), equalTo(200)); - } - - @Test - public void whenGetRequestWithQueryParameter_thenCorrect() throws IOException { - - OkHttpClient client = new OkHttpClient(); - - HttpUrl.Builder urlBuilder = HttpUrl.parse(BASE_URL + "/ex/bars").newBuilder(); - urlBuilder.addQueryParameter("id", "1"); - - String url = urlBuilder.build().toString(); - - Request request = new Request.Builder() - .url(url) - .build(); - - Call call = client.newCall(request); - Response response = call.execute(); - - assertThat(response.code(), equalTo(200)); - } - - @Test - public void whenAsynchronousGetRequest_thenCorrect() { - - OkHttpClient client = new OkHttpClient(); - - Request request = new Request.Builder() - .url(BASE_URL + "/date") - .build(); - - Call call = client.newCall(request); - - call.enqueue(new Callback() { - - public void onResponse(Call call, Response response) throws IOException { - assertThat(response.code(), equalTo(200)); - } - - public void onFailure(Call call, IOException e) { - - } - }); - } -} diff --git a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpHeaderTest.java b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpHeaderTest.java deleted file mode 100644 index 958eeb51ce..0000000000 --- a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpHeaderTest.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.baeldung.okhttp; - -import java.io.IOException; - -import org.junit.Test; - -import okhttp3.Call; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; - -public class OkHttpHeaderTest { - - private static final String SAMPLE_URL = "http://www.github.com"; - - @Test - public void whenSetHeader_thenCorrect() throws IOException { - - OkHttpClient client = new OkHttpClient(); - - Request request = new Request.Builder() - .url(SAMPLE_URL) - .addHeader("Content-Type", "application/json") - .build(); - - Call call = client.newCall(request); - Response response = call.execute(); - response.close(); - } - - @Test - public void whenSetDefaultHeader_thenCorrect() throws IOException { - - OkHttpClient client = new OkHttpClient.Builder() - .addInterceptor(new DefaultContentTypeInterceptor("application/json")) - .build(); - - Request request = new Request.Builder() - .url(SAMPLE_URL) - .build(); - - Call call = client.newCall(request); - Response response = call.execute(); - response.close(); - } - - -} diff --git a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpMiscTest.java b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpMiscTest.java deleted file mode 100644 index fe15a76200..0000000000 --- a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpMiscTest.java +++ /dev/null @@ -1,107 +0,0 @@ -package org.baeldung.okhttp; - -import java.io.File; -import java.io.IOException; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import okhttp3.Cache; -import okhttp3.Call; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; - -public class OkHttpMiscTest { - - private static final String BASE_URL = "http://localhost:8080/spring-rest"; - private static Logger logger = LoggerFactory.getLogger(OkHttpMiscTest.class); - - @Test - public void whenSetRequestTimeout_thenFail() throws IOException { - - OkHttpClient client = new OkHttpClient.Builder() - .readTimeout(1, TimeUnit.SECONDS) - .build(); - - Request request = new Request.Builder() - .url(BASE_URL + "/delay/2") // This URL is served with a 2 second delay. - .build(); - - Call call = client.newCall(request); - Response response = call.execute(); - response.close(); - } - - @Test - public void whenCancelRequest_thenCorrect() throws IOException { - - ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); - - OkHttpClient client = new OkHttpClient(); - - Request request = new Request.Builder() - .url(BASE_URL + "/delay/2") // This URL is served with a 2 second delay. - .build(); - - final int seconds = 1; - - final long startNanos = System.nanoTime(); - final Call call = client.newCall(request); - - // Schedule a job to cancel the call in 1 second. - executor.schedule(new Runnable() { - public void run() { - - logger.debug("Canceling call: " + (System.nanoTime() - startNanos) / 1e9f); - call.cancel(); - logger.debug("Canceled call: " + (System.nanoTime() - startNanos) / 1e9f); - } - }, seconds, TimeUnit.SECONDS); - - try { - - logger.debug("Executing call: " + (System.nanoTime() - startNanos) / 1e9f); - Response response = call.execute(); - logger.debug("Call was expected to fail, but completed: " + (System.nanoTime() - startNanos) / 1e9f, response); - - } catch (IOException e) { - - logger.debug("Call failed as expected: " + (System.nanoTime() - startNanos) / 1e9f, e); - } - } - - @Test - public void whenSetResponseCache_thenCorrect() throws IOException { - - int cacheSize = 10 * 1024 * 1024; // 10 MiB - File cacheDirectory = new File("src/test/resources/cache"); - Cache cache = new Cache(cacheDirectory, cacheSize); - - OkHttpClient client = new OkHttpClient.Builder() - .cache(cache) - .build(); - - Request request = new Request.Builder() - .url("http://publicobject.com/helloworld.txt") - .build(); - - Response response1 = client.newCall(request).execute(); - logResponse(response1); - - Response response2 = client.newCall(request).execute(); - logResponse(response2); - } - - private void logResponse(Response response) throws IOException { - - logger.debug("Response response: " + response); - logger.debug("Response cache response: " + response.cacheResponse()); - logger.debug("Response network response: " + response.networkResponse()); - logger.debug("Response responseBody: " + response.body().string()); - } -} diff --git a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpPostingTest.java b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpPostingTest.java deleted file mode 100644 index 41a024d2ee..0000000000 --- a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpPostingTest.java +++ /dev/null @@ -1,109 +0,0 @@ -package org.baeldung.okhttp; - -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; - -import java.io.File; -import java.io.IOException; - -import org.junit.Test; - -import okhttp3.Call; -import okhttp3.Credentials; -import okhttp3.FormBody; -import okhttp3.MediaType; -import okhttp3.MultipartBody; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.RequestBody; -import okhttp3.Response; - -public class OkHttpPostingTest { - - private static final String BASE_URL = "http://localhost:8080/spring-rest"; - private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://browserspy.dk/password-ok.php"; - - @Test - public void whenSendPostRequest_thenCorrect() throws IOException { - - OkHttpClient client = new OkHttpClient(); - - RequestBody formBody = new FormBody.Builder() - .add("username", "test") - .add("password", "test") - .build(); - - Request request = new Request.Builder() - .url(BASE_URL + "/users") - .post(formBody) - .build(); - - Call call = client.newCall(request); - Response response = call.execute(); - - assertThat(response.code(), equalTo(200)); - } - - @Test - public void whenSendPostRequestWithAuthorization_thenCorrect() throws IOException { - - String postBody = "test post"; - - OkHttpClient client = new OkHttpClient(); - - Request request = new Request.Builder() - .url(URL_SECURED_BY_BASIC_AUTHENTICATION) - .addHeader("Authorization", Credentials.basic("test", "test")) - .post(RequestBody.create(MediaType.parse("text/x-markdown; charset=utf-8"), postBody)) - .build(); - - Call call = client.newCall(request); - Response response = call.execute(); - - assertThat(response.code(), equalTo(200)); - } - - @Test - public void whenPostJson_thenCorrect() throws IOException { - - OkHttpClient client = new OkHttpClient(); - - String json = "{\"id\":1,\"name\":\"John\"}"; - - RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), json); - - Request request = new Request.Builder() - .url(BASE_URL + "/users/detail") - .post(body) - .build(); - - Call call = client.newCall(request); - Response response = call.execute(); - - assertThat(response.code(), equalTo(200)); - } - - @Test - public void whenSendMultipartRequest_thenCorrect() throws IOException { - - OkHttpClient client = new OkHttpClient(); - - RequestBody requestBody = new MultipartBody.Builder() - .setType(MultipartBody.FORM) - .addFormDataPart("username", "test") - .addFormDataPart("password", "test") - .addFormDataPart("file", "file.txt", - RequestBody.create(MediaType.parse("application/octet-stream"), new File("src/test/resources/test.txt"))) - .build(); - - Request request = new Request.Builder() - .url(BASE_URL + "/users/multipart") - .post(requestBody) - .build(); - - Call call = client.newCall(request); - Response response = call.execute(); - - assertThat(response.code(), equalTo(200)); - } -} diff --git a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpRedirectTest.java b/okhttp/src/test/java/org/baeldung/okhttp/OkHttpRedirectTest.java deleted file mode 100644 index c709253478..0000000000 --- a/okhttp/src/test/java/org/baeldung/okhttp/OkHttpRedirectTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.baeldung.okhttp; - -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; - -import java.io.IOException; - -import org.junit.Test; - -import okhttp3.Call; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; - -public class OkHttpRedirectTest { - - @Test - public void whenSetFollowRedirects_thenNotRedirected() throws IOException { - - OkHttpClient client = new OkHttpClient().newBuilder() - .followRedirects(false) - .build(); - - Request request = new Request.Builder() - .url("http://t.co/I5YYd9tddw") - .build(); - - Call call = client.newCall(request); - Response response = call.execute(); - - assertThat(response.code(), equalTo(301)); - } -} diff --git a/okhttp/src/test/resources/test.txt b/okhttp/src/test/resources/test.txt deleted file mode 100644 index 95d09f2b10..0000000000 --- a/okhttp/src/test/resources/test.txt +++ /dev/null @@ -1 +0,0 @@ -hello world \ No newline at end of file From 5329c54f28fc2c6b853454547b62b256f03c2ffc Mon Sep 17 00:00:00 2001 From: Ivan Paolillo Date: Thu, 13 Oct 2016 10:20:18 +0200 Subject: [PATCH 07/58] Code improvement --- pom.xml | 3 +-- spring-rest/README.md | 3 ++- ...ileUploadingTest.java => OkHttpFileUploadingLiveTest.java} | 2 +- .../okhttp/{OkHttpGetTest.java => OkHttpGetLiveTest.java} | 2 +- .../{OkHttpHeaderTest.java => OkHttpHeaderLiveTest.java} | 2 +- .../okhttp/{OkHttpMiscTest.java => OkHttpMiscLiveTest.java} | 4 ++-- .../{OkHttpPostingTest.java => OkHttpPostingLiveTest.java} | 2 +- .../{OkHttpRedirectTest.java => OkHttpRedirectLiveTest.java} | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) rename spring-rest/src/test/java/org/baeldung/okhttp/{OkHttpFileUploadingTest.java => OkHttpFileUploadingLiveTest.java} (95%) rename spring-rest/src/test/java/org/baeldung/okhttp/{OkHttpGetTest.java => OkHttpGetLiveTest.java} (94%) rename spring-rest/src/test/java/org/baeldung/okhttp/{OkHttpHeaderTest.java => OkHttpHeaderLiveTest.java} (93%) rename spring-rest/src/test/java/org/baeldung/okhttp/{OkHttpMiscTest.java => OkHttpMiscLiveTest.java} (95%) rename spring-rest/src/test/java/org/baeldung/okhttp/{OkHttpPostingTest.java => OkHttpPostingLiveTest.java} (95%) rename spring-rest/src/test/java/org/baeldung/okhttp/{OkHttpRedirectTest.java => OkHttpRedirectLiveTest.java} (91%) diff --git a/pom.xml b/pom.xml index 5526c1e2a3..0808397464 100644 --- a/pom.xml +++ b/pom.xml @@ -18,7 +18,7 @@ apache-cxf autovalue-tutorial - + cdi core-java core-java-8 @@ -69,7 +69,6 @@ rest-assured rest-testing resteasy - okhttp spring-all spring-akka diff --git a/spring-rest/README.md b/spring-rest/README.md index 7d993b38b8..77d12063ed 100644 --- a/spring-rest/README.md +++ b/spring-rest/README.md @@ -5,8 +5,9 @@ ###The Course The "REST With Spring" Classes: http://bit.ly/restwithspring -### Relevant Articles: +### Relevant Articles: - [Spring @RequestMapping](http://www.baeldung.com/spring-requestmapping) - [Http Message Converters with the Spring Framework](http://www.baeldung.com/spring-httpmessageconverter-rest) - [Redirect in Spring](http://www.baeldung.com/spring-redirect-and-forward) - [Returning Custom Status Codes from Spring Controllers](http://www.baeldung.com/spring-mvc-controller-custom-http-status-code) +- [A Guide to OkHttp](http://www.baeldung.com/guide-to-okhttp) diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingLiveTest.java similarity index 95% rename from spring-rest/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingTest.java rename to spring-rest/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingLiveTest.java index 77219b8e22..d1cc67b99a 100644 --- a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingTest.java +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpFileUploadingLiveTest.java @@ -18,7 +18,7 @@ import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; -public class OkHttpFileUploadingTest { +public class OkHttpFileUploadingLiveTest { private static final String BASE_URL = "http://localhost:8080/spring-rest"; diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java similarity index 94% rename from spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetTest.java rename to spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java index de954e3dd7..9a49c8d9a2 100644 --- a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetTest.java +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpGetLiveTest.java @@ -14,7 +14,7 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; -public class OkHttpGetTest { +public class OkHttpGetLiveTest { private static final String BASE_URL = "http://localhost:8080/spring-rest"; diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpHeaderTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpHeaderLiveTest.java similarity index 93% rename from spring-rest/src/test/java/org/baeldung/okhttp/OkHttpHeaderTest.java rename to spring-rest/src/test/java/org/baeldung/okhttp/OkHttpHeaderLiveTest.java index 958eeb51ce..8eddfcb135 100644 --- a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpHeaderTest.java +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpHeaderLiveTest.java @@ -9,7 +9,7 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; -public class OkHttpHeaderTest { +public class OkHttpHeaderLiveTest { private static final String SAMPLE_URL = "http://www.github.com"; diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpMiscTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpMiscLiveTest.java similarity index 95% rename from spring-rest/src/test/java/org/baeldung/okhttp/OkHttpMiscTest.java rename to spring-rest/src/test/java/org/baeldung/okhttp/OkHttpMiscLiveTest.java index fe15a76200..c44500f4be 100644 --- a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpMiscTest.java +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpMiscLiveTest.java @@ -16,10 +16,10 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; -public class OkHttpMiscTest { +public class OkHttpMiscLiveTest { private static final String BASE_URL = "http://localhost:8080/spring-rest"; - private static Logger logger = LoggerFactory.getLogger(OkHttpMiscTest.class); + private static Logger logger = LoggerFactory.getLogger(OkHttpMiscLiveTest.class); @Test public void whenSetRequestTimeout_thenFail() throws IOException { diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpPostingTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpPostingLiveTest.java similarity index 95% rename from spring-rest/src/test/java/org/baeldung/okhttp/OkHttpPostingTest.java rename to spring-rest/src/test/java/org/baeldung/okhttp/OkHttpPostingLiveTest.java index 41a024d2ee..18bd4cdcb3 100644 --- a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpPostingTest.java +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpPostingLiveTest.java @@ -18,7 +18,7 @@ import okhttp3.Request; import okhttp3.RequestBody; import okhttp3.Response; -public class OkHttpPostingTest { +public class OkHttpPostingLiveTest { private static final String BASE_URL = "http://localhost:8080/spring-rest"; private static final String URL_SECURED_BY_BASIC_AUTHENTICATION = "http://browserspy.dk/password-ok.php"; diff --git a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpRedirectTest.java b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpRedirectLiveTest.java similarity index 91% rename from spring-rest/src/test/java/org/baeldung/okhttp/OkHttpRedirectTest.java rename to spring-rest/src/test/java/org/baeldung/okhttp/OkHttpRedirectLiveTest.java index c709253478..d568a4fdf7 100644 --- a/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpRedirectTest.java +++ b/spring-rest/src/test/java/org/baeldung/okhttp/OkHttpRedirectLiveTest.java @@ -12,7 +12,7 @@ import okhttp3.OkHttpClient; import okhttp3.Request; import okhttp3.Response; -public class OkHttpRedirectTest { +public class OkHttpRedirectLiveTest { @Test public void whenSetFollowRedirects_thenNotRedirected() throws IOException { From f37718124ae2dc6ab9c7c12c68e4cb17e802cf1e Mon Sep 17 00:00:00 2001 From: DOHA Date: Fri, 14 Oct 2016 12:37:05 +0200 Subject: [PATCH 08/58] skip live test --- spring-zuul/spring-zuul-ui/pom.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/spring-zuul/spring-zuul-ui/pom.xml b/spring-zuul/spring-zuul-ui/pom.xml index 9eaf4b7c45..99df27f2f9 100644 --- a/spring-zuul/spring-zuul-ui/pom.xml +++ b/spring-zuul/spring-zuul-ui/pom.xml @@ -87,5 +87,18 @@ true + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*LiveTest.java + + + + + + \ No newline at end of file From eb2fc383161f3f77a2df45997b7eea24cc3a70c1 Mon Sep 17 00:00:00 2001 From: DOHA Date: Fri, 14 Oct 2016 16:40:06 +0200 Subject: [PATCH 09/58] configure live test --- spring-katharsis/pom.xml | 97 ++++++++++++++++++- .../main/java/org/baeldung/Application.java | 3 +- .../src/main/resources/application.properties | 5 +- .../org/baeldung/test/JsonApiLiveTest.java | 10 +- 4 files changed, 103 insertions(+), 12 deletions(-) diff --git a/spring-katharsis/pom.xml b/spring-katharsis/pom.xml index 892aaf24f1..e2e3ea6f97 100644 --- a/spring-katharsis/pom.xml +++ b/spring-katharsis/pom.xml @@ -3,11 +3,12 @@ org.springframework.samples spring-katharsis 0.0.1-SNAPSHOT + war org.springframework.boot spring-boot-starter-parent - 1.2.6.RELEASE + 1.3.3.RELEASE @@ -62,6 +63,7 @@ 1.8 1.0.0 2.4.0 + 1.6.0 @@ -71,7 +73,100 @@ org.springframework.boot spring-boot-maven-plugin + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*LiveTest.java + + + + + + + + + org.codehaus.cargo + cargo-maven2-plugin + ${cargo-maven2-plugin.version} + + true + + tomcat8x + embedded + + + + + + + 8082 + + + + + + + + + + live + + + + org.codehaus.cargo + cargo-maven2-plugin + + + start-server + pre-integration-test + + start + + + + stop-server + post-integration-test + + stop + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + none + + + **/*LiveTest.java + + + cargo + + + + + + + + + + + diff --git a/spring-katharsis/src/main/java/org/baeldung/Application.java b/spring-katharsis/src/main/java/org/baeldung/Application.java index 1b409f8b91..e7beb16e04 100644 --- a/spring-katharsis/src/main/java/org/baeldung/Application.java +++ b/spring-katharsis/src/main/java/org/baeldung/Application.java @@ -2,9 +2,10 @@ package org.baeldung; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.context.web.SpringBootServletInitializer; @SpringBootApplication -public class Application { +public class Application extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(Application.class, args); diff --git a/spring-katharsis/src/main/resources/application.properties b/spring-katharsis/src/main/resources/application.properties index 25d4559e3d..b55fdbba03 100644 --- a/spring-katharsis/src/main/resources/application.properties +++ b/spring-katharsis/src/main/resources/application.properties @@ -3,4 +3,7 @@ spring.datasource.username = sa spring.datasource.password = spring.jpa.show-sql = false spring.jpa.hibernate.ddl-auto = create-drop -spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.H2Dialect \ No newline at end of file +spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.H2Dialect + +server.port=8082 +server.context-path=/spring-katharsis \ No newline at end of file diff --git a/spring-katharsis/src/test/java/org/baeldung/test/JsonApiLiveTest.java b/spring-katharsis/src/test/java/org/baeldung/test/JsonApiLiveTest.java index bbddba3490..26a8c42a25 100644 --- a/spring-katharsis/src/test/java/org/baeldung/test/JsonApiLiveTest.java +++ b/spring-katharsis/src/test/java/org/baeldung/test/JsonApiLiveTest.java @@ -2,22 +2,14 @@ package org.baeldung.test; import static org.junit.Assert.assertEquals; -import org.baeldung.Application; import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; import com.jayway.restassured.RestAssured; import com.jayway.restassured.response.Response; -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = Application.class) -@WebAppConfiguration public class JsonApiLiveTest { - private final static String URL_PREFIX = "http://localhost:8080/users"; + private final static String URL_PREFIX = "http://localhost:8082/spring-katharsis/users"; @Test public void whenGettingAllUsers_thenCorrect() { From 63024cc8e92e8d93fdbcc0eeb3f6e787b5e48cd2 Mon Sep 17 00:00:00 2001 From: DOHA Date: Sat, 15 Oct 2016 13:48:40 +0200 Subject: [PATCH 10/58] cleanup test --- .../baeldung/spring/PersistenceConfig.java | 2 +- .../src/main/resources/data.sql | 5 ++ .../resources/persistence-h2.properties} | 0 .../baeldung/client/RestTemplateLiveTest.java | 2 +- .../baeldung/common/web/AbstractLiveTest.java | 2 +- .../query/JPACriteriaQueryTest.java | 22 ++++---- .../persistence/query/JPAQuerydslTest.java | 16 +++--- .../query/JPASpecificationLiveTest.java | 30 ++++------- .../query/JPASpecificationTest.java | 16 +++--- .../csrf/CsrfAbstractIntegrationTest.java | 4 +- .../csrf/CsrfEnabledIntegrationTest.java | 4 +- .../security/csrf/SecurityWithCsrfConfig.java | 2 +- .../java/org/baeldung/web/MyUserLiveTest.java | 50 +++++++------------ 13 files changed, 70 insertions(+), 85 deletions(-) create mode 100644 spring-security-rest-full/src/main/resources/data.sql rename spring-security-rest-full/src/{test/resources/persistence-mysql.properties => main/resources/persistence-h2.properties} (100%) diff --git a/spring-security-rest-full/src/main/java/org/baeldung/spring/PersistenceConfig.java b/spring-security-rest-full/src/main/java/org/baeldung/spring/PersistenceConfig.java index dad4808a56..f3a87b189e 100644 --- a/spring-security-rest-full/src/main/java/org/baeldung/spring/PersistenceConfig.java +++ b/spring-security-rest-full/src/main/java/org/baeldung/spring/PersistenceConfig.java @@ -23,7 +23,7 @@ import com.google.common.base.Preconditions; @Configuration @EnableTransactionManagement -@PropertySource({ "classpath:persistence-${envTarget:mysql}.properties" }) +@PropertySource({ "classpath:persistence-${envTarget:h2}.properties" }) @ComponentScan({ "org.baeldung.persistence" }) // @ImportResource("classpath*:springDataPersistenceConfig.xml") @EnableJpaRepositories(basePackages = "org.baeldung.persistence.dao") diff --git a/spring-security-rest-full/src/main/resources/data.sql b/spring-security-rest-full/src/main/resources/data.sql new file mode 100644 index 0000000000..5fba12dd85 --- /dev/null +++ b/spring-security-rest-full/src/main/resources/data.sql @@ -0,0 +1,5 @@ +insert into User (id, firstName, lastName, email, age) values (1, 'john', 'doe', 'john@doe.com', 22); +insert into User (id, firstName, lastName, email, age) values (2, 'tom', 'doe', 'tom@doe.com', 26); + +insert into MyUser (id, firstName, lastName, email, age) values (1, 'john', 'doe', 'john@doe.com', 22); +insert into MyUser (id, firstName, lastName, email, age) values (2, 'tom', 'doe', 'tom@doe.com', 26); diff --git a/spring-security-rest-full/src/test/resources/persistence-mysql.properties b/spring-security-rest-full/src/main/resources/persistence-h2.properties similarity index 100% rename from spring-security-rest-full/src/test/resources/persistence-mysql.properties rename to spring-security-rest-full/src/main/resources/persistence-h2.properties diff --git a/spring-security-rest-full/src/test/java/org/baeldung/client/RestTemplateLiveTest.java b/spring-security-rest-full/src/test/java/org/baeldung/client/RestTemplateLiveTest.java index fb40bd9d62..0f0a73b536 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/client/RestTemplateLiveTest.java +++ b/spring-security-rest-full/src/test/java/org/baeldung/client/RestTemplateLiveTest.java @@ -51,7 +51,7 @@ import com.google.common.base.Charsets; public class RestTemplateLiveTest { private RestTemplate restTemplate; - private static final String fooResourceUrl = "http://localhost:" + APPLICATION_PORT + "/foos"; + private static final String fooResourceUrl = "http://localhost:" + APPLICATION_PORT + "/auth/foos"; @Before public void beforeTest() { diff --git a/spring-security-rest-full/src/test/java/org/baeldung/common/web/AbstractLiveTest.java b/spring-security-rest-full/src/test/java/org/baeldung/common/web/AbstractLiveTest.java index 95fce10e45..a3e6c8858d 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/common/web/AbstractLiveTest.java +++ b/spring-security-rest-full/src/test/java/org/baeldung/common/web/AbstractLiveTest.java @@ -57,7 +57,7 @@ public abstract class AbstractLiveTest { // protected String getURL() { - return "http://localhost:" + APPLICATION_PORT + "/foos"; + return "http://localhost:" + APPLICATION_PORT + "/auth/foos"; } protected final RequestSpecification givenAuth() { diff --git a/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPACriteriaQueryTest.java b/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPACriteriaQueryTest.java index e9c8659347..1d0826e6ba 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPACriteriaQueryTest.java +++ b/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPACriteriaQueryTest.java @@ -36,15 +36,15 @@ public class JPACriteriaQueryTest { @Before public void init() { userJohn = new User(); - userJohn.setFirstName("John"); - userJohn.setLastName("Doe"); + userJohn.setFirstName("john"); + userJohn.setLastName("doe"); userJohn.setEmail("john@doe.com"); userJohn.setAge(22); userApi.save(userJohn); userTom = new User(); - userTom.setFirstName("Tom"); - userTom.setLastName("Doe"); + userTom.setFirstName("tom"); + userTom.setLastName("doe"); userTom.setEmail("tom@doe.com"); userTom.setAge(26); userApi.save(userTom); @@ -53,8 +53,8 @@ public class JPACriteriaQueryTest { @Test public void givenFirstAndLastName_whenGettingListOfUsers_thenCorrect() { final List params = new ArrayList(); - params.add(new SearchCriteria("firstName", ":", "John")); - params.add(new SearchCriteria("lastName", ":", "Doe")); + params.add(new SearchCriteria("firstName", ":", "john")); + params.add(new SearchCriteria("lastName", ":", "doe")); final List results = userApi.searchUser(params); @@ -65,7 +65,7 @@ public class JPACriteriaQueryTest { @Test public void givenLast_whenGettingListOfUsers_thenCorrect() { final List params = new ArrayList(); - params.add(new SearchCriteria("lastName", ":", "Doe")); + params.add(new SearchCriteria("lastName", ":", "doe")); final List results = userApi.searchUser(params); assertThat(userJohn, isIn(results)); @@ -75,7 +75,7 @@ public class JPACriteriaQueryTest { @Test public void givenLastAndAge_whenGettingListOfUsers_thenCorrect() { final List params = new ArrayList(); - params.add(new SearchCriteria("lastName", ":", "Doe")); + params.add(new SearchCriteria("lastName", ":", "doe")); params.add(new SearchCriteria("age", ">", "25")); final List results = userApi.searchUser(params); @@ -87,8 +87,8 @@ public class JPACriteriaQueryTest { @Test public void givenWrongFirstAndLast_whenGettingListOfUsers_thenCorrect() { final List params = new ArrayList(); - params.add(new SearchCriteria("firstName", ":", "Adam")); - params.add(new SearchCriteria("lastName", ":", "Fox")); + params.add(new SearchCriteria("firstName", ":", "adam")); + params.add(new SearchCriteria("lastName", ":", "fox")); final List results = userApi.searchUser(params); assertThat(userJohn, not(isIn(results))); @@ -98,7 +98,7 @@ public class JPACriteriaQueryTest { @Test public void givenPartialFirst_whenGettingListOfUsers_thenCorrect() { final List params = new ArrayList(); - params.add(new SearchCriteria("firstName", ":", "Jo")); + params.add(new SearchCriteria("firstName", ":", "jo")); final List results = userApi.searchUser(params); diff --git a/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPAQuerydslTest.java b/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPAQuerydslTest.java index b7b38a4fcb..d5fbc819fd 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPAQuerydslTest.java +++ b/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPAQuerydslTest.java @@ -35,15 +35,15 @@ public class JPAQuerydslTest { @Before public void init() { userJohn = new MyUser(); - userJohn.setFirstName("John"); - userJohn.setLastName("Doe"); + userJohn.setFirstName("john"); + userJohn.setLastName("doe"); userJohn.setEmail("john@doe.com"); userJohn.setAge(22); repo.save(userJohn); userTom = new MyUser(); - userTom.setFirstName("Tom"); - userTom.setLastName("Doe"); + userTom.setFirstName("tom"); + userTom.setLastName("doe"); userTom.setEmail("tom@doe.com"); userTom.setAge(26); repo.save(userTom); @@ -51,7 +51,7 @@ public class JPAQuerydslTest { @Test public void givenLast_whenGettingListOfUsers_thenCorrect() { - final MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder().with("lastName", ":", "Doe"); + final MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder().with("lastName", ":", "doe"); final Iterable results = repo.findAll(builder.build()); assertThat(results, containsInAnyOrder(userJohn, userTom)); @@ -59,7 +59,7 @@ public class JPAQuerydslTest { @Test public void givenFirstAndLastName_whenGettingListOfUsers_thenCorrect() { - final MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder().with("firstName", ":", "John").with("lastName", ":", "Doe"); + final MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder().with("firstName", ":", "john").with("lastName", ":", "doe"); final Iterable results = repo.findAll(builder.build()); @@ -69,7 +69,7 @@ public class JPAQuerydslTest { @Test public void givenLastAndAge_whenGettingListOfUsers_thenCorrect() { - final MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder().with("lastName", ":", "Doe").with("age", ">", "25"); + final MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder().with("lastName", ":", "doe").with("age", ">", "25"); final Iterable results = repo.findAll(builder.build()); @@ -79,7 +79,7 @@ public class JPAQuerydslTest { @Test public void givenWrongFirstAndLast_whenGettingListOfUsers_thenCorrect() { - final MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder().with("firstName", ":", "Adam").with("lastName", ":", "Fox"); + final MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder().with("firstName", ":", "adam").with("lastName", ":", "fox"); final Iterable results = repo.findAll(builder.build()); assertThat(results, emptyIterable()); diff --git a/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPASpecificationLiveTest.java b/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPASpecificationLiveTest.java index 544161dfd5..4fa15d536a 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPASpecificationLiveTest.java +++ b/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPASpecificationLiveTest.java @@ -3,52 +3,44 @@ package org.baeldung.persistence.query; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import org.baeldung.persistence.dao.UserRepository; import org.baeldung.persistence.model.User; -import org.baeldung.spring.ConfigTest; -import org.baeldung.spring.PersistenceConfig; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.support.AnnotationConfigContextLoader; import com.jayway.restassured.RestAssured; import com.jayway.restassured.response.Response; import com.jayway.restassured.specification.RequestSpecification; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { ConfigTest.class, PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) +//@RunWith(SpringJUnit4ClassRunner.class) +//@ContextConfiguration(classes = { ConfigTest.class, PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class) @ActiveProfiles("test") public class JPASpecificationLiveTest { - @Autowired - private UserRepository repository; + // @Autowired + // private UserRepository repository; private User userJohn; private User userTom; - private final String URL_PREFIX = "http://localhost:8080/users/spec?search="; + private final String URL_PREFIX = "http://localhost:8080/auth/users/spec?search="; @Before public void init() { userJohn = new User(); - userJohn.setFirstName("John"); - userJohn.setLastName("Doe"); + userJohn.setFirstName("john"); + userJohn.setLastName("doe"); userJohn.setEmail("john@doe.com"); userJohn.setAge(22); - repository.save(userJohn); + // repository.save(userJohn); userTom = new User(); - userTom.setFirstName("Tom"); - userTom.setLastName("Doe"); + userTom.setFirstName("tom"); + userTom.setLastName("doe"); userTom.setEmail("tom@doe.com"); userTom.setAge(26); - repository.save(userTom); + // repository.save(userTom); } @Test diff --git a/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPASpecificationTest.java b/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPASpecificationTest.java index 52bd43cc8c..0d8773dd61 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPASpecificationTest.java +++ b/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPASpecificationTest.java @@ -38,15 +38,15 @@ public class JPASpecificationTest { @Before public void init() { userJohn = new User(); - userJohn.setFirstName("John"); - userJohn.setLastName("Doe"); + userJohn.setFirstName("john"); + userJohn.setLastName("doe"); userJohn.setEmail("john@doe.com"); userJohn.setAge(22); repository.save(userJohn); userTom = new User(); - userTom.setFirstName("Tom"); - userTom.setLastName("Doe"); + userTom.setFirstName("tom"); + userTom.setLastName("doe"); userTom.setEmail("tom@doe.com"); userTom.setAge(26); repository.save(userTom); @@ -54,8 +54,8 @@ public class JPASpecificationTest { @Test public void givenFirstAndLastName_whenGettingListOfUsers_thenCorrect() { - final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.EQUALITY, "John")); - final UserSpecification spec1 = new UserSpecification(new SpecSearchCriteria("lastName", SearchOperation.EQUALITY, "Doe")); + final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.EQUALITY, "john")); + final UserSpecification spec1 = new UserSpecification(new SpecSearchCriteria("lastName", SearchOperation.EQUALITY, "doe")); final List results = repository.findAll(Specifications.where(spec).and(spec1)); assertThat(userJohn, isIn(results)); @@ -64,7 +64,7 @@ public class JPASpecificationTest { @Test public void givenFirstNameInverse_whenGettingListOfUsers_thenCorrect() { - final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.NEGATION, "John")); + final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.NEGATION, "john")); final List results = repository.findAll(Specifications.where(spec)); assertThat(userTom, isIn(results)); @@ -82,7 +82,7 @@ public class JPASpecificationTest { @Test public void givenFirstNamePrefix_whenGettingListOfUsers_thenCorrect() { - final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.STARTS_WITH, "Jo")); + final UserSpecification spec = new UserSpecification(new SpecSearchCriteria("firstName", SearchOperation.STARTS_WITH, "jo")); final List results = repository.findAll(spec); assertThat(userJohn, isIn(results)); diff --git a/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/CsrfAbstractIntegrationTest.java b/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/CsrfAbstractIntegrationTest.java index 13cb92a745..be9b7cf27e 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/CsrfAbstractIntegrationTest.java +++ b/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/CsrfAbstractIntegrationTest.java @@ -23,7 +23,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @Transactional -public class CsrfAbstractIntegrationTest { +public abstract class CsrfAbstractIntegrationTest { @Autowired private WebApplicationContext context; @@ -41,7 +41,7 @@ public class CsrfAbstractIntegrationTest { } protected RequestPostProcessor testUser() { - return user("user").password("userPass").roles("USER"); + return user("user1").password("user1Pass").roles("USER"); } protected RequestPostProcessor testAdmin() { diff --git a/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/CsrfEnabledIntegrationTest.java b/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/CsrfEnabledIntegrationTest.java index c7caf61525..b04644f847 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/CsrfEnabledIntegrationTest.java +++ b/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/CsrfEnabledIntegrationTest.java @@ -15,12 +15,12 @@ public class CsrfEnabledIntegrationTest extends CsrfAbstractIntegrationTest { @Test public void givenNoCsrf_whenAddFoo_thenForbidden() throws Exception { - mvc.perform(post("/foos").contentType(MediaType.APPLICATION_JSON).content(createFoo()).with(testUser())).andExpect(status().isForbidden()); + mvc.perform(post("/auth/foos").contentType(MediaType.APPLICATION_JSON).content(createFoo()).with(testUser())).andExpect(status().isForbidden()); } @Test public void givenCsrf_whenAddFoo_thenCreated() throws Exception { - mvc.perform(post("/foos").contentType(MediaType.APPLICATION_JSON).content(createFoo()).with(testUser()).with(csrf())).andExpect(status().isCreated()); + mvc.perform(post("/auth/foos").contentType(MediaType.APPLICATION_JSON).content(createFoo()).with(testUser()).with(csrf())).andExpect(status().isCreated()); } } diff --git a/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/SecurityWithCsrfConfig.java b/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/SecurityWithCsrfConfig.java index 99b94cd7b5..ae4a655265 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/SecurityWithCsrfConfig.java +++ b/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/SecurityWithCsrfConfig.java @@ -41,7 +41,7 @@ public class SecurityWithCsrfConfig extends WebSecurityConfigurerAdapter { // @formatter:off http .authorizeRequests() - .antMatchers("/admin/*").hasAnyRole("ROLE_ADMIN") + .antMatchers("/auth/admin/*").hasAnyRole("ROLE_ADMIN") .anyRequest().authenticated() .and() .httpBasic() diff --git a/spring-security-rest-full/src/test/java/org/baeldung/web/MyUserLiveTest.java b/spring-security-rest-full/src/test/java/org/baeldung/web/MyUserLiveTest.java index 835b32c95c..c7fb26d70b 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/web/MyUserLiveTest.java +++ b/spring-security-rest-full/src/test/java/org/baeldung/web/MyUserLiveTest.java @@ -3,52 +3,44 @@ package org.baeldung.web; import static org.junit.Assert.assertEquals; import org.baeldung.persistence.model.MyUser; -import org.baeldung.spring.ConfigTest; -import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.http.MediaType; import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.support.AnnotationConfigContextLoader; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.jayway.restassured.RestAssured; import com.jayway.restassured.response.Response; import com.jayway.restassured.specification.RequestSpecification; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { ConfigTest.class }, loader = AnnotationConfigContextLoader.class) +//@RunWith(SpringJUnit4ClassRunner.class) +//@ContextConfiguration(classes = { ConfigTest.class }, loader = AnnotationConfigContextLoader.class) @ActiveProfiles("test") public class MyUserLiveTest { - private ObjectMapper mapper = new ObjectMapper(); - private MyUser userJohn = new MyUser("john", "doe", "john@test.com", 11); - private MyUser userTom = new MyUser("tom", "doe", "tom@test.com", 20); + private final ObjectMapper mapper = new ObjectMapper(); + private final MyUser userJohn = new MyUser("john", "doe", "john@doe.com", 11); + private final MyUser userTom = new MyUser("tom", "doe", "tom@doe.com", 20); - private static boolean setupDataCreated = false; - - @Before - public void setupData() throws JsonProcessingException { - if (!setupDataCreated) { - withRequestBody(givenAuth(), userJohn).post("http://localhost:8080/myusers"); - withRequestBody(givenAuth(), userTom).post("http://localhost:8080/myusers"); - setupDataCreated = true; - } - } + // private static boolean setupDataCreated = false; + // + // @Before + // public void setupData() throws JsonProcessingException { + // if (!setupDataCreated) { + // withRequestBody(givenAuth(), userJohn).post("http://localhost:8080/auth/myusers"); + // withRequestBody(givenAuth(), userTom).post("http://localhost:8080/auth/myusers"); + // setupDataCreated = true; + // } + // } @Test public void whenGettingListOfUsers_thenCorrect() { - final Response response = givenAuth().get("http://localhost:8080/api/myusers"); + final Response response = givenAuth().get("http://localhost:8080/auth/api/myusers"); final MyUser[] result = response.as(MyUser[].class); assertEquals(result.length, 2); } @Test public void givenFirstName_whenGettingListOfUsers_thenCorrect() { - final Response response = givenAuth().get("http://localhost:8080/api/myusers?firstName=john"); + final Response response = givenAuth().get("http://localhost:8080/auth/api/myusers?firstName=john"); final MyUser[] result = response.as(MyUser[].class); assertEquals(result.length, 1); assertEquals(result[0].getEmail(), userJohn.getEmail()); @@ -56,14 +48,14 @@ public class MyUserLiveTest { @Test public void givenPartialLastName_whenGettingListOfUsers_thenCorrect() { - final Response response = givenAuth().get("http://localhost:8080/api/myusers?lastName=do"); + final Response response = givenAuth().get("http://localhost:8080/auth/api/myusers?lastName=do"); final MyUser[] result = response.as(MyUser[].class); assertEquals(result.length, 2); } @Test public void givenEmail_whenGettingListOfUsers_thenIgnored() { - final Response response = givenAuth().get("http://localhost:8080/api/myusers?email=john"); + final Response response = givenAuth().get("http://localhost:8080/auth/api/myusers?email=john"); final MyUser[] result = response.as(MyUser[].class); assertEquals(result.length, 2); } @@ -71,8 +63,4 @@ public class MyUserLiveTest { private RequestSpecification givenAuth() { return RestAssured.given().auth().preemptive().basic("user1", "user1Pass"); } - - private RequestSpecification withRequestBody(final RequestSpecification req, final Object obj) throws JsonProcessingException { - return req.contentType(MediaType.APPLICATION_JSON_VALUE).body(mapper.writeValueAsString(obj)); - } } From bf887e71d9949c815e6e521d85d4c17c60d03560 Mon Sep 17 00:00:00 2001 From: DOHA Date: Sat, 15 Oct 2016 16:44:51 +0200 Subject: [PATCH 11/58] minor cleanup --- ...dResultsRetrievedDiscoverabilityListener.java | 6 +++--- .../java/org/baeldung/web/MyUserLiveTest.java | 16 ---------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/hateoas/listener/PaginatedResultsRetrievedDiscoverabilityListener.java b/spring-security-rest-full/src/main/java/org/baeldung/web/hateoas/listener/PaginatedResultsRetrievedDiscoverabilityListener.java index 312ead0ab0..603c91007d 100644 --- a/spring-security-rest-full/src/main/java/org/baeldung/web/hateoas/listener/PaginatedResultsRetrievedDiscoverabilityListener.java +++ b/spring-security-rest-full/src/main/java/org/baeldung/web/hateoas/listener/PaginatedResultsRetrievedDiscoverabilityListener.java @@ -77,7 +77,7 @@ class PaginatedResultsRetrievedDiscoverabilityListener implements ApplicationLis } final boolean hasNextPage(final int page, final int totalPages) { - return page < totalPages - 1; + return page < (totalPages - 1); } final boolean hasPreviousPage(final int page) { @@ -89,7 +89,7 @@ class PaginatedResultsRetrievedDiscoverabilityListener implements ApplicationLis } final boolean hasLastPage(final int page, final int totalPages) { - return totalPages > 1 && hasNextPage(page, totalPages); + return (totalPages > 1) && hasNextPage(page, totalPages); } final void appendCommaIfNecessary(final StringBuilder linkHeader) { @@ -102,7 +102,7 @@ class PaginatedResultsRetrievedDiscoverabilityListener implements ApplicationLis protected void plural(final UriComponentsBuilder uriBuilder, final Class clazz) { final String resourceName = clazz.getSimpleName().toLowerCase() + "s"; - uriBuilder.path("/" + resourceName); + uriBuilder.path("/auth/" + resourceName); } } diff --git a/spring-security-rest-full/src/test/java/org/baeldung/web/MyUserLiveTest.java b/spring-security-rest-full/src/test/java/org/baeldung/web/MyUserLiveTest.java index c7fb26d70b..4a3bd50f90 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/web/MyUserLiveTest.java +++ b/spring-security-rest-full/src/test/java/org/baeldung/web/MyUserLiveTest.java @@ -6,30 +6,14 @@ import org.baeldung.persistence.model.MyUser; import org.junit.Test; import org.springframework.test.context.ActiveProfiles; -import com.fasterxml.jackson.databind.ObjectMapper; import com.jayway.restassured.RestAssured; import com.jayway.restassured.response.Response; import com.jayway.restassured.specification.RequestSpecification; -//@RunWith(SpringJUnit4ClassRunner.class) -//@ContextConfiguration(classes = { ConfigTest.class }, loader = AnnotationConfigContextLoader.class) @ActiveProfiles("test") public class MyUserLiveTest { - private final ObjectMapper mapper = new ObjectMapper(); private final MyUser userJohn = new MyUser("john", "doe", "john@doe.com", 11); - private final MyUser userTom = new MyUser("tom", "doe", "tom@doe.com", 20); - - // private static boolean setupDataCreated = false; - // - // @Before - // public void setupData() throws JsonProcessingException { - // if (!setupDataCreated) { - // withRequestBody(givenAuth(), userJohn).post("http://localhost:8080/auth/myusers"); - // withRequestBody(givenAuth(), userTom).post("http://localhost:8080/auth/myusers"); - // setupDataCreated = true; - // } - // } @Test public void whenGettingListOfUsers_thenCorrect() { From 66c5db02a3602c3d9c571f8d12938398e061e6eb Mon Sep 17 00:00:00 2001 From: DOHA Date: Sat, 15 Oct 2016 17:34:11 +0200 Subject: [PATCH 12/58] configure test profiles --- spring-security-rest-full/pom.xml | 39 ++++++++++++++++++- .../java/org/baeldung/spring/Application.java | 2 +- .../src/main/resources/application.properties | 2 + .../src/test/java/org/baeldung/Consts.java | 2 +- .../baeldung/client/RestTemplateLiveTest.java | 2 +- .../baeldung/common/web/AbstractLiveTest.java | 2 +- .../query/JPASpecificationLiveTest.java | 2 +- .../java/org/baeldung/web/MyUserLiveTest.java | 10 ++--- 8 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 spring-security-rest-full/src/main/resources/application.properties diff --git a/spring-security-rest-full/pom.xml b/spring-security-rest-full/pom.xml index b354e61b35..5cd0ed51f3 100644 --- a/spring-security-rest-full/pom.xml +++ b/spring-security-rest-full/pom.xml @@ -339,7 +339,7 @@ - 8080 + 8082 @@ -386,10 +386,45 @@ - none + **/*LiveTest.java **/*IntegrationTest.java + + + + + + + json + + + + + + + + + + live + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*IntegrationTest.java + + **/*LiveTest.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/spring/Application.java b/spring-security-rest-full/src/main/java/org/baeldung/spring/Application.java index c44e37fee8..f8bc6c0160 100644 --- a/spring-security-rest-full/src/main/java/org/baeldung/spring/Application.java +++ b/spring-security-rest-full/src/main/java/org/baeldung/spring/Application.java @@ -10,7 +10,7 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter /** * Main Application Class - uses Spring Boot. Just run this as a normal Java - * class to run up a Jetty Server (on http://localhost:8080) + * class to run up a Jetty Server (on http://localhost:8082/spring-security-rest-full) * */ @EnableScheduling diff --git a/spring-security-rest-full/src/main/resources/application.properties b/spring-security-rest-full/src/main/resources/application.properties new file mode 100644 index 0000000000..58c6f8eec7 --- /dev/null +++ b/spring-security-rest-full/src/main/resources/application.properties @@ -0,0 +1,2 @@ +server.port=8082 +server.context-path=/spring-security-rest-full \ No newline at end of file diff --git a/spring-security-rest-full/src/test/java/org/baeldung/Consts.java b/spring-security-rest-full/src/test/java/org/baeldung/Consts.java index 9c44d63c4d..e5f0be160f 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/Consts.java +++ b/spring-security-rest-full/src/test/java/org/baeldung/Consts.java @@ -1,5 +1,5 @@ package org.baeldung; public interface Consts { - int APPLICATION_PORT = 8080; + int APPLICATION_PORT = 8082; } diff --git a/spring-security-rest-full/src/test/java/org/baeldung/client/RestTemplateLiveTest.java b/spring-security-rest-full/src/test/java/org/baeldung/client/RestTemplateLiveTest.java index 0f0a73b536..a1cd9fcfe1 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/client/RestTemplateLiveTest.java +++ b/spring-security-rest-full/src/test/java/org/baeldung/client/RestTemplateLiveTest.java @@ -51,7 +51,7 @@ import com.google.common.base.Charsets; public class RestTemplateLiveTest { private RestTemplate restTemplate; - private static final String fooResourceUrl = "http://localhost:" + APPLICATION_PORT + "/auth/foos"; + private static final String fooResourceUrl = "http://localhost:" + APPLICATION_PORT + "/spring-security-rest-full/auth/foos"; @Before public void beforeTest() { diff --git a/spring-security-rest-full/src/test/java/org/baeldung/common/web/AbstractLiveTest.java b/spring-security-rest-full/src/test/java/org/baeldung/common/web/AbstractLiveTest.java index a3e6c8858d..a2890d8643 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/common/web/AbstractLiveTest.java +++ b/spring-security-rest-full/src/test/java/org/baeldung/common/web/AbstractLiveTest.java @@ -57,7 +57,7 @@ public abstract class AbstractLiveTest { // protected String getURL() { - return "http://localhost:" + APPLICATION_PORT + "/auth/foos"; + return "http://localhost:" + APPLICATION_PORT + "/spring-security-rest-full/auth/foos"; } protected final RequestSpecification givenAuth() { diff --git a/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPASpecificationLiveTest.java b/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPASpecificationLiveTest.java index 4fa15d536a..3b85cfb487 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPASpecificationLiveTest.java +++ b/spring-security-rest-full/src/test/java/org/baeldung/persistence/query/JPASpecificationLiveTest.java @@ -24,7 +24,7 @@ public class JPASpecificationLiveTest { private User userTom; - private final String URL_PREFIX = "http://localhost:8080/auth/users/spec?search="; + private final String URL_PREFIX = "http://localhost:8082/spring-security-rest-full/auth/users/spec?search="; @Before public void init() { diff --git a/spring-security-rest-full/src/test/java/org/baeldung/web/MyUserLiveTest.java b/spring-security-rest-full/src/test/java/org/baeldung/web/MyUserLiveTest.java index 4a3bd50f90..16ed9db253 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/web/MyUserLiveTest.java +++ b/spring-security-rest-full/src/test/java/org/baeldung/web/MyUserLiveTest.java @@ -14,17 +14,17 @@ import com.jayway.restassured.specification.RequestSpecification; public class MyUserLiveTest { private final MyUser userJohn = new MyUser("john", "doe", "john@doe.com", 11); - + private String URL_PREFIX = "http://localhost:8082/spring-security-rest-full/auth/api/myusers"; @Test public void whenGettingListOfUsers_thenCorrect() { - final Response response = givenAuth().get("http://localhost:8080/auth/api/myusers"); + final Response response = givenAuth().get(URL_PREFIX); final MyUser[] result = response.as(MyUser[].class); assertEquals(result.length, 2); } @Test public void givenFirstName_whenGettingListOfUsers_thenCorrect() { - final Response response = givenAuth().get("http://localhost:8080/auth/api/myusers?firstName=john"); + final Response response = givenAuth().get(URL_PREFIX + "?firstName=john"); final MyUser[] result = response.as(MyUser[].class); assertEquals(result.length, 1); assertEquals(result[0].getEmail(), userJohn.getEmail()); @@ -32,14 +32,14 @@ public class MyUserLiveTest { @Test public void givenPartialLastName_whenGettingListOfUsers_thenCorrect() { - final Response response = givenAuth().get("http://localhost:8080/auth/api/myusers?lastName=do"); + final Response response = givenAuth().get(URL_PREFIX + "?lastName=do"); final MyUser[] result = response.as(MyUser[].class); assertEquals(result.length, 2); } @Test public void givenEmail_whenGettingListOfUsers_thenIgnored() { - final Response response = givenAuth().get("http://localhost:8080/auth/api/myusers?email=john"); + final Response response = givenAuth().get(URL_PREFIX + "?email=john"); final MyUser[] result = response.as(MyUser[].class); assertEquals(result.length, 2); } From db2b93a1b65a217c6de07642f17d73950ec143ae Mon Sep 17 00:00:00 2001 From: Ante Pocedulic Date: Sun, 16 Oct 2016 11:12:51 +0200 Subject: [PATCH 13/58] Ehcache article source code (#751) * - created packages for each logical part of application - created validator for WebsiteUser rest API - created ValidatorEventRegister class which fixes known bug for not detecting generated events - created custom Exception Handler which creates better response messages * Code formatting * formated pom.xml replaced for loops with streams fixed bug while getting all beans * removed unnecessary code changed repository type * - added test for Spring Data REST APIs - changed bad request return code - formated code * - added source code for ehcache article - added ehcache dependency to pom.xml * - added test for ehcache article - removed main method which was only for testing purposes --- .../ehcache/SquareCalculatorTest.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 spring-all/src/test/java/org/baeldung/ehcache/SquareCalculatorTest.java diff --git a/spring-all/src/test/java/org/baeldung/ehcache/SquareCalculatorTest.java b/spring-all/src/test/java/org/baeldung/ehcache/SquareCalculatorTest.java new file mode 100644 index 0000000000..875fd2a25e --- /dev/null +++ b/spring-all/src/test/java/org/baeldung/ehcache/SquareCalculatorTest.java @@ -0,0 +1,43 @@ +package org.baeldung.ehcache; + +import static org.junit.Assert.*; + +import org.baeldung.ehcache.calculator.SquaredCalculator; +import org.baeldung.ehcache.config.CacheHelper; +import org.junit.Before; +import org.junit.Test; + +public class SquareCalculatorTest { + SquaredCalculator squaredCalculator = new SquaredCalculator(); + CacheHelper cacheHelper = new CacheHelper(); + + @Before + public void setup() { + squaredCalculator.setCache(cacheHelper); + + } + + @Test + public void whenCalculatingSquareValueOnce_thenCacheDontHaveValues() { + for (int i = 10; i < 15; i++) { + assertFalse(cacheHelper.getSquareNumberCache().containsKey(i)); + System.out.println("Square value of " + i + " is: " + + squaredCalculator.getSquareValueOfNumber(i) + "\n"); + } + } + + @Test + public void whenCalculatingSquareValueAgain_thenCacheHasAllValues() { + for (int i = 10; i < 15; i++) { + assertFalse(cacheHelper.getSquareNumberCache().containsKey(i)); + System.out.println("Square value of " + i + " is: " + + squaredCalculator.getSquareValueOfNumber(i) + "\n"); + } + + for (int i = 10; i < 15; i++) { + assertTrue(cacheHelper.getSquareNumberCache().containsKey(i)); + System.out.println("Square value of " + i + " is: " + + squaredCalculator.getSquareValueOfNumber(i) + "\n"); + } + } +} From 6c509ba738c326a31e03b867cfb4e8c1729926b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20van=20de=20Giessen?= Date: Sun, 16 Oct 2016 12:00:10 +0200 Subject: [PATCH 14/58] some minor cleanup (#649) * minor cleanup pom maven.compiler java versions as properties only specifing spring-data-elasticsearch as dependency formatting net.java.dev.jna dependency grouping main/test and logging dependencies removed unused org.springframework.data.version property * updated logback conf to this example * builder patttern code on multiple lines for readablilty * autowire via constructor into final variable as of spring-4.3 the @Autowired can be omitted \o/ jaj * @ContextConfiguration with less config --- spring-data-elasticsearch/pom.xml | 33 ++++++++----------- .../spring/data/es/config/Config.java | 14 +++++--- .../data/es/service/ArticleServiceImpl.java | 6 ++-- .../src/main/resources/logback.xml | 6 ++-- .../data/es/ElasticSearchQueryTest.java | 3 +- .../spring/data/es/ElasticSearchTest.java | 3 +- 6 files changed, 30 insertions(+), 35 deletions(-) diff --git a/spring-data-elasticsearch/pom.xml b/spring-data-elasticsearch/pom.xml index 084695c2f3..42cf8fc740 100644 --- a/spring-data-elasticsearch/pom.xml +++ b/spring-data-elasticsearch/pom.xml @@ -11,8 +11,9 @@ UTF-8 + 1.8 + 1.8 - 1.3.2.RELEASE 4.2.5.RELEASE 4.11 @@ -27,6 +28,12 @@ spring-core ${org.springframework.version} + + org.springframework.data + spring-data-elasticsearch + ${elasticsearch.version} + + junit junit-dep @@ -39,16 +46,13 @@ ${org.springframework.version} test - - org.springframework.data - spring-data-elasticsearch - ${elasticsearch.version} - - net.java.dev.jna + + net.java.dev.jna jna 4.1.0 test + org.slf4j slf4j-api @@ -81,16 +85,5 @@ 1.2.13 - - - - maven-compiler-plugin - 2.3.2 - - 1.8 - 1.8 - - - - - + + \ No newline at end of file diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/config/Config.java b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/config/Config.java index f93999a1cc..37e9fd46eb 100644 --- a/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/config/Config.java +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/config/Config.java @@ -32,18 +32,22 @@ public class Config { public Client client() { try { final Path tmpDir = Files.createTempDirectory(Paths.get(System.getProperty("java.io.tmpdir")), "elasticsearch_data"); - + logger.debug(tmpDir.toAbsolutePath().toString()); + // @formatter:off final Settings.Builder elasticsearchSettings = Settings.settingsBuilder().put("http.enabled", "false") .put("path.data", tmpDir.toAbsolutePath().toString()) .put("path.home", elasticsearchHome); + + return new NodeBuilder() + .local(true) + .settings(elasticsearchSettings) + .node() + .client(); + // @formatter:on - - logger.debug(tmpDir.toAbsolutePath().toString()); - - return new NodeBuilder().local(true).settings(elasticsearchSettings.build()).node().client(); } catch (final IOException ioex) { logger.error("Cannot create temp dir", ioex); throw new RuntimeException(); diff --git a/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleServiceImpl.java b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleServiceImpl.java index 0ea922bdd3..2a31b52602 100644 --- a/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleServiceImpl.java +++ b/spring-data-elasticsearch/src/main/java/com/baeldung/spring/data/es/service/ArticleServiceImpl.java @@ -10,10 +10,10 @@ import org.springframework.stereotype.Service; @Service public class ArticleServiceImpl implements ArticleService { - private ArticleRepository articleRepository; - + private final ArticleRepository articleRepository; + @Autowired - public void setArticleRepository(ArticleRepository articleRepository) { + public ArticleServiceImpl(ArticleRepository articleRepository) { this.articleRepository = articleRepository; } diff --git a/spring-data-elasticsearch/src/main/resources/logback.xml b/spring-data-elasticsearch/src/main/resources/logback.xml index 37a9e2edbf..db75fcbe40 100644 --- a/spring-data-elasticsearch/src/main/resources/logback.xml +++ b/spring-data-elasticsearch/src/main/resources/logback.xml @@ -8,10 +8,10 @@ - - - + + + diff --git a/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchQueryTest.java b/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchQueryTest.java index 1551d6442e..ddf0ef4dac 100644 --- a/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchQueryTest.java +++ b/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchQueryTest.java @@ -34,7 +34,6 @@ import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilde import org.springframework.data.elasticsearch.core.query.SearchQuery; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.support.AnnotationConfigContextLoader; import com.baeldung.spring.data.es.config.Config; import com.baeldung.spring.data.es.model.Article; @@ -42,7 +41,7 @@ import com.baeldung.spring.data.es.model.Author; import com.baeldung.spring.data.es.service.ArticleService; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { Config.class }, loader = AnnotationConfigContextLoader.class) +@ContextConfiguration(classes = Config.class) public class ElasticSearchQueryTest { @Autowired diff --git a/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchTest.java b/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchTest.java index e10b5f48d7..863e1e4620 100644 --- a/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchTest.java +++ b/spring-data-elasticsearch/src/test/java/com/baeldung/spring/data/es/ElasticSearchTest.java @@ -21,7 +21,6 @@ import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilde import org.springframework.data.elasticsearch.core.query.SearchQuery; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.support.AnnotationConfigContextLoader; import com.baeldung.spring.data.es.config.Config; import com.baeldung.spring.data.es.model.Article; @@ -29,7 +28,7 @@ import com.baeldung.spring.data.es.model.Author; import com.baeldung.spring.data.es.service.ArticleService; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { Config.class }, loader = AnnotationConfigContextLoader.class) +@ContextConfiguration(classes = Config.class) public class ElasticSearchTest { @Autowired From 722f932795adabee6c9f36810f74caa21c1d6289 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 14:55:31 +0600 Subject: [PATCH 15/58] Updated README.md --- spring-security-rest-full/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spring-security-rest-full/README.md b/spring-security-rest-full/README.md index 1cbe1191a8..f79df797c2 100644 --- a/spring-security-rest-full/README.md +++ b/spring-security-rest-full/README.md @@ -25,6 +25,9 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com - [REST Query Language with RSQL](http://www.baeldung.com/rest-api-search-language-rsql-fiql) - [Spring RestTemplate Tutorial](http://www.baeldung.com/rest-template) - [A Guide to CSRF Protection in Spring Security](http://www.baeldung.com/spring-security-csrf) +- [Intro to Spring Security Expressions](http://www.baeldung.com/spring-security-expressions) +- [Changing Spring Model Parameters with Handler Interceptor](http://www.baeldung.com/spring-model-parameters-with-handler-interceptor) +- [Introduction to Spring MVC HandlerInterceptor](http://www.baeldung.com/spring-mvc-handlerinterceptor) ### Build the Project ``` From f22c3060497d4a987b87d660fedee3585455cb78 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 14:56:26 +0600 Subject: [PATCH 16/58] Updated README.md --- core-java/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core-java/README.md b/core-java/README.md index 23fe12465f..a93a5dad47 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -13,3 +13,5 @@ - [Java – Write to File](http://www.baeldung.com/java-write-to-file) - [Java Scanner](http://www.baeldung.com/java-scanner) - [Java Timer](http://www.baeldung.com/java-timer-and-timertask) +- [Java – Byte Array to Writer](http://www.baeldung.com/java-convert-byte-array-to-writer) +- [How to Run a Shell Command in Java](http://www.baeldung.com/run-shell-command-in-java) From 46604ddf6dfc6b146564d4d1fca5ff6912d6935c Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 14:57:16 +0600 Subject: [PATCH 17/58] Updated README.md --- spring-hibernate4/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spring-hibernate4/README.md b/spring-hibernate4/README.md index 1f18e1d0e8..7888e8b4ee 100644 --- a/spring-hibernate4/README.md +++ b/spring-hibernate4/README.md @@ -10,6 +10,8 @@ - [Auditing with JPA, Hibernate, and Spring Data JPA](http://www.baeldung.com/database-auditing-jpa) - [Stored Procedures with Hibernate](http://www.baeldung.com/stored-procedures-with-hibernate-tutorial) - [Hibernate: save, persist, update, merge, saveOrUpdate](http://www.baeldung.com/hibernate-save-persist-update-merge-saveorupdate/) +- [Eager/Lazy Loading In Hibernate](http://www.baeldung.com/hibernate-lazy-eager-loading) +- [Hibernate Criteria Queries](http://www.baeldung.com/hibernate-criteria-queries) ### Quick Start From d148076180138cf557a2b2f7e4d842ec002d678f Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 14:58:16 +0600 Subject: [PATCH 18/58] Updated README.md --- spring-all/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spring-all/README.md b/spring-all/README.md index 0bbb600860..aae98440f3 100644 --- a/spring-all/README.md +++ b/spring-all/README.md @@ -12,3 +12,6 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring Profiles](http://www.baeldung.com/spring-profiles) - [A Spring Custom Annotation for a Better DAO](http://www.baeldung.com/spring-annotation-bean-pre-processor) - [What's New in Spring 4.3?](http://www.baeldung.com/whats-new-in-spring-4-3/) +- [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 Bean Scopes](http://www.baeldung.com/spring-bean-scopes) From e2e9ac294dc91caaeb1c23e465aadc91272e5e6d Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 14:59:03 +0600 Subject: [PATCH 19/58] Updated README.md --- spring-mvc-java/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spring-mvc-java/README.md b/spring-mvc-java/README.md index 951d80033e..996a7d96b1 100644 --- a/spring-mvc-java/README.md +++ b/spring-mvc-java/README.md @@ -10,3 +10,9 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Introduction to Pointcut Expressions in Spring](http://www.baeldung.com/spring-aop-pointcut-tutorial) - [Introduction to Advice Types in Spring](http://www.baeldung.com/spring-aop-advice-tutorial) - [A Guide to the ViewResolver in Spring MVC](http://www.baeldung.com/spring-mvc-view-resolver-tutorial) +- [Integration Testing in Spring](http://www.baeldung.com/integration-testing-in-spring) +- [Spring JSON-P with Jackson](http://www.baeldung.com/spring-jackson-jsonp) +- [A Quick Guide to Spring MVC Matrix Variables](http://www.baeldung.com/spring-mvc-matrix-variables) +- [Intro to WebSockets with Spring](http://www.baeldung.com/websockets-spring) +- [File Upload with Spring MVC](http://www.baeldung.com/spring-file-upload) +- [Spring MVC Content Negotiation](http://www.baeldung.com/spring-mvc-content-negotiation-json-xml) From 5d9131771cff5aaf9b485843cd14725c87373dd7 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 14:59:44 +0600 Subject: [PATCH 20/58] Updated README.md --- spring-jpa/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-jpa/README.md b/spring-jpa/README.md index f974c6e22c..066e009c72 100644 --- a/spring-jpa/README.md +++ b/spring-jpa/README.md @@ -10,3 +10,4 @@ - [JPA Pagination](http://www.baeldung.com/jpa-pagination) - [Sorting with JPA](http://www.baeldung.com/jpa-sort) - [Spring JPA – Multiple Databases](http://www.baeldung.com/spring-data-jpa-multiple-databases) +- [Hibernate Second-Level Cache](http://www.baeldung.com/hibernate-second-level-cache) From 918257839f1266b12b268c6650ab952f7c984465 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:00:35 +0600 Subject: [PATCH 21/58] Updated README.md --- gson/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/gson/README.md b/gson/README.md index 67651b732e..60c80477b1 100644 --- a/gson/README.md +++ b/gson/README.md @@ -5,3 +5,4 @@ ### Relevant Articles: - [Gson Deserialization Cookbook](http://www.baeldung.com/gson-deserialization-guide) +- [Jackson vs Gson](http://www.baeldung.com/jackson-vs-gson) From 45dc8efe1c36a2ef86b26cac6ab0c57f4d1b6b29 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:01:26 +0600 Subject: [PATCH 22/58] Updated README.md --- jackson/README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/jackson/README.md b/jackson/README.md index 68765de686..f48a7dc8ab 100644 --- a/jackson/README.md +++ b/jackson/README.md @@ -19,3 +19,8 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Jackson – Decide What Fields Get Serialized/Deserializaed](http://www.baeldung.com/jackson-field-serializable-deserializable-or-not) - [A Guide to Jackson Annotations](http://www.baeldung.com/jackson-annotations) - [Working with Tree Model Nodes in Jackson](http://www.baeldung.com/jackson-json-node-tree-model) +- [Jackson vs Gson](http://www.baeldung.com/jackson-vs-gson) +- [Intro to the Jackson ObjectMapper](http://www.baeldung.com/jackson-object-mapper-tutorial) +- [XML Serialization and Deserialization with Jackson](http://www.baeldung.com/jackson-xml-serialization-and-deserialization) +- [More Jackson Annotations](http://www.baeldung.com/jackson-advanced-annotations) +- [Inheritance with Jackson](http://www.baeldung.com/jackson-inheritance) From 779c6dd52cc279170daaf5550abce54cad0b6a40 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:02:05 +0600 Subject: [PATCH 23/58] Update README.md --- spring-exceptions/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-exceptions/README.md b/spring-exceptions/README.md index ab6a9643e9..fd9250c6da 100644 --- a/spring-exceptions/README.md +++ b/spring-exceptions/README.md @@ -10,3 +10,4 @@ This project is used to replicate Spring Exceptions only. - [Spring DataIntegrityViolationException](http://www.baeldung.com/spring-dataIntegrityviolationexception) - [Spring BeanDefinitionStoreException](http://www.baeldung.com/spring-beandefinitionstoreexception) - [Spring NoSuchBeanDefinitionException](http://www.baeldung.com/spring-nosuchbeandefinitionexception) +- [Guide to Spring NonTransientDataAccessException](http://www.baeldung.com/nontransientdataaccessexception) From c8716019a05d53d81e9b95743ae86d289be7cb4c Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:04:39 +0600 Subject: [PATCH 24/58] Updated README.md --- json/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/json/README.md b/json/README.md index c47eca3e84..e217da170f 100644 --- a/json/README.md +++ b/json/README.md @@ -5,3 +5,5 @@ ### Relevant Articles: - [Introduction to JSON Schema in Java](http://www.baeldung.com/introduction-to-json-schema-in-java) - [A Guide to FastJson](http://www.baeldung.com/????????) +- [Introduction to JSONForms](http://www.baeldung.com/introduction-to-jsonforms) +- [Introduction to JsonPath](http://www.baeldung.com/guide-to-jayway-jsonpath) From c1dcfd5d92d3c7f3174bc0a38eca3e4df52fb43f Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:05:14 +0600 Subject: [PATCH 25/58] Updated README.md --- mutation-testing/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mutation-testing/README.md b/mutation-testing/README.md index 5dd60620ba..f49aeeb881 100644 --- a/mutation-testing/README.md +++ b/mutation-testing/README.md @@ -4,3 +4,5 @@ ### Relevant Articles: - [Introduction to Mutation Testing Using the PITest Library](http://www.baeldung.com/java-mutation-testing-with-pitest) +- [Intro to JaCoCo](http://www.baeldung.com/jacoco) +- [Mutation Testing with PITest](http://www.baeldung.com/java-mutation-testing-with-pitest) From 41f26d8acf0555f5b6f2f98d849e6239c4f492e3 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:06:11 +0600 Subject: [PATCH 26/58] Updated README.md --- mocks/jmockit/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/mocks/jmockit/README.md b/mocks/jmockit/README.md index db78b2a3ac..3063fdc31d 100644 --- a/mocks/jmockit/README.md +++ b/mocks/jmockit/README.md @@ -7,3 +7,4 @@ - [JMockit 101](http://www.baeldung.com/jmockit-101) - [A Guide to JMockit Expectations](http://www.baeldung.com/jmockit-expectations) - [JMockit Advanced Topics](http://www.baeldung.com/jmockit-advanced-topics) +- [JMockit Advanced Usage](http://www.baeldung.com/jmockit-advanced-usage) From 201d3b255196bdd84d59b85a21ae8d09d438d2c8 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:07:13 +0600 Subject: [PATCH 27/58] Updated README.md --- spring-security-custom-permission/README.MD | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spring-security-custom-permission/README.MD b/spring-security-custom-permission/README.MD index 5ac974203b..760cf41c63 100644 --- a/spring-security-custom-permission/README.MD +++ b/spring-security-custom-permission/README.MD @@ -1,2 +1,5 @@ ###The Course The "REST With Spring" Classes: http://github.learnspringsecurity.com + +###Relevant Articles: +- [A Custom Security Expression with Spring Security](http://www.baeldung.com/spring-security-create-new-custom-security-expression) From 2bff26194979e00620e49e307227c3982441cb07 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:08:02 +0600 Subject: [PATCH 28/58] Updated README.md --- xmlunit2-tutorial/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/xmlunit2-tutorial/README.md b/xmlunit2-tutorial/README.md index e69de29bb2..72b683796e 100644 --- a/xmlunit2-tutorial/README.md +++ b/xmlunit2-tutorial/README.md @@ -0,0 +1,2 @@ +###Relevant Articles: +- [Introduction To XMLUnit 2.x](http://www.baeldung.com/xmlunit2) From 38dc8ad0a5ae5fdacefe8c7ba917f0dedfda9fa0 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:08:58 +0600 Subject: [PATCH 29/58] Updated README.md --- rest-assured/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rest-assured/README.md b/rest-assured/README.md index e69de29bb2..50f36f61eb 100644 --- a/rest-assured/README.md +++ b/rest-assured/README.md @@ -0,0 +1,2 @@ +###Relevant Articles: +- [A Guide to REST-assured](http://www.baeldung.com/rest-assured-tutorial) From d106b886358d7c759e5cc05255e4923d517ed787 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:09:51 +0600 Subject: [PATCH 30/58] Updated README.md --- spring-boot/README.MD | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spring-boot/README.MD b/spring-boot/README.MD index 2a87b46021..1610d77e81 100644 --- a/spring-boot/README.MD +++ b/spring-boot/README.MD @@ -1,2 +1,7 @@ ###The Course The "REST With Spring" Classes: http://bit.ly/restwithspring + +###Relevant Articles: +- [Quick Guide to @RestClientTest in Spring Boot](http://www.baeldung.com/restclienttest-in-spring-boot) +- [Intro to Spring Boot Starters](http://www.baeldung.com/spring-boot-starters) +- [A Guide to Spring in Eclipse STS](http://www.baeldung.com/eclipse-sts-spring) From 7433424dba3d4ccc4c7e70a02045c42c2ae4780a Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:10:41 +0600 Subject: [PATCH 31/58] Updated README.md --- spring-rest/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spring-rest/README.md b/spring-rest/README.md index 77d12063ed..671fa4996b 100644 --- a/spring-rest/README.md +++ b/spring-rest/README.md @@ -1,5 +1,3 @@ -========= - ## Spring REST Example Project ###The Course @@ -11,3 +9,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Redirect in Spring](http://www.baeldung.com/spring-redirect-and-forward) - [Returning Custom Status Codes from Spring Controllers](http://www.baeldung.com/spring-mvc-controller-custom-http-status-code) - [A Guide to OkHttp](http://www.baeldung.com/guide-to-okhttp) +- [Binary Data Formats in a Spring REST API](http://www.baeldung.com/spring-rest-api-with-binary-data-formats) From cd853fafbc686af65ff43e15a4eaf909e50acd41 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:11:13 +0600 Subject: [PATCH 32/58] Updated README.md --- guava/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/guava/README.md b/guava/README.md index 28bcfeb912..40e7f19f41 100644 --- a/guava/README.md +++ b/guava/README.md @@ -15,3 +15,4 @@ - [Guava – Lists](http://www.baeldung.com/guava-lists) - [Guava – Sets](http://www.baeldung.com/guava-sets) - [Guava – Maps](http://www.baeldung.com/guava-maps) +- [Guava Set + Function = Map](http://www.baeldung.com/guava-set-function-map-tutorial) From 4ebd8b7f7b4c869134b66065feffa9611456902c Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:11:52 +0600 Subject: [PATCH 33/58] Updated README.md --- rest-testing/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rest-testing/README.md b/rest-testing/README.md index 54a2e98dda..5dd4e49162 100644 --- a/rest-testing/README.md +++ b/rest-testing/README.md @@ -7,3 +7,5 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring ### Relevant Articles: - [Test a REST API with Java](http://www.baeldung.com/2011/10/13/integration-testing-a-rest-api/) +- [Introduction to WireMock](http://www.baeldung.com/introduction-to-wiremock) +- [REST API Testing with Cucumber](http://www.baeldung.com/cucumber-rest-api-testing) From ce7621c66e75efa73962029ebbaeecb69d491dae Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:16:59 +0600 Subject: [PATCH 34/58] Updated README.md --- spring-rest-docs/README.MD | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spring-rest-docs/README.MD b/spring-rest-docs/README.MD index 2a87b46021..f5d001d126 100644 --- a/spring-rest-docs/README.MD +++ b/spring-rest-docs/README.MD @@ -1,2 +1,5 @@ ###The Course The "REST With Spring" Classes: http://bit.ly/restwithspring + +###Relevant Articles: +- [Introduction to Spring REST Docs](http://www.baeldung.com/spring-rest-docs) From 38ad5840f6c612c5ce56c8eb07863341f9845965 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:17:41 +0600 Subject: [PATCH 35/58] Updated README.md --- spring-mvc-xml/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-mvc-xml/README.md b/spring-mvc-xml/README.md index ce823a9682..783bbb2ef4 100644 --- a/spring-mvc-xml/README.md +++ b/spring-mvc-xml/README.md @@ -11,3 +11,4 @@ The "REST With Spring" Classes: http://bit.ly/restwithspring - [Spring MVC Tutorial](http://www.baeldung.com/spring-mvc-tutorial) - [Servlet Session Timeout](http://www.baeldung.com/servlet-session-timeout) - [Basic Forms with Spring MVC](http://www.baeldung.com/spring-mvc-form-tutorial) +- [Returning Image/Media Data with Spring MVC](http://www.baeldung.com/spring-mvc-image-media-data) From caa9bc658510961e8e2d5ee4b183cc66d575a70d Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:18:43 +0600 Subject: [PATCH 36/58] Updated README.md --- spring-security-mvc-login/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-security-mvc-login/README.md b/spring-security-mvc-login/README.md index 7cddc42e1d..d1f6b884b1 100644 --- a/spring-security-mvc-login/README.md +++ b/spring-security-mvc-login/README.md @@ -9,7 +9,7 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com - [Spring Security Form Login](http://www.baeldung.com/spring-security-login) - [Spring Security Logout](http://www.baeldung.com/spring-security-logout) - [Spring Security Expressions – hasRole Example](http://www.baeldung.com/spring-security-expressions-basic) - +- [Spring HTTP/HTTPS Channel Security](http://www.baeldung.com/spring-channel-security-https) ### Build the Project ``` From c0a6cb227d1a147d41ea6a4bfa72d95a9cace45b Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:19:28 +0600 Subject: [PATCH 37/58] Updated README.md --- mockito/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mockito/README.md b/mockito/README.md index 5e7cd19f78..6de2fb0c7a 100644 --- a/mockito/README.md +++ b/mockito/README.md @@ -8,3 +8,5 @@ - [Mockito When/Then Cookbook](http://www.baeldung.com/mockito-behavior) - [Mockito – Using Spies](http://www.baeldung.com/mockito-spy) - [Mockito – @Mock, @Spy, @Captor and @InjectMocks](http://www.baeldung.com/mockito-annotations) +- [Mockito’s Mock Methods](http://www.baeldung.com/mockito-mock-methods) +- [Introduction to PowerMock](http://www.baeldung.com/intro-to-powermock) From f4ada6eaa1ce58e18afaaf0509aac0d042c5ac7e Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:21:09 +0600 Subject: [PATCH 38/58] Updated README.md --- spring-data-elasticsearch/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spring-data-elasticsearch/README.md b/spring-data-elasticsearch/README.md index 74d9e4f642..589343710b 100644 --- a/spring-data-elasticsearch/README.md +++ b/spring-data-elasticsearch/README.md @@ -1,6 +1,9 @@ ## Spring Data Elasticsearch - [Introduction to Spring Data Elasticsearch](http://www.baeldung.com/spring-data-elasticsearch-tutorial) +###Relevant Articles: +- [Elasticsearch Queries with Spring Data](http://www.baeldung.com/spring-data-elasticsearch-queries) + ### Build the Project with Tests Running ``` mvn clean install From 488850ce9ab2f18e4be724f4d2379a7948534609 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:22:02 +0600 Subject: [PATCH 39/58] Updated README.md --- spring-data-redis/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-data-redis/README.md b/spring-data-redis/README.md index 89eae99f05..da44920e16 100644 --- a/spring-data-redis/README.md +++ b/spring-data-redis/README.md @@ -2,6 +2,7 @@ ### Relevant Articles: - [Introduction to Spring Data Redis](http://www.baeldung.com/spring-data-redis-tutorial) +- [PubSub Messaging with Spring Data Redis](http://www.baeldung.com/spring-data-redis-pub-sub) ### Build the Project with Tests Running ``` From 94ad1f631f8a7c85a9c5476dbf95abfa8a80c172 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:24:08 +0600 Subject: [PATCH 40/58] Updated README.md --- gson-jackson-performance/README.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 gson-jackson-performance/README.md diff --git a/gson-jackson-performance/README.md b/gson-jackson-performance/README.md new file mode 100644 index 0000000000..e662219718 --- /dev/null +++ b/gson-jackson-performance/README.md @@ -0,0 +1,6 @@ +## Performance of Gson and Jackson + +Standalone java programs to measure the performance of both JSON APIs based on file size and object graph complexity. + +###Relevant Articles: +- [Jackson vs Gson: A Quick Look At Performance](http://www.baeldung.com/jackson-gson-performance) From fe805ea2022dd12963bd48f8c00984b6f0fa1a73 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:26:33 +0600 Subject: [PATCH 41/58] Updated README.md --- spring-thymeleaf/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-thymeleaf/README.md b/spring-thymeleaf/README.md index 8cb1c2e982..52c8dda13e 100644 --- a/spring-thymeleaf/README.md +++ b/spring-thymeleaf/README.md @@ -4,7 +4,7 @@ ### Relevant Articles: - +- [Introduction to Using Thymeleaf in Spring](http://www.baeldung.com/thymeleaf-in-spring-mvc) ### Build the Project From 87fd44bc38b78c03f0e51b02e5cd58cc487ad911 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:28:03 +0600 Subject: [PATCH 42/58] Updated README.md --- core-java/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/core-java/README.md b/core-java/README.md index a93a5dad47..440af67252 100644 --- a/core-java/README.md +++ b/core-java/README.md @@ -15,3 +15,6 @@ - [Java Timer](http://www.baeldung.com/java-timer-and-timertask) - [Java – Byte Array to Writer](http://www.baeldung.com/java-convert-byte-array-to-writer) - [How to Run a Shell Command in Java](http://www.baeldung.com/run-shell-command-in-java) +- [MD5 Hashing in Java](http://www.baeldung.com/java-md5) +- [Guide to the Java ArrayList](http://www.baeldung.com/java-arraylist) +- [Guide to Java Reflection](http://www.baeldung.com/java-reflection) From 8748eb504151daf1a7d3ac0a684d9d83d4e1bf0a Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:28:55 +0600 Subject: [PATCH 43/58] Updated README.md --- spring-data-elasticsearch/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-data-elasticsearch/README.md b/spring-data-elasticsearch/README.md index 589343710b..a7b090818e 100644 --- a/spring-data-elasticsearch/README.md +++ b/spring-data-elasticsearch/README.md @@ -3,6 +3,7 @@ ###Relevant Articles: - [Elasticsearch Queries with Spring Data](http://www.baeldung.com/spring-data-elasticsearch-queries) +- [Guide to Elasticsearch in Java](http://www.baeldung.com/elasticsearch-java) ### Build the Project with Tests Running ``` From 8a7c5968212abb40d76e7ef0c1d70a626ee8acd1 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:30:35 +0600 Subject: [PATCH 44/58] Updated README.md --- spring-data-rest/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spring-data-rest/README.md b/spring-data-rest/README.md index 7dc439206b..4e8828a688 100644 --- a/spring-data-rest/README.md +++ b/spring-data-rest/README.md @@ -12,3 +12,6 @@ The application uses [Spring Boot](http://projects.spring.io/spring-boot/), so i # Viewing the running application To view the running application, visit [http://localhost:8080](http://localhost:8080) in your browser + +###Relevant Articles: +- [Guide to Spring Data REST Validators](http://www.baeldung.com/spring-data-rest-validators) From ef363e2684897ff81874ab8d569a92cc8ca4cd7a Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:32:01 +0600 Subject: [PATCH 45/58] Updated README.md --- spring-jpa/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-jpa/README.md b/spring-jpa/README.md index 066e009c72..4568c0bc7f 100644 --- a/spring-jpa/README.md +++ b/spring-jpa/README.md @@ -11,3 +11,4 @@ - [Sorting with JPA](http://www.baeldung.com/jpa-sort) - [Spring JPA – Multiple Databases](http://www.baeldung.com/spring-data-jpa-multiple-databases) - [Hibernate Second-Level Cache](http://www.baeldung.com/hibernate-second-level-cache) +- [Spring, Hibernate and a JNDI Datasource](http://www.baeldung.com/spring-persistence-jpa-jndi-datasource) From fc68da25dfd0b5968582e476f6e37c4788241b59 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:33:02 +0600 Subject: [PATCH 46/58] Updated README.md --- spring-thymeleaf/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-thymeleaf/README.md b/spring-thymeleaf/README.md index 52c8dda13e..a8ca755044 100644 --- a/spring-thymeleaf/README.md +++ b/spring-thymeleaf/README.md @@ -5,6 +5,7 @@ ### Relevant Articles: - [Introduction to Using Thymeleaf in Spring](http://www.baeldung.com/thymeleaf-in-spring-mvc) +- [CSRF Protection with Spring MVC and Thymeleaf](http://www.baeldung.com/csrf-thymeleaf-with-spring-security) ### Build the Project From e5c171f8971f2194de775163f737b655085cde03 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:34:40 +0600 Subject: [PATCH 47/58] Updated README.md --- spring-security-rest-full/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-security-rest-full/README.md b/spring-security-rest-full/README.md index f79df797c2..faeeac1ec2 100644 --- a/spring-security-rest-full/README.md +++ b/spring-security-rest-full/README.md @@ -28,6 +28,7 @@ The "Learn Spring Security" Classes: http://github.learnspringsecurity.com - [Intro to Spring Security Expressions](http://www.baeldung.com/spring-security-expressions) - [Changing Spring Model Parameters with Handler Interceptor](http://www.baeldung.com/spring-model-parameters-with-handler-interceptor) - [Introduction to Spring MVC HandlerInterceptor](http://www.baeldung.com/spring-mvc-handlerinterceptor) +- [Using a Custom Spring MVC’s Handler Interceptor to Manage Sessions](http://www.baeldung.com/spring-mvc-custom-handler-interceptor) ### Build the Project ``` From 14ca00a93c3497d0fbc61a0ca07e685a3ba3022e Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Tue, 4 Oct 2016 15:35:25 +0600 Subject: [PATCH 48/58] Updated README.md --- feign-client/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/feign-client/README.md b/feign-client/README.md index e6ade4d161..149f7320d9 100644 --- a/feign-client/README.md +++ b/feign-client/README.md @@ -3,3 +3,6 @@ This is the implementation of a [spring-hypermedia-api][1] client using Feign. [1]: https://github.com/eugenp/spring-hypermedia-api + +###Relevant Articles: +- [Intro to Feign](http://www.baeldung.com/intro-to-feign) From 298c5e309100d2104096d74f0299596bc5d90718 Mon Sep 17 00:00:00 2001 From: Naoshadul Islam Date: Sun, 16 Oct 2016 16:25:05 +0600 Subject: [PATCH 49/58] Created README.md and added relevant articles (#742) * Updated readme.md * Updated readme.md * Updated readme.md * Updated readme.md * Updated readme.md * Updated readme.md * Updated readme.md * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Updated readme.md * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Updated readme.md * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Updated readme.md * Created README.md and added relevant articles * Created README.md and added relevant articles * Created README.md and added relevant articles * Updated readme.md * Updated readme.md * Created README.md and added relevant articles * Created README.md and added relevant articles --- annotations/readme.md | 3 ++- apache-cxf/cxf-introduction/README.md | 2 ++ assertj/README.md | 3 +++ autovalue-tutorial/README.md | 2 ++ cdi/README.md | 2 ++ core-java-8/src/main/java/com/baeldung/datetime/README.md | 2 ++ core-java-8/src/main/java/com/baeldung/enums/README.md | 2 ++ core-java-9/src/test/java/com/baeldung/java9/README.MD | 3 ++- core-java/src/test/java/org/baeldung/java/lists/README.md | 2 ++ dependency-injection/README.md | 2 ++ dozer/README.md | 2 ++ flyway-migration/README.MD | 3 ++- gatling/README.md | 2 ++ guava/src/test/java/org/baeldung/hamcrest/README.md | 2 ++ handling-spring-static-resources/README.md | 3 +++ hystrix/README.md | 3 +++ immutables/README.md | 2 ++ jee7schedule/README.md | 2 ++ jooq-spring/README.md | 3 +++ jpa-storedprocedure/README.md | 2 ++ jsf/README.md | 4 ++++ junit5/REDAME.md | 2 ++ log4j/README.md | 2 ++ lombok/README.md | 2 ++ orika/README.md | 2 ++ querydsl/README.md | 2 ++ raml/resource-types-and-traits/README.md | 2 ++ sockets/README.md | 2 ++ spring-akka/README.md | 2 ++ spring-autowire/README.md | 2 ++ spring-boot/src/main/java/com/baeldung/git/README.md | 2 ++ spring-cloud-data-flow/README.MD | 4 +++- spring-cloud/spring-cloud-bootstrap/README.MD | 3 ++- spring-cloud/spring-cloud-config/README.md | 2 ++ spring-cloud/spring-cloud-eureka/README.md | 2 ++ spring-cloud/spring-cloud-hystrix/README.MD | 3 ++- spring-cucumber/README.md | 2 ++ spring-mvc-java/src/main/README.md | 2 ++ spring-mvc-java/src/test/README.md | 2 ++ .../src/test/java/com/baeldung/web/controller/README.md | 2 ++ spring-mvc-velocity/README.md | 2 ++ spring-mvc-web-vs-initializer/README.MD | 3 ++- spring-protobuf/README.md | 2 ++ spring-security-x509/README.md | 2 ++ spring-spel/README.md | 2 ++ xml/README.md | 2 ++ xstream/README.md | 4 ++++ 47 files changed, 103 insertions(+), 7 deletions(-) create mode 100644 apache-cxf/cxf-introduction/README.md create mode 100644 assertj/README.md create mode 100644 autovalue-tutorial/README.md create mode 100644 cdi/README.md create mode 100644 core-java-8/src/main/java/com/baeldung/datetime/README.md create mode 100644 core-java-8/src/main/java/com/baeldung/enums/README.md create mode 100644 core-java/src/test/java/org/baeldung/java/lists/README.md create mode 100644 dependency-injection/README.md create mode 100644 dozer/README.md create mode 100644 gatling/README.md create mode 100644 guava/src/test/java/org/baeldung/hamcrest/README.md create mode 100644 handling-spring-static-resources/README.md create mode 100644 hystrix/README.md create mode 100644 immutables/README.md create mode 100644 jee7schedule/README.md create mode 100644 jooq-spring/README.md create mode 100644 jpa-storedprocedure/README.md create mode 100644 jsf/README.md create mode 100644 junit5/REDAME.md create mode 100644 log4j/README.md create mode 100644 lombok/README.md create mode 100644 orika/README.md create mode 100644 querydsl/README.md create mode 100644 raml/resource-types-and-traits/README.md create mode 100644 sockets/README.md create mode 100644 spring-akka/README.md create mode 100644 spring-autowire/README.md create mode 100644 spring-boot/src/main/java/com/baeldung/git/README.md create mode 100644 spring-cloud/spring-cloud-config/README.md create mode 100644 spring-cloud/spring-cloud-eureka/README.md create mode 100644 spring-cucumber/README.md create mode 100644 spring-mvc-java/src/main/README.md create mode 100644 spring-mvc-java/src/test/README.md create mode 100644 spring-mvc-java/src/test/java/com/baeldung/web/controller/README.md create mode 100644 spring-mvc-velocity/README.md create mode 100644 spring-protobuf/README.md create mode 100644 spring-security-x509/README.md create mode 100644 spring-spel/README.md create mode 100644 xml/README.md create mode 100644 xstream/README.md diff --git a/annotations/readme.md b/annotations/readme.md index 8b13789179..2b052803e6 100644 --- a/annotations/readme.md +++ b/annotations/readme.md @@ -1 +1,2 @@ - +### Relevant Articles: +- [Java Annotation Processing and Creating a Builder](http://www.baeldung.com/java-annotation-processing-builder) diff --git a/apache-cxf/cxf-introduction/README.md b/apache-cxf/cxf-introduction/README.md new file mode 100644 index 0000000000..9a076524b7 --- /dev/null +++ b/apache-cxf/cxf-introduction/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Introduction to Apache CXF](http://www.baeldung.com/introduction-to-apache-cxf) diff --git a/assertj/README.md b/assertj/README.md new file mode 100644 index 0000000000..86eff05057 --- /dev/null +++ b/assertj/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: +- [AssertJ’s Java 8 Features](http://www.baeldung.com/assertJ-java-8-features) +- [AssertJ for Guava](http://www.baeldung.com/assertJ-for-guava) diff --git a/autovalue-tutorial/README.md b/autovalue-tutorial/README.md new file mode 100644 index 0000000000..2385e82847 --- /dev/null +++ b/autovalue-tutorial/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Introduction to AutoValue](http://www.baeldung.com/introduction-to-autovalue) diff --git a/cdi/README.md b/cdi/README.md new file mode 100644 index 0000000000..a27c35772a --- /dev/null +++ b/cdi/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [CDI Interceptor vs Spring AspectJ](http://www.baeldung.com/cdi-interceptor-vs-spring-aspectj) diff --git a/core-java-8/src/main/java/com/baeldung/datetime/README.md b/core-java-8/src/main/java/com/baeldung/datetime/README.md new file mode 100644 index 0000000000..1e4adbb612 --- /dev/null +++ b/core-java-8/src/main/java/com/baeldung/datetime/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Introduction to the Java 8 Date/Time API](http://www.baeldung.com/java-8-date-time-intro) diff --git a/core-java-8/src/main/java/com/baeldung/enums/README.md b/core-java-8/src/main/java/com/baeldung/enums/README.md new file mode 100644 index 0000000000..6ccfa725f5 --- /dev/null +++ b/core-java-8/src/main/java/com/baeldung/enums/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [A Guide to Java Enums](http://www.baeldung.com/a-guide-to-java-enums) diff --git a/core-java-9/src/test/java/com/baeldung/java9/README.MD b/core-java-9/src/test/java/com/baeldung/java9/README.MD index 8b13789179..2f44a2336b 100644 --- a/core-java-9/src/test/java/com/baeldung/java9/README.MD +++ b/core-java-9/src/test/java/com/baeldung/java9/README.MD @@ -1 +1,2 @@ - +### Relevant Artiles: +- [Filtering a Stream of Optionals in Java](http://www.baeldung.com/java-filter-stream-of-optional) diff --git a/core-java/src/test/java/org/baeldung/java/lists/README.md b/core-java/src/test/java/org/baeldung/java/lists/README.md new file mode 100644 index 0000000000..2a1e8aeeaa --- /dev/null +++ b/core-java/src/test/java/org/baeldung/java/lists/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Check If Two Lists are Equal in Java](http://www.baeldung.com/java-test-a-list-for-ordinality-and-equality) diff --git a/dependency-injection/README.md b/dependency-injection/README.md new file mode 100644 index 0000000000..5554412c31 --- /dev/null +++ b/dependency-injection/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Wiring in Spring: @Autowired, @Resource and @Inject](http://www.baeldung.com/spring-annotations-resource-inject-autowire) diff --git a/dozer/README.md b/dozer/README.md new file mode 100644 index 0000000000..5e104d914c --- /dev/null +++ b/dozer/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [A Guide to Mapping With Dozer](http://www.baeldung.com/dozer) diff --git a/flyway-migration/README.MD b/flyway-migration/README.MD index 8b13789179..1b3f3c05ee 100644 --- a/flyway-migration/README.MD +++ b/flyway-migration/README.MD @@ -1 +1,2 @@ - +### Relevant Articles: +- [Database Migrations with Flyway](http://www.baeldung.com/database-migrations-with-flyway) diff --git a/gatling/README.md b/gatling/README.md new file mode 100644 index 0000000000..5c81c4bd6a --- /dev/null +++ b/gatling/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Intro to Gatling](http://www.baeldung.com/introduction-to-gatling) diff --git a/guava/src/test/java/org/baeldung/hamcrest/README.md b/guava/src/test/java/org/baeldung/hamcrest/README.md new file mode 100644 index 0000000000..7266ecda3a --- /dev/null +++ b/guava/src/test/java/org/baeldung/hamcrest/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Testing with Hamcrest](http://www.baeldung.com/java-junit-hamcrest-guide) diff --git a/handling-spring-static-resources/README.md b/handling-spring-static-resources/README.md new file mode 100644 index 0000000000..d8f64bc427 --- /dev/null +++ b/handling-spring-static-resources/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: +- [Cachable Static Assets with Spring MVC](http://www.baeldung.com/cachable-static-assets-with-spring-mvc) +- [Minification of JS and CSS Assets with Maven](http://www.baeldung.com/maven-minification-of-js-and-css-assets) diff --git a/hystrix/README.md b/hystrix/README.md new file mode 100644 index 0000000000..cc5c8a197f --- /dev/null +++ b/hystrix/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: +- [Hystrix Integration with Existing Spring Application](http://www.baeldung.com/hystrix-integration-with-spring-aop) +- [Introduction to Hystrix](http://www.baeldung.com/introduction-to-hystrix) diff --git a/immutables/README.md b/immutables/README.md new file mode 100644 index 0000000000..b69a14f035 --- /dev/null +++ b/immutables/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Introduction to Immutables](http://www.baeldung.com/immutables) diff --git a/jee7schedule/README.md b/jee7schedule/README.md new file mode 100644 index 0000000000..44ca9c2f6e --- /dev/null +++ b/jee7schedule/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Scheduling in Java EE](http://www.baeldung.com/scheduling-in-java-enterprise-edition) diff --git a/jooq-spring/README.md b/jooq-spring/README.md new file mode 100644 index 0000000000..79718e74c6 --- /dev/null +++ b/jooq-spring/README.md @@ -0,0 +1,3 @@ +### Relevant Articles: +- [Spring Boot Support for jOOQ](http://www.baeldung.com/spring-boot-support-for-jooq) +- [Introduction to jOOQ with Spring](http://www.baeldung.com/jooq-with-spring) diff --git a/jpa-storedprocedure/README.md b/jpa-storedprocedure/README.md new file mode 100644 index 0000000000..39d6784d8b --- /dev/null +++ b/jpa-storedprocedure/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [A Guide to Stored Procedures with JPA](http://www.baeldung.com/jpa-stored-procedures) diff --git a/jsf/README.md b/jsf/README.md new file mode 100644 index 0000000000..ae92ffc42f --- /dev/null +++ b/jsf/README.md @@ -0,0 +1,4 @@ +### Relevant Articles: +- [Introduction to JSF Expression Language 3.0](http://www.baeldung.com/jsf-expression-language-el-3) +- [Introduction to JSF EL 2](http://www.baeldung.com/intro-to-jsf-expression-language) +- [JavaServer Faces (JSF) with Spring](http://www.baeldung.com/spring-jsf) diff --git a/junit5/REDAME.md b/junit5/REDAME.md new file mode 100644 index 0000000000..d4e30cd257 --- /dev/null +++ b/junit5/REDAME.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [The Basics of JUnit 5 – A Preview](http://www.baeldung.com/junit-5-preview) diff --git a/log4j/README.md b/log4j/README.md new file mode 100644 index 0000000000..7355372f23 --- /dev/null +++ b/log4j/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Introduction to Java Logging](http://www.baeldung.com/java-logging-intro) diff --git a/lombok/README.md b/lombok/README.md new file mode 100644 index 0000000000..4dc1c2d09d --- /dev/null +++ b/lombok/README.md @@ -0,0 +1,2 @@ +## Relevant Articles: +- [Introduction to Project Lombok](http://www.baeldung.com/intro-to-project-lombok) diff --git a/orika/README.md b/orika/README.md new file mode 100644 index 0000000000..4ed033c170 --- /dev/null +++ b/orika/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Mapping with Orika](http://www.baeldung.com/orika-mapping) diff --git a/querydsl/README.md b/querydsl/README.md new file mode 100644 index 0000000000..ef9f8f894c --- /dev/null +++ b/querydsl/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Intro to Querydsl](http://www.baeldung.com/intro-to-querydsl) diff --git a/raml/resource-types-and-traits/README.md b/raml/resource-types-and-traits/README.md new file mode 100644 index 0000000000..72e7b454d6 --- /dev/null +++ b/raml/resource-types-and-traits/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Eliminate Redundancies in RAML with Resource Types and Traits](http://www.baeldung.com/simple-raml-with-resource-types-and-traits) diff --git a/sockets/README.md b/sockets/README.md new file mode 100644 index 0000000000..ad8811ee80 --- /dev/null +++ b/sockets/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [A Guide to Java Sockets](http://www.baeldung.com/a-guide-to-java-sockets) diff --git a/spring-akka/README.md b/spring-akka/README.md new file mode 100644 index 0000000000..0f1c013214 --- /dev/null +++ b/spring-akka/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Introduction to Spring with Akka](http://www.baeldung.com/akka-with-spring) diff --git a/spring-autowire/README.md b/spring-autowire/README.md new file mode 100644 index 0000000000..d5b8221b25 --- /dev/null +++ b/spring-autowire/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Guide to Spring @Autowired](http://www.baeldung.com/spring-autowire) diff --git a/spring-boot/src/main/java/com/baeldung/git/README.md b/spring-boot/src/main/java/com/baeldung/git/README.md new file mode 100644 index 0000000000..7e6a597c28 --- /dev/null +++ b/spring-boot/src/main/java/com/baeldung/git/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Injecting Git Information Into Spring](http://www.baeldung.com/spring-git-information) diff --git a/spring-cloud-data-flow/README.MD b/spring-cloud-data-flow/README.MD index 8b13789179..17d0ec6286 100644 --- a/spring-cloud-data-flow/README.MD +++ b/spring-cloud-data-flow/README.MD @@ -1 +1,3 @@ - +### Relevant Articles: +- [Batch Processing with Spring Cloud Data Flow](http://www.baeldung.com/spring-cloud-data-flow-batch-processing) +- [Getting Started with Stream Processing with Spring Cloud Data Flow](http://www.baeldung.com/spring-cloud-data-flow-stream-processing) diff --git a/spring-cloud/spring-cloud-bootstrap/README.MD b/spring-cloud/spring-cloud-bootstrap/README.MD index 8b13789179..c16ba3e247 100644 --- a/spring-cloud/spring-cloud-bootstrap/README.MD +++ b/spring-cloud/spring-cloud-bootstrap/README.MD @@ -1 +1,2 @@ - +### Relevant Articles: +- [Spring Cloud – Bootstrapping](http://www.baeldung.com/spring-cloud-bootstrapping) diff --git a/spring-cloud/spring-cloud-config/README.md b/spring-cloud/spring-cloud-config/README.md new file mode 100644 index 0000000000..b28c750ee6 --- /dev/null +++ b/spring-cloud/spring-cloud-config/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Dockerizing a Spring Boot Application](http://www.baeldung.com/dockerizing-spring-boot-application) diff --git a/spring-cloud/spring-cloud-eureka/README.md b/spring-cloud/spring-cloud-eureka/README.md new file mode 100644 index 0000000000..badf4c8d50 --- /dev/null +++ b/spring-cloud/spring-cloud-eureka/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Introduction to Spring Cloud Netflix – Eureka](http://www.baeldung.com/spring-cloud-netflix-eureka) diff --git a/spring-cloud/spring-cloud-hystrix/README.MD b/spring-cloud/spring-cloud-hystrix/README.MD index 8b13789179..a235f6311f 100644 --- a/spring-cloud/spring-cloud-hystrix/README.MD +++ b/spring-cloud/spring-cloud-hystrix/README.MD @@ -1 +1,2 @@ - +### Relevant Articles: +- [A Guide to Spring Cloud Netflix – Hystrix](http://www.baeldung.com/spring-cloud-netflix-hystrix) diff --git a/spring-cucumber/README.md b/spring-cucumber/README.md new file mode 100644 index 0000000000..1e506f3a09 --- /dev/null +++ b/spring-cucumber/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Cucumber Spring Integration](http://www.baeldung.com/cucumber-spring-integration) diff --git a/spring-mvc-java/src/main/README.md b/spring-mvc-java/src/main/README.md new file mode 100644 index 0000000000..20ee1918af --- /dev/null +++ b/spring-mvc-java/src/main/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Circular Dependencies in Spring](http://www.baeldung.com/circular-dependencies-in-spring) diff --git a/spring-mvc-java/src/test/README.md b/spring-mvc-java/src/test/README.md new file mode 100644 index 0000000000..20ee1918af --- /dev/null +++ b/spring-mvc-java/src/test/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Circular Dependencies in Spring](http://www.baeldung.com/circular-dependencies-in-spring) diff --git a/spring-mvc-java/src/test/java/com/baeldung/web/controller/README.md b/spring-mvc-java/src/test/java/com/baeldung/web/controller/README.md new file mode 100644 index 0000000000..9923962dde --- /dev/null +++ b/spring-mvc-java/src/test/java/com/baeldung/web/controller/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [WebAppConfiguration in Spring Tests](http://www.baeldung.com/spring-webappconfiguration) diff --git a/spring-mvc-velocity/README.md b/spring-mvc-velocity/README.md new file mode 100644 index 0000000000..401e135f75 --- /dev/null +++ b/spring-mvc-velocity/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Quick Guide to Spring MVC with Velocity](http://www.baeldung.com/spring-mvc-with-velocity) diff --git a/spring-mvc-web-vs-initializer/README.MD b/spring-mvc-web-vs-initializer/README.MD index 8b13789179..4759cf6137 100644 --- a/spring-mvc-web-vs-initializer/README.MD +++ b/spring-mvc-web-vs-initializer/README.MD @@ -1 +1,2 @@ - +### Relevant Articles: +- [web.xml vs Initializer with Spring](http://www.baeldung.com/spring-xml-vs-java-config) diff --git a/spring-protobuf/README.md b/spring-protobuf/README.md new file mode 100644 index 0000000000..dad0e3f54a --- /dev/null +++ b/spring-protobuf/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Spring REST API with Protocol Buffers](http://www.baeldung.com/spring-rest-api-with-protocol-buffers) diff --git a/spring-security-x509/README.md b/spring-security-x509/README.md new file mode 100644 index 0000000000..2a4b84eae6 --- /dev/null +++ b/spring-security-x509/README.md @@ -0,0 +1,2 @@ +Relevant Articles: +- [X.509 Authentication in Spring Security](http://www.baeldung.com/x-509-authentication-in-spring-security) diff --git a/spring-spel/README.md b/spring-spel/README.md new file mode 100644 index 0000000000..d7e69e114c --- /dev/null +++ b/spring-spel/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Spring Expression Language Guide](http://www.baeldung.com/spring-expression-language) diff --git a/xml/README.md b/xml/README.md new file mode 100644 index 0000000000..8531f8b063 --- /dev/null +++ b/xml/README.md @@ -0,0 +1,2 @@ +### Relevant Articles: +- [Intro to XPath with Java](http://www.baeldung.com/java-xpath) diff --git a/xstream/README.md b/xstream/README.md new file mode 100644 index 0000000000..e8302c14ef --- /dev/null +++ b/xstream/README.md @@ -0,0 +1,4 @@ +### Relevant Articles: +- [XStream User Guide: JSON](http://www.baeldung.com/xstream-json-processing) +- [XStream User Guide: Converting XML to Objects](http://www.baeldung.com/xstream-deserialize-xml-to-object) +- [XStream User Guide: Converting Objects to XML](http://www.baeldung.com/xstream-serialize-object-to-xml) From f9ec757a44087f793bf90d9344d0426a500cb69f Mon Sep 17 00:00:00 2001 From: eugenp Date: Mon, 17 Oct 2016 07:49:55 +0300 Subject: [PATCH 50/58] minor httpclient cleanup --- .../{HttpAsyncClientTest.java => HttpAsyncClientLiveTest.java} | 2 +- .../httpclient/{SandboxTest.java => SandboxLiveTest.java} | 2 +- ...entTest.java => HttpClientConnectionManagementLiveTest.java} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename httpclient/src/test/java/org/baeldung/httpclient/{HttpAsyncClientTest.java => HttpAsyncClientLiveTest.java} (99%) rename httpclient/src/test/java/org/baeldung/httpclient/{SandboxTest.java => SandboxLiveTest.java} (99%) rename httpclient/src/test/java/org/baeldung/httpclient/conn/{HttpClientConnectionManagementTest.java => HttpClientConnectionManagementLiveTest.java} (99%) diff --git a/httpclient/src/test/java/org/baeldung/httpclient/HttpAsyncClientTest.java b/httpclient/src/test/java/org/baeldung/httpclient/HttpAsyncClientLiveTest.java similarity index 99% rename from httpclient/src/test/java/org/baeldung/httpclient/HttpAsyncClientTest.java rename to httpclient/src/test/java/org/baeldung/httpclient/HttpAsyncClientLiveTest.java index 151ed10f37..bfe1e68ebe 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/HttpAsyncClientTest.java +++ b/httpclient/src/test/java/org/baeldung/httpclient/HttpAsyncClientLiveTest.java @@ -33,7 +33,7 @@ import org.apache.http.protocol.BasicHttpContext; import org.apache.http.protocol.HttpContext; import org.junit.Test; -public class HttpAsyncClientTest { +public class HttpAsyncClientLiveTest { private static final String HOST = "http://www.google.com"; private static final String HOST_WITH_SSL = "https://mms.nw.ru/"; diff --git a/httpclient/src/test/java/org/baeldung/httpclient/SandboxTest.java b/httpclient/src/test/java/org/baeldung/httpclient/SandboxLiveTest.java similarity index 99% rename from httpclient/src/test/java/org/baeldung/httpclient/SandboxTest.java rename to httpclient/src/test/java/org/baeldung/httpclient/SandboxLiveTest.java index dc1a206f0d..61269c33a1 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/SandboxTest.java +++ b/httpclient/src/test/java/org/baeldung/httpclient/SandboxLiveTest.java @@ -29,7 +29,7 @@ import org.apache.http.util.EntityUtils; import org.junit.Ignore; import org.junit.Test; -public class SandboxTest { +public class SandboxLiveTest { // original example @Ignore diff --git a/httpclient/src/test/java/org/baeldung/httpclient/conn/HttpClientConnectionManagementTest.java b/httpclient/src/test/java/org/baeldung/httpclient/conn/HttpClientConnectionManagementLiveTest.java similarity index 99% rename from httpclient/src/test/java/org/baeldung/httpclient/conn/HttpClientConnectionManagementTest.java rename to httpclient/src/test/java/org/baeldung/httpclient/conn/HttpClientConnectionManagementLiveTest.java index c5c960f527..e9db8c1e16 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/conn/HttpClientConnectionManagementTest.java +++ b/httpclient/src/test/java/org/baeldung/httpclient/conn/HttpClientConnectionManagementLiveTest.java @@ -36,7 +36,7 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; -public class HttpClientConnectionManagementTest { +public class HttpClientConnectionManagementLiveTest { private static final String SERVER1 = "http://www.petrikainulainen.net/"; private static final String SERVER7 = "http://www.baeldung.com/"; From 299504659b29d5d36316329448e745c9c1c2677d Mon Sep 17 00:00:00 2001 From: eugenp Date: Mon, 17 Oct 2016 07:52:17 +0300 Subject: [PATCH 51/58] adding a sandbox test --- .../baeldung/httpclient/SandboxLiveTest.java | 188 ------------------ .../base/HttpClientSandboxLiveTest.java | 12 ++ 2 files changed, 12 insertions(+), 188 deletions(-) delete mode 100644 httpclient/src/test/java/org/baeldung/httpclient/SandboxLiveTest.java diff --git a/httpclient/src/test/java/org/baeldung/httpclient/SandboxLiveTest.java b/httpclient/src/test/java/org/baeldung/httpclient/SandboxLiveTest.java deleted file mode 100644 index 61269c33a1..0000000000 --- a/httpclient/src/test/java/org/baeldung/httpclient/SandboxLiveTest.java +++ /dev/null @@ -1,188 +0,0 @@ -package org.baeldung.httpclient; - -import static org.junit.Assert.assertEquals; - -import java.io.IOException; - -import org.apache.http.Header; -import org.apache.http.HttpHost; -import org.apache.http.HttpResponse; -import org.apache.http.auth.AuthScope; -import org.apache.http.auth.AuthenticationException; -import org.apache.http.auth.MalformedChallengeException; -import org.apache.http.auth.UsernamePasswordCredentials; -import org.apache.http.client.AuthCache; -import org.apache.http.client.ClientProtocolException; -import org.apache.http.client.CookieStore; -import org.apache.http.client.CredentialsProvider; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.protocol.HttpClientContext; -import org.apache.http.impl.auth.DigestScheme; -import org.apache.http.impl.client.BasicAuthCache; -import org.apache.http.impl.client.BasicCookieStore; -import org.apache.http.impl.client.BasicCredentialsProvider; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.impl.cookie.BasicClientCookie; -import org.apache.http.util.EntityUtils; -import org.junit.Ignore; -import org.junit.Test; - -public class SandboxLiveTest { - - // original example - @Ignore - @Test - public final void whenInterestingDigestAuthScenario_then401UnAuthorized() throws AuthenticationException, ClientProtocolException, IOException, MalformedChallengeException { - final HttpHost targetHost = new HttpHost("httpbin.org", 80, "http"); - - // set up the credentials to run agains the server - final CredentialsProvider credsProvider = new BasicCredentialsProvider(); - credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials("user", "passwd")); - - // We need a first run to get a 401 to seed the digest auth - - // Make a client using those creds - final CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); - - // And make a call to the URL we are after - final HttpGet httpget = new HttpGet("http://httpbin.org/digest-auth/auth/user/passwd"); - - // Create a context to use - final HttpClientContext context = HttpClientContext.create(); - - // Get a response from the sever (expect a 401!) - final HttpResponse authResponse = client.execute(targetHost, httpget, context); - - // Pull out the auth header that came back from the server - final Header challenge = authResponse.getHeaders("WWW-Authenticate")[0]; - - // Lets use a digest scheme to solve it - final DigestScheme digest = new DigestScheme(); - digest.processChallenge(challenge); - - // Make a header with the solution based upon user/password and what the digest got out of the initial 401 reponse - final Header solution = digest.authenticate(new UsernamePasswordCredentials("user", "passwd"), httpget, context); - - // Need an auth cache to use the new digest we made - final AuthCache authCache = new BasicAuthCache(); - authCache.put(targetHost, digest); - - // Add the authCache and thus solved digest to the context - context.setAuthCache(authCache); - - // Pimp up our http get with the solved header made by the digest - httpget.addHeader(solution); - - // use it! - System.out.println("Executing request " + httpget.getRequestLine() + " to target " + targetHost); - - for (int i = 0; i < 3; i++) { - final CloseableHttpResponse responseGood = client.execute(targetHost, httpget, context); - - try { - System.out.println("----------------------------------------"); - System.out.println(responseGood.getStatusLine()); - System.out.println(EntityUtils.toString(responseGood.getEntity())); - } finally { - responseGood.close(); - } - } - } - - @Test - public final void whenInterestingDigestAuthScenario_then200OK() throws AuthenticationException, ClientProtocolException, IOException, MalformedChallengeException { - final HttpHost targetHost = new HttpHost("httpbin.org", 80, "http"); - - // set up the credentials to run agains the server - final CredentialsProvider credsProvider = new BasicCredentialsProvider(); - credsProvider.setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials("user", "passwd")); - - // This endpoint need fake cookie to work properly - final CookieStore cookieStore = new BasicCookieStore(); - final BasicClientCookie cookie = new BasicClientCookie("fake", "fake_value"); - cookie.setDomain("httpbin.org"); - cookie.setPath("/"); - cookieStore.addCookie(cookie); - - // Make a client using those creds - final CloseableHttpClient client = HttpClients.custom().setDefaultCookieStore(cookieStore).setDefaultCredentialsProvider(credsProvider).build(); - - // And make a call to the URL we are after - final HttpGet httpget = new HttpGet("http://httpbin.org/digest-auth/auth/user/passwd"); - - // Create a context to use - final HttpClientContext context = HttpClientContext.create(); - - // Get a response from the sever (401 implicitly) - final HttpResponse authResponse = client.execute(targetHost, httpget, context); - assertEquals(200, authResponse.getStatusLine().getStatusCode()); - - // HttpClient will use cached digest parameters for future requests - System.out.println("Executing request " + httpget.getRequestLine() + " to target " + targetHost); - - for (int i = 0; i < 3; i++) { - final CloseableHttpResponse responseGood = client.execute(targetHost, httpget, context); - - try { - System.out.println("----------------------------------------"); - System.out.println(responseGood.getStatusLine()); - assertEquals(200, responseGood.getStatusLine().getStatusCode()); - } finally { - responseGood.close(); - } - } - client.close(); - } - - // This test needs module spring-security-rest-digest-auth to be running - @Test - public final void whenWeKnowDigestParameters_thenNo401Status() throws AuthenticationException, ClientProtocolException, IOException, MalformedChallengeException { - final HttpHost targetHost = new HttpHost("localhost", 8080, "http"); - - final CredentialsProvider credsProvider = new BasicCredentialsProvider(); - credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("user1", "user1Pass")); - - final CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); - - final HttpGet httpget = new HttpGet("http://localhost:8080/spring-security-rest-digest-auth/api/foos/1"); - - final HttpClientContext context = HttpClientContext.create(); - // == make it preemptive - final AuthCache authCache = new BasicAuthCache(); - final DigestScheme digestAuth = new DigestScheme(); - digestAuth.overrideParamter("realm", "Custom Realm Name"); - digestAuth.overrideParamter("nonce", "nonce value goes here"); - authCache.put(targetHost, digestAuth); - context.setAuthCache(authCache); - // == end - System.out.println("Executing The Request knowing the digest parameters ==== "); - final HttpResponse authResponse = client.execute(targetHost, httpget, context); - assertEquals(200, authResponse.getStatusLine().getStatusCode()); - client.close(); - } - - // This test needs module spring-security-rest-digest-auth to be running - @Test - public final void whenDoNotKnowParameters_thenOnlyOne401() throws AuthenticationException, ClientProtocolException, IOException, MalformedChallengeException { - final HttpClientContext context = HttpClientContext.create(); - final HttpHost targetHost = new HttpHost("localhost", 8080, "http"); - final CredentialsProvider credsProvider = new BasicCredentialsProvider(); - credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("user1", "user1Pass")); - final CloseableHttpClient client = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build(); - - final HttpGet httpget = new HttpGet("http://localhost:8080/spring-security-rest-digest-auth/api/foos/1"); - System.out.println("Executing The Request NOT knowing the digest parameters ==== "); - final HttpResponse tempResponse = client.execute(targetHost, httpget, context); - assertEquals(200, tempResponse.getStatusLine().getStatusCode()); - - for (int i = 0; i < 3; i++) { - System.out.println("No more Challenges or 401"); - final CloseableHttpResponse authResponse = client.execute(targetHost, httpget, context); - assertEquals(200, authResponse.getStatusLine().getStatusCode()); - authResponse.close(); - } - client.close(); - } -} diff --git a/httpclient/src/test/java/org/baeldung/httpclient/base/HttpClientSandboxLiveTest.java b/httpclient/src/test/java/org/baeldung/httpclient/base/HttpClientSandboxLiveTest.java index ff2f1cd194..2333e2f8c9 100644 --- a/httpclient/src/test/java/org/baeldung/httpclient/base/HttpClientSandboxLiveTest.java +++ b/httpclient/src/test/java/org/baeldung/httpclient/base/HttpClientSandboxLiveTest.java @@ -10,9 +10,11 @@ import org.apache.http.client.ClientProtocolException; import org.apache.http.client.CredentialsProvider; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; +import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.HttpClients; import org.junit.After; import org.junit.Test; @@ -58,4 +60,14 @@ public class HttpClientSandboxLiveTest { System.out.println(response.getStatusLine()); } + @Test + public final void givenIgnoringCertificates_whenHttpsUrlIsConsumed_thenCorrect() throws ClientProtocolException, IOException { + final CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); + + final HttpGet httpGet = new HttpGet("https://sesar3.geoinfogeochem.org/sample/igsn/ODP000002"); + httpGet.setHeader("Accept", "application/xml"); + + response = httpClient.execute(httpGet); + } + } From 04482ef902b9a2cc3c1cff5407719d2d8f6030d1 Mon Sep 17 00:00:00 2001 From: maibin Date: Mon, 17 Oct 2016 10:10:12 +0200 Subject: [PATCH 52/58] Executable Jar Maven (#752) * Expression-Based Access Control PermitAll, hasRole, hasAnyRole etc. I modified classes regards to Security * Added test cases for Spring Security Expressions * Handler Interceptor - logging example * Test for logger interceptor * Removed conflicted part * UserInterceptor (adding user information to model) * Spring Handler Interceptor - session timers * Spring Security CSRF attack protection with Thymeleaf * Fix and(); * Logger update * Changed config for Thymeleaf * Thymeleaf Natural Processing and Inlining * Expression Utility Objects, Thymeleaf * listOfStudents edited * Thymeleaf layout decorators * Executable Jar with Maven --- core-java/pom.xml | 454 +++++++++++------- .../executable/ExecutableMavenJar.java | 11 + 2 files changed, 293 insertions(+), 172 deletions(-) create mode 100644 core-java/src/main/java/org/baeldung/executable/ExecutableMavenJar.java diff --git a/core-java/pom.xml b/core-java/pom.xml index a5e89d2a76..75608b59ba 100644 --- a/core-java/pom.xml +++ b/core-java/pom.xml @@ -1,211 +1,321 @@ - - 4.0.0 - com.baeldung - core-java - 0.1.0-SNAPSHOT + + 4.0.0 + com.baeldung + core-java + 0.1.0-SNAPSHOT + jar - core-java + core-java - + - - - net.sourceforge.collections - collections-generic - 4.01 - - - com.google.guava - guava - ${guava.version} - + + + net.sourceforge.collections + collections-generic + 4.01 + + + com.google.guava + guava + ${guava.version} + - - org.apache.commons - commons-collections4 - 4.0 - + + org.apache.commons + commons-collections4 + 4.0 + - - commons-io - commons-io - 2.4 - + + commons-io + commons-io + 2.4 + - - org.apache.commons - commons-lang3 - ${commons-lang3.version} - + + org.apache.commons + commons-lang3 + ${commons-lang3.version} + - - org.apache.commons - commons-math3 - 3.3 - + + org.apache.commons + commons-math3 + 3.3 + - + - + - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + - + - - org.slf4j - slf4j-api - ${org.slf4j.version} - - - ch.qos.logback - logback-classic - ${logback.version} - - - - org.slf4j - jcl-over-slf4j - ${org.slf4j.version} - - - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - + + org.slf4j + slf4j-api + ${org.slf4j.version} + + + ch.qos.logback + logback-classic + ${logback.version} + + + + org.slf4j + jcl-over-slf4j + ${org.slf4j.version} + + + + org.slf4j + log4j-over-slf4j + ${org.slf4j.version} + - + - - junit - junit - ${junit.version} - test - + + junit + junit + ${junit.version} + test + - - org.hamcrest - hamcrest-core - ${org.hamcrest.version} - test - - - org.hamcrest - hamcrest-library - ${org.hamcrest.version} - test - + + org.hamcrest + hamcrest-core + ${org.hamcrest.version} + test + + + org.hamcrest + hamcrest-library + ${org.hamcrest.version} + test + - - org.assertj - assertj-core - ${assertj.version} - test - + + org.assertj + assertj-core + ${assertj.version} + test + - - org.testng - testng - ${testng.version} - test - + + org.testng + testng + ${testng.version} + test + - - org.mockito - mockito-core - ${mockito.version} - test - - - - commons-codec - commons-codec - 1.10 - + + org.mockito + mockito-core + ${mockito.version} + test + - + + commons-codec + commons-codec + 1.10 + - - core-java - - - src/main/resources - true - - + - + + core-java + + + src/main/resources + true + + - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - + - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - **/*IntegrationTest.java - - - + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + 1.8 + 1.8 + + - + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + **/*IntegrationTest.java + + + - + + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + prepare-package + + copy-dependencies + + + ${project.build.directory}/libs + + + + - - - 4.3.11.Final - 5.1.38 + + org.apache.maven.plugins + maven-jar-plugin + + + + true + libs/ + org.baeldung.executable.ExecutableMavenJar + + + + - - 2.7.8 + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + + + org.baeldung.executable.ExecutableMavenJar + + + + jar-with-dependencies + + + + + - - 1.7.13 - 1.1.3 + + org.apache.maven.plugins + maven-shade-plugin + + + + shade + + + true + + + org.baeldung.executable.ExecutableMavenJar + + + + + + - - 5.1.3.Final + + com.jolira + onejar-maven-plugin + + + + org.baeldung.executable.ExecutableMavenJar + true + ${project.build.finalName}-onejar.${project.packaging} + + + one-jar + + + + - - 19.0 - 3.4 + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + spring-boot + org.baeldung.executable.ExecutableMavenJar + + + + + + - - 1.3 - 4.12 - 1.10.19 - 6.8 - 3.5.1 + - 4.4.1 - 4.5 + + + 4.3.11.Final + 5.1.38 - 2.9.0 + + 2.7.8 - - 3.5.1 - 2.6 - 2.19.1 - 2.7 - 1.4.18 + + 1.7.13 + 1.1.3 - + + 5.1.3.Final + + + 19.0 + 3.4 + + + 1.3 + 4.12 + 1.10.19 + 6.8 + 3.5.1 + + 4.4.1 + 4.5 + + 2.9.0 + + + 3.5.1 + 2.6 + 2.19.1 + 2.7 + 1.4.18 + + \ No newline at end of file diff --git a/core-java/src/main/java/org/baeldung/executable/ExecutableMavenJar.java b/core-java/src/main/java/org/baeldung/executable/ExecutableMavenJar.java new file mode 100644 index 0000000000..2c52a17904 --- /dev/null +++ b/core-java/src/main/java/org/baeldung/executable/ExecutableMavenJar.java @@ -0,0 +1,11 @@ +package org.baeldung.executable; + +import javax.swing.JOptionPane; + +public class ExecutableMavenJar { + + public static void main(String[] args) { + JOptionPane.showMessageDialog(null, "It worked!", "Executable Jar with Maven", 1); + } + +} From 091d02afbbf534434317dd7c423ca6470cf18c94 Mon Sep 17 00:00:00 2001 From: DOHA Date: Mon, 17 Oct 2016 12:39:30 +0200 Subject: [PATCH 53/58] add integration test profile --- spring-userservice/pom.xml | 59 +++++++++++-------- ...tomUserDetailsServiceIntegrationTest.java} | 2 +- 2 files changed, 37 insertions(+), 24 deletions(-) rename spring-userservice/src/test/java/org/baeldung/userservice/{CustomUserDetailsServiceTest.java => CustomUserDetailsServiceIntegrationTest.java} (98%) diff --git a/spring-userservice/pom.xml b/spring-userservice/pom.xml index 93b01ee49c..dc0d4d295c 100644 --- a/spring-userservice/pom.xml +++ b/spring-userservice/pom.xml @@ -240,39 +240,52 @@ ${maven-surefire-plugin.version} - + **/*IntegrationTest.java - - - org.codehaus.cargo - cargo-maven2-plugin - ${cargo-maven2-plugin.version} - - true - - jetty8x - embedded - - - - - - - 8082 - - - - - + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + + + **/*IntegrationTest.java + + + + + + + json + + + + + + + + 4.1.3.RELEASE diff --git a/spring-userservice/src/test/java/org/baeldung/userservice/CustomUserDetailsServiceTest.java b/spring-userservice/src/test/java/org/baeldung/userservice/CustomUserDetailsServiceIntegrationTest.java similarity index 98% rename from spring-userservice/src/test/java/org/baeldung/userservice/CustomUserDetailsServiceTest.java rename to spring-userservice/src/test/java/org/baeldung/userservice/CustomUserDetailsServiceIntegrationTest.java index 6e1cd67e06..79d60aa540 100644 --- a/spring-userservice/src/test/java/org/baeldung/userservice/CustomUserDetailsServiceTest.java +++ b/spring-userservice/src/test/java/org/baeldung/userservice/CustomUserDetailsServiceIntegrationTest.java @@ -25,7 +25,7 @@ import java.util.logging.Logger; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = { MvcConfig.class, PersistenceDerbyJPAConfig.class, SecSecurityConfig.class }) @WebAppConfiguration -public class CustomUserDetailsServiceTest { +public class CustomUserDetailsServiceIntegrationTest { private static final Logger LOG = Logger.getLogger("CustomUserDetailsServiceTest"); From 7667d25bb7fd4ca0da58f0452d828af5f6d96f65 Mon Sep 17 00:00:00 2001 From: DOHA Date: Mon, 17 Oct 2016 12:57:13 +0200 Subject: [PATCH 54/58] add integration test profile --- spring-thymeleaf/pom.xml | 58 ++++++++++++------- ...lityObjectsControllerIntegrationTest.java} | 2 +- ...youtDialectControllerIntegrationTest.java} | 2 +- 3 files changed, 39 insertions(+), 23 deletions(-) rename spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/{ExpressionUtilityObjectsControllerTest.java => ExpressionUtilityObjectsControllerIntegrationTest.java} (97%) rename spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/{LayoutDialectControllerTest.java => LayoutDialectControllerIntegrationTest.java} (97%) diff --git a/spring-thymeleaf/pom.xml b/spring-thymeleaf/pom.xml index 960b358fe2..d2b3be1651 100644 --- a/spring-thymeleaf/pom.xml +++ b/spring-thymeleaf/pom.xml @@ -166,31 +166,47 @@ ${maven-surefire-plugin.version} + **/*IntegrationTest.java + **/*LiveTest.java - - - - - - org.codehaus.cargo - cargo-maven2-plugin - ${cargo-maven2-plugin.version} - - true - - jetty8x - embedded - - - - - - 8082 - - + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + + + **/*IntegrationTest.java + + + + + + + json + + + + + + + diff --git a/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/ExpressionUtilityObjectsControllerTest.java b/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/ExpressionUtilityObjectsControllerIntegrationTest.java similarity index 97% rename from spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/ExpressionUtilityObjectsControllerTest.java rename to spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/ExpressionUtilityObjectsControllerIntegrationTest.java index f6a79b7570..0638dbbc11 100644 --- a/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/ExpressionUtilityObjectsControllerTest.java +++ b/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/ExpressionUtilityObjectsControllerIntegrationTest.java @@ -29,7 +29,7 @@ import com.baeldung.thymeleaf.config.WebMVCSecurity; @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration(classes = { WebApp.class, WebMVCConfig.class, WebMVCSecurity.class, InitSecurity.class }) -public class ExpressionUtilityObjectsControllerTest { +public class ExpressionUtilityObjectsControllerIntegrationTest { @Autowired WebApplicationContext wac; diff --git a/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/LayoutDialectControllerTest.java b/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/LayoutDialectControllerIntegrationTest.java similarity index 97% rename from spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/LayoutDialectControllerTest.java rename to spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/LayoutDialectControllerIntegrationTest.java index 33731f130d..23113dc229 100644 --- a/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/LayoutDialectControllerTest.java +++ b/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/LayoutDialectControllerIntegrationTest.java @@ -29,7 +29,7 @@ import com.baeldung.thymeleaf.config.WebMVCSecurity; @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration(classes = { WebApp.class, WebMVCConfig.class, WebMVCSecurity.class, InitSecurity.class }) -public class LayoutDialectControllerTest { +public class LayoutDialectControllerIntegrationTest { @Autowired WebApplicationContext wac; From 167d2de4acd9723813028c49efb5d5c18e28dbbd Mon Sep 17 00:00:00 2001 From: DOHA Date: Mon, 17 Oct 2016 13:19:52 +0200 Subject: [PATCH 55/58] add integration test profile --- spring-spel/pom.xml | 46 +++++++++++++++++++ ...SpelTest.java => SpelIntegrationTest.java} | 2 +- 2 files changed, 47 insertions(+), 1 deletion(-) rename spring-spel/src/test/java/com/baeldung/spel/{SpelTest.java => SpelIntegrationTest.java} (99%) diff --git a/spring-spel/pom.xml b/spring-spel/pom.xml index 12b7164e27..add5e53348 100644 --- a/spring-spel/pom.xml +++ b/spring-spel/pom.xml @@ -46,7 +46,53 @@ true + + + org.apache.maven.plugins + maven-surefire-plugin + 2.19.1 + + + **/*IntegrationTest.java + **/*LiveTest.java + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + + + **/*IntegrationTest.java + + + + + + + json + + + + + + + \ No newline at end of file diff --git a/spring-spel/src/test/java/com/baeldung/spel/SpelTest.java b/spring-spel/src/test/java/com/baeldung/spel/SpelIntegrationTest.java similarity index 99% rename from spring-spel/src/test/java/com/baeldung/spel/SpelTest.java rename to spring-spel/src/test/java/com/baeldung/spel/SpelIntegrationTest.java index 5cf18bc1d2..bff42caead 100644 --- a/spring-spel/src/test/java/com/baeldung/spel/SpelTest.java +++ b/spring-spel/src/test/java/com/baeldung/spel/SpelIntegrationTest.java @@ -13,7 +13,7 @@ import static org.junit.Assert.assertThat; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = {"classpath:applicationContext.xml"}) -public class SpelTest { +public class SpelIntegrationTest { @Autowired private SpelArithmetic spelArithmetic = new SpelArithmetic(); From 1e9d1a75663a4c02bbdab5aeebd85345bb6d1ef6 Mon Sep 17 00:00:00 2001 From: DOHA Date: Mon, 17 Oct 2016 13:30:13 +0200 Subject: [PATCH 56/58] add integration test profile --- .../spring-security-x509-basic-auth/pom.xml | 63 ++++++++++++++++--- ...9AuthenticationServerIntegrationTest.java} | 2 +- .../spring-security-x509-client-auth/pom.xml | 62 +++++++++++++++--- ...9AuthenticationServerIntegrationTest.java} | 2 +- 4 files changed, 111 insertions(+), 18 deletions(-) rename spring-security-x509/spring-security-x509-basic-auth/src/test/java/com/baeldung/spring/security/x509/{X509AuthenticationServerTests.java => X509AuthenticationServerIntegrationTest.java} (85%) rename spring-security-x509/spring-security-x509-client-auth/src/test/java/com/baeldung/spring/security/x509/{X509AuthenticationServerTests.java => X509AuthenticationServerIntegrationTest.java} (85%) diff --git a/spring-security-x509/spring-security-x509-basic-auth/pom.xml b/spring-security-x509/spring-security-x509-basic-auth/pom.xml index 87fdd64727..8f460c83ec 100644 --- a/spring-security-x509/spring-security-x509-basic-auth/pom.xml +++ b/spring-security-x509/spring-security-x509-basic-auth/pom.xml @@ -16,12 +16,59 @@ 0.0.1-SNAPSHOT - - - - org.springframework.boot - spring-boot-maven-plugin - - - + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*IntegrationTest.java + **/*LiveTest.java + + + + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + + + **/*IntegrationTest.java + + + + + + + json + + + + + + + + diff --git a/spring-security-x509/spring-security-x509-basic-auth/src/test/java/com/baeldung/spring/security/x509/X509AuthenticationServerTests.java b/spring-security-x509/spring-security-x509-basic-auth/src/test/java/com/baeldung/spring/security/x509/X509AuthenticationServerIntegrationTest.java similarity index 85% rename from spring-security-x509/spring-security-x509-basic-auth/src/test/java/com/baeldung/spring/security/x509/X509AuthenticationServerTests.java rename to spring-security-x509/spring-security-x509-basic-auth/src/test/java/com/baeldung/spring/security/x509/X509AuthenticationServerIntegrationTest.java index 0b9a11552a..5eb1c25ed6 100644 --- a/spring-security-x509/spring-security-x509-basic-auth/src/test/java/com/baeldung/spring/security/x509/X509AuthenticationServerTests.java +++ b/spring-security-x509/spring-security-x509-basic-auth/src/test/java/com/baeldung/spring/security/x509/X509AuthenticationServerIntegrationTest.java @@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest -public class X509AuthenticationServerTests { +public class X509AuthenticationServerIntegrationTest { @Test public void contextLoads() { } diff --git a/spring-security-x509/spring-security-x509-client-auth/pom.xml b/spring-security-x509/spring-security-x509-client-auth/pom.xml index 56cef8ea07..ffddabef40 100644 --- a/spring-security-x509/spring-security-x509-client-auth/pom.xml +++ b/spring-security-x509/spring-security-x509-client-auth/pom.xml @@ -16,12 +16,58 @@ 0.0.1-SNAPSHOT - - - - org.springframework.boot - spring-boot-maven-plugin - - - + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*IntegrationTest.java + **/*LiveTest.java + + + + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + + + **/*IntegrationTest.java + + + + + + + json + + + + + + + diff --git a/spring-security-x509/spring-security-x509-client-auth/src/test/java/com/baeldung/spring/security/x509/X509AuthenticationServerTests.java b/spring-security-x509/spring-security-x509-client-auth/src/test/java/com/baeldung/spring/security/x509/X509AuthenticationServerIntegrationTest.java similarity index 85% rename from spring-security-x509/spring-security-x509-client-auth/src/test/java/com/baeldung/spring/security/x509/X509AuthenticationServerTests.java rename to spring-security-x509/spring-security-x509-client-auth/src/test/java/com/baeldung/spring/security/x509/X509AuthenticationServerIntegrationTest.java index 0b9a11552a..5eb1c25ed6 100644 --- a/spring-security-x509/spring-security-x509-client-auth/src/test/java/com/baeldung/spring/security/x509/X509AuthenticationServerTests.java +++ b/spring-security-x509/spring-security-x509-client-auth/src/test/java/com/baeldung/spring/security/x509/X509AuthenticationServerIntegrationTest.java @@ -7,7 +7,7 @@ import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest -public class X509AuthenticationServerTests { +public class X509AuthenticationServerIntegrationTest { @Test public void contextLoads() { } From 903c9c52999f1421f2f3d8c18a78865e29b73c36 Mon Sep 17 00:00:00 2001 From: DOHA Date: Mon, 17 Oct 2016 19:35:24 +0200 Subject: [PATCH 57/58] add integration test profile --- spring-protobuf/pom.xml | 48 ++++++++++- ...t.java => ApplicationIntegrationTest.java} | 2 +- spring-rest-angular/pom.xml | 85 ++++++++++++++----- ...ava => StudentServiceIntegrationTest.java} | 2 +- 4 files changed, 113 insertions(+), 24 deletions(-) rename spring-protobuf/src/test/java/com/baeldung/protobuf/{ApplicationTest.java => ApplicationIntegrationTest.java} (98%) rename spring-rest-angular/src/test/java/org/baeldung/web/service/{StudentServiceTest.java => StudentServiceIntegrationTest.java} (98%) diff --git a/spring-protobuf/pom.xml b/spring-protobuf/pom.xml index 1275d72edf..a080d51221 100644 --- a/spring-protobuf/pom.xml +++ b/spring-protobuf/pom.xml @@ -37,7 +37,6 @@ org.apache.httpcomponents httpclient - 4.5.2 @@ -47,12 +46,57 @@ org.apache.maven.plugins maven-compiler-plugin - 3.3 1.8 1.8 + + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*IntegrationTest.java + **/*LiveTest.java + + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + + + **/*IntegrationTest.java + + + + + + + json + + + + + + + diff --git a/spring-protobuf/src/test/java/com/baeldung/protobuf/ApplicationTest.java b/spring-protobuf/src/test/java/com/baeldung/protobuf/ApplicationIntegrationTest.java similarity index 98% rename from spring-protobuf/src/test/java/com/baeldung/protobuf/ApplicationTest.java rename to spring-protobuf/src/test/java/com/baeldung/protobuf/ApplicationIntegrationTest.java index a17082cea7..914cf18627 100644 --- a/spring-protobuf/src/test/java/com/baeldung/protobuf/ApplicationTest.java +++ b/spring-protobuf/src/test/java/com/baeldung/protobuf/ApplicationIntegrationTest.java @@ -24,7 +24,7 @@ import static org.junit.Assert.assertThat; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = Application.class) @WebIntegrationTest -public class ApplicationTest { +public class ApplicationIntegrationTest { private static final String COURSE1_URL = "http://localhost:8080/courses/1"; diff --git a/spring-rest-angular/pom.xml b/spring-rest-angular/pom.xml index 981ee9dabc..ce496df742 100644 --- a/spring-rest-angular/pom.xml +++ b/spring-rest-angular/pom.xml @@ -71,30 +71,75 @@ - - angular-spring-rest-sample - + + angular-spring-rest-sample + - - org.apache.maven.plugins - maven-compiler-plugin - - 1.8 - 1.8 - - + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + - - org.apache.maven.plugins - maven-war-plugin - - false - - + + org.apache.maven.plugins + maven-war-plugin + + false + + - - + + org.apache.maven.plugins + maven-surefire-plugin + + + **/*IntegrationTest.java + **/*LiveTest.java + + + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + + + **/*IntegrationTest.java + + + + + + + json + + + + + + + + 19.0 diff --git a/spring-rest-angular/src/test/java/org/baeldung/web/service/StudentServiceTest.java b/spring-rest-angular/src/test/java/org/baeldung/web/service/StudentServiceIntegrationTest.java similarity index 98% rename from spring-rest-angular/src/test/java/org/baeldung/web/service/StudentServiceTest.java rename to spring-rest-angular/src/test/java/org/baeldung/web/service/StudentServiceIntegrationTest.java index 1199f15ab3..6ad80e5caf 100644 --- a/spring-rest-angular/src/test/java/org/baeldung/web/service/StudentServiceTest.java +++ b/spring-rest-angular/src/test/java/org/baeldung/web/service/StudentServiceIntegrationTest.java @@ -18,7 +18,7 @@ import static org.hamcrest.core.IsEqual.*; @SpringApplicationConfiguration(classes = Application.class) @WebAppConfiguration @IntegrationTest("server.port:8888") -public class StudentServiceTest { +public class StudentServiceIntegrationTest { private static final String ENDPOINT = "http://localhost:8888/student/get"; From e9f3cfd7c6e872d86b84132c98b760da2b33eca0 Mon Sep 17 00:00:00 2001 From: DOHA Date: Mon, 17 Oct 2016 19:43:48 +0200 Subject: [PATCH 58/58] add integration test profile --- spring-mvc-web-vs-initializer/pom.xml | 67 ++++++++++++++++--- ...t.java => JavaServletIntegrationTest.java} | 2 +- ...st.java => XmlServletIntegrationTest.java} | 2 +- 3 files changed, 59 insertions(+), 12 deletions(-) rename spring-mvc-web-vs-initializer/src/test/java/org/baeldung/controller/{JavaServletTest.java => JavaServletIntegrationTest.java} (97%) rename spring-mvc-web-vs-initializer/src/test/java/org/baeldung/controller/{XmlServletTest.java => XmlServletIntegrationTest.java} (97%) diff --git a/spring-mvc-web-vs-initializer/pom.xml b/spring-mvc-web-vs-initializer/pom.xml index 0d735e7188..b448673ef8 100644 --- a/spring-mvc-web-vs-initializer/pom.xml +++ b/spring-mvc-web-vs-initializer/pom.xml @@ -146,17 +146,64 @@ - - spring-mvc-web-vs-initializer - - - src/main/resources - true - - - - + + spring-mvc-web-vs-initializer + + + src/main/resources + true + + + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + + + **/*IntegrationTest.java + **/*LiveTest.java + + + + + + + + integration + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration-test + + test + + + + **/*LiveTest.java + + + **/*IntegrationTest.java + + + + + + + json + + + + + + + + 4.3.1.RELEASE diff --git a/spring-mvc-web-vs-initializer/src/test/java/org/baeldung/controller/JavaServletTest.java b/spring-mvc-web-vs-initializer/src/test/java/org/baeldung/controller/JavaServletIntegrationTest.java similarity index 97% rename from spring-mvc-web-vs-initializer/src/test/java/org/baeldung/controller/JavaServletTest.java rename to spring-mvc-web-vs-initializer/src/test/java/org/baeldung/controller/JavaServletIntegrationTest.java index 99b5ef8c2f..0461cc8fcc 100644 --- a/spring-mvc-web-vs-initializer/src/test/java/org/baeldung/controller/JavaServletTest.java +++ b/spring-mvc-web-vs-initializer/src/test/java/org/baeldung/controller/JavaServletIntegrationTest.java @@ -20,7 +20,7 @@ import org.springframework.web.servlet.ModelAndView; @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration(loader=AnnotationConfigWebContextLoader.class, classes = MvcConfig.class) -public class JavaServletTest { +public class JavaServletIntegrationTest { private MockMvc mockMvc; diff --git a/spring-mvc-web-vs-initializer/src/test/java/org/baeldung/controller/XmlServletTest.java b/spring-mvc-web-vs-initializer/src/test/java/org/baeldung/controller/XmlServletIntegrationTest.java similarity index 97% rename from spring-mvc-web-vs-initializer/src/test/java/org/baeldung/controller/XmlServletTest.java rename to spring-mvc-web-vs-initializer/src/test/java/org/baeldung/controller/XmlServletIntegrationTest.java index e7695e36c0..e1273f8f88 100644 --- a/spring-mvc-web-vs-initializer/src/test/java/org/baeldung/controller/XmlServletTest.java +++ b/spring-mvc-web-vs-initializer/src/test/java/org/baeldung/controller/XmlServletIntegrationTest.java @@ -19,7 +19,7 @@ import org.springframework.web.servlet.ModelAndView; @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration @ContextConfiguration(loader=GenericXmlWebContextLoader.class, locations = "classpath*:mvc-configuration.xml") -public class XmlServletTest { +public class XmlServletIntegrationTest { private MockMvc mockMvc;