Search in sources :

Example 1 with JarResources

use of co.cask.cdap.common.lang.jar.JarResources in project cdap by caskdata.

the class ServePathGeneratorTest method testGetServePath.

@Test
public void testGetServePath() throws Exception {
    URL jarUrl = getClass().getResource("/CountRandomWebapp-localhost.jar");
    Assert.assertNotNull(jarUrl);
    final JarResources jarResources = new JarResources(new LocalLocationFactory().create(jarUrl.toURI()));
    Predicate<String> fileExists = new Predicate<String>() {

        @Override
        public boolean apply(@Nullable String file) {
            return file != null && jarResources.getResource(file) != null;
        }
    };
    ServePathGenerator servePathGenerator = new ServePathGenerator(Constants.Webapp.WEBAPP_DIR, fileExists);
    Assert.assertEquals("/webapp/127.0.0.1:20000/netlens/src/index.html", servePathGenerator.getServePath("127.0.0.1:20000", "/netlens"));
    Assert.assertEquals("/webapp/127.0.0.1:20000/netlens/src/index.html", servePathGenerator.getServePath("127.0.0.1:20000", "/netlens/index.html"));
    Assert.assertEquals("/webapp/127.0.0.1:20000/netlens/src/index.html", servePathGenerator.getServePath("127.0.0.1:20000", "/netlens/"));
    Assert.assertEquals("/webapp/127.0.0.1:20000/netlens/src/index.html", servePathGenerator.getServePath("127.0.0.1:20000", "/netlens/"));
    Assert.assertEquals("/webapp/default/src/index.html", servePathGenerator.getServePath("127.0.0.1:30000", "/"));
    Assert.assertEquals("/webapp/default/src/index.html", servePathGenerator.getServePath("127.0.0.1:30000", "/index.html"));
    Assert.assertEquals("/webapp/127.0.0.1:20000/src/netlens/2.txt", servePathGenerator.getServePath("127.0.0.1:20000", "netlens/2.txt"));
    Assert.assertEquals("/webapp/default/netlens/src/1.txt", servePathGenerator.getServePath("127.0.0.1:80", "/netlens/1.txt?count=100"));
    Assert.assertEquals("/webapp/default/netlens/src/data/data.txt", servePathGenerator.getServePath("127.0.0.1:30000", "/netlens/data/data.txt"));
    Assert.assertEquals("/v3/apps?count=10", servePathGenerator.getServePath("127.0.0.1:30000", "/netlens/v3/apps?count=10"));
    Assert.assertEquals("/v3/apps?count=10", servePathGenerator.getServePath("127.0.0.1:30000", "/v3/apps?count=10"));
    Assert.assertEquals("/status", servePathGenerator.getServePath("127.0.0.1:30000", "/netlens/status"));
    Assert.assertEquals("/status", servePathGenerator.getServePath("127.0.0.1:30000", "/status"));
    servePathGenerator = new ServePathGenerator(Constants.Webapp.WEBAPP_DIR + "/", fileExists);
    Assert.assertEquals("/webapp/www.abc.com:80/geo/src/data/data.txt", servePathGenerator.getServePath("www.abc.com", "/geo/data/data.txt"));
    Assert.assertEquals("/webapp/www.abc.com:80/geo/src/data/data.txt", servePathGenerator.getServePath("www.abc.com:80", "/geo/data/data.txt"));
    Assert.assertEquals("/webapp/default/netlens/src/data/data.txt", servePathGenerator.getServePath("www.abc.com:30000", "/netlens/data/data.txt"));
    Assert.assertEquals("/geo/data/data.txt", servePathGenerator.getServePath("www.abc.com:30000", "/geo/data/data.txt"));
}
Also used : LocalLocationFactory(org.apache.twill.filesystem.LocalLocationFactory) URL(java.net.URL) JarResources(co.cask.cdap.common.lang.jar.JarResources) Nullable(javax.annotation.Nullable) Predicate(com.google.common.base.Predicate) Test(org.junit.Test)

Aggregations

JarResources (co.cask.cdap.common.lang.jar.JarResources)1 Predicate (com.google.common.base.Predicate)1 URL (java.net.URL)1 Nullable (javax.annotation.Nullable)1 LocalLocationFactory (org.apache.twill.filesystem.LocalLocationFactory)1 Test (org.junit.Test)1