当前位置: 首页>>代码示例>>Java>>正文


Java MockHttpServletRequest类代码示例

本文整理汇总了Java中org.springframework.mock.web.MockHttpServletRequest的典型用法代码示例。如果您正苦于以下问题:Java MockHttpServletRequest类的具体用法?Java MockHttpServletRequest怎么用?Java MockHttpServletRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MockHttpServletRequest类属于org.springframework.mock.web包,在下文中一共展示了MockHttpServletRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testAddEventWithWebAuthenticationDetails

import org.springframework.mock.web.MockHttpServletRequest; //导入依赖的package包/类
@Test
public void testAddEventWithWebAuthenticationDetails() {
    HttpSession session = new MockHttpSession(null, "test-session-id");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setSession(session);
    request.setRemoteAddr("1.2.3.4");
    WebAuthenticationDetails details = new WebAuthenticationDetails(request);
    Map<String, Object> data = new HashMap<>();
    data.put("test-key", details);
    AuditEvent event = new AuditEvent("test-user", "test-type", data);
    customAuditEventRepository.add(event);
    List<PersistentAuditEvent> persistentAuditEvents = persistenceAuditEventRepository.findAll();
    assertThat(persistentAuditEvents).hasSize(1);
    PersistentAuditEvent persistentAuditEvent = persistentAuditEvents.get(0);
    assertThat(persistentAuditEvent.getData().get("remoteAddress")).isEqualTo("1.2.3.4");
    assertThat(persistentAuditEvent.getData().get("sessionId")).isEqualTo("test-session-id");
}
 
开发者ID:xm-online,项目名称:xm-uaa,代码行数:18,代码来源:CustomAuditEventRepositoryIntTest.java

示例2: testSuccessfulAuthenticationWithNoServiceAndWarn

import org.springframework.mock.web.MockHttpServletRequest; //导入依赖的package包/类
@Test
    public void testSuccessfulAuthenticationWithNoServiceAndWarn()
        throws Exception {
        final MockHttpServletRequest request = new MockHttpServletRequest();
        final MockHttpServletResponse response = new MockHttpServletResponse();
        final MockRequestContext context = new MockRequestContext();

        request.addParameter("username", "test");
        request.addParameter("password", "test");
        request.addParameter("warn", "true");

        context.setExternalContext(new ServletExternalContext(
            new MockServletContext(), request, response));
        context.getRequestScope().put("credentials",
            TestUtils.getCredentialsWithSameUsernameAndPassword());
  //      this.action.bind(context);
   //     assertEquals("success", this.action.submit(context).getId());
//        assertNotNull(response.getCookie(this.warnCookieGenerator
//            .getCookieName()));
    }
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:21,代码来源:AuthenticationViaFormActionTests.java

示例3: verifyNoCasService

import org.springframework.mock.web.MockHttpServletRequest; //导入依赖的package包/类
@Test
public void verifyNoCasService() throws Exception {
    clearAllServices();

    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT
            + OAuthConstants.ACCESS_TOKEN_URL);
    mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
    mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI);
    mockRequest.setParameter(OAuthConstants.CLIENT_SECRET, CLIENT_SECRET);
    mockRequest.setParameter(OAuthConstants.CODE, CODE);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();


    oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(400, mockResponse.getStatus());
    assertEquals("error=" + OAuthConstants.INVALID_REQUEST, mockResponse.getContentAsString());
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:18,代码来源:OAuth20AccessTokenControllerTests.java

示例4: test_for_issue

