upgrade and cleanup
This commit is contained in:
parent
55c2b3a338
commit
0099c22654
@ -47,13 +47,13 @@
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.0.1</version>
|
||||
<version>${javax.servlet-api.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>jstl</artifactId>
|
||||
<version>1.2</version>
|
||||
<version>${jstl.version}</version>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
@ -78,7 +78,7 @@
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
<version>1.3.1</version>
|
||||
<version>${commons-fileupload.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.htmlunit</groupId>
|
||||
@ -150,7 +150,7 @@
|
||||
<dependency>
|
||||
<groupId>com.jayway.jsonpath</groupId>
|
||||
<artifactId>json-path</artifactId>
|
||||
<version>2.2.0</version>
|
||||
<version>${jsonpath.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -184,7 +184,7 @@
|
||||
|
||||
<plugin>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.7</version>
|
||||
<version>${maven-resources-plugin.version}</version>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
@ -250,42 +250,46 @@
|
||||
<!-- Spring -->
|
||||
<org.springframework.version>4.3.4.RELEASE</org.springframework.version>
|
||||
<org.springframework.security.version>4.2.0.RELEASE</org.springframework.security.version>
|
||||
<thymeleaf.version>2.1.4.RELEASE</thymeleaf.version>
|
||||
<jackson.version>2.7.8</jackson.version>
|
||||
<thymeleaf.version>2.1.5.RELEASE</thymeleaf.version>
|
||||
<jackson.version>2.8.5</jackson.version>
|
||||
|
||||
<!-- persistence -->
|
||||
<hibernate.version>4.3.11.Final</hibernate.version>
|
||||
<mysql-connector-java.version>5.1.38</mysql-connector-java.version>
|
||||
<hibernate.version>5.2.5.Final</hibernate.version>
|
||||
<mysql-connector-java.version>5.1.40</mysql-connector-java.version>
|
||||
|
||||
<!-- logging -->
|
||||
<org.slf4j.version>1.7.21</org.slf4j.version>
|
||||
<logback.version>1.1.5</logback.version>
|
||||
<logback.version>1.1.7</logback.version>
|
||||
|
||||
<!-- various -->
|
||||
<hibernate-validator.version>5.2.2.Final</hibernate-validator.version>
|
||||
<hibernate-validator.version>5.3.3.Final</hibernate-validator.version>
|
||||
<javax.servlet-api.version>3.1.0</javax.servlet-api.version>
|
||||
<jstl.version>1.2</jstl.version>
|
||||
|
||||
<!-- util -->
|
||||
<guava.version>19.0</guava.version>
|
||||
<commons-lang3.version>3.4</commons-lang3.version>
|
||||
<commons-lang3.version>3.5</commons-lang3.version>
|
||||
<commons-fileupload.version>1.3.2</commons-fileupload.version>
|
||||
<jsonpath.version>2.2.0</jsonpath.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>
|
||||
<httpcore.version>4.4.5</httpcore.version>
|
||||
<httpclient.version>4.5.2</httpclient.version>
|
||||
<rest-assured.version>2.9.0</rest-assured.version>
|
||||
<net.sourceforge.htmlunit>2.23</net.sourceforge.htmlunit>
|
||||
|
||||
<!-- maven plugins -->
|
||||
<maven-compiler-plugin.version>3.5.1</maven-compiler-plugin.version>
|
||||
<maven-compiler-plugin.version>3.6.0</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>
|
||||
<cargo-maven2-plugin.version>1.6.1</cargo-maven2-plugin.version>
|
||||
|
||||
<!-- AspectJ -->
|
||||
<aspectj.version>1.8.7</aspectj.version>
|
||||
<aspectj.version>1.8.9</aspectj.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
@ -2,6 +2,11 @@ package com.baeldung.htmlunit;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.gargoylesoftware.htmlunit.WebClient;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
|
||||
import com.gargoylesoftware.htmlunit.html.HtmlHeading1;
|
||||
@ -9,34 +14,31 @@ import com.gargoylesoftware.htmlunit.html.HtmlPage;
|
||||
|
||||
public class HtmlUnitWebScraping {
|
||||
|
||||
private WebClient webClient;
|
||||
private WebClient webClient;
|
||||
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
webClient = new WebClient();
|
||||
}
|
||||
@Before
|
||||
public void init() throws Exception {
|
||||
webClient = new WebClient();
|
||||
}
|
||||
|
||||
@After
|
||||
public void close() throws Exception {
|
||||
webClient.close();
|
||||
}
|
||||
@After
|
||||
public void close() throws Exception {
|
||||
webClient.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenBaeldungArchive_whenRetrievingArticle_thenHasH1()
|
||||
throws Exception {
|
||||
webClient.getOptions().setCssEnabled(false);
|
||||
webClient.getOptions().setJavaScriptEnabled(false);
|
||||
@Test
|
||||
public void givenBaeldungArchive_whenRetrievingArticle_thenHasH1() throws Exception {
|
||||
webClient.getOptions().setCssEnabled(false);
|
||||
webClient.getOptions().setJavaScriptEnabled(false);
|
||||
|
||||
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 String url = "http://www.baeldung.com/full_archive";
|
||||
final HtmlPage page = webClient.getPage(url);
|
||||
final String xpath = "(//ul[@class='car-monthlisting']/li)[1]/a";
|
||||
final HtmlAnchor latestPostLink = (HtmlAnchor) page.getByXPath(xpath).get(0);
|
||||
final HtmlPage postPage = latestPostLink.click();
|
||||
|
||||
List<HtmlHeading1> h1
|
||||
= (List<HtmlHeading1>) postPage.getByXPath("//h1");
|
||||
final List<HtmlHeading1> h1 = (List<HtmlHeading1>) postPage.getByXPath("//h1");
|
||||
|
||||
Assert.assertTrue(h1.size() > 0);
|
||||
}
|
||||
Assert.assertTrue(h1.size() > 0);
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class GreetControllerIntegrationTest {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
|
||||
private static final String CONTENT_TYPE = "application/json";
|
||||
private static final String CONTENT_TYPE = "application/json;charset=UTF-8";
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
@ -41,7 +41,7 @@ public class GreetControllerIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenWAC_whenServletContext_thenItProvidesGreetController() {
|
||||
ServletContext servletContext = wac.getServletContext();
|
||||
final ServletContext servletContext = wac.getServletContext();
|
||||
Assert.assertNotNull(servletContext);
|
||||
Assert.assertTrue(servletContext instanceof MockServletContext);
|
||||
Assert.assertNotNull(wac.getBean("greetController"));
|
||||
@ -54,7 +54,7 @@ public class GreetControllerIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenGreetURI_whenMockMVC_thenVerifyResponse() throws Exception {
|
||||
MvcResult mvcResult = this.mockMvc.perform(MockMvcRequestBuilders.get("/greet")).andDo(print()).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World!!!")).andReturn();
|
||||
final MvcResult mvcResult = this.mockMvc.perform(MockMvcRequestBuilders.get("/greet")).andDo(print()).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.jsonPath("$.message").value("Hello World!!!")).andReturn();
|
||||
Assert.assertEquals(CONTENT_TYPE, mvcResult.getResponse().getContentType());
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
public class GreetControllerUnitTest {
|
||||
|
||||
private MockMvc mockMvc;
|
||||
private static final String CONTENT_TYPE = "application/json";
|
||||
private static final String CONTENT_TYPE = "application/json;charset=UTF-8";
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user