Пример #1
0
  public void testELEvalDisabledIfNoExpressionEvaluated() throws Exception {

    ResourceManager manager = new ResourceManager(null);
    ClientResourceInfo resource =
        (ClientResourceInfo)
            manager.findResource(null, "simple.css", "text/css", getFacesContext());
    assertNotNull(resource);
    assertTrue(resource.supportsEL());
    ResourceImpl resImpl = new ResourceImpl(resource, "text/css", 0, 0);
    InputStream in = resImpl.getInputStream();
    for (int i = in.read(); i != -1; i = in.read()) {}
    try {
      in.close();
    } catch (Exception ioe) {
      fail(ioe.toString());
    }
    assertTrue(!resource.supportsEL());

    resource =
        (ClientResourceInfo)
            manager.findResource(null, "simple-with-el.css", "text/css", getFacesContext());

    assertNotNull(resource);
    assertTrue(resource.supportsEL());
    resImpl = new ResourceImpl(resource, "text/css", 0, 0);
    in = resImpl.getInputStream();
    for (int i = in.read(); i != -1; i = in.read()) {}
    try {
      in.close();
    } catch (Exception ioe) {
      fail(ioe.toString());
    }
    assertTrue(resource.supportsEL());
  }
Пример #2
0
  public void testClientResourceInfoCompression() throws Exception {
    WebConfiguration config = WebConfiguration.getInstance();
    config.overrideContextInitParameter(
        WebConfiguration.WebContextInitParameter.CompressableMimeTypes,
        "image/gif,text/css,text/plain");
    // create a new ResourceManager so that the mime type configuration is picked up
    ResourceManager manager = new ResourceManager(null);
    ClientResourceInfo resource =
        (ClientResourceInfo)
            manager.findResource("nvLibrary", "duke-nv.gif", "image/gif", getFacesContext());
    assertTrue(resource != null);
    assertTrue(resource.isCompressable());
    assertTrue(compressionPathIsValid(resource));

    // ensure compression disabled for a content type that is null
    resource =
        (ClientResourceInfo)
            manager.findResource("nvLibrary", "duke-nv.gif", "text/javascript", getFacesContext());
    assertTrue(resource != null);
    assertTrue(!resource.isCompressable());
    assertTrue(resource.getCompressedPath() == null);

    // if a resource is compressable, but the compressed result is larger
    // than the original resource, the returned ClientResourceInfo shouldn't
    // be marked as compressable and getCompressedPath() will be null
    resource =
        (ClientResourceInfo)
            manager.findResource(null, "simple.txt", "text/plain", getFacesContext());
    assertTrue(resource != null);
    assertTrue(!resource.isCompressable());
    assertTrue(resource.getCompressedPath() == null);

    // if a resource is compressable, but the compressed result is larger
    // than the original resource, the returned ClientResourceInfo should be
    // marked compressable.  However, since css files may have EL expressions
    // embedded within, the the resource will be marked as supporting such.
    resource =
        (ClientResourceInfo)
            manager.findResource(null, "simple.css", "text/plain", getFacesContext());
    assertTrue(resource != null);
    assertTrue(resource.isCompressable());
    assertTrue(resource.supportsEL());
    assertTrue(resource.getCompressedPath() == null);
  }
Пример #3
0
 public void testWebappVersionedResource() throws Exception {
   ClientResourceInfo resource =
       (ClientResourceInfo) manager.findResource(null, "duke.gif", "image/gif", getFacesContext());
   assertTrue(resource != null);
   assertTrue(resource.getLibraryInfo() == null);
   assertTrue(resource.getHelper() instanceof WebappResourceHelper);
   assertTrue(!resource.isCompressable());
   assertTrue(resource.getCompressedPath() == null);
   assertTrue("1_1".equals(resource.getVersion().toString()));
   assertTrue("duke.gif".equals(resource.getName()));
   assertTrue("/resources/duke.gif/1_1.gif".equals(resource.getPath()));
 }
Пример #4
0
 public void testJarNonVersionedResources() throws Exception {
   ClientResourceInfo resource =
       (ClientResourceInfo)
           manager.findResource(null, "duke-jar-nv.gif", "image/gif", getFacesContext());
   assertTrue(resource != null);
   assertTrue(resource.getLibraryInfo() == null);
   assertTrue(resource.getHelper() instanceof ClasspathResourceHelper);
   assertTrue(resource.getVersion() == null);
   assertTrue(!resource.isCompressable());
   assertTrue(resource.getCompressedPath() == null);
   assertTrue("duke-jar-nv.gif".equals(resource.getName()));
   assertTrue("META-INF/resources/duke-jar-nv.gif".equals(resource.getPath()));
 }
Пример #5
0
  public void testWebappVersionedLibraryNonVersionedResource() throws Exception {
    ClientResourceInfo resource =
        (ClientResourceInfo)
            manager.findResource("vLibrary", "duke-nv.gif", "image/gif", getFacesContext());
    assertTrue(resource != null);

    // validate the library
    assertTrue(resource.getLibraryInfo() != null);
    assertTrue("vLibrary".equals(resource.getLibraryInfo().getName()));
    assertTrue("2_0".equals(resource.getLibraryInfo().getVersion().toString()));
    assertTrue(resource.getLibraryInfo().getHelper() instanceof WebappResourceHelper);
    assertTrue("/resources/vLibrary/2_0".equals(resource.getLibraryInfo().getPath()));

    // validate the resource
    assertTrue(resource.getHelper() instanceof WebappResourceHelper);
    assertTrue(!resource.isCompressable());
    assertTrue(resource.getCompressedPath() == null);
    assertTrue(resource.getVersion() == null);
    assertTrue("duke-nv.gif".equals(resource.getName()));
    assertTrue("/resources/vLibrary/2_0/duke-nv.gif".equals(resource.getPath()));
  }
Пример #6
0
 public void testInvalidResourceName() throws Exception {
   assertTrue(manager.findResource(null, "duke.fig", null, getFacesContext()) == null);
   assertTrue(manager.findResource("nvLibrary", "duke.fig", null, getFacesContext()) == null);
 }
Пример #7
0
 public void testInvalidLibraryName() throws Exception {
   assertTrue(
       manager.findResource("noSuchLibrary", "duke.gif", "image/gif", getFacesContext()) == null);
 }