Example usage for org.springframework.mock.web MockFilterChain MockFilterChain

List of usage examples for org.springframework.mock.web MockFilterChain MockFilterChain

Introduction

In this page you can find the example usage for org.springframework.mock.web MockFilterChain MockFilterChain.

Prototype

public MockFilterChain() 

Source Link

Document

Register a single do-nothing Filter implementation.

Usage

From source file:com.jl.crm.web.OAuthTest.java

@Before
public void setup() {
    request = new MockHttpServletRequest();
    request.setMethod("GET");
    response = new MockHttpServletResponse();
    chain = new MockFilterChain();
}

From source file:com.nebhale.cyclinglibrary.web.GzipFilterTest.java

@Test
public void gzipRequest() throws ServletException, IOException {
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.addHeader("Content-Encoding", "gzip");
    request.setContent(gzipContent("test-request-content"));

    MockHttpServletResponse response = new MockHttpServletResponse();
    MockFilterChain filterChain = new MockFilterChain();

    this.filter.doFilterInternal(request, response, filterChain);
    writeContent("test-response-content", filterChain.getResponse().getOutputStream());

    assertEquals("test-request-content", readContent(filterChain.getRequest().getInputStream()));
    assertEquals("test-response-content", response.getContentAsString());
}

From source file:com.gopivotal.cla.security.AdminEmailDomainFilterTest.java

@Test(expected = AccessDeniedException.class)
public void attemptAuthenticationNonVerifiedEmail() throws IOException, ServletException {
    Emails emails = new Emails();
    when(this.gitHubClient.getEmails()).thenReturn(emails);
    emails.add(new Email("email@test.domain", false, false));

    this.filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());
}

From source file:otherpackage.MyConfigurerTests.java

@Before
public void setup() {
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    chain = new MockFilterChain();
    request.setMethod("GET");
}

From source file:org.piraso.web.base.PirasoFilterTest.java

@Before
public void setUp() throws Exception {
    registry = spy(new DefaultUserRegistryImpl());
    request = CommonMockObjects.mockRequest(MONITORED_ADDR);
    response = spy(new MockHttpServletResponse());
    chain = spy(new MockFilterChain());

    request.setCookies(new Cookie("name", "value"));
    request.addParameter("name", "value");
    request.addHeader("name", "value");

    filter = new PirasoFilter();
    LoggerRegistrySingleton.INSTANCE.setRegistry(registry);
}

From source file:org.jasig.cas.client.session.SingleSignOutFilterTests.java

@Before
public void setUp() throws Exception {
    filter = new SingleSignOutFilter();
    filter.setCasServerUrlPrefix(CAS_SERVER_URL_PREFIX);
    filter.setIgnoreInitConfiguration(true);
    filter.init(new MockFilterConfig());
    request = new MockHttpServletRequest();
    response = new MockHttpServletResponse();
    filterChain = new MockFilterChain();
}

From source file:com.surevine.alfresco.audit.integration.RevertWikiPageTest.java

/**
 * Test sunny day scenario.  In fact, this is the only scenario as everything else is a CREATE
 *///from www.  ja v a2s.  c  o m