import org.springframework.mock.web.MockHttpServletRequest; //导入依赖的package包/类
public void test_for_issue() throws Exception {
        MockHttpServletRequest mockReq = new MockHttpServletRequest();
        DefaultSavedRequest request = new DefaultSavedRequest(mockReq, new PortResolver() {

            public int getServerPort(ServletRequest servletRequest) {
                return 0;
            }
        });

        String str = JSON.toJSONString(request, SerializerFeature.WriteClassName);
//        System.out.println(str);


        JSON.parseObject(str, Object.class, config);

        JSON.parseObject(str);
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:DefaultSavedRequestTest.java

示例5: renderView

import org.springframework.mock.web.MockHttpServletRequest; //导入依赖的package包/类
private Map<?, ?> renderView() throws Exception{
    final ModelAndView modelAndView = this.getModelAndViewUponServiceValidationWithSecurePgtUrl();
    final JstlView v = (JstlView) resolver.resolveViewName(modelAndView.getViewName(), Locale.getDefault());
    final MockHttpServletRequest req = new MockHttpServletRequest(new MockServletContext());
    v.setServletContext(req.getServletContext());
    req.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE,
            new GenericWebApplicationContext(req.getServletContext()));

    final Cas30ResponseView view = new Cas30ResponseView(v);
    view.setServicesManager(this.servicesManager);
    view.setCasAttributeEncoder(new DefaultCasAttributeEncoder(this.servicesManager));

    final MockHttpServletResponse resp = new MockHttpServletResponse();
    view.render(modelAndView.getModel(), req, resp);
    return (Map<?, ?>) req.getAttribute(CasProtocolConstants.VALIDATION_CAS_MODEL_ATTRIBUTE_NAME_ATTRIBUTES);
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:17,代码来源:Cas30ResponseViewTests.java

示例6: verifySuccessfulAuthenticationWithServiceAndWarn

import org.springframework.mock.web.MockHttpServletRequest; //导入依赖的package包/类
@Test
public void verifySuccessfulAuthenticationWithServiceAndWarn() throws Exception {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockRequestContext context = new MockRequestContext();

    request.addParameter(USERNAME_PARAM, TEST);
    request.addParameter(PASSWORD_PARAM, TEST);
    request.addParameter("warn", "true");
    request.addParameter(CasProtocolConstants.PARAMETER_SERVICE, TEST);

    context.setExternalContext(new ServletExternalContext(new MockServletContext(), request, response));
    final Credential c = CoreAuthenticationTestUtils.getCredentialsWithSameUsernameAndPassword();
    putCredentialInRequestScope(context, c);

    assertEquals(CasWebflowConstants.TRANSITION_ID_SUCCESS, this.action.execute(context).getId());
    assertNotNull(response.getCookie(this.warnCookieGenerator.getCookieName()));
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:19,代码来源:AuthenticationViaFormActionTests.java

示例7: ensureHostnameAndIpShouldDoSpnego

import org.springframework.mock.web.MockHttpServletRequest; //导入依赖的package包/类
@Test
public void ensureHostnameAndIpShouldDoSpnego() {
    final HostNameSpnegoKnownClientSystemsFilterAction action =
            new HostNameSpnegoKnownClientSystemsFilterAction("74\\..+", "", 0, "\\w+\\.\\w+\\.\\w+");

    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr(ALTERNATE_REMOTE_IP);
    final ServletExternalContext extCtx = new ServletExternalContext(
            new MockServletContext(), req,
            new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);

    final Event ev = action.doExecute(ctx);
    assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());

}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:18,代码来源:AllSpnegoKnownClientSystemsFilterActionTests.java

示例8: ensureRemoteIpShouldBeChecked

import org.springframework.mock.web.MockHttpServletRequest; //导入依赖的package包/类
@Test
public void ensureRemoteIpShouldBeChecked() {
    final BaseSpnegoKnownClientSystemsFilterAction action =
            new BaseSpnegoKnownClientSystemsFilterAction("^192\\.158\\..+");

    final MockRequestContext ctx = new MockRequestContext();
    final MockHttpServletRequest req = new MockHttpServletRequest();
    req.setRemoteAddr("192.158.5.781");
    final ServletExternalContext extCtx = new ServletExternalContext(
            new MockServletContext(), req,
            new MockHttpServletResponse());
    ctx.setExternalContext(extCtx);

    final Event ev = action.doExecute(ctx);
    assertEquals(ev.getId(), new EventFactorySupport().yes(this).getId());
}
 
开发者ID:hsj-xiaokang,项目名称:springboot-shiro-cas-mybatis,代码行数:17,代码来源:AllSpnegoKnownClientSystemsFilterActionTest.java

示例9: testRenewWithServiceAndSameCredentials

import org.springframework.mock.web.MockHttpServletRequest; //导入依赖的package包/类
@Test
public void testRenewWithServiceAndSameCredentials() throws Exception {
    final String ticketGrantingTicket = getCentralAuthenticationService()
        .createTicketGrantingTicket(
            TestUtils.getCredentialsWithSameUsernameAndPassword());
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockRequestContext context = new MockRequestContext();

    context.getFlowScope().put("ticketGrantingTicketId", ticketGrantingTicket);
    request.addParameter("renew", "true");
    request.addParameter("service", "test");
    request.addParameter("username", "test");
    request.addParameter("password", "test");

    context.setExternalContext(new ServletExternalContext(
        new MockServletContext(), request, new MockHttpServletResponse()));
    context.getFlowScope().put("service", TestUtils.getService("test"));
//    this.action.bind(context);
 //   assertEquals("warn", this.action.submit(context).getId());
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:21,代码来源:AuthenticationViaFormActionTests.java

示例10: testNoCasService

import org.springframework.mock.web.MockHttpServletRequest; //导入依赖的package包/类
@Test
public void testNoCasService() throws Exception {
    final MockHttpServletRequest mockRequest = new MockHttpServletRequest("GET", CONTEXT
            + OAuthConstants.ACCESS_TOKEN_URL);
    mockRequest.setParameter(OAuthConstants.CLIENT_ID, CLIENT_ID);
    mockRequest.setParameter(OAuthConstants.REDIRECT_URI, REDIRECT_URI);
    mockRequest.setParameter(OAuthConstants.CLIENT_SECRET, CLIENT_SECRET);
    mockRequest.setParameter(OAuthConstants.CODE, CODE);
    final MockHttpServletResponse mockResponse = new MockHttpServletResponse();
    final ServicesManager servicesManager = mock(ServicesManager.class);
    when(servicesManager.getAllServices()).thenReturn(new ArrayList<RegisteredService>());
    final OAuth20WrapperController oauth20WrapperController = new OAuth20WrapperController();
    oauth20WrapperController.setServicesManager(servicesManager);
    oauth20WrapperController.afterPropertiesSet();
    oauth20WrapperController.handleRequest(mockRequest, mockResponse);
    assertEquals(400, mockResponse.getStatus());
    assertEquals("error=" + OAuthConstants.INVALID_REQUEST, mockResponse.getContentAsString());
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:19,代码来源:OAuth20AccessTokenControllerTests.java

示例11: verifyValidServiceTicketAndPgtUrlMismatch

import org.springframework.mock.web.MockHttpServletRequest; //导入依赖的package包/类
@Test
public void verifyValidServiceTicketAndPgtUrlMismatch() throws Exception {
    final Service svc = CoreAuthenticationTestUtils.getService("proxyService");
    final AuthenticationResult ctx = CoreAuthenticationTestUtils.getAuthenticationResult(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_PARAM, svc.getId());
    request.addParameter(TICKET_PARAM, sId.getId());
    request.addParameter(PGT_URL_PARAM, "http://www.github.com");

    final ModelAndView modelAndView = this.serviceValidateController.handleRequestInternal(request, new MockHttpServletResponse());
    assertFalse(modelAndView.getView().toString().contains(SUCCESS));
    assertNull(modelAndView.getModel().get(PGT_IOU_PARAM));
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:19,代码来源:AbstractServiceValidateControllerTests.java

示例12: testFailedAuthenticationWithNoService

import org.springframework.mock.web.MockHttpServletRequest; //导入依赖的package包/类
@Test
    public void testFailedAuthenticationWithNoService() throws Exception {
        final MockHttpServletRequest request = new MockHttpServletRequest();
        final MockRequestContext context = new MockRequestContext();

        request.addParameter("username", "test");
        request.addParameter("password", "test2");

        context.setExternalContext(new ServletExternalContext(
            new MockServletContext(), request, new MockHttpServletResponse()));

        context.getRequestScope().put("credentials",
            TestUtils.getCredentialsWithDifferentUsernameAndPassword());
        context.getRequestScope().put(
            "org.springframework.validation.BindException.credentials",
            new BindException(TestUtils
                .getCredentialsWithDifferentUsernameAndPassword(),
                "credentials"));

    //    this.action.bind(context);
//        assertEquals("error", this.action.submit(context).getId());
    }
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:23,代码来源:AuthenticationViaFormActionTests.java

示例13: testRenewWithServiceAndDifferentCredentials

import org.springframework.mock.web.MockHttpServletRequest; //导入依赖的package包/类
@Test
public void testRenewWithServiceAndDifferentCredentials() throws Exception {
    final String ticketGrantingTicket = getCentralAuthenticationService()
        .createTicketGrantingTicket(
            TestUtils.getCredentialsWithSameUsernameAndPassword());
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockRequestContext context = new MockRequestContext();

    context.getFlowScope().put("ticketGrantingTicketId", ticketGrantingTicket);
    request.addParameter("renew", "true");
    request.addParameter("service", "test");
    request.addParameter("username", "test2");
    request.addParameter("password", "test2");

    context.setExternalContext(new ServletExternalContext(
        new MockServletContext(), request, new MockHttpServletResponse()));
//    this.action.bind(context);

//    assertEquals("success", this.action.submit(context).getId());
}
 
开发者ID:luotuo,项目名称:cas4.0.x-server-wechat,代码行数:21,代码来源:AuthenticationViaFormActionTests.java

示例14: verifyAddRegisteredServiceWithValues

import org.springframework.mock.web.MockHttpServletRequest; //导入依赖的package包/类
@Test
public void verifyAddRegisteredServiceWithValues() throws Exception {
    final RegisteredServiceImpl svc = new RegisteredServiceImpl();
    svc.setDescription("description");
    svc.setServiceId("serviceId");
    svc.setName("name");
    svc.setEvaluationOrder(123);
    
    assertTrue(this.manager.getAllServices().isEmpty());
    final RegisteredServiceEditBean.ServiceData data = registeredServiceFactory.createServiceData(svc);
    this.controller.saveService(new MockHttpServletRequest(),
            new MockHttpServletResponse(),
            data, mock(BindingResult.class));

    final Collection<RegisteredService> services = this.manager.getAllServices();
    assertEquals(1, services.size());
    for(final RegisteredService rs : this.manager.getAllServices()) {
        assertTrue(rs instanceof RegexRegisteredService);
    }
}
 
开发者ID:yuweijun,项目名称:cas-server-4.2.1,代码行数:21,代码来源:RegisteredServiceSimpleFormControllerTests.java

示例15: testJWTFilter

import org.springframework.mock.web.MockHttpServletRequest; //导入依赖的package包/类
@Test
public void testJWTFilter() throws Exception {
    UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(
        "test-user",
        "test-password",
        Collections.singletonList(new SimpleGrantedAuthority(AuthoritiesConstants.USER))
    );
    String jwt = tokenProvider.createToken(authentication, false);
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader(JWTConfigurer.AUTHORIZATION_HEADER, "Bearer " + jwt);
    request.setRequestURI("/api/test");
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockFilterChain filterChain = new MockFilterChain();
    jwtFilter.doFilter(request, response, filterChain);
    assertThat(response.getStatus()).isEqualTo(HttpStatus.OK.value());
    assertThat(SecurityContextHolder.getContext().getAuthentication().getName()).isEqualTo("test-user");
    assertThat(SecurityContextHolder.getContext().getAuthentication().getCredentials().toString()).isEqualTo(jwt);
}
 
开发者ID:asanzdiego,项目名称:codemotion-2017-taller-de-jhipster,代码行数:19,代码来源:JWTFilterTest.java


注:本文中的org.springframework.mock.web.MockHttpServletRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。