EverrestServletContextInitializer { public Application getApplication() { Application application = null; String applicationFQN = getParameter(JAXRS_APPLICATION); boolean scan = getBoolean(EVERREST_SCAN_COMPONENTS, false); if (applicationFQN != null) { if (scan) { String msg = "Scan of JAX-RS components is disabled cause to specified 'javax.ws.rs.Application'."; LOG.warn(msg); } try { Class<?> cl = Thread.currentThread().getContextClassLoader().loadClass(applicationFQN); application = (Application)cl.newInstance(); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } } else if (scan) { application = new Application() { @Override public Set<Class<?>> getClasses() { return new LinkedHashSet<>(ComponentFinder.findComponents()); } }; } return application; } EverrestServletContextInitializer(ServletContext servletContext); Application getApplication(); EverrestConfiguration createConfiguration(); RequestHandler createRequestHandler(); RequestDispatcher createRequestDispatcher(); ResourceBinder createResourceBinder(); DependencySupplier getDependencySupplier(); ProviderBinder createProviderBinder(); EverrestProcessor createEverrestProcessor(); static final String EVERREST_SCAN_COMPONENTS; static final String EVERREST_SCAN_SKIP_PACKAGES; static final String JAXRS_APPLICATION; }
@Test public void createsApplicationIsConfiguredInServletContext() { when(servletContext.getInitParameter("javax.ws.rs.Application")).thenReturn(SomeApplication.class.getName()); EverrestServletContextInitializer everrestServletContextInitializer = new EverrestServletContextInitializer(servletContext); Application application = everrestServletContextInitializer.getApplication(); assertEquals(SomeApplication.class, application.getClass()); }
@Test public void scansForJaxRsComponentsAndCreatesApplication() throws Exception { when(servletContext.getInitParameter("org.everrest.scan.components")).thenReturn("true"); EverrestServletContextInitializer everrestServletContextInitializer = new EverrestServletContextInitializer(servletContext); Application application = everrestServletContextInitializer.getApplication(); assertEquals(scannedClasses, application.getClasses()); }
@Test public void ignoresScanParameterIfApplicationIsConfiguredInServletContext() throws Exception { when(servletContext.getInitParameter("javax.ws.rs.Application")).thenReturn(SomeApplication.class.getName()); when(servletContext.getInitParameter("org.everrest.scan.components")).thenReturn("true"); EverrestServletContextInitializer everrestServletContextInitializer = new EverrestServletContextInitializer(servletContext); Application application = everrestServletContextInitializer.getApplication(); assertEquals(SomeApplication.class, application.getClass()); assertTrue("Must ignore scan 'org.everrest.scan.components' parameter if FQN of Application class configured in ServletContext", application.getClasses() == null || application.getClasses().isEmpty()); }