Merge remote-tracking branch 'origin/master'

This commit is contained in:
pivovarit 2016-12-10 14:43:45 +01:00
commit 5679aa4e5c
12 changed files with 98 additions and 94 deletions

View File

@ -38,3 +38,4 @@
- [Guide to the Fork/Join Framework in Java](http://www.baeldung.com/java-fork-join)
- [How to Print Screen in Java](http://www.baeldung.com/print-screen-in-java)
- [How to Convert String to different data types in Java](http://www.baeldung.com/java-string-conversions)
- [Introduction to Java Generics](http://www.baeldung.com/java-generics)

View File

@ -14,11 +14,14 @@ import java.util.HashMap;
import java.util.Map;
import static java.util.stream.Collectors.joining;
import static org.hamcrest.CoreMatchers.*;
public class EncoderDecoderUnitTest {
private static final Logger LOGGER = LoggerFactory.getLogger(EncoderDecoderUnitTest.class);
private static final String testUrl = "http://www.baeldung.com/path+1?key1=value+1&key2=value%40%21%242&key3=value%253#dummy+Fragment";
private static final String testUrl = "http://www.baeldung.com?key1=value+1&key2=value%40%21%242&key3=value%253";
private static final String testUrlWithPath = "http://www.baeldung.com/path+1?key1=value+1&key2=value%40%21%242&key3=value%253";
private String encodeValue(String value) {
String encoded = null;
@ -42,13 +45,11 @@ public class EncoderDecoderUnitTest {
@Test
public void givenURL_whenAnalyze_thenCorrect() throws Exception {
URI uri = new URI(testUrl);
URL url = new URL(testUrl);
Assert.assertThat(uri.getScheme(), CoreMatchers.is("http"));
Assert.assertThat(uri.getHost(), CoreMatchers.is("www.baeldung.com"));
Assert.assertThat(uri.getRawPath(), CoreMatchers.is("/path+1"));
Assert.assertThat(uri.getRawQuery(), CoreMatchers.is("key1=value+1&key2=value%40%21%242&key3=value%253"));
Assert.assertThat(uri.getRawFragment(), CoreMatchers.is("dummy+Fragment"));
Assert.assertThat(url.getProtocol(), is("http"));
Assert.assertThat(url.getHost(), is("www.baeldung.com"));
Assert.assertThat(url.getQuery(), is("key1=value+1&key2=value%40%21%242&key3=value%253"));
}
@Test
@ -58,35 +59,29 @@ public class EncoderDecoderUnitTest {
requestParams.put("key2", "value@!$2");
requestParams.put("key3", "value%3");
String path = "path+1";
String fragment = "dummy Fragment";
String encodedURL = requestParams.keySet().stream()
.map(key -> key + "=" + encodeValue(requestParams.get(key)))
.collect(joining("&", "http://www.baeldung.com?", ""));
String encodedURL = requestParams.keySet().stream().map(key -> key + "=" + encodeValue(requestParams.get(key))).collect(joining("&", "http://www.baeldung.com/" + getPath(path) + "?", "#" + encodeValue(fragment)));
Assert.assertThat(testUrl, CoreMatchers.is(encodedURL));
Assert.assertThat(testUrl, is(encodedURL));
}
@Test
public void givenRequestParam_whenUTF8Scheme_thenDecodeRequestParams() throws Exception {
URI uri = new URI(testUrl);
URL url = new URL(testUrl);
String scheme = uri.getScheme();
String host = uri.getHost();
String query = uri.getRawQuery();
String path = uri.getRawPath();
String fragment = uri.getRawFragment();
String query = url.getQuery();
String decodedQuery = Arrays.stream(query.split("&")).map(param -> param.split("=")[0] + "=" + decode(param.split("=")[1])).collect(joining("&"));
String decodedPath = Arrays.stream(path.split("/")).map(param -> getPath(param)).collect(joining("/"));
Assert.assertEquals("http://www.baeldung.com/path+1?key1=value 1&key2=value@!$2&key3=value%3#dummy Fragment", scheme + "://" + host + decodedPath + "?" + decodedQuery + "#" + decode(fragment));
Assert.assertEquals("http://www.baeldung.com?key1=value 1&key2=value@!$2&key3=value%3", url.getProtocol() + "://" + url.getHost() + "?" + decodedQuery);
}
private String getPath(String path) {
private String encodePath(String path) {
try {
path = new URI(null, null, path, null).getPath();
} catch (URISyntaxException e) {
e.printStackTrace();
LOGGER.error("Error encoding parameter {}", e.getMessage(), e);
}
return path;
}
@ -98,4 +93,22 @@ public class EncoderDecoderUnitTest {
Assert.assertEquals("/Path 1/Path+2", uri.getPath());
Assert.assertEquals("/Path%201/Path+2", uri.getRawPath());
}
@Test
public void givenPathAndRequestParam_whenUTF8Scheme_thenEncode() throws Exception {
Map<String, String> requestParams = new HashMap<>();
requestParams.put("key1", "value 1");
requestParams.put("key2", "value@!$2");
requestParams.put("key3", "value%3");
String path = "path+1";
String encodedURL = requestParams.keySet().stream()
.map(key -> key + "=" + encodeValue(requestParams.get(key)))
.collect(joining("&", "http://www.baeldung.com/" + encodePath(path) + "?", ""));
Assert.assertThat(testUrlWithPath, is(encodedURL));
}
}

View File

@ -9,9 +9,11 @@
<packaging>war</packaging>
<properties>
<resteasy.version>3.0.14.Final</resteasy.version>
<resteasy.version>3.0.19.Final</resteasy.version>
<junit.version>4.12</junit.version>
<commons-io.version>2.5</commons-io.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
<cargo-maven2-plugin.version>1.6.0</cargo-maven2-plugin.version>
<cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version>
</properties>
<build>
@ -93,13 +95,13 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
<version>${commons-io.version}</version>
</dependency>
</dependencies>

View File

@ -9,7 +9,7 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
@ -18,7 +18,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<includes>
@ -38,7 +38,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<includes>
<include>**/*LiveTest.java</include>
@ -55,17 +55,26 @@
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.0.1</version>
<version>${selenium-java.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.13.6</version>
<version>${testng.version}</version>
</dependency>
</dependencies>
<properties>
<junit.version>4.12</junit.version>
<testng.version>6.10</testng.version>
<selenium-java.version>3.0.1</selenium-java.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
</properties>
</project>

View File

@ -115,11 +115,11 @@
</profiles>
<properties>
<spring.version>4.3.2.RELEASE</spring.version>
<akka.version>2.4.8</akka.version>
<spring.version>4.3.4.RELEASE</spring.version>
<akka.version>2.4.14</akka.version>
<junit.version>4.12</junit.version>
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
</properties>

View File

@ -11,7 +11,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.6.RELEASE</version>
<version>1.4.2.RELEASE</version>
</parent>
<dependencies>
@ -134,7 +134,7 @@
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.5.1</version>
<version>${assertj.version}</version>
<scope>test</scope>
</dependency>
@ -158,13 +158,13 @@
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.4</version>
<version>${easymock.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.1.3</version>
<version>${ehcache.version}</version>
</dependency>
</dependencies>
@ -273,42 +273,17 @@
<properties>
<!-- Spring -->
<org.springframework.version>4.3.1.RELEASE</org.springframework.version>
<org.springframework.security.version>4.0.4.RELEASE</org.springframework.security.version>
<javassist.version>3.20.0-GA</javassist.version>
<jstl.version>1.2</jstl.version>
<org.springframework.version>4.3.4.RELEASE</org.springframework.version>
<org.springframework.security.version>4.2.0.RELEASE</org.springframework.security.version>
<!-- persistence -->
<hibernate.version>4.3.11.Final</hibernate.version>
<mysql-connector-java.version>5.1.38</mysql-connector-java.version>
<!-- logging -->
<org.slf4j.version>1.7.13</org.slf4j.version>
<logback.version>1.1.3</logback.version>
<!-- various -->
<hibernate-validator.version>5.2.2.Final</hibernate-validator.version>
<hibernate.version>5.2.5.Final</hibernate.version>
<!-- util -->
<guava.version>19.0</guava.version>
<commons-lang3.version>3.4</commons-lang3.version>
<!-- testing -->
<org.hamcrest.version>1.3</org.hamcrest.version>
<junit.version>4.12</junit.version>
<mockito.version>1.10.19</mockito.version>
<httpcore.version>4.4.1</httpcore.version>
<httpclient.version>4.5</httpclient.version>
<rest-assured.version>2.9.0</rest-assured.version>
<!-- maven plugins -->
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
<maven-war-plugin.version>2.6</maven-war-plugin.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
<maven-resources-plugin.version>2.7</maven-resources-plugin.version>
<cargo-maven2-plugin.version>1.4.18</cargo-maven2-plugin.version>
<ehcache.version>3.1.3</ehcache.version>
<easymock.version>3.4</easymock.version>
<assertj.version>3.6.1</assertj.version>
</properties>

View File

@ -10,9 +10,9 @@
<properties>
<env.camel.version>2.16.1</env.camel.version>
<env.spring.version>4.2.4.RELEASE</env.spring.version>
<env.spring.version>4.3.4.RELEASE</env.spring.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
<java.version>1.7</java.version>
<java.version>1.8</java.version>
<junit.version>4.12</junit.version>
</properties>

View File

@ -12,8 +12,9 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<org.springframework.version>4.2.5.RELEASE</org.springframework.version>
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
<org.springframework.version>4.3.4.RELEASE</org.springframework.version>
<junit.version>4.12</junit.version>
<maven-compiler-plugin.version>3.6.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
</properties>
@ -21,7 +22,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>

View File

@ -11,9 +11,9 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.version>4.2.0.RELEASE</spring.version>
<spring.batch.version>3.0.5.RELEASE</spring.batch.version>
<sqlite.version>3.8.11.2</sqlite.version>
<spring.version>4.3.4.RELEASE</spring.version>
<spring.batch.version>3.0.7.RELEASE</spring.batch.version>
<sqlite.version>3.15.1</sqlite.version>
</properties>
<dependencies>

View File

@ -73,19 +73,19 @@
<dependency>
<groupId>org.subethamail</groupId>
<artifactId>subethasmtp</artifactId>
<version>3.1.7</version>
<version>${subethasmtp.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.7-1</version>
<version>${bootstrap.version}</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>jquery</artifactId>
<version>3.1.1</version>
<version>${jquery.version}</version>
</dependency>
</dependencies>
@ -122,7 +122,7 @@
<plugin>
<groupId>pl.project13.maven</groupId>
<artifactId>git-commit-id-plugin</artifactId>
<version>2.2.1</version>
<version>${git-commit-id-plugin.version}</version>
</plugin>
<plugin>
@ -182,6 +182,10 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<spring.version>4.3.4.RELEASE</spring.version>
<git-commit-id-plugin.version>2.2.1</git-commit-id-plugin.version>
<jquery.version>3.1.1</jquery.version>
<bootstrap.version>3.3.7-1</bootstrap.version>
<subethasmtp.version>3.1.7</subethasmtp.version>
</properties>
</project>

View File

@ -1,10 +1,7 @@
package com.baeldung.htmlunit;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@ -14,7 +11,6 @@ import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.htmlunit.MockMvcWebClientBuilder;
import org.springframework.web.context.WebApplicationContext;
import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlForm;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
@ -33,8 +29,7 @@ public class HtmlUnitAndSpringTest {
@Before
public void setup() {
webClient = MockMvcWebClientBuilder
.webAppContextSetup(wac).build();
webClient = MockMvcWebClientBuilder.webAppContextSetup(wac).build();
}
@Test
@ -49,12 +44,10 @@ public class HtmlUnitAndSpringTest {
messageText.setValueAttribute(text);
HtmlForm form = page.getForms().get(0);
HtmlSubmitInput submit = form.getOneHtmlElementByAttribute(
"input", "type", "submit");
HtmlSubmitInput submit = form.getOneHtmlElementByAttribute("input", "type", "submit");
HtmlPage newPage = submit.click();
String receivedText = newPage.getHtmlElementById("received")
.getTextContent();
String receivedText = newPage.getHtmlElementById("received").getTextContent();
Assert.assertEquals(receivedText, text);
}

6
spring-session/README.md Normal file
View File

@ -0,0 +1,6 @@
=========
## Spring Session Examples
### Relevant Articles:
- [Introduction to Spring Session](http://www.baeldung.com/spring-session)