Search in sources :

Example 26 with MockHttpServletRequest

use of com.thoughtworks.go.http.mocks.MockHttpServletRequest in project gocd by gocd.

the class AlwaysCreateSessionFilterTest method setUp.

@BeforeEach
void setUp() throws Exception {
    response = new MockHttpServletResponse();
    request = new MockHttpServletRequest();
    alwaysCreateSessionFilter = new AlwaysCreateSessionFilter();
}
Also used : MockHttpServletRequest(com.thoughtworks.go.http.mocks.MockHttpServletRequest) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 27 with MockHttpServletRequest

use of com.thoughtworks.go.http.mocks.MockHttpServletRequest in project gocd by gocd.

the class AgentSessionReduceIdleTimeoutFilterTest method shouldReduceSessionTimeoutWhenAppliedAndNewSessionIsCreatedAfterApplyingFilter.

@Test
public void shouldReduceSessionTimeoutWhenAppliedAndNewSessionIsCreatedAfterApplyingFilter() throws IOException, ServletException {
    final MockHttpServletRequest request = new MockHttpServletRequest();
    final MockHttpServletResponse response = new MockHttpServletResponse();
    final SystemEnvironment systemEnvironment = mock(SystemEnvironment.class);
    when(systemEnvironment.get(SystemEnvironment.AGENT_REQUEST_IDLE_TIMEOUT_IN_SECONDS)).thenReturn(30);
    assertThat(request.getSession(false)).isNull();
    doAnswer(new Answer() {

        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            request.getSession(true);
            return null;
        }
    }).when(filterChain).doFilter(request, response);
    new AgentSessionReduceIdleTimeoutFilter(systemEnvironment).doFilter(request, response, filterChain);
    verify(filterChain).doFilter(request, response);
    assertThat(request.getSession(false).getMaxInactiveInterval()).isEqualTo(30);
    assertThat(request.getSession(false)).isNotNull();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) Answer(org.mockito.stubbing.Answer) MockHttpServletRequest(com.thoughtworks.go.http.mocks.MockHttpServletRequest) InvocationOnMock(org.mockito.invocation.InvocationOnMock) MockHttpServletResponse(com.thoughtworks.go.http.mocks.MockHttpServletResponse) Test(org.junit.jupiter.api.Test)

Example 28 with MockHttpServletRequest

use of com.thoughtworks.go.http.mocks.MockHttpServletRequest in project gocd by gocd.

the class BackupFilterTest method shouldReturn503WhenXMLAPICallIsMadeAndBackupBeingTaken.

@Test
public void shouldReturn503WhenXMLAPICallIsMadeAndBackupBeingTaken() throws Exception {
    when(backupService.isBackingUp()).thenReturn(true);
    when(backupService.backupRunningSinceISO8601()).thenReturn(BACKUP_STARTED_AT);
    when(backupService.backupStartedBy()).thenReturn(BACKUP_STARTED_BY);
    MockHttpServletRequest request = HttpRequestBuilder.GET("/api/config.xml").withHeader("Accept", "application/json").build();
    backupFilter.doFilter(request, res, chain);
    verify(res, times(1)).setContentType("application/json");
    JsonObject json = new JsonObject();
    assertResponse(json);
}
Also used : MockHttpServletRequest(com.thoughtworks.go.http.mocks.MockHttpServletRequest) JsonObject(com.google.gson.JsonObject) Test(org.junit.jupiter.api.Test)

Aggregations

MockHttpServletRequest (com.thoughtworks.go.http.mocks.MockHttpServletRequest)28 MockHttpServletResponse (com.thoughtworks.go.http.mocks.MockHttpServletResponse)19 Test (org.junit.jupiter.api.Test)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 BeforeEach (org.junit.jupiter.api.BeforeEach)7 ValueSource (org.junit.jupiter.params.provider.ValueSource)6 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)5 ContentTypeAwareResponse (com.thoughtworks.go.server.newsecurity.models.ContentTypeAwareResponse)4 SecurityService (com.thoughtworks.go.server.service.SecurityService)4 FilterChain (javax.servlet.FilterChain)4 JsonObject (com.google.gson.JsonObject)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 HttpSession (javax.servlet.http.HttpSession)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Answer (org.mockito.stubbing.Answer)2 SavedRequest (org.springframework.security.web.savedrequest.SavedRequest)2 MockFilterChain (com.thoughtworks.go.http.mocks.MockFilterChain)1 AgentSessionReduceIdleTimeoutFilter (com.thoughtworks.go.server.newsecurity.filters.AgentSessionReduceIdleTimeoutFilter)1 AlwaysCreateSessionFilter (com.thoughtworks.go.server.newsecurity.filters.AlwaysCreateSessionFilter)1