@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,18 +35,20 @@ public class XpathRequestMatchersTests {
|
||||
|
||||
private MockClientHttpRequest request;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws IOException {
|
||||
this.request = new MockClientHttpRequest();
|
||||
this.request.getBody().write(RESPONSE_CONTENT.getBytes());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNodeMatcher() throws Exception {
|
||||
new XpathRequestMatchers("/foo/bar", null).node(Matchers.notNullValue()).match(this.request);
|
||||
}
|
||||
|
||||
@Test(expected=AssertionError.class)
|
||||
@Test(expected = AssertionError.class)
|
||||
public void testNodeMatcherNoMatch() throws Exception {
|
||||
new XpathRequestMatchers("/foo/bar", null).node(Matchers.nullValue()).match(this.request);
|
||||
}
|
||||
@@ -56,7 +58,7 @@ public class XpathRequestMatchersTests {
|
||||
new XpathRequestMatchers("/foo/bar", null).exists().match(this.request);
|
||||
}
|
||||
|
||||
@Test(expected=AssertionError.class)
|
||||
@Test(expected = AssertionError.class)
|
||||
public void testExistsNoMatch() throws Exception {
|
||||
new XpathRequestMatchers("/foo/Bar", null).exists().match(this.request);
|
||||
}
|
||||
@@ -66,7 +68,7 @@ public class XpathRequestMatchersTests {
|
||||
new XpathRequestMatchers("/foo/Bar", null).doesNotExist().match(this.request);
|
||||
}
|
||||
|
||||
@Test(expected=AssertionError.class)
|
||||
@Test(expected = AssertionError.class)
|
||||
public void testDoesNotExistNoMatch() throws Exception {
|
||||
new XpathRequestMatchers("/foo/bar", null).doesNotExist().match(this.request);
|
||||
}
|
||||
@@ -76,7 +78,7 @@ public class XpathRequestMatchersTests {
|
||||
new XpathRequestMatchers("/foo/bar", null).nodeCount(2).match(this.request);
|
||||
}
|
||||
|
||||
@Test(expected=AssertionError.class)
|
||||
@Test(expected = AssertionError.class)
|
||||
public void testNodeCountNoMatch() throws Exception {
|
||||
new XpathRequestMatchers("/foo/bar", null).nodeCount(1).match(this.request);
|
||||
}
|
||||
@@ -86,7 +88,7 @@ public class XpathRequestMatchersTests {
|
||||
new XpathRequestMatchers("/foo/bar[1]", null).string("111").match(this.request);
|
||||
}
|
||||
|
||||
@Test(expected=AssertionError.class)
|
||||
@Test(expected = AssertionError.class)
|
||||
public void testStringNoMatch() throws Exception {
|
||||
new XpathRequestMatchers("/foo/bar[1]", null).string("112").match(this.request);
|
||||
}
|
||||
@@ -96,7 +98,7 @@ public class XpathRequestMatchersTests {
|
||||
new XpathRequestMatchers("/foo/bar[1]", null).number(111.0).match(this.request);
|
||||
}
|
||||
|
||||
@Test(expected=AssertionError.class)
|
||||
@Test(expected = AssertionError.class)
|
||||
public void testNumberNoMatch() throws Exception {
|
||||
new XpathRequestMatchers("/foo/bar[1]", null).number(111.1).match(this.request);
|
||||
}
|
||||
@@ -106,7 +108,7 @@ public class XpathRequestMatchersTests {
|
||||
new XpathRequestMatchers("/foo/bar[2]", null).booleanValue(true).match(this.request);
|
||||
}
|
||||
|
||||
@Test(expected=AssertionError.class)
|
||||
@Test(expected = AssertionError.class)
|
||||
public void testBooleanNoMatch() throws Exception {
|
||||
new XpathRequestMatchers("/foo/bar[2]", null).booleanValue(false).match(this.request);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.test.web.client.response;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
@@ -39,7 +39,6 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
|
||||
* Examples of defining expectations on request content and content type.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*
|
||||
* @see JsonPathRequestMatchersIntegrationTests
|
||||
* @see XmlContentRequestMatchersIntegrationTests
|
||||
* @see XpathRequestMatchersIntegrationTests
|
||||
@@ -50,9 +49,10 @@ public class ContentRequestMatchersIntegrationTests {
|
||||
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<>();
|
||||
converters.add(new StringHttpMessageConverter());
|
||||
converters.add(new MappingJackson2HttpMessageConverter());
|
||||
|
||||
@@ -62,6 +62,7 @@ public class ContentRequestMatchersIntegrationTests {
|
||||
this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void contentType() throws Exception {
|
||||
this.mockServer.expect(content().contentType("application/json;charset=UTF-8")).andRespond(withSuccess());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -44,13 +44,15 @@ public class HeaderRequestMatchersIntegrationTests {
|
||||
|
||||
private static final String RESPONSE_BODY = "{\"name\" : \"Ludwig van Beethoven\", \"someDouble\" : \"1.6035\"}";
|
||||
|
||||
|
||||
private MockRestServiceServer mockServer;
|
||||
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<>();
|
||||
converters.add(new StringHttpMessageConverter());
|
||||
converters.add(new MappingJackson2HttpMessageConverter());
|
||||
|
||||
@@ -60,9 +62,9 @@ public class HeaderRequestMatchersIntegrationTests {
|
||||
this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testString() throws Exception {
|
||||
|
||||
this.mockServer.expect(requestTo("/person/1"))
|
||||
.andExpect(header("Accept", "application/json, application/*+json"))
|
||||
.andRespond(withSuccess(RESPONSE_BODY, MediaType.APPLICATION_JSON));
|
||||
@@ -73,7 +75,6 @@ public class HeaderRequestMatchersIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testStringContains() throws Exception {
|
||||
|
||||
this.mockServer.expect(requestTo("/person/1"))
|
||||
.andExpect(header("Accept", containsString("json")))
|
||||
.andRespond(withSuccess(RESPONSE_BODY, MediaType.APPLICATION_JSON));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,6 +19,7 @@ package org.springframework.test.web.client.samples.matchers;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
@@ -45,7 +46,7 @@ import static org.springframework.test.web.client.response.MockRestResponseCreat
|
||||
*/
|
||||
public class JsonPathRequestMatchersIntegrationTests {
|
||||
|
||||
private static final MultiValueMap<String, Person> people = new LinkedMultiValueMap<String, Person>();
|
||||
private static final MultiValueMap<String, Person> people = new LinkedMultiValueMap<>();
|
||||
|
||||
static {
|
||||
people.add("composers", new Person("Johann Sebastian Bach"));
|
||||
@@ -56,7 +57,9 @@ public class JsonPathRequestMatchersIntegrationTests {
|
||||
people.add("performers", new Person("Yehudi Menuhin"));
|
||||
}
|
||||
|
||||
private final RestTemplate restTemplate = new RestTemplate(Arrays.asList(new MappingJackson2HttpMessageConverter()));
|
||||
|
||||
private final RestTemplate restTemplate =
|
||||
new RestTemplate(Collections.singletonList(new MappingJackson2HttpMessageConverter()));
|
||||
|
||||
private final MockRestServiceServer mockServer = MockRestServiceServer.createServer(this.restTemplate);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -57,6 +57,7 @@ public class XmlContentRequestMatchersIntegrationTests {
|
||||
"<composer><name>Robert Schumann</name><someBoolean>false</someBoolean><someDouble>NaN</someDouble></composer>" +
|
||||
"</composers></people>";
|
||||
|
||||
|
||||
private MockRestServiceServer mockServer;
|
||||
|
||||
private RestTemplate restTemplate;
|
||||
@@ -66,7 +67,6 @@ public class XmlContentRequestMatchersIntegrationTests {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
|
||||
List<Person> composers = Arrays.asList(
|
||||
new Person("Johann Sebastian Bach").setSomeDouble(21),
|
||||
new Person("Johannes Brahms").setSomeDouble(.0025),
|
||||
@@ -75,7 +75,7 @@ public class XmlContentRequestMatchersIntegrationTests {
|
||||
|
||||
this.people = new PeopleWrapper(composers);
|
||||
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<>();
|
||||
converters.add(new Jaxb2RootElementHttpMessageConverter());
|
||||
|
||||
this.restTemplate = new RestTemplate();
|
||||
@@ -97,7 +97,6 @@ public class XmlContentRequestMatchersIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testHamcrestNodeMatcher() throws Exception {
|
||||
|
||||
this.mockServer.expect(requestTo("/composers"))
|
||||
.andExpect(content().contentType("application/xml"))
|
||||
.andExpect(content().node(hasXPath("/people/composers/composer[1]")))
|
||||
@@ -128,4 +127,5 @@ public class XmlContentRequestMatchersIntegrationTests {
|
||||
return this.composers;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -53,15 +53,16 @@ public class XpathRequestMatchersIntegrationTests {
|
||||
private static final Map<String, String> NS =
|
||||
Collections.singletonMap("ns", "http://example.org/music/people");
|
||||
|
||||
|
||||
private MockRestServiceServer mockServer;
|
||||
|
||||
private RestTemplate restTemplate;
|
||||
|
||||
private PeopleWrapper people;
|
||||
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
|
||||
List<Person> composers = Arrays.asList(
|
||||
new Person("Johann Sebastian Bach").setSomeDouble(21),
|
||||
new Person("Johannes Brahms").setSomeDouble(.0025),
|
||||
@@ -74,7 +75,7 @@ public class XpathRequestMatchersIntegrationTests {
|
||||
|
||||
this.people = new PeopleWrapper(composers, performers);
|
||||
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
|
||||
List<HttpMessageConverter<?>> converters = new ArrayList<>();
|
||||
converters.add(new Jaxb2RootElementHttpMessageConverter());
|
||||
|
||||
this.restTemplate = new RestTemplate();
|
||||
@@ -83,9 +84,9 @@ public class XpathRequestMatchersIntegrationTests {
|
||||
this.mockServer = MockRestServiceServer.createServer(this.restTemplate);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testExists() throws Exception {
|
||||
|
||||
String composer = "/ns:people/composers/composer[%s]";
|
||||
String performer = "/ns:people/performers/performer[%s]";
|
||||
|
||||
@@ -105,7 +106,6 @@ public class XpathRequestMatchersIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testDoesNotExist() throws Exception {
|
||||
|
||||
String composer = "/ns:people/composers/composer[%s]";
|
||||
String performer = "/ns:people/performers/performer[%s]";
|
||||
|
||||
@@ -123,7 +123,6 @@ public class XpathRequestMatchersIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testString() throws Exception {
|
||||
|
||||
String composerName = "/ns:people/composers/composer[%s]/name";
|
||||
String performerName = "/ns:people/performers/performer[%s]/name";
|
||||
|
||||
@@ -146,7 +145,6 @@ public class XpathRequestMatchersIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testNumber() throws Exception {
|
||||
|
||||
String composerDouble = "/ns:people/composers/composer[%s]/someDouble";
|
||||
|
||||
this.mockServer.expect(requestTo("/composers"))
|
||||
@@ -180,7 +178,6 @@ public class XpathRequestMatchersIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void testNodeCount() throws Exception {
|
||||
|
||||
this.mockServer.expect(requestTo("/composers"))
|
||||
.andExpect(content().contentType("application/xml"))
|
||||
.andExpect(xpath("/ns:people/composers/composer", NS).nodeCount(4))
|
||||
@@ -223,4 +220,5 @@ public class XpathRequestMatchersIntegrationTests {
|
||||
return this.performers;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user