Uploaded image for project: 'Seam 2'
  1. Seam 2
  2. JBSEAM-1301

Bugs with MockServletContext.getResourcePaths()

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Major
    • Resolution: Done
    • Affects Version/s: 1.2.1.GA
    • Fix Version/s: 1.3.0.ALPHA
    • Component/s: Core
    • Labels:
      None

      Description

      I've been doing some work with Seam integration testing lately and noticed getResourcePaths() wasn't working correctly. It appeared to never return anything beyond the webroot. So, I fixed that problem and enhanced getResourcePaths so that it could handle situations where a users directory structure may have multiple webroots (e.g. one for test and main). I changed from searching for webroot by looking for WEB-INF/web.xml files to only WEB-INF.

      If nobody has any objections to my implementation I'll go ahead and commit this.

      This is how I've rewritten getResourcePaths():

      public Set getResourcePaths(String name)
      {
      Enumeration<URL> enumeration = null;
      try

      { enumeration = getClass().getClassLoader().getResources("WEB-INF"); }

      catch (IOException e)

      { throw new RuntimeException("Error finding webroot.",e); }

      Set<String> result = new HashSet<String>();
      while(enumeration.hasMoreElements()) {
      URL url = enumeration.nextElement();
      File rootFile = new File(url.getPath()).getParentFile();
      File newFile = new File(rootFile.getPath()+name);
      File[] files = newFile.listFiles();
      if(files != null)

      { addPaths( result, files, rootFile.getPath() ); }

      }
      return result;
      }

      private static void addPaths(Set<String> result, File[] files, String rootPath)
      {
      for (File file: files)
      {
      String filePath = file.getPath().substring( rootPath.length() ).replace('
      ', '/');
      if(file.isDirectory())

      { result.add(filePath+"/"); }

      else

      { result.add(filePath); }

      }
      }

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                youngm youngm
                Reporter:
                youngm youngm
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: