Here are the examples of the java api org.springframework.mock.web.MockHttpServletRequest taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1191 Examples
19
View Source File : CompositeHandlerExceptionResolverTests.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
/**
* Tests for {@link CompositeHandlerExceptionResolver}.
*
* @author Madhura Bhave
*/
public clreplaced CompositeHandlerExceptionResolverTests {
private AnnotationConfigApplicationContext context;
private MockHttpServletRequest request = new MockHttpServletRequest();
private MockHttpServletResponse response = new MockHttpServletResponse();
@Test
public void resolverShouldDelegateToOtherResolversInContext() {
load(TestConfiguration.clreplaced);
CompositeHandlerExceptionResolver resolver = (CompositeHandlerExceptionResolver) this.context.getBean(DispatcherServlet.HANDLER_EXCEPTION_RESOLVER_BEAN_NAME);
ModelAndView resolved = resolver.resolveException(this.request, this.response, null, new HttpRequestMethodNotSupportedException("POST"));
replacedertThat(resolved.getViewName()).isEqualTo("test-view");
}
@Test
public void resolverShouldAddDefaultResolverIfNonePresent() {
load(BaseConfiguration.clreplaced);
CompositeHandlerExceptionResolver resolver = (CompositeHandlerExceptionResolver) this.context.getBean(DispatcherServlet.HANDLER_EXCEPTION_RESOLVER_BEAN_NAME);
ModelAndView resolved = resolver.resolveException(this.request, this.response, null, new HttpRequestMethodNotSupportedException("POST"));
replacedertThat(resolved).isNotNull();
}
private void load(Clreplaced<?>... configs) {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(configs);
context.refresh();
this.context = context;
}
@Configuration
static clreplaced BaseConfiguration {
@Bean(name = DispatcherServlet.HANDLER_EXCEPTION_RESOLVER_BEAN_NAME)
public CompositeHandlerExceptionResolver compositeHandlerExceptionResolver() {
return new CompositeHandlerExceptionResolver();
}
}
@Configuration
@Import(BaseConfiguration.clreplaced)
static clreplaced TestConfiguration {
@Bean
public HandlerExceptionResolver testResolver() {
return new TestHandlerExceptionResolver();
}
}
static clreplaced TestHandlerExceptionResolver implements HandlerExceptionResolver {
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
return new ModelAndView("test-view");
}
}
}
19
View Source File : TraceableHttpServletRequestTests.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
/**
* Tests for {@link TraceableHttpServletRequest}.
*
* @author Madhura Bhave
*/
public clreplaced TraceableHttpServletRequestTests {
private MockHttpServletRequest request;
@Before
public void setup() {
this.request = new MockHttpServletRequest("GET", "/script");
}
@Test
public void getUriWithoutQueryStringShouldReturnUri() {
validate("http://localhost/script");
}
@Test
public void getUriShouldReturnUriWithQueryString() {
this.request.setQueryString("a=b");
validate("http://localhost/script?a=b");
}
@Test
public void getUriWithSpecialCharactersInQueryStringShouldEncode() {
this.request.setQueryString("a=${b}");
validate("http://localhost/script?a=$%7Bb%7D");
}
@Test
public void getUriWithSpecialCharactersEncodedShouldNotDoubleEncode() {
this.request.setQueryString("a=$%7Bb%7D");
validate("http://localhost/script?a=$%7Bb%7D");
}
private void validate(String expectedUri) {
TraceableHttpServletRequest trace = new TraceableHttpServletRequest(this.request);
replacedertThat(trace.getUri().toString()).isEqualTo(expectedUri);
}
}
19
View Source File : WebMvcTagsTests.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
/**
* Tests for {@link WebMvcTags}.
*
* @author Andy Wilkinson
* @author Brian Clozel
* @author Michael McFadyen
*/
public clreplaced WebMvcTagsTests {
private final MockHttpServletRequest request = new MockHttpServletRequest();
private final MockHttpServletResponse response = new MockHttpServletResponse();
@Test
public void uriTagIsDataRestsEffectiveRepositoryLookupPathWhenAvailable() {
this.request.setAttribute("org.springframework.data.rest.webmvc.RepositoryRestHandlerMapping.EFFECTIVE_REPOSITORY_RESOURCE_LOOKUP_PATH", new PathPatternParser().parse("/api/cities"));
this.request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, "/api/{repository}");
Tag tag = WebMvcTags.uri(this.request, this.response);
replacedertThat(tag.getValue()).isEqualTo("/api/cities");
}
@Test
public void uriTagValueIsBestMatchingPatternWhenAvailable() {
this.request.setAttribute(HandlerMapping.BEST_MATCHING_PATTERN_ATTRIBUTE, "/spring");
this.response.setStatus(301);
Tag tag = WebMvcTags.uri(this.request, this.response);
replacedertThat(tag.getValue()).isEqualTo("/spring");
}
@Test
public void uriTagValueIsRootWhenRequestHasNoPatternOrPathInfo() {
replacedertThat(WebMvcTags.uri(this.request, null).getValue()).isEqualTo("root");
}
@Test
public void uriTagValueIsRootWhenRequestHasNoPatternAndSlashPathInfo() {
this.request.setPathInfo("/");
replacedertThat(WebMvcTags.uri(this.request, null).getValue()).isEqualTo("root");
}
@Test
public void uriTagValueIsUnknownWhenRequestHasNoPatternAndNonRootPathInfo() {
this.request.setPathInfo("/example");
replacedertThat(WebMvcTags.uri(this.request, null).getValue()).isEqualTo("UNKNOWN");
}
@Test
public void uriTagValueIsRedirectionWhenResponseStatusIs3xx() {
this.response.setStatus(301);
Tag tag = WebMvcTags.uri(this.request, this.response);
replacedertThat(tag.getValue()).isEqualTo("REDIRECTION");
}
@Test
public void uriTagValueIsNotFoundWhenResponseStatusIs404() {
this.response.setStatus(404);
Tag tag = WebMvcTags.uri(this.request, this.response);
replacedertThat(tag.getValue()).isEqualTo("NOT_FOUND");
}
@Test
public void uriTagToleratesCustomResponseStatus() {
this.response.setStatus(601);
Tag tag = WebMvcTags.uri(this.request, this.response);
replacedertThat(tag.getValue()).isEqualTo("root");
}
@Test
public void uriTagIsUnknownWhenRequestIsNull() {
Tag tag = WebMvcTags.uri(null, null);
replacedertThat(tag.getValue()).isEqualTo("UNKNOWN");
}
@Test
public void outcomeTagIsUnknownWhenResponseIsNull() {
Tag tag = WebMvcTags.outcome(null);
replacedertThat(tag.getValue()).isEqualTo("UNKNOWN");
}
@Test
public void outcomeTagIsInformationalWhenResponseIs1xx() {
this.response.setStatus(100);
Tag tag = WebMvcTags.outcome(this.response);
replacedertThat(tag.getValue()).isEqualTo("INFORMATIONAL");
}
@Test
public void outcomeTagIsSuccessWhenResponseIs2xx() {
this.response.setStatus(200);
Tag tag = WebMvcTags.outcome(this.response);
replacedertThat(tag.getValue()).isEqualTo("SUCCESS");
}
@Test
public void outcomeTagIsRedirectionWhenResponseIs3xx() {
this.response.setStatus(301);
Tag tag = WebMvcTags.outcome(this.response);
replacedertThat(tag.getValue()).isEqualTo("REDIRECTION");
}
@Test
public void outcomeTagIsClientErrorWhenResponseIs4xx() {
this.response.setStatus(400);
Tag tag = WebMvcTags.outcome(this.response);
replacedertThat(tag.getValue()).isEqualTo("CLIENT_ERROR");
}
@Test
public void outcomeTagIsServerErrorWhenResponseIs5xx() {
this.response.setStatus(500);
Tag tag = WebMvcTags.outcome(this.response);
replacedertThat(tag.getValue()).isEqualTo("SERVER_ERROR");
}
}
19
View Source File : MustacheViewTests.java
License : Apache License 2.0
Project Creator : yuanmabiji
License : Apache License 2.0
Project Creator : yuanmabiji
/**
* Tests for {@link MustacheView}.
*
* @author Dave Syer
*/
public clreplaced MustacheViewTests {
private final String templateUrl = "clreplacedpath:/" + getClreplaced().getPackage().getName().replace(".", "/") + "/template.html";
private MockHttpServletRequest request = new MockHttpServletRequest();
private MockHttpServletResponse response = new MockHttpServletResponse();
private AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
@Before
public void init() {
this.context.refresh();
MockServletContext servletContext = new MockServletContext();
this.context.setServletContext(servletContext);
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.context);
}
@Test
public void viewResolvesHandlebars() throws Exception {
MustacheView view = new MustacheView();
view.setCompiler(Mustache.compiler());
view.setUrl(this.templateUrl);
view.setApplicationContext(this.context);
view.render(Collections.singletonMap("World", "Spring"), this.request, this.response);
replacedertThat(this.response.getContentreplacedtring()).isEqualTo("Hello Spring");
}
}
19
View Source File : AuthorizationExtractorTest.java
License : MIT License
Project Creator : woowacourse-teams
License : MIT License
Project Creator : woowacourse-teams
clreplaced AuthorizationExtractorTest {
private AuthorizationExtractor authorizationExtractor;
private MockHttpServletRequest request;
@BeforeEach
void setUp() {
authorizationExtractor = new AuthorizationExtractor();
request = new MockHttpServletRequest();
}
@DisplayName("요청의 헤더에서 토큰을 추출한다.")
@Test
void extractTest() {
request.addHeader("Authorization", TOKEN_TYPE + TOKEN);
replacedertThat(authorizationExtractor.extract(request)).isEqualTo(TOKEN);
}
@DisplayName("올바르지 않은 토큰인 경우 예외를 반환한다.")
@ParameterizedTest
@ValueSource(strings = { "", "Barer abc", "Digest ABC" })
void invalidTokenExtractTest(String expectedToken) {
request.addHeader("Authorization", expectedToken);
replacedertThatThrownBy(() -> authorizationExtractor.extract(request)).isInstanceOf(TokenInvalidException.clreplaced).hasMessage("유효하지 않은 토큰입니다.");
}
}
19
View Source File : ClassPathBeanDefinitionScannerScopeIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Before
public void setUp() {
MockHttpServletRequest oldRequestWithSession = new MockHttpServletRequest();
oldRequestWithSession.setSession(new MockHttpSession());
this.oldRequestAttributesWithSession = new ServletRequestAttributes(oldRequestWithSession);
MockHttpServletRequest newRequestWithSession = new MockHttpServletRequest();
newRequestWithSession.setSession(new MockHttpSession());
this.newRequestAttributesWithSession = new ServletRequestAttributes(newRequestWithSession);
}
19
View Source File : ClassPathBeanDefinitionScannerJsr330ScopeIntegrationTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Before
public void setUp() {
this.oldRequestAttributes = new ServletRequestAttributes(new MockHttpServletRequest());
this.newRequestAttributes = new ServletRequestAttributes(new MockHttpServletRequest());
MockHttpServletRequest oldRequestWithSession = new MockHttpServletRequest();
oldRequestWithSession.setSession(new MockHttpSession());
this.oldRequestAttributesWithSession = new ServletRequestAttributes(oldRequestWithSession);
MockHttpServletRequest newRequestWithSession = new MockHttpServletRequest();
newRequestWithSession.setSession(new MockHttpSession());
this.newRequestAttributesWithSession = new ServletRequestAttributes(newRequestWithSession);
}
19
View Source File : StubMvcResult.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
public void setRequest(MockHttpServletRequest request) {
this.request = request;
}
19
View Source File : StatusResultMatchersTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
/**
* Tests for {@link StatusResultMatchers}.
*
* @author Rossen Stoyanchev
*/
public clreplaced StatusResultMatchersTests {
private StatusResultMatchers matchers;
private MockHttpServletRequest request;
@Before
public void setup() {
this.matchers = new StatusResultMatchers();
this.request = new MockHttpServletRequest();
}
@Test
public void testHttpStatusCodeResultMatchers() throws Exception {
List<replacedertionError> failures = new ArrayList<>();
for (HttpStatus status : HttpStatus.values()) {
MockHttpServletResponse response = new MockHttpServletResponse();
response.setStatus(status.value());
MvcResult mvcResult = new StubMvcResult(request, null, null, null, null, null, response);
try {
Method method = getMethodForHttpStatus(status);
ResultMatcher matcher = (ResultMatcher) ReflectionUtils.invokeMethod(method, this.matchers);
try {
matcher.match(mvcResult);
} catch (replacedertionError error) {
failures.add(error);
}
} catch (Exception ex) {
throw new Exception("Failed to obtain ResultMatcher for status " + status, ex);
}
}
if (!failures.isEmpty()) {
fail("Failed status codes: " + failures);
}
}
private Method getMethodForHttpStatus(HttpStatus status) throws NoSuchMethodException {
String name = status.name().toLowerCase().replace("_", "-");
name = "is" + StringUtils.capitalize(Conventions.attributeNameToPropertyName(name));
return StatusResultMatchers.clreplaced.getMethod(name);
}
@Test
public void statusRanges() throws Exception {
for (HttpStatus status : HttpStatus.values()) {
MockHttpServletResponse response = new MockHttpServletResponse();
response.setStatus(status.value());
MvcResult mvcResult = new StubMvcResult(request, null, null, null, null, null, response);
switch(status.series().value()) {
case 1:
this.matchers.is1xxInformational().match(mvcResult);
break;
case 2:
this.matchers.is2xxSuccessful().match(mvcResult);
break;
case 3:
this.matchers.is3xxRedirection().match(mvcResult);
break;
case 4:
this.matchers.is4xxClientError().match(mvcResult);
break;
case 5:
this.matchers.is5xxServerError().match(mvcResult);
break;
default:
fail("Unexpected range for status code value " + status);
}
}
}
}
19
View Source File : MockHttpServletRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void requestUriWithEncoding() {
this.builder = new MockHttpServletRequestBuilder(HttpMethod.GET, "/foo bar");
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
replacedertEquals("/foo%20bar", request.getRequestURI());
}
19
View Source File : MockHttpServletRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void requestAttribute() {
this.builder.requestAttr("foo", "bar");
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
replacedertEquals("bar", request.getAttribute("foo"));
}
19
View Source File : MockHttpServletRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void principal() {
User user = new User();
this.builder.principal(user);
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
replacedertEquals(user, request.getUserPrincipal());
}
19
View Source File : MockHttpServletRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void characterEncoding() {
String encoding = "UTF-8";
this.builder.characterEncoding(encoding);
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
replacedertEquals(encoding, request.getCharacterEncoding());
}
19
View Source File : MockHttpServletRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void flashAttribute() {
this.builder.flashAttr("foo", "bar");
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
FlashMap flashMap = new SessionFlashMapManager().retrieveAndUpdate(request, null);
replacedertNotNull(flashMap);
replacedertEquals("bar", flashMap.get("foo"));
}
19
View Source File : MockHttpServletRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void requestUriAndFragment() {
this.builder = new MockHttpServletRequestBuilder(HttpMethod.GET, "/foo#bar");
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
replacedertEquals("/foo", request.getRequestURI());
}
19
View Source File : MockHttpServletRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
// SPR-12945
@Test
public void mergeInvokesDefaultRequestPostProcessorFirst() {
final String ATTR = "ATTR";
final String EXPECTED = "override";
MockHttpServletRequestBuilder defaultBuilder = new MockHttpServletRequestBuilder(HttpMethod.GET, "/foo/bar").with(requestAttr(ATTR).value("default")).with(requestAttr(ATTR).value(EXPECTED));
builder.merge(defaultBuilder);
MockHttpServletRequest request = builder.buildRequest(servletContext);
request = builder.postProcessRequest(request);
replacedertEquals(EXPECTED, request.getAttribute(ATTR));
}
19
View Source File : MockHttpServletRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void body() throws IOException {
byte[] body = "Hello World".getBytes("UTF-8");
this.builder.content(body);
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
byte[] result = FileCopyUtils.copyToByteArray(request.getInputStream());
replacedertArrayEquals(body, result);
}
19
View Source File : MockHttpServletRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void header() {
this.builder.header("foo", "bar", "baz");
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
List<String> headers = Collections.list(request.getHeaders("foo"));
replacedertEquals(2, headers.size());
replacedertEquals("bar", headers.get(0));
replacedertEquals("baz", headers.get(1));
}
19
View Source File : MockHttpServletRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void requestParameterFromRequestBodyFormData() throws Exception {
String contentType = "application/x-www-form-urlencoded;charset=UTF-8";
String body = "name+1=value+1&name+2=value+A&name+2=value+B&name+3";
MockHttpServletRequest request = new MockHttpServletRequestBuilder(HttpMethod.POST, "/foo").contentType(contentType).content(body.getBytes(StandardCharsets.UTF_8)).buildRequest(this.servletContext);
replacedertArrayEquals(new String[] { "value 1" }, request.getParameterMap().get("name 1"));
replacedertArrayEquals(new String[] { "value A", "value B" }, request.getParameterMap().get("name 2"));
replacedertArrayEquals(new String[] { null }, request.getParameterMap().get("name 3"));
}
19
View Source File : MockHttpServletRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void noCookies() {
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
replacedertNull(request.getCookies());
}
19
View Source File : MockHttpServletRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void session() {
MockHttpSession session = new MockHttpSession(this.servletContext);
session.setAttribute("foo", "bar");
this.builder.session(session);
this.builder.sessionAttr("baz", "qux");
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
replacedertEquals(session, request.getSession());
replacedertEquals("bar", request.getSession().getAttribute("foo"));
replacedertEquals("qux", request.getSession().getAttribute("baz"));
}
19
View Source File : MockHttpServletRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void cookie() {
Cookie cookie1 = new Cookie("foo", "bar");
Cookie cookie2 = new Cookie("baz", "qux");
this.builder.cookie(cookie1, cookie2);
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
Cookie[] cookies = request.getCookies();
replacedertEquals(2, cookies.length);
replacedertEquals("foo", cookies[0].getName());
replacedertEquals("bar", cookies[0].getValue());
replacedertEquals("baz", cookies[1].getName());
replacedertEquals("qux", cookies[1].getValue());
}
19
View Source File : MockHttpServletRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
// SPR-13801
@Test
public void requestParameterFromMultiValueMap() throws Exception {
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
params.add("foo", "bar");
params.add("foo", "baz");
this.builder = new MockHttpServletRequestBuilder(HttpMethod.POST, "/foo");
this.builder.params(params);
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
replacedertArrayEquals(new String[] { "bar", "baz" }, request.getParameterMap().get("foo"));
}
19
View Source File : MockHttpServletRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void sessionAttribute() {
this.builder.sessionAttr("foo", "bar");
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
replacedertEquals("bar", request.getSession().getAttribute("foo"));
}
19
View Source File : MockHttpServletRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void method() {
MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
replacedertEquals("GET", request.getMethod());
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestLocaleEnQ07() {
webRequest.setAdditionalHeader("Accept-Language", "en");
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getLocale(), equalTo(new Locale("en", "")));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestQueryWithSingleQueryParamWithValueSetToEncodedSpace() throws Exception {
String expectedQuery = "param=%20";
webRequest.setUrl(new URL("https://example.com/example?" + expectedQuery));
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getQueryString(), equalTo(expectedQuery));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestQueryWithSingleQueryParamWithoutValueButWithEqualsSign() throws Exception {
String expectedQuery = "param=";
webRequest.setUrl(new URL("https://example.com/example?" + expectedQuery));
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getQueryString(), equalTo(expectedQuery));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestRequestedSessionIdNull() throws Exception {
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getRequestedSessionId(), nullValue());
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestLocalName() {
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getLocalName(), equalTo("localhost"));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestCharacterEncoding() {
webRequest.setCharset(StandardCharsets.UTF_8);
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getCharacterEncoding(), equalTo("UTF-8"));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestLocalPort() {
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getLocalPort(), equalTo(80));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestCookiesSingle() {
webRequest.setAdditionalHeader("Cookie", "name=value");
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
Cookie[] cookies = actualRequest.getCookies();
replacedertThat(cookies.length, equalTo(1));
replacedertThat(cookies[0].getName(), equalTo("name"));
replacedertThat(cookies[0].getValue(), equalTo("value"));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestServletPath() throws Exception {
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getServletPath(), equalTo("/this/here"));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestLocaleDefault() {
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getLocale(), equalTo(Locale.getDefault()));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestRequestedSessionId() throws Exception {
String sessionId = "session-id";
webRequest.setAdditionalHeader("Cookie", "JSESSIONID=" + sessionId);
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getRequestedSessionId(), equalTo(sessionId));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestQueryWithMultipleQueryParams() throws Exception {
String expectedQuery = "param1=value1¶m2=value2";
webRequest.setUrl(new URL("https://example.com/example?" + expectedQuery));
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getQueryString(), equalTo(expectedQuery));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestServerPort() throws Exception {
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getServerPort(), equalTo(80));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestLocaleEnUs() {
webRequest.setAdditionalHeader("Accept-Language", "en-US");
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getLocale(), equalTo(Locale.US));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestLocaleMulti() {
webRequest.setAdditionalHeader("Accept-Language", "en-gb;q=0.8, da, en;q=0.7");
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
List<Locale> expected = asList(new Locale("da"), new Locale("en", "gb"), new Locale("en", ""));
replacedertThat(Collections.list(actualRequest.getLocales()), equalTo(expected));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestSessionIsNew() throws Exception {
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getSession().isNew(), equalTo(true));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestQueryWithSingleQueryParam() throws Exception {
String expectedQuery = "param=value";
webRequest.setUrl(new URL("https://example.com/example?" + expectedQuery));
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getQueryString(), equalTo(expectedQuery));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestDefaultCharacterEncoding() {
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getCharacterEncoding(), equalTo("ISO-8859-1"));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestServerPortDefault() throws Exception {
webRequest.setUrl(new URL("https://example.com/"));
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getServerPort(), equalTo(-1));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestQueryWithSingleQueryParamWithoutValueAndWithoutEqualsSign() throws Exception {
String expectedQuery = "param";
webRequest.setUrl(new URL("https://example.com/example?" + expectedQuery));
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getQueryString(), equalTo(expectedQuery));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestLocaleEnGbQ08() {
webRequest.setAdditionalHeader("Accept-Language", "en-gb;q=0.8");
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getLocale(), equalTo(new Locale("en", "gb")));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestProtocol() throws Exception {
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getProtocol(), equalTo("HTTP/1.1"));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestLocalMissing() throws Exception {
webRequest.setUrl(new URL("http://localhost/test/this"));
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getLocalPort(), equalTo(-1));
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestCookiesNull() {
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getCookies(), nullValue());
}
19
View Source File : HtmlUnitRequestBuilderTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void buildRequestLocaleDa() {
webRequest.setAdditionalHeader("Accept-Language", "da");
MockHttpServletRequest actualRequest = requestBuilder.buildRequest(servletContext);
replacedertThat(actualRequest.getLocale(), equalTo(new Locale("da")));
}
See More Examples