当前位置: 首页>>代码示例>>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;未经允许,请勿转载。