Search in sources :

Example 36 with MockServletConfig

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);
}
Also used : Path(java.nio.file.Path) ArchivaConfiguration(org.apache.archiva.configuration.ArchivaConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) Configuration(org.apache.archiva.configuration.Configuration) ContextConfiguration(org.springframework.test.context.ContextConfiguration) ManagedRepositoryConfiguration(org.apache.archiva.configuration.ManagedRepositoryConfiguration) ArrayList(java.util.ArrayList) MockServletConfig(org.springframework.mock.web.MockServletConfig) HttpAuthenticator(org.apache.archiva.redback.integration.filter.authentication.HttpAuthenticator) MockServletContext(org.springframework.mock.web.MockServletContext) WebApplicationContext(org.springframework.web.context.WebApplicationContext) ServletAuthenticator(org.apache.archiva.security.ServletAuthenticator) Before(org.junit.Before)

Example 37 with 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;
}
Also used : ServletConfig(javax.servlet.ServletConfig) MockServletConfig(org.springframework.mock.web.MockServletConfig) MockServletConfig(org.springframework.mock.web.MockServletConfig) Before(org.junit.Before)

Example 38 with MockServletConfig

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);
}
Also used : AutowiredAnnotationBeanPostProcessor(org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor) MockServletConfig(org.springframework.mock.web.MockServletConfig) MockServletContext(org.springframework.mock.web.MockServletContext) MockMvc(org.springframework.test.web.servlet.MockMvc)

Example 39 with MockServletConfig

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);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) MockServletConfig(org.springframework.mock.web.MockServletConfig) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Test(org.junit.Test)

Example 40 with MockServletConfig

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"));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockServletConfig(org.springframework.mock.web.MockServletConfig) StatViewServlet(com.alibaba.druid.support.http.StatViewServlet)

Aggregations

MockServletConfig (org.springframework.mock.web.MockServletConfig)45 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)18 MockServletContext (org.springframework.mock.web.MockServletContext)12 StatViewServlet (com.alibaba.druid.support.http.StatViewServlet)10 ServletContext (javax.servlet.ServletContext)8 Before (org.junit.Before)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 Decorator (com.opensymphony.module.sitemesh.Decorator)7 Page (com.opensymphony.module.sitemesh.Page)7 HTMLPageParser (com.opensymphony.module.sitemesh.parser.HTMLPageParser)7 Config (grails.config.Config)7 PropertySourcesConfig (org.grails.config.PropertySourcesConfig)7 MockApplicationContext (org.grails.support.MockApplicationContext)7 GrailsWebRequest (org.grails.web.servlet.mvc.GrailsWebRequest)7 GroovyClassLoader (groovy.lang.GroovyClassLoader)5 GroovyObject (groovy.lang.GroovyObject)5 Test (org.junit.Test)4 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)3 Method (java.lang.reflect.Method)3 WebApplicationContext (org.springframework.web.context.WebApplicationContext)3