congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
MockHttpServletRequestBuilder.contextPath
Code IndexAdd Tabnine to your IDE (free)

How to use
contextPath
method
in
org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder

Best Java code snippets using org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder.contextPath (Showing top 20 results out of 315)

origin: spring-projects/spring-framework

private void testContextPathServletPathInvalid(String contextPath, String servletPath, String message) {
  try {
    this.builder.contextPath(contextPath);
    this.builder.servletPath(servletPath);
    this.builder.buildRequest(this.servletContext);
  }
  catch (IllegalArgumentException ex) {
    assertEquals(message, ex.getMessage());
  }
}
origin: spring-projects/spring-framework

@Test
public void chainMultiple() {
  MockMvcBuilders
      .webAppContextSetup(wac)
      .addFilter(new CharacterEncodingFilter() )
      .defaultRequest(get("/").contextPath("/mywebapp"))
      .build();
}
origin: spring-projects/spring-framework

@Test
public void contextPathServletPathEmpty() {
  this.builder = new MockHttpServletRequestBuilder(HttpMethod.GET, "/travel/hotels/42");
  this.builder.contextPath("/travel");
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertEquals("/travel", request.getContextPath());
  assertEquals("", request.getServletPath());
  assertEquals("/hotels/42", request.getPathInfo());
}
origin: spring-projects/spring-framework

@Test
public void contextPathServletPath() {
  this.builder = new MockHttpServletRequestBuilder(HttpMethod.GET, "/travel/main/hotels/42");
  this.builder.contextPath("/travel");
  this.builder.servletPath("/main");
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertEquals("/travel", request.getContextPath());
  assertEquals("/main", request.getServletPath());
  assertEquals("/hotels/42", request.getPathInfo());
}
origin: spring-projects/spring-framework

@Test
public void contextPathServletPathInfoEmpty() {
  this.builder = new MockHttpServletRequestBuilder(HttpMethod.GET, "/travel/hotels/42");
  this.builder.contextPath("/travel");
  this.builder.servletPath("/hotels/42");
  MockHttpServletRequest request = this.builder.buildRequest(this.servletContext);
  assertEquals("/travel", request.getContextPath());
  assertEquals("/hotels/42", request.getServletPath());
  assertNull(request.getPathInfo());
}
origin: cloudfoundry/uaa

@Test
public void testHandleForcePasswordChange() throws Exception {
  setAuthentication();
  mockMvc.perform(
    post("/uaa/force_password_change")
      .param("password","pwd")
      .param("password_confirmation", "pwd")
      .contextPath("/uaa"))
      .andExpect(status().isFound())
      .andExpect(redirectedUrl("/uaa/force_password_change_completed"));
  verify(authentication, times(1)).setAuthenticatedTime(anyLong());
}
origin: cloudfoundry/uaa

private static void attemptUnsuccessfulLogin(MockMvc mockMvc, int numberOfAttempts, String username, String subdomain) throws Exception {
  String requestDomain = subdomain.equals("") ? "localhost" : subdomain + ".localhost";
  MockHttpServletRequestBuilder post = post("/uaa/login.do")
      .with(new SetServerNameRequestPostProcessor(requestDomain))
      .with(cookieCsrf())
      .contextPath("/uaa")
      .param("username", username)
      .param("password", "wrong_password");
  for (int i = 0; i < numberOfAttempts; i++) {
    mockMvc.perform(post)
        .andExpect(redirectedUrl("/uaa/login?error=login_failure"))
        .andExpect(emptyCurrentUserCookie());
  }
}
origin: cloudfoundry/uaa

@Test
void testLogOut() throws Exception {
  mockMvc.perform(get("/uaa/logout.do").contextPath("/uaa"))
      .andExpect(status().isFound())
      .andExpect(redirectedUrl("/uaa/login"))
      .andExpect(emptyCurrentUserCookie());
}
origin: cloudfoundry/uaa

