當前位置: 首頁>>代碼示例>>Java>>正文


Java MockHttpServletRequest.addParameter方法代碼示例

本文整理匯總了Java中org.springframework.mock.web.MockHttpServletRequest.addParameter方法的典型用法代碼示例。如果您正苦於以下問題:Java MockHttpServletRequest.addParameter方法的具體用法?Java MockHttpServletRequest.addParameter怎麽用?Java MockHttpServletRequest.addParameter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.mock.web.MockHttpServletRequest的用法示例。


在下文中一共展示了MockHttpServletRequest.addParameter方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testParamsComplete

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
/**
 * ?zone={zone_id}&pub={publisher_id}&prot={protocol}&h={height}&w={width}&sd={startdelay}&mime={mime_type}&domain={domain}&page={page}&ad={adid}
 */

@Test
public void testParamsComplete() {
	final MockHttpServletRequest request = new MockHttpServletRequest();
	final MockHttpServletResponse response = new MockHttpServletResponse();

	request.addParameter("site", "1");

	RequestSessionAgent agent = null;
	try {
		agent = new RequestSessionAgent(request, response);
	} catch (final RequestException e) {
		Assert.fail(e.getMessage());
	}

	Assert.assertEquals("1", agent.getParamValues().getSite().getId());
}
 
開發者ID:ad-tech-group,項目名稱:openssp,代碼行數:21,代碼來源:SessionAgentParamsTest.java

示例2: verifyValidServiceTicketWithValidPgtAndProxyHandling

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyValidServiceTicketWithValidPgtAndProxyHandling() throws Exception {
    final AuthenticationContext ctx = org.jasig.cas.authentication.TestUtils
            .getAuthenticationContext(getAuthenticationSystemSupport(), SERVICE);

    final TicketGrantingTicket tId = getCentralAuthenticationService()
            .createTicketGrantingTicket(ctx);
    final ServiceTicket sId = getCentralAuthenticationService().grantServiceTicket(tId.getId(),
            SERVICE, ctx);

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("service", SERVICE.getId());
    request.addParameter("ticket", sId.getId());
    request.addParameter("pgtUrl", "https://www.github.com");

    final ModelAndView modelAndView = this.serviceValidateController.handleRequestInternal(request, new MockHttpServletResponse());
    assertEquals(AbstractServiceValidateController.DEFAULT_SERVICE_SUCCESS_VIEW_NAME, modelAndView.getViewName());
    assertNotNull(modelAndView.getModel().get("pgtIou"));
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:20,代碼來源:AbstractServiceValidateControllerTests.java

示例3: testUnacceptableRequestContentType

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void testUnacceptableRequestContentType() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest(servletContext);
	request.setMethod("GET");
	request.setContextPath("");
	request.setServletPath("/api");
	request.setPathInfo("/tasks");
	request.setRequestURI("/api/tasks");
	request.setContentType(HttpHeaders.JSONAPI_CONTENT_TYPE);
	request.addHeader("Accept", "application/xml");
	request.addParameter("filter[Task][name]", "John");
	request.setQueryString(URLEncoder.encode("filter[Task][name]", StandardCharsets.UTF_8.name()) + "=John");

	MockHttpServletResponse response = new MockHttpServletResponse();

	servlet.service(request, response);

	assertEquals(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, response.getStatus());
	String responseContent = response.getContentAsString();
	assertTrue(responseContent == null || "".equals(responseContent.trim()));
}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:22,代碼來源:CrnkServletTest.java

示例4: verifyValidServiceTicketAndPgtUrlMismatch

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyValidServiceTicketAndPgtUrlMismatch() throws Exception {
    final Service svc = org.jasig.cas.authentication.TestUtils.getService("proxyService");
    final AuthenticationContext ctx = org.jasig.cas.authentication.TestUtils
            .getAuthenticationContext(getAuthenticationSystemSupport(), svc);

    final TicketGrantingTicket tId = getCentralAuthenticationService()
            .createTicketGrantingTicket(ctx);

    final ServiceTicket sId = getCentralAuthenticationService().grantServiceTicket(tId.getId(), svc, ctx);

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("service", svc.getId());
    request.addParameter("ticket", sId.getId());
    request.addParameter("pgtUrl", "http://www.github.com");
    
    final ModelAndView modelAndView = this.serviceValidateController.handleRequestInternal(request, new MockHttpServletResponse());
    assertEquals(AbstractServiceValidateController.DEFAULT_SERVICE_FAILURE_VIEW_NAME, modelAndView.getViewName());
    assertNull(modelAndView.getModel().get("pgtIou"));
}
 
開發者ID:yuweijun,項目名稱:cas-server-4.2.1,代碼行數:21,代碼來源:AbstractServiceValidateControllerTests.java

