use of jakarta.servlet.ServletContextEvent in project spring-framework by spring-projects.
the class ContextLoaderTests method registeredContextInitializerCanAccessServletContextParamsViaEnvironment.
@Test
void registeredContextInitializerCanAccessServletContextParamsViaEnvironment() {
MockServletContext sc = new MockServletContext("");
// config file doesn't matter - just a placeholder
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "/org/springframework/web/context/WEB-INF/empty-context.xml");
sc.addInitParameter("someProperty", "someValue");
sc.addInitParameter(ContextLoader.CONTEXT_INITIALIZER_CLASSES_PARAM, EnvApplicationContextInitializer.class.getName());
ContextLoaderListener listener = new ContextLoaderListener();
listener.contextInitialized(new ServletContextEvent(sc));
}
use of jakarta.servlet.ServletContextEvent in project spring-framework by spring-projects.
the class ContextLoaderTests method contextLoaderWithDefaultLocation.
@Test
void contextLoaderWithDefaultLocation() throws Exception {
MockServletContext sc = new MockServletContext("");
ServletContextListener listener = new ContextLoaderListener();
ServletContextEvent event = new ServletContextEvent(sc);
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(() -> listener.contextInitialized(event)).havingCause().isInstanceOf(IOException.class).withMessageContaining("/WEB-INF/applicationContext.xml");
}
use of jakarta.servlet.ServletContextEvent in project metrics by dropwizard.
the class InstrumentedFilterContextListenerTest method injectsTheMetricRegistryIntoTheServletContext.
@Test
public void injectsTheMetricRegistryIntoTheServletContext() {
final ServletContext context = mock(ServletContext.class);
final ServletContextEvent event = mock(ServletContextEvent.class);
when(event.getServletContext()).thenReturn(context);
listener.contextInitialized(event);
verify(context).setAttribute("io.dropwizard.metrics.servlet.InstrumentedFilter.registry", registry);
}
Aggregations