public ResultActions performSPAuthentication(String assertion) throws Exception {
  String spEntityId = spZone.getIdentityZone().getSubdomain() + ".cloudfoundry-saml-login";
  return getMockMvc().perform(
    post("/uaa/saml/SSO/alias/"+spEntityId)
      .contextPath("/uaa")
      .header(HttpHeaders.HOST, spZone.getIdentityZone().getSubdomain()+".localhost:8080")
      .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
      .param("SAMLResponse", assertion)
  );
}
origin: cloudfoundry/uaa

@Test
void testLogOutIgnoreRedirectParameter() throws Exception {
  mockMvc.perform(get("/uaa/logout.do").param("redirect", "https://www.google.com").contextPath("/uaa"))
      .andExpect(status().isFound())
      .andExpect(redirectedUrl("/uaa/login"))
      .andExpect(emptyCurrentUserCookie());
}
origin: cloudfoundry/uaa

@Test
void login_LockoutPolicySucceeds_ForDefaultZone(
    @Autowired ScimUserProvisioning scimUserProvisioning
) throws Exception {
  ScimUser userToLockout = createUser(scimUserProvisioning, generator, getUaa().getId());
  attemptUnsuccessfulLogin(mockMvc, 5, userToLockout.getUserName(), "");
  mockMvc.perform(post("/uaa/login.do")
      .contextPath("/uaa")
      .with(cookieCsrf())
      .param("username", userToLockout.getUserName())
      .param("password", userToLockout.getPassword()))
      .andExpect(redirectedUrl("/uaa/login?error=account_locked"))
      .andExpect(emptyCurrentUserCookie());
}
origin: cloudfoundry/uaa

@Test
void login_LockoutPolicySucceeds_WhenPolicyIsUpdatedByApi(
    @Autowired ScimUserProvisioning scimUserProvisioning,
    @Autowired JdbcIdentityProviderProvisioning jdbcIdentityProviderProvisioning
) throws Exception {
  String subdomain = generator.generate();
  IdentityZone zone = createOtherIdentityZone(subdomain, mockMvc, webApplicationContext, false);
  changeLockoutPolicyForIdpInZone(jdbcIdentityProviderProvisioning, zone);
  ScimUser userToLockout = createUser(scimUserProvisioning, generator, zone.getId());
  attemptUnsuccessfulLogin(mockMvc, 2, userToLockout.getUserName(), subdomain);
  mockMvc.perform(post("/uaa/login.do")
      .contextPath("/uaa")
      .with(new SetServerNameRequestPostProcessor(subdomain + ".localhost"))
      .with(cookieCsrf())
      .param("username", userToLockout.getUserName())
      .param("password", userToLockout.getPassword()))
      .andExpect(redirectedUrl("/uaa/login?error=account_locked"))
      .andExpect(emptyCurrentUserCookie());
}
origin: cloudfoundry/uaa

@Test
void testLogOutWhitelistedRedirectParameter() throws Exception {
  Links.Logout original = MockMvcUtils.getLogout(webApplicationContext, getUaa().getId());
  Links.Logout logout = MockMvcUtils.getLogout(webApplicationContext, getUaa().getId());
  logout.setDisableRedirectParameter(false);
  logout.setWhitelist(singletonList("https://www.google.com"));
  MockMvcUtils.setLogout(webApplicationContext, getUaa().getId(), logout);
  try {
    mockMvc.perform(get("/uaa/logout.do").param("redirect", "https://www.google.com").contextPath("/uaa"))
        .andExpect(status().isFound())
        .andExpect(redirectedUrl("https://www.google.com"))
        .andExpect(emptyCurrentUserCookie());
  } finally {
    MockMvcUtils.setLogout(webApplicationContext, getUaa().getId(), original);
  }
}
origin: cloudfoundry/uaa

