Esempio n. 1
0
 @Test(expected=org.apache.hadoop.yarn.webapp.WebAppException.class)
 public void testCreateWithNonZeroPort() {
   WebApp app = WebApps.$for(this).at(50000).start();
   int port = app.getListenerAddress().getPort();
   assertEquals(50000, port);
   // start another WebApp with same NonZero port
   WebApp app2 = WebApps.$for(this).at(50000).start();
   // An exception occurs (findPort disabled)
   app.stop();
   app2.stop();
 }
Esempio n. 2
0
 @Test public void testCreateWithPort() {
   // see if the ephemeral port is updated
   WebApp app = WebApps.$for(this).at(0).start();
   int port = app.getListenerAddress().getPort();
   assertTrue(port > 0);
   app.stop();
   // try to reuse the port
   app = WebApps.$for(this).at(port).start();
   assertEquals(port, app.getListenerAddress().getPort());
   app.stop();
 }
Esempio n. 3
0
  @Test public void testCustomRoutes() throws Exception {
    WebApp app =
        WebApps.$for("test", TestWebApp.class, this, "ws").start(new WebApp() {
          @Override
          public void setup() {
            bind(MyTestJAXBContextResolver.class);
            bind(MyTestWebService.class);

            route("/:foo", FooController.class);
            route("/bar/foo", FooController.class, "bar");
            route("/foo/:foo", DefaultController.class);
            route("/foo/bar/:foo", DefaultController.class, "index");
          }
        });
    String baseUrl = baseUrl(app);
    try {
      assertEquals("foo", getContent(baseUrl).trim());
      assertEquals("foo", getContent(baseUrl +"test").trim());
      assertEquals("foo1", getContent(baseUrl +"test/1").trim());
      assertEquals("bar", getContent(baseUrl +"test/bar/foo").trim());
      assertEquals("default", getContent(baseUrl +"test/foo/bar").trim());
      assertEquals("default1", getContent(baseUrl +"test/foo/1").trim());
      assertEquals("default2", getContent(baseUrl +"test/foo/bar/2").trim());
      assertEquals(404, getResponseCode(baseUrl +"test/goo"));
      assertEquals(200, getResponseCode(baseUrl +"ws/v1/test"));
      assertTrue(getContent(baseUrl +"ws/v1/test").contains("myInfo"));
    } finally {
      app.stop();
    }
  }
Esempio n. 4
0
 @Test public void testServePathsNoName() {
   WebApp app = WebApps.$for("", this).start();
   assertEquals("/", app.getRedirectPath());
   String[] expectedPaths = { "/*" };
   String[] pathSpecs = app.getServePathSpecs();
    
   assertEquals(1, pathSpecs.length);
   for(int i = 0; i < expectedPaths.length; i++) {
     assertTrue(ArrayUtils.contains(pathSpecs, expectedPaths[i]));
   }
   app.stop();
 }
Esempio n. 5
0
 @Test public void testDefaultRoutes() throws Exception {
   WebApp app = WebApps.$for("test", this).start();
   String baseUrl = baseUrl(app);
   try {
     assertEquals("foo", getContent(baseUrl +"test/foo").trim());
     assertEquals("foo", getContent(baseUrl +"test/foo/index").trim());
     assertEquals("bar", getContent(baseUrl +"test/foo/bar").trim());
     assertEquals("default", getContent(baseUrl +"test").trim());
     assertEquals("default", getContent(baseUrl +"test/").trim());
     assertEquals("default", getContent(baseUrl).trim());
   } finally {
     app.stop();
   }
 }
Esempio n. 6
0
 // This is to test the GuiceFilter should only be applied to webAppContext,
 // not to staticContext  and logContext;
 @Test public void testYARNWebAppContext() throws Exception {
   // setting up the log context
   System.setProperty("hadoop.log.dir", "/Not/Existing/dir");
   WebApp app = WebApps.$for("test", this).start(new WebApp() {
     @Override public void setup() {
       route("/", FooController.class);
     }
   });
   String baseUrl = baseUrl(app);
   try {
     // should not redirect to foo
     assertFalse("foo".equals(getContent(baseUrl +"static").trim()));
     // Not able to access a non-existing dir, should not redirect to foo.
     assertEquals(404, getResponseCode(baseUrl +"logs"));
     // should be able to redirect to foo.
     assertEquals("foo", getContent(baseUrl).trim());
   } finally {
     app.stop();
   }
 }
Esempio n. 7
0
 @Test public void testCreate() {
   WebApp app = WebApps.$for(this).start();
   app.stop();
 }