Пример #1
0
  private boolean compressionPathIsValid(ClientResourceInfo resource) throws IOException {

    ExternalContext extContext = getFacesContext().getExternalContext();
    File tempDir = (File) extContext.getApplicationMap().get("javax.servlet.context.tempdir");
    File expected = new File(tempDir, "/jsf-compressed" + File.separatorChar + resource.getPath());
    return expected.getCanonicalPath().equals(resource.getCompressedPath());
  }
Пример #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()));
  }