示例5: verifyFailedAuthenticationWithNoService

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyFailedAuthenticationWithNoService() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockRequestContext context = new MockRequestContext();

    final UsernamePasswordCredential c = org.jasig.cas.authentication.TestUtils.getCredentialsWithDifferentUsernameAndPassword();
    
    request.addParameter("username", c.getUsername());
    request.addParameter("password", c.getPassword());
    context.setExternalContext(new ServletExternalContext(
            new MockServletContext(), request, new MockHttpServletResponse()));
    
    putCredentialInRequestScope(context, c);
    context.getRequestScope().put(
        "org.springframework.validation.BindException.credentials",
        new BindException(c, "credentials"));

    final MessageContext messageContext = mock(MessageContext.class);
    assertEquals("authenticationFailure", this.action.submit(context, c, messageContext).getId());
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:21,代碼來源:AuthenticationViaFormActionTests.java

示例6: verifyRenewWithServiceAndBadCredentials

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyRenewWithServiceAndBadCredentials() throws Exception {
    final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    final Service service = RegisteredServiceTestUtils.getService(TEST);
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(
            getAuthenticationSystemSupport(), service, c);

    final TicketGrantingTicket ticketGrantingTicket = getCentralAuthenticationService().createTicketGrantingTicket(ctx);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockRequestContext context = new MockRequestContext();

    WebUtils.putTicketGrantingTicketInScopes(context, ticketGrantingTicket);
    request.addParameter(CasProtocolConstants.PARAMETER_RENEW, "true");
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, service.getId());

    final Credential c2 = CoreAuthenticationTestUtils.getCredentialsWithDifferentUsernameAndPassword();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    putCredentialInRequestScope(context, c2);
    assertEquals(CasWebflowConstants.TRANSITION_ID_AUTHENTICATION_FAILURE, this.action.execute(context).getId());
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:21,代碼來源:AuthenticationViaFormActionTests.java

示例7: verifyTicketGrantingTicketNotTgtButGateway

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyTicketGrantingTicketNotTgtButGateway() throws Exception {
    final MockRequestContext context = new MockRequestContext();
    context.getFlowScope().put("service", org.jasig.cas.services.TestUtils.getService());
    final MockHttpServletRequest request = new MockHttpServletRequest();
    context.setExternalContext(new ServletExternalContext(
            new MockServletContext(), request, new MockHttpServletResponse()));
    request.addParameter("service", "service");
    request.addParameter("gateway", "true");
    final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
    when(tgt.getId()).thenReturn("bleh");
    WebUtils.putTicketGrantingTicketInScopes(context, tgt);


    assertEquals("gateway", this.action.execute(context).getId());
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:17,代碼來源:GenerateServiceTicketActionTests.java

示例8: verifySsoSessionCookieOnRenewAsParameter

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifySsoSessionCookieOnRenewAsParameter() throws Exception {
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(CasProtocolConstants.PARAMETER_RENEW, "true");

    final TicketGrantingTicket tgt = mock(TicketGrantingTicket.class);
    when(tgt.getId()).thenReturn("test");
    request.setCookies(new Cookie("TGT", "test5"));
    WebUtils.putTicketGrantingTicketInScopes(this.context, tgt);
    this.context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));

    this.action.setCreateSsoSessionCookieOnRenewAuthentications(false);
    assertEquals("success", this.action.execute(this.context).getId());
    assertEquals(0, response.getCookies().length);
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:17,代碼來源:SendTicketGrantingTicketActionTests.java

示例9: testGetTicketsFromRegistryEqualToTicketsAdded

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void testGetTicketsFromRegistryEqualToTicketsAdded() {
    final Collection<Ticket> tickets = new ArrayList<Ticket>();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("service", "test");

    for (int i = 0; i < TICKETS_IN_REGISTRY; i++) {
        final TicketGrantingTicket ticketGrantingTicket = new TicketGrantingTicketImpl(
                "TEST" + i, TestUtils.getAuthentication(),
                new NeverExpiresExpirationPolicy());
        final ServiceTicket st = ticketGrantingTicket.grantServiceTicket(
                "tests" + i, SimpleWebApplicationServiceImpl.createServiceFrom(request),
                new NeverExpiresExpirationPolicy(), false);
        tickets.add(ticketGrantingTicket);
        tickets.add(st);
        this.ticketRegistry.addTicket(ticketGrantingTicket);
        this.ticketRegistry.addTicket(st);
    }

    try {
        Collection<Ticket> ticketRegistryTickets = this.ticketRegistry.getTickets();
        assertEquals(
                "The size of the registry is not the same as the collection.",
                ticketRegistryTickets.size(), tickets.size());

        for (final Ticket ticket : tickets) {
            if (!ticketRegistryTickets.contains(ticket)) {
                fail("Ticket was added to registry but was not found in retrieval of collection of all tickets.");
            }
        }
    } catch (final Exception e) {
        fail("Caught an exception. But no exception should have been thrown.");
    }
}
 
開發者ID:luotuo,項目名稱:cas4.0.x-server-wechat,代碼行數:35,代碼來源:JBossCacheTicketRegistryTests.java