@Test
public void testSuccessfulReversion() {

    try {

        JSONObject json = new JSONObject();

        json.put(AlfrescoJSONKeys.PAGE, "wiki-page");
        json.put(AlfrescoJSONKeys.WIKI_PAGE_CONTENT, "<p>in europa league action.</p>");
        eslFixture.addToJSON(json);

        mockRequest.setRequestURI("/alfresco/s/slingshot/wiki/page/mytestsite/" + TEST_WIKIPAGE_NAME);
        mockRequest.setContent(json.toString().getBytes());
        mockResponse = new MockHttpServletResponse();
        mockChain = new MockFilterChain();

        springAuditFilterBean.doFilter(mockRequest, mockResponse, mockChain);

        Auditable audited = getSingleAuditedEvent();

        verifyGenericAuditMetadata(audited);
        assertEquals(audited.getAction(), "WIKI_PAGE_REVERTED");
        assertEquals(eslFixture.toString(), audited.getSecLabel());

    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}

From source file:com.surevine.alfresco.audit.integration.CreateWikiPageTest.java

/**
 * Test sunny day scenario.//from   ww  w .j  a  v  a2  s  .  com
 */
@Test
public void testSuccessfulCreation() {

    try {

        JSONObject json = new JSONObject();

        json.put(AlfrescoJSONKeys.PAGE, "wiki-page");
        json.put(AlfrescoJSONKeys.PAGETITLE, TEST_WIKIPAGE_NAME);
        json.put(AlfrescoJSONKeys.WIKI_PAGE_CONTENT, "<p>in europa league action.</p>");
        eslFixture.addToJSON(json);

        mockRequest.setRequestURI("/alfresco/s/slingshot/wiki/page/mytestsite/" + TEST_WIKIPAGE_NAME);
        mockRequest.setContent(json.toString().getBytes());
        mockResponse = new MockHttpServletResponse();
        mockChain = new MockFilterChain();

        springAuditFilterBean.doFilter(mockRequest, mockResponse, mockChain);

        Auditable audited = getSingleAuditedEvent();

        verifyGenericAuditMetadata(audited);
        assertEquals(TEST_WIKIPAGE_NAME, audited.getSource());
        assertEquals(eslFixture.toString(), audited.getSecLabel());

    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}

From source file:org.openmrs.module.owa.filter.OwaFilterTest.java

/**
 * Test that the OwaFilter class actually services from the base path defined in the global
 * property and ignore any other requests.
 *//* w w  w .ja va  2s  . com*/
@Test
public void testOwaFilterUsesGlobalProperty() throws Exception {
    OwaFilter owaFilter = new OwaFilter();
    owaFilter.init(filterConfig);

    MockFilterChain mockFilterChain = new MockFilterChain();
    MockHttpServletResponse rsp = new MockHttpServletResponse();

    // First make sure that it works with the default base URL
    Context.getAdministrationService()
            .saveGlobalProperty(new GlobalProperty(AppManager.KEY_APP_BASE_URL, DEFAULT_APP_BASE_URL));

    MockHttpServletRequest req = new MockHttpServletRequest("GET", DEFAULT_APP_BASE_URI + SOME_PATH_IN_APP);
    owaFilter.doFilter(req, rsp, mockFilterChain);
    Assert.assertEquals(rsp.getStatus(), 200);
    Assert.assertEquals(FILE_SERVLET_REDIRECT_URL + SOME_PATH_IN_APP, rsp.getForwardedUrl());

    // Now try a custom base URL
    Context.getAdministrationService()
            .saveGlobalProperty(new GlobalProperty(AppManager.KEY_APP_BASE_URL, SOME_RANDOM_BASE_URL));
    mockFilterChain = new MockFilterChain();
    req = new MockHttpServletRequest("GET", SOME_RANDOM_BASE_URI + SOME_PATH_IN_APP);
    rsp = new MockHttpServletResponse();
    owaFilter.doFilter(req, rsp, mockFilterChain);
    Assert.assertEquals(rsp.getStatus(), 200);
    Assert.assertEquals(FILE_SERVLET_REDIRECT_URL + SOME_PATH_IN_APP, rsp.getForwardedUrl());

    // Ensure non-OWA base URLs are ignored
    req = new MockHttpServletRequest("GET", DEFAULT_APP_BASE_URI + SOME_PATH_IN_APP); // we can reuse this URL because the global property has been reset
    rsp = new MockHttpServletResponse();
    owaFilter.doFilter(req, rsp, mockFilterChain);
    Assert.assertEquals(rsp.getStatus(), 200);
    Assert.assertNull(rsp.getForwardedUrl());
}

From source file:io.jmnarloch.spring.request.correlation.filter.RequestCorrelationFilterTest.java

@Test
public void shouldInitiateCorrelationId() throws IOException, ServletException {

    // given//from   w  w w.  j a  v a  2 s . com
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final MockFilterChain chain = new MockFilterChain();

    // when
    instance.doFilter(request, response, chain);

    // then
    assertNotNull(request.getAttribute(RequestCorrelationConsts.ATTRIBUTE_NAME));
    assertNotNull(((HttpServletRequest) chain.getRequest()).getHeader(RequestCorrelationConsts.HEADER_NAME));
}