@Test
 public void testConstructorWithInvalidPort() throws ServerConfigurationFailedException {
   PTestServerConfiguration cfg = new PTestServerConfiguration();
   cfg.addContextHandlerSetting("/test", new BasicNameValuePair("test", "test"));
   cfg.setHostname("localhost");
   cfg.setSocketPoolSize(1);
   try {
     new PTestServerChannelUpstreamHandler(cfg);
     Assert.fail("Port must not be -1");
   } catch (ServerConfigurationFailedException e) {
   }
 }
 @Test
 public void testConstructorWithInvalidHandlerClass() throws ServerConfigurationFailedException {
   PTestServerConfiguration cfg = new PTestServerConfiguration();
   cfg.setHostname("localhost");
   cfg.setPort(1);
   cfg.addContextHandlerSetting("/test", new PTestNameValuePair("test", "test"));
   cfg.setSocketPoolSize(1);
   try {
     new PTestServerChannelUpstreamHandler(cfg);
     Assert.fail("No class provided for context");
   } catch (ServerConfigurationFailedException e) {
     //
   }
   cfg.addContextHandlerSetting("/test", new PTestNameValuePair("class", "wtf"));
   try {
     new PTestServerChannelUpstreamHandler(cfg);
     Assert.fail("No valid class provided for context");
   } catch (ServerConfigurationFailedException e) {
     //
   }
   cfg.addContextHandlerSetting("/test", new PTestNameValuePair("class", "java.lang.String"));
   try {
     new PTestServerChannelUpstreamHandler(cfg);
     Assert.fail("Valid class but it does not implement the required interface");
   } catch (ServerConfigurationFailedException e) {
   }
   cfg.addContextHandlerSetting(
       "/test",
       new PTestNameValuePair("class", SamplePTestServerContextRequestHandler.class.getName()));
   new PTestServerChannelUpstreamHandler(cfg);
 }
 @Test
 public void testConstructorWithInvalidHostname() throws ServerConfigurationFailedException {
   PTestServerConfiguration cfg = new PTestServerConfiguration();
   cfg.addContextHandlerSetting("/test", new BasicNameValuePair("test", "test"));
   cfg.setPort(1);
   cfg.setSocketPoolSize(1);
   try {
     new PTestServerChannelUpstreamHandler(cfg);
     Assert.fail("Hostname is null");
   } catch (ServerConfigurationFailedException e) {
   }
   cfg.setHostname("");
   try {
     new PTestServerChannelUpstreamHandler(cfg);
     Assert.fail("Hostname is empty");
   } catch (ServerConfigurationFailedException e) {
   }
   cfg.setHostname("    ");
   try {
     new PTestServerChannelUpstreamHandler(cfg);
     Assert.fail("Hostname contains nothing but spaces");
   } catch (ServerConfigurationFailedException e) {
   }
   cfg.setHostname("    \r\r\n\t\t");
   try {
     new PTestServerChannelUpstreamHandler(cfg);
     Assert.fail("Hostname contains spaces, carriage return and tab chars but nothing else");
   } catch (ServerConfigurationFailedException e) {
   }
 }
 @Test
 public void testConstructorWithInvalidServerContextSetting()
     throws ServerConfigurationFailedException {
   try {
     new PTestServerChannelUpstreamHandler(null);
     Assert.fail("Invalid server context setting");
   } catch (ServerConfigurationFailedException e) {
   }
   try {
     new PTestServerChannelUpstreamHandler(new PTestServerConfiguration());
     Assert.fail("Invalid server context setting");
   } catch (ServerConfigurationFailedException e) {
   }
   PTestServerConfiguration cfg = new PTestServerConfiguration();
   cfg.setPort(1);
   cfg.setSocketPoolSize(1);
   cfg.setHostname("localhost");
   try {
     new PTestServerChannelUpstreamHandler(cfg);
     Assert.fail("Missing context handlers");
   } catch (ServerConfigurationFailedException e) {
   }
 }