@Test
void testLogOutNotWhitelistedRedirectParameter() throws Exception {
  Links.Logout original = MockMvcUtils.getLogout(webApplicationContext, getUaa().getId());
  Links.Logout logout = MockMvcUtils.getLogout(webApplicationContext, getUaa().getId());
  logout.setDisableRedirectParameter(false);
  logout.setWhitelist(singletonList("https://www.yahoo.com"));
  MockMvcUtils.setLogout(webApplicationContext, getUaa().getId(), logout);
  try {
    mockMvc.perform(get("/uaa/logout.do").param("redirect", "https://www.google.com").contextPath("/uaa"))
        .andExpect(status().isFound())
        .andExpect(redirectedUrl("/uaa/login"))
        .andExpect(emptyCurrentUserCookie());
  } finally {
    MockMvcUtils.setLogout(webApplicationContext, getUaa().getId(), original);
  }
}
origin: cloudfoundry/uaa

@Test
void testLogOutNullWhitelistedRedirectParameter() throws Exception {
  Links.Logout original = MockMvcUtils.getLogout(webApplicationContext, getUaa().getId());
  Links.Logout logout = MockMvcUtils.getLogout(webApplicationContext, getUaa().getId());
  logout.setDisableRedirectParameter(false);
  logout.setWhitelist(singletonList("http*://www.google.com"));
  MockMvcUtils.setLogout(webApplicationContext, getUaa().getId(), logout);
  try {
    mockMvc.perform(get("/uaa/logout.do").param("redirect", "https://www.google.com").contextPath("/uaa"))
        .andExpect(status().isFound())
        .andExpect(redirectedUrl("https://www.google.com"))
        .andExpect(emptyCurrentUserCookie());
  } finally {
    MockMvcUtils.setLogout(webApplicationContext, getUaa().getId(), original);
  }
}
origin: cloudfoundry/uaa

@Test
void testLogOutEnableRedirectParameter() throws Exception {
  Links.Logout original = MockMvcUtils.getLogout(webApplicationContext, getUaa().getId());
  Links.Logout logout = MockMvcUtils.getLogout(webApplicationContext, getUaa().getId());
  logout.setDisableRedirectParameter(false);
  logout.setWhitelist(singletonList("https://www.google.com"));
  MockMvcUtils.setLogout(webApplicationContext, getUaa().getId(), logout);
  try {
    mockMvc.perform(get("/uaa/logout.do").param("redirect", "https://www.google.com").contextPath("/uaa"))
        .andExpect(status().isFound())
        .andExpect(redirectedUrl("https://www.google.com"))
        .andExpect(emptyCurrentUserCookie());
  } finally {
    MockMvcUtils.setLogout(webApplicationContext, getUaa().getId(), original);
  }
}
origin: cloudfoundry/uaa

@Test
void testLogOutAllowInternalRedirect() throws Exception {
  Links.Logout original = MockMvcUtils.getLogout(webApplicationContext, getUaa().getId());
  Links.Logout logout = MockMvcUtils.getLogout(webApplicationContext, getUaa().getId());
  MockMvcUtils.setLogout(webApplicationContext, getUaa().getId(), logout);
  try {
    mockMvc.perform(get("/uaa/logout.do").param("redirect", "http://localhost/uaa/internal-location").contextPath("/uaa"))
        .andExpect(status().isFound())
        .andExpect(redirectedUrl("http://localhost/uaa/internal-location"))
        .andExpect(emptyCurrentUserCookie());
  } finally {
    MockMvcUtils.setLogout(webApplicationContext, getUaa().getId(), original);
  }
}
origin: cloudfoundry/uaa

@Test
void testLogOutChangeUrlValue() throws Exception {
  Links.Logout original = MockMvcUtils.getLogout(webApplicationContext, getUaa().getId());
  assertFalse(original.isDisableRedirectParameter());
  Links.Logout logout = MockMvcUtils.getLogout(webApplicationContext, getUaa().getId());
  logout.setRedirectUrl("https://www.google.com");
  MockMvcUtils.setLogout(webApplicationContext, getUaa().getId(), logout);
  try {
    mockMvc.perform(get("/uaa/logout.do").contextPath("/uaa"))
        .andExpect(status().isFound())
        .andExpect(redirectedUrl("https://www.google.com"))
        .andExpect(emptyCurrentUserCookie());
  } finally {
    MockMvcUtils.setLogout(webApplicationContext, getUaa().getId(), original);
  }
}
origin: cloudfoundry/uaa

