use of org.springframework.mock.web.MockHttpServletResponse in project gocd by gocd.
the class EchoAttributeServletTest method shouldEchoAttributeInBody.
@Theory
public void shouldEchoAttributeInBody(Req dataPt) throws UnsupportedEncodingException {
MockHttpServletRequest req = new MockHttpServletRequest();
req.setAttribute(EchoAttributeServlet.ECHO_BODY_ATTRIBUTE, "some-random-echo-body");
MockHttpServletResponse res = new MockHttpServletResponse();
res.setContentType("foo/bar");
dataPt.call(servlet, req, res);
assertThat(res.getContentAsString(), is("some-random-echo-body"));
assertThat(res.getContentType(), is("foo/bar"));
assertThat(res.getStatus(), is(200));
}
use of org.springframework.mock.web.MockHttpServletResponse in project gocd by gocd.
the class FlashLoadingFilterIntegrationTest method shouldLoadExistingFlashFromSession.
@Test
public void shouldLoadExistingFlashFromSession() throws IOException, ServletException {
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpSession session = new MockHttpSession();
FlashMessageService.Flash oldFlash = new FlashMessageService.Flash();
oldFlash.put("my_key", new FlashMessageModel("my other message", "warning"));
session.putValue(FlashLoadingFilter.FLASH_SESSION_KEY, oldFlash);
req.setSession(session);
MockHttpServletResponse res = new MockHttpServletResponse();
FilterChain filterChain = new MockFilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) {
flash = service.get("my_key");
}
};
filter.doFilter(req, res, filterChain);
assertThat(flash.toString(), is("my other message"));
assertThat(flash.getFlashClass(), is("warning"));
}
use of org.springframework.mock.web.MockHttpServletResponse in project gocd by gocd.
the class FlashLoadingFilterIntegrationTest method shouldClearThreadContext.
@Test
public void shouldClearThreadContext() throws IOException, ServletException {
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpServletResponse res = new MockHttpServletResponse();
FilterChain filterChain = new MockFilterChain() {
@Override
public void doFilter(ServletRequest request, ServletResponse response) {
messageKey = service.add(new FlashMessageModel("my message", "error"));
flash = service.get(messageKey);
}
};
filter.doFilter(req, res, filterChain);
assertThat(flash.toString(), is("my message"));
try {
service.get(messageKey);
fail("attempt to load flash message should fail, as no thread local is cleared out");
} catch (Exception e) {
assertThat(e.getMessage(), is("No flash context found, this call should only be made within a request."));
}
}
use of org.springframework.mock.web.MockHttpServletResponse in project gocd by gocd.
the class JobControllerIntegrationTest method setUp.
@Before
public void setUp() throws Exception {
request = new MockHttpServletRequest();
response = new MockHttpServletResponse();
configHelper = new GoConfigFileHelper();
configHelper.usingCruiseConfigDao(goConfigDao);
fixture = new PipelineWithTwoStages(materialRepository, transactionTemplate, temporaryFolder);
fixture.usingConfigHelper(configHelper).usingDbHelper(dbHelper).onSetUp();
controller = new JobController(jobInstanceService, agentService, jobInstanceDao, goConfigService, pipelineService, restfulService, artifactService, propertiesService, stageService, localizer, jobAgentMetadataDao);
}
use of org.springframework.mock.web.MockHttpServletResponse in project gocd by gocd.
the class PropertiesControllerTest method setUp.
@Before
public void setUp() throws Exception {
configHelper = new GoConfigFileHelper();
fixture = new PipelineWithTwoStages(materialRepository, transactionTemplate, temporaryFolder);
fixture.usingConfigHelper(configHelper).usingDbHelper(dbHelper).onSetUp();
controller = new PropertiesController(propertiesService, restfulService, pipelineService, systemEnvironment);
response = new MockHttpServletResponse();
}
Aggregations