[Bug 362696] expand virtual host configuration options to ContextHandler
and add associated test case for new behavior
This commit is contained in:
parent
317baa1010
commit
25f70e9060
|
@ -325,10 +325,10 @@ public class ContextHandler extends ScopedHandler implements Attributes, Server.
|
|||
|
||||
for (int i = 0; i < virtualHosts.length; i++)
|
||||
{
|
||||
String normalizedVirtualHost = normalizeHostname(virtualHosts[i]);
|
||||
if (!existingVirtualHosts.contains(normalizedVirtualHost))
|
||||
String toRemoveVirtualHost = normalizeHostname(virtualHosts[i]);
|
||||
if (existingVirtualHosts.contains(toRemoveVirtualHost))
|
||||
{
|
||||
existingVirtualHosts.remove(normalizedVirtualHost);
|
||||
existingVirtualHosts.remove(toRemoveVirtualHost);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -232,6 +232,37 @@ public class ContextHandlerTest
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVirtualHostManagement() throws Exception
|
||||
{
|
||||
ContextHandler context = new ContextHandler("/");
|
||||
|
||||
// test singular
|
||||
context.setVirtualHosts(new String[] { "www.example.com"} );
|
||||
Assert.assertEquals(1,context.getVirtualHosts().length);
|
||||
|
||||
// test adding two more
|
||||
context.addVirtualHosts(new String[] { "www.example2.com", "www.example3.com"});
|
||||
Assert.assertEquals(3,context.getVirtualHosts().length);
|
||||
|
||||
// test adding existing context
|
||||
context.addVirtualHosts(new String[] { "www.example.com" });
|
||||
Assert.assertEquals(3,context.getVirtualHosts().length);
|
||||
|
||||
// test removing existing
|
||||
context.removeVirtualHosts(new String[] { "www.example3.com" });
|
||||
Assert.assertEquals(2,context.getVirtualHosts().length);
|
||||
|
||||
// test removing non-existent
|
||||
context.removeVirtualHosts(new String[] { "www.example3.com" });
|
||||
Assert.assertEquals(2,context.getVirtualHosts().length);
|
||||
|
||||
// test removing all remaining and resets to null
|
||||
context.removeVirtualHosts(new String[] { "www.example.com", "www.example2.com" });
|
||||
Assert.assertEquals(null,context.getVirtualHosts());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAttributes() throws Exception
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue