Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
7d09a2c3df
@ -0,0 +1,15 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||||
|
xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form action="#" th:action="@{/message/processForm}" method="post">
|
||||||
|
Message: <input type="text" value="message" id="message" name="message"/>
|
||||||
|
<input type="submit" />
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<span th:text="${message}" id="received"></span>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -0,0 +1,31 @@
|
|||||||
|
package com.baeldung.htmlunit;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import com.gargoylesoftware.htmlunit.WebClient;
|
||||||
|
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||||
|
|
||||||
|
public class HtmlUnitAndJUnitTest {
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void init() throws Exception {
|
||||||
|
webClient = new WebClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void close() throws Exception {
|
||||||
|
webClient.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAClient_whenEnteringBaeldung_thenPageTitleIsOk()
|
||||||
|
throws Exception {
|
||||||
|
webClient.getOptions().setThrowExceptionOnScriptError(false);
|
||||||
|
HtmlPage page = webClient.getPage("http://www.baeldung.com/");
|
||||||
|
Assert.assertEquals(
|
||||||
|
"Baeldung | Java, Spring and Web Development tutorials",
|
||||||
|
page.getTitleText());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,72 +0,0 @@
|
|||||||
package com.baeldung.htmlunit;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
|
|
||||||
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;
|
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
||||||
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;
|
|
||||||
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
|
|
||||||
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
|
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
|
||||||
@WebAppConfiguration
|
|
||||||
@ContextConfiguration(classes = { TestConfig.class })
|
|
||||||
public class HtmlUnitAndSpringIntegrationTest {
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private WebApplicationContext wac;
|
|
||||||
|
|
||||||
private WebClient webClient;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setup() {
|
|
||||||
webClient = MockMvcWebClientBuilder.webAppContextSetup(wac).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Ignore("Related view message.html does not exist check MessageController")
|
|
||||||
public void givenAMessage_whenSent_thenItShows() throws FailingHttpStatusCodeException, MalformedURLException, IOException {
|
|
||||||
final String text = "Hello world!";
|
|
||||||
final HtmlPage page = webClient.getPage("http://localhost/message/showForm");
|
|
||||||
System.out.println(page.asXml());
|
|
||||||
|
|
||||||
final HtmlTextInput messageText = page.getHtmlElementById("message");
|
|
||||||
messageText.setValueAttribute(text);
|
|
||||||
|
|
||||||
final HtmlForm form = page.getForms().get(0);
|
|
||||||
final HtmlSubmitInput submit = form.getOneHtmlElementByAttribute("input", "type", "submit");
|
|
||||||
final HtmlPage newPage = submit.click();
|
|
||||||
|
|
||||||
final String receivedText = newPage.getHtmlElementById("received").getTextContent();
|
|
||||||
|
|
||||||
Assert.assertEquals(receivedText, text);
|
|
||||||
System.out.println(newPage.asXml());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void givenAClient_whenEnteringBaeldung_thenPageTitleIsCorrect() throws Exception {
|
|
||||||
try (final WebClient client = new WebClient()) {
|
|
||||||
webClient.getOptions().setThrowExceptionOnScriptError(false);
|
|
||||||
|
|
||||||
final HtmlPage page = webClient.getPage("http://www.baeldung.com/");
|
|
||||||
Assert.assertEquals("Baeldung | Java, Spring and Web Development tutorials", page.getTitleText());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -0,0 +1,61 @@
|
|||||||
|
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;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
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;
|
||||||
|
import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput;
|
||||||
|
import com.gargoylesoftware.htmlunit.html.HtmlTextInput;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@WebAppConfiguration
|
||||||
|
@ContextConfiguration(classes = { TestConfig.class })
|
||||||
|
public class HtmlUnitAndSpringTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private WebApplicationContext wac;
|
||||||
|
|
||||||
|
private WebClient webClient;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
webClient = MockMvcWebClientBuilder
|
||||||
|
.webAppContextSetup(wac).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenAMessage_whenSent_thenItShows() throws Exception {
|
||||||
|
String text = "Hello world!";
|
||||||
|
HtmlPage page;
|
||||||
|
|
||||||
|
String url = "http://localhost/message/showForm";
|
||||||
|
page = webClient.getPage(url);
|
||||||
|
|
||||||
|
HtmlTextInput messageText = page.getHtmlElementById("message");
|
||||||
|
messageText.setValueAttribute(text);
|
||||||
|
|
||||||
|
HtmlForm form = page.getForms().get(0);
|
||||||
|
HtmlSubmitInput submit = form.getOneHtmlElementByAttribute(
|
||||||
|
"input", "type", "submit");
|
||||||
|
HtmlPage newPage = submit.click();
|
||||||
|
|
||||||
|
String receivedText = newPage.getHtmlElementById("received")
|
||||||
|
.getTextContent();
|
||||||
|
|
||||||
|
Assert.assertEquals(receivedText, text);
|
||||||
|
}
|
||||||
|
}
|
@ -1,21 +0,0 @@
|
|||||||
package com.baeldung.htmlunit;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import com.gargoylesoftware.htmlunit.WebClient;
|
|
||||||
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
|
||||||
|
|
||||||
public class HtmlUnitTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void givenAClient_whenEnteringBaeldung_thenPageTitleIsCorrect() throws Exception {
|
|
||||||
try (final WebClient webClient = new WebClient()) {
|
|
||||||
webClient.getOptions().setThrowExceptionOnScriptError(false);
|
|
||||||
|
|
||||||
final HtmlPage page = webClient.getPage("http://www.baeldung.com/");
|
|
||||||
Assert.assertEquals("Baeldung | Java, Spring and Web Development tutorials", page.getTitleText());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -5,36 +5,38 @@ import java.util.List;
|
|||||||
import com.gargoylesoftware.htmlunit.WebClient;
|
import com.gargoylesoftware.htmlunit.WebClient;
|
||||||
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
|
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
|
||||||
import com.gargoylesoftware.htmlunit.html.HtmlHeading1;
|
import com.gargoylesoftware.htmlunit.html.HtmlHeading1;
|
||||||
import com.gargoylesoftware.htmlunit.html.HtmlHeading2;
|
|
||||||
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||||
|
|
||||||
public class HtmlUnitWebScraping {
|
public class HtmlUnitWebScraping {
|
||||||
|
|
||||||
public static void main(final String[] args) throws Exception {
|
private WebClient webClient;
|
||||||
try (final WebClient webClient = new WebClient()) {
|
|
||||||
|
|
||||||
webClient.getOptions().setCssEnabled(false);
|
@Before
|
||||||
webClient.getOptions().setJavaScriptEnabled(false);
|
public void init() throws Exception {
|
||||||
|
webClient = new WebClient();
|
||||||
|
}
|
||||||
|
|
||||||
final HtmlPage page = webClient.getPage("http://www.baeldung.com/full_archive");
|
@After
|
||||||
final HtmlAnchor latestPostLink = (HtmlAnchor) page.getByXPath("(//ul[@class='car-monthlisting']/li)[1]/a").get(0);
|
public void close() throws Exception {
|
||||||
|
webClient.close();
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("Entering: " + latestPostLink.getHrefAttribute());
|
@Test
|
||||||
|
public void givenBaeldungArchive_whenRetrievingArticle_thenHasH1()
|
||||||
|
throws Exception {
|
||||||
|
webClient.getOptions().setCssEnabled(false);
|
||||||
|
webClient.getOptions().setJavaScriptEnabled(false);
|
||||||
|
|
||||||
final HtmlPage postPage = latestPostLink.click();
|
String url = "http://www.baeldung.com/full_archive";
|
||||||
|
HtmlPage page = webClient.getPage(url);
|
||||||
|
String xpath = "(//ul[@class='car-monthlisting']/li)[1]/a";
|
||||||
|
HtmlAnchor latestPostLink
|
||||||
|
= (HtmlAnchor) page.getByXPath(xpath).get(0);
|
||||||
|
HtmlPage postPage = latestPostLink.click();
|
||||||
|
|
||||||
final HtmlHeading1 heading1 = (HtmlHeading1) postPage.getByXPath("//h1").get(0);
|
List<HtmlHeading1> h1
|
||||||
System.out.println("Title: " + heading1.getTextContent());
|
= (List<HtmlHeading1>) postPage.getByXPath("//h1");
|
||||||
|
|
||||||
final List<HtmlHeading2> headings2 = (List<HtmlHeading2>) postPage.getByXPath("//h2");
|
|
||||||
|
|
||||||
final StringBuilder sb = new StringBuilder(heading1.getTextContent());
|
|
||||||
for (final HtmlHeading2 h2 : headings2) {
|
|
||||||
sb.append("\n").append(h2.getTextContent());
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.println(sb.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Assert.assertTrue(h1.size() > 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,393 +1,400 @@
|
|||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<artifactId>spring-security-rest</artifactId>
|
<artifactId>spring-security-rest</artifactId>
|
||||||
<version>0.1-SNAPSHOT</version>
|
<version>0.1-SNAPSHOT</version>
|
||||||
|
|
||||||
<name>spring-security-rest</name>
|
<name>spring-security-rest</name>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<!-- Spring Security -->
|
<!-- Spring Security -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.security</groupId>
|
<groupId>org.springframework.security</groupId>
|
||||||
<artifactId>spring-security-web</artifactId>
|
<artifactId>spring-security-web</artifactId>
|
||||||
<version>${org.springframework.security.version}</version>
|
<version>${org.springframework.security.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.security</groupId>
|
<groupId>org.springframework.security</groupId>
|
||||||
<artifactId>spring-security-config</artifactId>
|
<artifactId>spring-security-config</artifactId>
|
||||||
<version>${org.springframework.security.version}</version>
|
<version>${org.springframework.security.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Spring -->
|
<!-- Spring -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-core</artifactId>
|
<artifactId>spring-core</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
<version>${org.springframework.version}</version>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<artifactId>commons-logging</artifactId>
|
<artifactId>commons-logging</artifactId>
|
||||||
<groupId>commons-logging</groupId>
|
<groupId>commons-logging</groupId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-context</artifactId>
|
<artifactId>spring-context</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
<version>${org.springframework.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-jdbc</artifactId>
|
<artifactId>spring-jdbc</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
<version>${org.springframework.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-beans</artifactId>
|
<artifactId>spring-beans</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
<version>${org.springframework.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-aop</artifactId>
|
<artifactId>spring-aop</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
<version>${org.springframework.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-tx</artifactId>
|
<artifactId>spring-tx</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
<version>${org.springframework.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-expression</artifactId>
|
<artifactId>spring-expression</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
<version>${org.springframework.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-web</artifactId>
|
<artifactId>spring-web</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
<version>${org.springframework.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.springframework</groupId>
|
||||||
<artifactId>spring-webmvc</artifactId>
|
<artifactId>spring-webmvc</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
<version>${org.springframework.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Spring HATEOAS -->
|
<!-- Spring HATEOAS -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.hateoas</groupId>
|
<groupId>org.springframework.hateoas</groupId>
|
||||||
<artifactId>spring-hateoas</artifactId>
|
<artifactId>spring-hateoas</artifactId>
|
||||||
<version>${org.springframework.hateoas.version}</version>
|
<version>${org.springframework.hateoas.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- web -->
|
<!-- web -->
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>javax.servlet-api</artifactId>
|
<artifactId>javax.servlet-api</artifactId>
|
||||||
<version>${javax.servlet-api.version}</version>
|
<version>${javax.servlet-api.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>jstl</artifactId>
|
<artifactId>jstl</artifactId>
|
||||||
<version>${jstl.version}</version>
|
<version>${jstl.version}</version>
|
||||||
<scope>runtime</scope>
|
<scope>runtime</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.validation</groupId>
|
<groupId>javax.validation</groupId>
|
||||||
<artifactId>validation-api</artifactId>
|
<artifactId>validation-api</artifactId>
|
||||||
<version>${javax.validation.version}</version>
|
<version>${javax.validation.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<!-- marshalling -->
|
<!-- marshalling -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.fasterxml.jackson.core</groupId>
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
<artifactId>jackson-databind</artifactId>
|
<artifactId>jackson-databind</artifactId>
|
||||||
<version>${jackson.version}</version>
|
<version>${jackson.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- util -->
|
<!-- util -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.google.guava</groupId>
|
<groupId>com.google.guava</groupId>
|
||||||
<artifactId>guava</artifactId>
|
<artifactId>guava</artifactId>
|
||||||
<version>${guava.version}</version>
|
<version>${guava.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.commons</groupId>
|
<groupId>org.apache.commons</groupId>
|
||||||
<artifactId>commons-lang3</artifactId>
|
<artifactId>commons-lang3</artifactId>
|
||||||
<version>${commons-lang3.version}</version>
|
<version>${commons-lang3.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- logging -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-api</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>ch.qos.logback</groupId>
|
|
||||||
<artifactId>logback-classic</artifactId>
|
|
||||||
<version>${logback.version}</version>
|
|
||||||
<!-- <scope>runtime</scope> -->
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>jcl-over-slf4j</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
|
||||||
</dependency>
|
|
||||||
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>log4j-over-slf4j</artifactId>
|
|
||||||
<version>${org.slf4j.version}</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- test scoped -->
|
<!-- logging -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>spring-test</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>${org.springframework.version}</version>
|
<version>${org.slf4j.version}</version>
|
||||||
<scope>test</scope>
|
</dependency>
|
||||||
</dependency>
|
<dependency>
|
||||||
|
<groupId>ch.qos.logback</groupId>
|
||||||
|
<artifactId>logback-classic</artifactId>
|
||||||
|
<version>${logback.version}</version>
|
||||||
|
<!-- <scope>runtime</scope> -->
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>jcl-over-slf4j</artifactId>
|
||||||
|
<version>${org.slf4j.version}</version>
|
||||||
|
<!-- <scope>runtime</scope> --> <!-- some spring dependencies need to compile against jcl -->
|
||||||
|
</dependency>
|
||||||
|
<dependency> <!-- needed to bridge to slf4j for projects that use the log4j APIs directly -->
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>log4j-over-slf4j</artifactId>
|
||||||
|
<version>${org.slf4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<!-- test scoped -->
|
||||||
<groupId>org.springframework.security</groupId>
|
<dependency>
|
||||||
<artifactId>spring-security-test</artifactId>
|
<groupId>org.springframework</groupId>
|
||||||
<version>${org.springframework.security.version}</version>
|
<artifactId>spring-test</artifactId>
|
||||||
<scope>test</scope>
|
<version>${org.springframework.version}</version>
|
||||||
</dependency>
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.security</groupId>
|
||||||
|
<artifactId>spring-security-test</artifactId>
|
||||||
|
<version>${org.springframework.security.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.jayway.restassured</groupId>
|
<groupId>com.jayway.restassured</groupId>
|
||||||
<artifactId>rest-assured</artifactId>
|
<artifactId>rest-assured</artifactId>
|
||||||
<version>${rest-assured.version}</version>
|
<version>${rest-assured.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion>
|
<exclusion>
|
||||||
<artifactId>commons-logging</artifactId>
|
<artifactId>commons-logging</artifactId>
|
||||||
<groupId>commons-logging</groupId>
|
<groupId>commons-logging</groupId>
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
<version>${junit.version}</version>
|
<version>${junit.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-core</artifactId>
|
<artifactId>hamcrest-core</artifactId>
|
||||||
<version>${org.hamcrest.version}</version>
|
<version>${org.hamcrest.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.hamcrest</groupId>
|
||||||
<artifactId>hamcrest-library</artifactId>
|
<artifactId>hamcrest-library</artifactId>
|
||||||
<version>${org.hamcrest.version}</version>
|
<version>${org.hamcrest.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.mockito</groupId>
|
<groupId>org.mockito</groupId>
|
||||||
<artifactId>mockito-core</artifactId>
|
<artifactId>mockito-core</artifactId>
|
||||||
<version>${mockito.version}</version>
|
<version>${mockito.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- swagger -->
|
<!-- swagger -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.springfox</groupId>
|
<groupId>io.springfox</groupId>
|
||||||
<artifactId>springfox-swagger2</artifactId>
|
<artifactId>springfox-swagger2</artifactId>
|
||||||
<version>${springfox-swagger.version}</version>
|
<version>${springfox-swagger.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.springfox</groupId>
|
<groupId>io.springfox</groupId>
|
||||||
<artifactId>springfox-swagger-ui</artifactId>
|
<artifactId>springfox-swagger-ui</artifactId>
|
||||||
<version>${springfox-swagger.version}</version>
|
<version>${springfox-swagger.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-fileupload</groupId>
|
||||||
|
<artifactId>commons-fileupload</artifactId>
|
||||||
|
<version>1.3.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<build>
|
</dependencies>
|
||||||
<finalName>spring-security-rest</finalName>
|
|
||||||
<resources>
|
|
||||||
<resource>
|
|
||||||
<directory>src/main/resources</directory>
|
|
||||||
<filtering>true</filtering>
|
|
||||||
</resource>
|
|
||||||
</resources>
|
|
||||||
|
|
||||||
<plugins>
|
<build>
|
||||||
|
<finalName>spring-security-rest</finalName>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
|
||||||
<plugin>
|
<plugins>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<version>${maven-compiler-plugin.version}</version>
|
|
||||||
<configuration>
|
|
||||||
<source>1.8</source>
|
|
||||||
<target>1.8</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-war-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>${maven-war-plugin.version}</version>
|
<version>${maven-compiler-plugin.version}</version>
|
||||||
</plugin>
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
<version>${maven-surefire-plugin.version}</version>
|
<version>${maven-war-plugin.version}</version>
|
||||||
<configuration>
|
</plugin>
|
||||||
<excludes>
|
|
||||||
<exclude>**/*LiveTest.java</exclude>
|
|
||||||
</excludes>
|
|
||||||
<systemPropertyVariables>
|
|
||||||
<!-- <provPersistenceTarget>h2</provPersistenceTarget> -->
|
|
||||||
</systemPropertyVariables>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.codehaus.cargo</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>cargo-maven2-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>${cargo-maven2-plugin.version}</version>
|
<version>${maven-surefire-plugin.version}</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<container>
|
<excludes>
|
||||||
<containerId>jetty8x</containerId>
|
<exclude>**/*LiveTest.java</exclude>
|
||||||
<type>embedded</type>
|
</excludes>
|
||||||
<systemProperties>
|
<systemPropertyVariables>
|
||||||
<!-- <provPersistenceTarget>cargo</provPersistenceTarget> -->
|
<!-- <provPersistenceTarget>h2</provPersistenceTarget> -->
|
||||||
</systemProperties>
|
</systemPropertyVariables>
|
||||||
</container>
|
</configuration>
|
||||||
<configuration>
|
</plugin>
|
||||||
<properties>
|
|
||||||
<cargo.servlet.port>8082</cargo.servlet.port>
|
|
||||||
</properties>
|
|
||||||
</configuration>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
</plugins>
|
<plugin>
|
||||||
|
<groupId>org.codehaus.cargo</groupId>
|
||||||
|
<artifactId>cargo-maven2-plugin</artifactId>
|
||||||
|
<version>${cargo-maven2-plugin.version}</version>
|
||||||
|
<configuration>
|
||||||
|
<container>
|
||||||
|
<containerId>jetty8x</containerId>
|
||||||
|
<type>embedded</type>
|
||||||
|
<systemProperties>
|
||||||
|
<!-- <provPersistenceTarget>cargo</provPersistenceTarget> -->
|
||||||
|
</systemProperties>
|
||||||
|
</container>
|
||||||
|
<configuration>
|
||||||
|
<properties>
|
||||||
|
<cargo.servlet.port>8082</cargo.servlet.port>
|
||||||
|
</properties>
|
||||||
|
</configuration>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
</build>
|
</plugins>
|
||||||
|
|
||||||
<profiles>
|
</build>
|
||||||
<profile>
|
|
||||||
<id>live</id>
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.codehaus.cargo</groupId>
|
|
||||||
<artifactId>cargo-maven2-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>start-server</id>
|
|
||||||
<phase>pre-integration-test</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>start</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
<execution>
|
|
||||||
<id>stop-server</id>
|
|
||||||
<phase>post-integration-test</phase>
|
|
||||||
<goals>
|
|
||||||
<goal>stop</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
|
|
||||||
<plugin>
|
<profiles>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<profile>
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<id>live</id>
|
||||||
<executions>
|
<build>
|
||||||
<execution>
|
<plugins>
|
||||||
<phase>integration-test</phase>
|
<plugin>
|
||||||
<goals>
|
<groupId>org.codehaus.cargo</groupId>
|
||||||
<goal>test</goal>
|
<artifactId>cargo-maven2-plugin</artifactId>
|
||||||
</goals>
|
<executions>
|
||||||
<configuration>
|
<execution>
|
||||||
<excludes>
|
<id>start-server</id>
|
||||||
<exclude>none</exclude>
|
<phase>pre-integration-test</phase>
|
||||||
</excludes>
|
<goals>
|
||||||
<includes>
|
<goal>start</goal>
|
||||||
<include>**/*LiveTest.java</include>
|
</goals>
|
||||||
</includes>
|
</execution>
|
||||||
<systemPropertyVariables>
|
<execution>
|
||||||
<webTarget>cargo</webTarget>
|
<id>stop-server</id>
|
||||||
</systemPropertyVariables>
|
<phase>post-integration-test</phase>
|
||||||
</configuration>
|
<goals>
|
||||||
</execution>
|
<goal>stop</goal>
|
||||||
</executions>
|
</goals>
|
||||||
</plugin>
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
</plugins>
|
<plugin>
|
||||||
</build>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
</profile>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
</profiles>
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>integration-test</phase>
|
||||||
<properties>
|
<goals>
|
||||||
<!-- Spring -->
|
<goal>test</goal>
|
||||||
<org.springframework.version>4.2.5.RELEASE</org.springframework.version>
|
</goals>
|
||||||
<org.springframework.security.version>4.0.4.RELEASE</org.springframework.security.version>
|
<configuration>
|
||||||
<org.springframework.hateoas.version>0.19.0.RELEASE</org.springframework.hateoas.version>
|
<excludes>
|
||||||
|
<exclude>none</exclude>
|
||||||
|
</excludes>
|
||||||
|
<includes>
|
||||||
|
<include>**/*LiveTest.java</include>
|
||||||
|
</includes>
|
||||||
|
<systemPropertyVariables>
|
||||||
|
<webTarget>cargo</webTarget>
|
||||||
|
</systemPropertyVariables>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
|
||||||
<!-- persistence -->
|
</plugins>
|
||||||
<hibernate.version>4.3.11.Final</hibernate.version>
|
</build>
|
||||||
<mysql-connector-java.version>5.1.38</mysql-connector-java.version>
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
<!-- logging -->
|
|
||||||
<org.slf4j.version>1.7.13</org.slf4j.version>
|
|
||||||
<logback.version>1.1.3</logback.version>
|
|
||||||
|
|
||||||
<!-- various -->
|
<properties>
|
||||||
<hibernate-validator.version>5.2.2.Final</hibernate-validator.version>
|
<!-- Spring -->
|
||||||
<javax.servlet-api.version>3.0.1</javax.servlet-api.version>
|
<org.springframework.version>4.2.5.RELEASE</org.springframework.version>
|
||||||
<javax.validation.version>1.1.0.Final</javax.validation.version>
|
<org.springframework.security.version>4.0.4.RELEASE</org.springframework.security.version>
|
||||||
<jstl.version>1.2</jstl.version>
|
<org.springframework.hateoas.version>0.19.0.RELEASE</org.springframework.hateoas.version>
|
||||||
<jackson.version>2.7.8</jackson.version>
|
|
||||||
|
|
||||||
<!-- util -->
|
<!-- persistence -->
|
||||||
<guava.version>19.0</guava.version>
|
<hibernate.version>4.3.11.Final</hibernate.version>
|
||||||
<commons-lang3.version>3.4</commons-lang3.version>
|
<mysql-connector-java.version>5.1.38</mysql-connector-java.version>
|
||||||
|
|
||||||
<!-- testing -->
|
<!-- logging -->
|
||||||
<org.hamcrest.version>1.3</org.hamcrest.version>
|
<org.slf4j.version>1.7.13</org.slf4j.version>
|
||||||
<junit.version>4.12</junit.version>
|
<logback.version>1.1.3</logback.version>
|
||||||
<mockito.version>1.10.19</mockito.version>
|
|
||||||
<rest-assured.version>2.9.0</rest-assured.version>
|
|
||||||
|
|
||||||
<!-- swagger -->
|
<!-- various -->
|
||||||
<springfox-swagger.version>2.4.0</springfox-swagger.version>
|
<hibernate-validator.version>5.2.2.Final</hibernate-validator.version>
|
||||||
|
<javax.servlet-api.version>3.0.1</javax.servlet-api.version>
|
||||||
|
<javax.validation.version>1.1.0.Final</javax.validation.version>
|
||||||
|
<jstl.version>1.2</jstl.version>
|
||||||
|
<jackson.version>2.7.8</jackson.version>
|
||||||
|
|
||||||
<httpcore.version>4.4.1</httpcore.version>
|
<!-- util -->
|
||||||
<httpclient.version>4.5</httpclient.version>
|
<guava.version>19.0</guava.version>
|
||||||
|
<commons-lang3.version>3.4</commons-lang3.version>
|
||||||
|
|
||||||
<rest-assured.version>2.9.0</rest-assured.version>
|
<!-- testing -->
|
||||||
|
<org.hamcrest.version>1.3</org.hamcrest.version>
|
||||||
|
<junit.version>4.12</junit.version>
|
||||||
|
<mockito.version>1.10.19</mockito.version>
|
||||||
|
<rest-assured.version>2.9.0</rest-assured.version>
|
||||||
|
|
||||||
<!-- Maven plugins -->
|
<!-- swagger -->
|
||||||
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
|
<springfox-swagger.version>2.4.0</springfox-swagger.version>
|
||||||
<maven-war-plugin.version>2.6</maven-war-plugin.version>
|
|
||||||
<maven-surefire-plugin.version>2.19.1</maven-surefire-plugin.version>
|
|
||||||
<cargo-maven2-plugin.version>1.4.18</cargo-maven2-plugin.version>
|
|
||||||
|
|
||||||
</properties>
|
<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>
|
||||||
|
<cargo-maven2-plugin.version>1.4.18</cargo-maven2-plugin.version>
|
||||||
|
|
||||||
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
package org.baeldung.web.controller;
|
||||||
|
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMethod;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
@Controller
|
||||||
|
public class AsyncController {
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.POST, value = "/upload")
|
||||||
|
public Callable<Boolean> processUpload(final MultipartFile file) {
|
||||||
|
|
||||||
|
return new Callable<Boolean>() {
|
||||||
|
public Boolean call() throws Exception {
|
||||||
|
// ...
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,6 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd" >
|
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.2.xsd">
|
||||||
|
|
||||||
|
<bean id="multipartResolver"
|
||||||
|
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
|
||||||
|
<property name="maxUploadSize" value="1000000" />
|
||||||
|
</bean>
|
||||||
</beans>
|
</beans>
|
@ -1,54 +1,57 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
|
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xsi:schemaLocation="
|
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
|
||||||
|
xsi:schemaLocation="
|
||||||
http://java.sun.com/xml/ns/javaee
|
http://java.sun.com/xml/ns/javaee
|
||||||
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"
|
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
|
||||||
>
|
id="WebApp_ID" version="3.0">
|
||||||
|
|
||||||
<display-name>Spring MVC Application</display-name>
|
<display-name>Spring MVC Application</display-name>
|
||||||
|
|
||||||
<!-- Spring root -->
|
<!-- Spring root -->
|
||||||
<context-param>
|
<context-param>
|
||||||
<param-name>contextClass</param-name>
|
<param-name>contextClass</param-name>
|
||||||
<param-value>
|
<param-value>
|
||||||
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
|
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
|
||||||
</param-value>
|
</param-value>
|
||||||
</context-param>
|
</context-param>
|
||||||
<context-param>
|
<context-param>
|
||||||
<param-name>contextConfigLocation</param-name>
|
<param-name>contextConfigLocation</param-name>
|
||||||
<param-value>org.baeldung.spring</param-value>
|
<param-value>org.baeldung.spring</param-value>
|
||||||
</context-param>
|
</context-param>
|
||||||
|
|
||||||
<listener>
|
<listener>
|
||||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||||
</listener>
|
</listener>
|
||||||
|
|
||||||
<!-- Spring child -->
|
<!-- Spring child -->
|
||||||
<servlet>
|
<servlet>
|
||||||
<servlet-name>api</servlet-name>
|
<servlet-name>api</servlet-name>
|
||||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||||
<init-param>
|
<init-param>
|
||||||
<param-name>throwExceptionIfNoHandlerFound</param-name>
|
<param-name>throwExceptionIfNoHandlerFound</param-name>
|
||||||
<param-value>true</param-value>
|
<param-value>true</param-value>
|
||||||
</init-param>
|
</init-param>
|
||||||
</servlet>
|
</servlet>
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>api</servlet-name>
|
<servlet-name>api</servlet-name>
|
||||||
<url-pattern>/api/*</url-pattern>
|
<url-pattern>/api/*</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
|
|
||||||
<!-- Spring Security -->
|
<!-- Spring Security -->
|
||||||
<filter>
|
<filter>
|
||||||
<filter-name>springSecurityFilterChain</filter-name>
|
<filter-name>springSecurityFilterChain</filter-name>
|
||||||
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
|
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
|
||||||
</filter>
|
</filter>
|
||||||
<filter-mapping>
|
<filter-mapping>
|
||||||
<filter-name>springSecurityFilterChain</filter-name>
|
<filter-name>springSecurityFilterChain</filter-name>
|
||||||
<url-pattern>/*</url-pattern>
|
<url-pattern>/*</url-pattern>
|
||||||
</filter-mapping>
|
<dispatcher>REQUEST</dispatcher>
|
||||||
|
<dispatcher>ASYNC</dispatcher>
|
||||||
|
</filter-mapping>
|
||||||
|
|
||||||
<!-- <welcome-file-list> -->
|
<!-- <welcome-file-list> -->
|
||||||
<!-- <welcome-file>index.html</welcome-file> -->
|
<!-- <welcome-file>index.html</welcome-file> -->
|
||||||
<!-- </welcome-file-list> -->
|
<!-- </welcome-file-list> -->
|
||||||
|
|
||||||
</web-app>
|
</web-app>
|
@ -0,0 +1,51 @@
|
|||||||
|
package org.baeldung.web;
|
||||||
|
|
||||||
|
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
import org.baeldung.spring.ClientWebConfig;
|
||||||
|
import org.baeldung.spring.SecurityJavaConfig;
|
||||||
|
import org.baeldung.spring.WebConfig;
|
||||||
|
import org.baeldung.web.controller.AsyncController;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.mock.web.MockHttpSession;
|
||||||
|
import org.springframework.mock.web.MockMultipartFile;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.test.context.web.WebAppConfiguration;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||||
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@WebAppConfiguration
|
||||||
|
@ContextConfiguration(classes = { ClientWebConfig.class, SecurityJavaConfig.class, WebConfig.class})
|
||||||
|
public class AsyncControllerTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
WebApplicationContext wac;
|
||||||
|
@Autowired
|
||||||
|
MockHttpSession session;
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
AsyncController controller;
|
||||||
|
|
||||||
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testProcessUpload() throws Exception {
|
||||||
|
MockMultipartFile jsonFile = new MockMultipartFile("json", "", "application/json",
|
||||||
|
"{\"json\": \"someValue\"}".getBytes());
|
||||||
|
mockMvc.perform(MockMvcRequestBuilders.fileUpload("/upload").file(jsonFile)).andExpect(status().isOk());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,10 +1,19 @@
|
|||||||
package org.baeldung.web;
|
package org.baeldung.web;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.ComponentScan;
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.web.multipart.MultipartResolver;
|
||||||
|
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
||||||
|
|
||||||
@Configuration
|
@Configuration
|
||||||
@ComponentScan({ "org.baeldung.web" })
|
@ComponentScan({ "org.baeldung.web" })
|
||||||
public class TestConfig {
|
public class TestConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public MultipartResolver multipartResolver() {
|
||||||
|
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
|
||||||
|
return multipartResolver;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user