@Test
  public void testNonVirtualCollectionList() throws Exception {
    List<StorageItem> result = new ArrayList<StorageItem>();

    expect(repository.getId()).andReturn("dummy").anyTimes();
    expect(repository.createUid("/a/some/dir/coll"))
        .andAnswer(
            new IAnswer<RepositoryItemUid>() {
              @Override
              public RepositoryItemUid answer() throws Throwable {
                return getRepositoryItemUidFactory().createUid(repository, "/a/some/dir/coll");
              }
            });
    expect(repository.createUid("/a/some/dir/coll/A"))
        .andAnswer(
            new IAnswer<RepositoryItemUid>() {
              @Override
              public RepositoryItemUid answer() throws Throwable {
                return getRepositoryItemUidFactory().createUid(repository, "/a/some/dir/coll/A");
              }
            });
    expect(repository.createUid("/a/some/dir/coll/B"))
        .andAnswer(
            new IAnswer<RepositoryItemUid>() {
              @Override
              public RepositoryItemUid answer() throws Throwable {
                return getRepositoryItemUidFactory().createUid(repository, "/a/some/dir/coll/B");
              }
            });
    expect(repository.createUid("/a/some/dir/coll/C"))
        .andAnswer(
            new IAnswer<RepositoryItemUid>() {
              @Override
              public RepositoryItemUid answer() throws Throwable {
                return getRepositoryItemUidFactory().createUid(repository, "/a/some/dir/coll/C");
              }
            });
    expect(repository.list(anyBoolean(), isA(StorageCollectionItem.class))).andReturn(result);

    replay(repository);

    // and now fill in result, since repo is active
    result.add(
        new DefaultStorageFileItem(
            repository, "/a/some/dir/coll/A", true, true, new StringContentLocator("A")));
    result.add(
        new DefaultStorageFileItem(
            repository, "/a/some/dir/coll/B", true, true, new StringContentLocator("B")));
    result.add(
        new DefaultStorageFileItem(
            repository, "/a/some/dir/coll/C", true, true, new StringContentLocator("C")));

    DefaultStorageCollectionItem coll =
        new DefaultStorageCollectionItem(repository, "/a/some/dir/coll", true, true);
    checkAbstractStorageItem(repository, coll, false, "coll", "/a/some/dir/coll", "/a/some/dir");

    Collection<StorageItem> items = coll.list();
    assertEquals(3, items.size());
  }
  protected StorageItem retrieveVirtualPath(ResourceStoreRequest request, RequestRoute route)
      throws ItemNotFoundException {
    ResourceStoreRequest req = new ResourceStoreRequest(route.getOriginalRequestPath());

    DefaultStorageCollectionItem result = new DefaultStorageCollectionItem(this, req, true, false);

    result.getItemContext().putAll(request.getRequestContext());

    return result;
  }
  @Test
  public void testVirtualCollectionList() throws Exception {
    List<StorageItem> result = new ArrayList<StorageItem>();

    expect(router.list(isA(ResourceStoreRequest.class))).andReturn(result);

    replay(router);

    // and now fill in result, since repo is active
    result.add(
        new DefaultStorageFileItem(
            router, "/a/some/dir/coll/A", true, true, new StringContentLocator("A")));
    result.add(
        new DefaultStorageFileItem(
            router, "/a/some/dir/coll/B", true, true, new StringContentLocator("B")));

    DefaultStorageCollectionItem coll =
        new DefaultStorageCollectionItem(router, "/and/another/coll", true, true);
    checkAbstractStorageItem(router, coll, true, "coll", "/and/another/coll", "/and/another");

    Collection<StorageItem> items = coll.list();
    assertEquals(2, items.size());
  }
  protected Collection<StorageItem> listVirtualPath(
      ResourceStoreRequest request, RequestRoute route) throws ItemNotFoundException {
    if (route.getRequestDepth() == 0) {
      // 1st level
      ArrayList<StorageItem> result = new ArrayList<StorageItem>();

      for (RepositoryTypeDescriptor rtd :
          repositoryTypeRegistry.getRegisteredRepositoryTypeDescriptors()) {
        // check is there any repo registered
        if (!repositoryRegistry.getRepositoriesWithFacet(rtd.getRole()).isEmpty()) {
          ResourceStoreRequest req =
              new ResourceStoreRequest(
                  ItemPathUtils.concatPaths(request.getRequestPath(), rtd.getPrefix()));

          DefaultStorageCollectionItem repositories =
              new DefaultStorageCollectionItem(this, req, true, false);

          repositories.getItemContext().putAll(request.getRequestContext());

          result.add(repositories);
        }
      }

      return result;
    } else if (route.getRequestDepth() == 1) {
      // 2nd level
      List<? extends Repository> repositories = null;

      Class<? extends Repository> kind = null;

      for (RepositoryTypeDescriptor rtd :
          repositoryTypeRegistry.getRegisteredRepositoryTypeDescriptors()) {
        if (route.getStrippedPrefix().startsWith("/" + rtd.getPrefix())) {
          kind = rtd.getRole();

          repositories = repositoryRegistry.getRepositoriesWithFacet(kind);

          break;
        }
      }

      // if no prefix matched, Item not found
      if (repositories == null || repositories.isEmpty()) {
        throw new ItemNotFoundException(request);
      }

      // filter access to the repositories
      // NOTE: do this AFTER the null/empty check so we return an empty list vs. an ItemNotFound
      repositories = filterAccessToRepositories(repositories);

      ArrayList<StorageItem> result = new ArrayList<StorageItem>(repositories.size());

      for (Repository repository : repositories) {
        if (repository.isExposed() && repository.isBrowseable()) {
          DefaultStorageCollectionItem repoItem = null;

          ResourceStoreRequest req = null;

          if (Repository.class.equals(kind)) {
            req =
                new ResourceStoreRequest(
                    ItemPathUtils.concatPaths(request.getRequestPath(), repository.getId()));
          } else {
            req =
                new ResourceStoreRequest(
                    ItemPathUtils.concatPaths(
                        request.getRequestPath(), repository.getPathPrefix()));
          }

          repoItem = new DefaultStorageCollectionItem(this, req, true, false);

          repoItem.getItemContext().putAll(request.getRequestContext());

          result.add(repoItem);
        }
      }

      return result;
    } else {
      throw new ItemNotFoundException(request);
    }
  }