@Test
void testLogin_Post_When_DisableInternalUserManagement_Is_True(
    @Autowired ScimUserProvisioning scimUserProvisioning
) throws Exception {
  ScimUser user = createUser(scimUserProvisioning, generator, getUaa().getId());
  MockMvcUtils.setDisableInternalAuth(webApplicationContext, getUaa().getId(), true);
  try {
    mockMvc.perform(post("/login.do")
        .with(cookieCsrf())
        .param("username", user.getUserName())
        .param("password", user.getPassword()))
        .andExpect(redirectedUrl("/login?error=login_failure"));
  } finally {
    MockMvcUtils.setDisableInternalAuth(webApplicationContext, getUaa().getId(), false);
  }
  mockMvc.perform(post("/uaa/login.do")
      .with(cookieCsrf())
      .contextPath("/uaa")
      .param("username", user.getUserName())
      .param("password", user.getPassword()))
      .andDo(print())
      .andExpect(redirectedUrl("/uaa/"));
}
origin: cloudfoundry/uaa

@Test
void testLogOutEmptyWhitelistedRedirectParameter() throws Exception {
  Links.Logout original = MockMvcUtils.getLogout(webApplicationContext, getUaa().getId());
  Links.Logout logout = MockMvcUtils.getLogout(webApplicationContext, getUaa().getId());
  logout.setDisableRedirectParameter(false);
  logout.setWhitelist(EMPTY_LIST);
  MockMvcUtils.setLogout(webApplicationContext, getUaa().getId(), logout);
  try {
    mockMvc.perform(get("/uaa/logout.do").param("redirect", "https://www.google.com").contextPath("/uaa"))
        .andExpect(status().isFound())
        .andExpect(redirectedUrl("/uaa/login"))
        .andExpect(emptyCurrentUserCookie());
  } finally {
    MockMvcUtils.setLogout(webApplicationContext, getUaa().getId(), original);
  }
}
org.springframework.test.web.servlet.requestMockHttpServletRequestBuildercontextPath

Javadoc

Specify the portion of the requestURI that represents the context path. The context path, if specified, must match to the start of the request URI.

In most cases, tests can be written by omitting the context path from the requestURI. This is because most applications don't actually depend on the name under which they're deployed. If specified here, the context path must start with a "/" and must not end with a "/".

Popular methods of MockHttpServletRequestBuilder

  • contentType
    Set the 'Content-Type' header of the request.
  • content
    Set the request body.
  • param
    Add a request parameter to the MockHttpServletRequest.If called more than once, new values get added
  • accept
    Set the 'Accept' header to the given media type(s).
  • header
    Add a header to the request. Values are always added.
  • with
    An extension point for further initialization of MockHttpServletRequestin ways not built directly in
  • requestAttr
    Set a request attribute.
  • buildRequest
    Build a MockHttpServletRequest.
  • principal
    Set the principal of the request.
  • flashAttr
    Set an "input" flash attribute.
  • headers
    Add all headers to the request. Values are always added.
  • session
    Set the HTTP session to use, possibly re-used across requests.Individual attributes provided via #se
  • headers,
  • session,
  • sessionAttr,
  • cookie,
  • params,
  • servletPath,
  • <init>,
  • characterEncoding,
  • locale

Popular in Java

  • Parsing JSON documents to java classes using gson
  • setScale (BigDecimal)
  • getSystemService (Context)
  • compareTo (BigDecimal)
  • InputStream (java.io)
    A readable source of bytes.Most clients will use input streams that read data from the file system (
  • Path (java.nio.file)
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • Top Vim plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now