use of org.springframework.mock.web.MockServletConfig in project archiva by apache.
the class RepositoryServletSecurityTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
String appserverBase = System.getProperty("appserver.base", Paths.get("target/appserver-base").toAbsolutePath().toString());
Path testConf = Paths.get("src/test/resources/repository-archiva.xml");
Path testConfDest = Paths.get(appserverBase, "conf/archiva.xml");
FileUtils.copyFile(testConf.toFile(), testConfDest.toFile());
Configuration config = archivaConfiguration.getConfiguration();
// clear managed repository
List<ManagedRepositoryConfiguration> f1 = new ArrayList<>(config.getManagedRepositories());
for (ManagedRepositoryConfiguration f : f1) {
config.removeManagedRepository(f);
}
assertEquals(0, config.getManagedRepositories().size());
// add internal repo
config.addManagedRepository(createManagedRepository(REPOID_INTERNAL, "Internal Test Repo", repoRootInternal.getRoot()));
saveConfiguration(archivaConfiguration);
CacheManager.getInstance().clearAll();
servletAuthControl = EasyMock.createControl();
servletAuth = servletAuthControl.createMock(ServletAuthenticator.class);
httpAuthControl = EasyMock.createControl();
httpAuth = httpAuthControl.createMock(HttpAuthenticator.class);
davSessionProvider = new ArchivaDavSessionProvider(servletAuth, httpAuth);
final MockServletContext mockServletContext = new MockServletContext();
WebApplicationContext webApplicationContext = new AbstractRepositoryServletTestCase.TestWebapplicationContext(applicationContext, mockServletContext);
mockServletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webApplicationContext);
MockServletConfig mockServletConfig = new MockServletConfig() {
@Override
public ServletContext getServletContext() {
return mockServletContext;
}
};
servlet = new RepositoryServlet();
servlet.init(mockServletConfig);
}
use of org.springframework.mock.web.MockServletConfig in project iaf by ibissource.
the class ApiListenerServletTest method setUp.
@Before
public void setUp() throws ServletException {
servlet = spy(ApiListenerServlet.class);
ServletConfig servletConfig = new MockServletConfig();
when(servlet.getServletConfig()).thenReturn(servletConfig);
servlet.init();
session = null;
}
use of org.springframework.mock.web.MockServletConfig in project spring-security by spring-projects.
the class SpringTestContext method autowire.
public void autowire() {
this.context.setServletContext(new MockServletContext());
this.context.setServletConfig(new MockServletConfig());
this.context.refresh();
if (this.context.containsBean(BeanIds.SPRING_SECURITY_FILTER_CHAIN)) {
// @formatter:off
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).apply(springSecurity()).apply(new AddFilter()).build();
// @formatter:on
this.context.getBeanFactory().registerResolvableDependency(MockMvc.class, mockMvc);
}
AutowiredAnnotationBeanPostProcessor bpp = new AutowiredAnnotationBeanPostProcessor();
bpp.setBeanFactory(this.context.getBeanFactory());
bpp.processInjection(this.test);
}
use of org.springframework.mock.web.MockServletConfig in project pinpoint by naver.
the class SpringWebMvc_5_x_IT method testRequest.
@Test
public void testRequest() throws Exception {
MockServletConfig config = new MockServletConfig();
MockHttpServletRequest req = new MockHttpServletRequest();
MockHttpServletResponse res = new MockHttpServletResponse();
config.addInitParameter("contextConfigLocation", "classpath:spring-web-test.xml");
req.setMethod("GET");
req.setRequestURI("/");
req.setRemoteAddr("1.2.3.4");
DispatcherServlet servlet = new DispatcherServlet();
servlet.init(config);
servlet.service(req, res);
Method method = FrameworkServlet.class.getDeclaredMethod("doGet", HttpServletRequest.class, HttpServletResponse.class);
PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
verifier.printCache();
verifier.verifyTrace(Expectations.event(SPRING_MVC, method));
verifier.verifyTraceCount(0);
}
use of org.springframework.mock.web.MockServletConfig in project druid by alibaba.
the class StatViewSerlvetTest_allow method test_allow_1.
public void test_allow_1() throws Exception {
MockServletConfig servletConfig = new MockServletConfig();
servletConfig.addInitParameter(StatViewServlet.PARAM_NAME_ALLOW, "128.242.127.2,xx");
StatViewServlet servlet = new StatViewServlet();
servlet.init(servletConfig);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setRemoteAddr("128.242.127.2");
Assert.assertTrue(servlet.isPermittedRequest(request));
Assert.assertFalse(servlet.isPermittedRequest("128.242.127.3"));
}
Aggregations