@Override public Host next() { return TomcatEngine.this.registry.getHostFactory().createHost(TomcatEngine.this.registry, (org.apache.catalina.Host) children.next(), TomcatEngine.this); }
@Override public Host findHost(String name) { org.apache.catalina.Host host = (org.apache.catalina.Host) this.engine.findChild(name); return (host != null) ? this.registry.getHostFactory().createHost(this.registry, host, this) : null; }
@Override public Host createHost(org.apache.catalina.Host host) { return this.hostFactory.createHost(this, host, this.createEngine((org.apache.catalina.Engine) host.getParent())); }
@Test public void findHost() { org.apache.catalina.Host host = mock(org.apache.catalina.Host.class); HostFactory hostFactory = mock(HostFactory.class); Host expected = mock(Host.class); when(this.engine.findChild("host")).thenReturn(host); when(this.registry.getHostFactory()).thenReturn(hostFactory); when(hostFactory.createHost(same(this.registry), same(host), same(this.catalinaEngine))).thenReturn(expected); Host result = this.catalinaEngine.findHost("host"); assertSame(expected, result); }
@Test public void getHosts() { org.apache.catalina.Host host = mock(org.apache.catalina.Host.class); HostFactory hostFactory = mock(HostFactory.class); Host expected = mock(Host.class); when(this.engine.findChildren()).thenReturn(new Container[] { host }); when(this.registry.getHostFactory()).thenReturn(hostFactory); when(hostFactory.createHost(same(this.registry), same(host), same(this.catalinaEngine))).thenReturn(expected); Iterable<Host> result = this.catalinaEngine.getHosts(); Iterator<Host> hosts = result.iterator(); assertTrue(hosts.hasNext()); assertSame(expected, hosts.next()); assertFalse(hosts.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)); }