示例10: verifyTicketGrantingTicketFromRequest

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyTicketGrantingTicketFromRequest() throws Exception {
    final MockRequestContext context = new MockRequestContext();
    context.getFlowScope().put(SERVICE_PARAM, RegisteredServiceTestUtils.getService());
    final MockHttpServletRequest request = new MockHttpServletRequest();
    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, new MockHttpServletResponse()));
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, SERVICE_PARAM);
    WebUtils.putTicketGrantingTicketInScopes(context, this.ticketGrantingTicket);

    this.action.execute(context);

    assertNotNull(WebUtils.getServiceTicketFromRequestScope(context));
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:14,代碼來源:GenerateServiceTicketActionTests.java

示例11: testAddRegisteredServiceWithValues

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void testAddRegisteredServiceWithValues() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();

    request.addParameter("description", "description");
    request.addParameter("serviceId", "serviceId");
    request.addParameter("name", "name");
    request.addParameter("theme", "theme");
    request.addParameter("allowedToProxy", "true");
    request.addParameter("enabled", "true");
    request.addParameter("ssoEnabled", "true");
    request.addParameter("anonymousAccess", "false");
    request.addParameter("evaluationOrder", "1");

    request.setMethod("POST");

    assertTrue(this.manager.getAllServices().isEmpty());

    this.controller.handleRequest(
            request, response);

    final Collection<RegisteredService> services = this.manager.getAllServices();
    assertEquals(1, services.size());
    for(RegisteredService rs : this.manager.getAllServices()) {
        assertTrue(rs instanceof RegisteredServiceImpl);
    }
}
 
開發者ID:luotuo,項目名稱:cas4.0.x-server-wechat,代碼行數:29,代碼來源:RegisteredServiceSimpleFormControllerTests.java

示例12: verifyNotAuthorizedPGT

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyNotAuthorizedPGT() throws Exception {
    final ProxyGrantingTicket ticket = new ProxyGrantingTicketImpl("ticketGrantingTicketId",
            org.jasig.cas.authentication.TestUtils.getAuthentication(),
            new NeverExpiresExpirationPolicy());
    getTicketRegistry().addTicket(ticket);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("pgt", ticket.getId());
    request.addParameter("targetService", "service");

    final Map<String, Object> map = this.proxyController.handleRequestInternal(request,  new MockHttpServletResponse()).getModel();
    assertTrue(!map.containsKey("ticket"));
}
 
開發者ID:yuweijun,項目名稱:cas-server-4.2.1,代碼行數:14,代碼來源:ProxyControllerTests.java

示例13: verifyExistingPGT

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyExistingPGT() throws Exception {
    final ProxyGrantingTicket ticket = new ProxyGrantingTicketImpl(
            "ticketGrantingTicketId", org.jasig.cas.authentication.TestUtils.getAuthentication(),
            new NeverExpiresExpirationPolicy());
    getTicketRegistry().addTicket(ticket);
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("pgt", ticket.getId());
    request.addParameter("targetService", "testDefault");

    assertTrue(this.proxyController.handleRequestInternal(request,
            new MockHttpServletResponse()).getModel().containsKey(
                    "ticket"));
}
 
開發者ID:yuweijun,項目名稱:cas-server-4.2.1,代碼行數:15,代碼來源:ProxyControllerTests.java

示例14: getHttpServletRequest

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
private HttpServletRequest getHttpServletRequest() throws Exception {
    final String tId = getCentralAuthenticationService()
            .createTicketGrantingTicket(TestUtils.getCredentialsWithSameUsernameAndPassword());
    getCentralAuthenticationService().grantServiceTicket(tId, TestUtils.getService());
    final String sId2 = getCentralAuthenticationService().grantServiceTicket(tId, TestUtils.getService());

    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter("service", TestUtils.getService().getId());
    request.addParameter("ticket", sId2);
    request.addParameter("renew", "true");

    return request;
}
 
開發者ID:luotuo,項目名稱:cas4.0.x-server-wechat,代碼行數:14,代碼來源:ServiceValidateControllerTests.java

示例15: verifyEntityIdUIInfoExistsDynamically

import org.springframework.mock.web.MockHttpServletRequest; //導入方法依賴的package包/類
@Test
public void verifyEntityIdUIInfoExistsDynamically() throws Exception {
    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest request = new MockHttpServletRequest();
    request.addParameter(SamlMetadataUIParserAction.ENTITY_ID_PARAMETER_NAME, "https://carmenwiki.osu.edu/shibboleth");

    final MockHttpServletResponse response = new MockHttpServletResponse();

    final MockServletContext sCtx = new MockServletContext();
    ctx.setExternalContext(new ServletExternalContext(sCtx, request, response));
    samlDynamicMetadataUIParserAction.doExecute(ctx);
    assertTrue(ctx.getFlowScope().contains(SamlMetadataUIParserAction.MDUI_FLOW_PARAMETER_NAME));
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:14,代碼來源:SamlMetadataUIParserActionTests.java


注:本文中的org.springframework.mock.web.MockHttpServletRequest.addParameter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。