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();
}
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();
}
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);
}
Aggregations