@Override public Context next() { return TomcatHost.this.registry.getContextFactory().createContext((org.apache.catalina.Context) children.next(), TomcatHost.this); }
@Override public Context findContext(String path) { org.apache.catalina.Context context = (org.apache.catalina.Context) this.host.findChild(path); return (context != null) ? TomcatHost.this.registry.getContextFactory().createContext(context, this) : null; }
@Override public Context createContext(org.apache.catalina.Context context) { return this.contextFactory.createContext(context, this.createHost((org.apache.catalina.Host) context.getParent())); }
@Test public void findContext() { org.apache.catalina.Context context = mock(org.apache.catalina.Context.class); Context expected = mock(Context.class); ContextFactory contextFactory = mock(ContextFactory.class); when(this.host.findChild("path")).thenReturn(context); when(this.registry.getContextFactory()).thenReturn(contextFactory); when(contextFactory.createContext(same(context), same(this.catalinaHost))).thenReturn(expected); Context result = this.catalinaHost.findContext("path"); assertSame(expected, result); }
@Test public void getContexts() { org.apache.catalina.Context context = mock(org.apache.catalina.Context.class); Context expected = mock(Context.class); ContextFactory contextFactory = mock(ContextFactory.class); when(this.host.findChildren()).thenReturn(new Container[] { context }); when(this.registry.getContextFactory()).thenReturn(contextFactory); when(contextFactory.createContext(same(context), same(this.catalinaHost))).thenReturn(expected); Iterable<Context> result = this.catalinaHost.getContexts(); Iterator<Context> contexts = result.iterator(); assertTrue(contexts.hasNext()); assertSame(expected, contexts.next()); assertFalse(contexts.hasNext()); }
@Test public void testCatalinaFactories() throws Exception { ServiceLoaderTomcatFactory factory = new ServiceLoaderTomcatFactory(this.serverFactory, this.engineFactory, this.hostFactory, this.contextFactory, this.connectorFactory, this.provider); org.apache.catalina.Server catalinaServer = mock(org.apache.catalina.Server.class); Server server = mock(Server.class); when(this.serverFactory.createServer(same(factory), same(catalinaServer))).thenReturn(server); assertSame(server, factory.createServer(catalinaServer)); org.apache.catalina.Service service = mock(org.apache.catalina.Service.class); org.apache.catalina.Engine catalinaEngine = mock(org.apache.catalina.Engine.class); Engine engine = mock(Engine.class); when(catalinaEngine.getService()).thenReturn(service); when(service.getServer()).thenReturn(catalinaServer); when(this.engineFactory.createEngine(same(factory), same(catalinaEngine), same(server))).thenReturn(engine); assertSame(engine, factory.createEngine(catalinaEngine)); org.apache.catalina.Host catalinaHost = mock(org.apache.catalina.Host.class); Host host = mock(Host.class); when(catalinaHost.getParent()).thenReturn(catalinaEngine); when(this.hostFactory.createHost(same(factory), same(catalinaHost), same(engine))).thenReturn(host); assertSame(host, factory.createHost(catalinaHost)); org.apache.catalina.Context catalinaContext = mock(org.apache.catalina.Context.class); Context context = mock(Context.class); when(catalinaContext.getParent()).thenReturn(catalinaHost); when(this.contextFactory.createContext(same(catalinaContext), same(host))).thenReturn(context); assertSame(context, factory.createContext(catalinaContext)); }