@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; }
@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()); }
protected void verifyCatalinaFactoryTypes(TomcatFactoryRegistry registry) { assertSame(TomcatServerFactory.class, registry.getServerFactory().getClass()); assertSame(TomcatEngineFactory.class, registry.getEngineFactory().getClass()); assertSame(TomcatHostFactory.class, registry.getHostFactory().getClass()); assertSame(TomcatContextFactory.class, registry.getContextFactory().getClass()); assertSame(TomcatConnectorFactory.class, registry.getConnectorFactory().getClass()); assertSame(this.provider, registry.getProxyConnectorProvider()); } }
@Test public void testCatalinaFactoryRegistry() { TomcatFactoryRegistry registry = new ServiceLoaderTomcatFactory(this.serverFactory, this.engineFactory, this.hostFactory, this.contextFactory, this.connectorFactory, this.provider); assertSame(this.serverFactory, registry.getServerFactory()); assertSame(this.engineFactory, registry.getEngineFactory()); assertSame(this.hostFactory, registry.getHostFactory()); assertSame(this.contextFactory, registry.getContextFactory()); assertSame(this.connectorFactory, registry.getConnectorFactory()); assertSame(this.provider, registry.getProxyConnectorProvider()); }