use of org.springframework.mock.web.MockHttpServletResponse in project entando-core by entando.
the class ApsAdminBaseTestCase method setUp.
@Override
protected void setUp() throws Exception {
boolean refresh = false;
if (null == _applicationContext) {
// Link the servlet context and the Spring context
_servletContext = new MockServletContext("", new FileSystemResourceLoader());
_applicationContext = this.getConfigUtils().createApplicationContext(_servletContext);
_servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, _applicationContext);
} else {
refresh = true;
}
this._request = new MockHttpServletRequest();
this._response = new MockHttpServletResponse();
this._request.setSession(new MockHttpSession(this._servletContext));
if (refresh) {
try {
ApsWebApplicationUtils.executeSystemRefresh(this._request);
this.waitNotifyingThread();
} catch (Throwable e) {
}
}
// Use spring as the object factory for Struts
StrutsSpringObjectFactory ssf = new StrutsSpringObjectFactory(null, null, null, null, _servletContext, null, this.createContainer());
ssf.setApplicationContext(_applicationContext);
// Dispatcher is the guy that actually handles all requests. Pass in
// an empty Map as the parameters but if you want to change stuff like
// what config files to read, you need to specify them here
// (see Dispatcher's source code)
java.net.URL url = ClassLoader.getSystemResource("struts.properties");
Properties props = new Properties();
props.load(url.openStream());
this.setInitParameters(props);
Map params = new HashMap(props);
this._dispatcher = new Dispatcher(_servletContext, params);
this._dispatcher.init();
Dispatcher.setInstance(this._dispatcher);
}
use of org.springframework.mock.web.MockHttpServletResponse in project opennms by OpenNMS.
the class LdapAuthTest method assertAccessAllowed.
/**
* @param request
* @throws IOException
* @throws ServletException
*/
private void assertAccessAllowed(MockHttpServletRequest request) throws IOException, ServletException {
MockHttpServletResponse response = new MockHttpServletResponse();
m_authFilterChain.doFilter(request, response, m_chain);
assertEquals(200, response.getStatus());
m_chain.assertAccessAllowed();
}
use of org.springframework.mock.web.MockHttpServletResponse in project CzechIdMng by bcvsolutions.
the class NotificationRestTest method testSendNotification.
@Test
public void testSendNotification() throws Exception {
final IdmIdentityDto sender = createTestIdentity(TEST_SENDER_1);
final IdmIdentityDto recipient = createTestIdentity(TEST_RECIPIENT_1);
//
final IdmNotificationDto notif = createTestNotification(NotificationLevel.INFO, TEST_SUBJECT, TEST_MESSAGE, TEST_TOPIC, sender, recipient);
final String jsonContent = jsonify(notif);
//
MockHttpServletResponse response = getMockMvc().perform(MockMvcRequestBuilders.post(BaseDtoController.BASE_PATH + "/notifications").with(authentication(getAuthentication())).contentType(MediaTypes.HAL_JSON).content(jsonContent)).andReturn().getResponse();
//
assertEquals(200, response.getStatus());
}
use of org.springframework.mock.web.MockHttpServletResponse in project CzechIdMng by bcvsolutions.
the class AbstractSwaggerTest method convertSwagger.
/**
* Converts module's swagger endpoint to json
*
* @see ModuleDescriptor#getId()
* @param moduleId
* @throws Exception
*/
public void convertSwagger(String moduleId) throws Exception {
MvcResult mvcResult = getMockMvc().perform(get(String.format("%s?group=%s", path, moduleId)).accept(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andReturn();
MockHttpServletResponse response = mvcResult.getResponse();
String swaggerJson = response.getContentAsString();
Files.createDirectories(Paths.get(outputDir));
try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(outputDir, filename), StandardCharsets.UTF_8)) {
writer.write(swaggerJson);
}
}
use of org.springframework.mock.web.MockHttpServletResponse in project vboard by voyages-sncf-technologies.
the class RssControllerTest method modelAndViewAsString.
private String modelAndViewAsString(final ModelAndView mav) throws Exception {
final MockHttpServletRequest mockReq = new MockHttpServletRequest();
final MockHttpServletResponse mockResp = new MockHttpServletResponse();
mav.getView().render(mav.getModel(), mockReq, mockResp);
return mockResp.getContentAsString();
}
Aggregations