Package org.jboss.test.ejb3.vfs.impl.vfs2

Source Code of org.jboss.test.ejb3.vfs.impl.vfs2.VirtualFileFilterUnitTest

/*
* JBoss, Home of Professional Open Source
* Copyright (c) 2010, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.test.ejb3.vfs.impl.vfs2;

import java.io.IOException;
import java.net.URL;
import java.util.List;

import org.jboss.ejb3.vfs.impl.vfs2.VirtualFileFilterAdapter;
import org.jboss.ejb3.vfs.spi.VirtualFileFilter;
import org.jboss.test.BaseTestCase;
import org.jboss.virtual.VFS;
import org.jboss.virtual.VirtualFile;
import org.jboss.virtual.VisitorAttributes;
import org.jboss.virtual.plugins.vfs.helpers.FilterVirtualFileVisitor;

/**
* Test to verify the {@link VirtualFileFilterAdapter} correctly delegates to the {@link VirtualFileFilter}
* defined in the VFS2 abstraction.
*
* @author John Bailey
*
*/
public class VirtualFileFilterUnitTest extends BaseTestCase
{
   public VirtualFileFilterUnitTest(String name)
   {
      super(name);
   }

   public void testFilterAdapter() throws Exception
   {
      final VirtualFileFilter filter = getFilter();
      final VirtualFileFilterAdapter filterAdapter = new VirtualFileFilterAdapter(filter);
      final VirtualFile virtuFile = getRoot();
      final FilterVirtualFileVisitor visitor = new FilterVirtualFileVisitor(filterAdapter, VisitorAttributes.RECURSE_LEAVES_ONLY);
      virtuFile.visit(visitor);
     
      final List<VirtualFile> matched = visitor.getMatched();
     
      assertEquals(4, matched.size());
   }

   private VirtualFileFilter getFilter()
   {
      return new VirtualFileFilter()
      {
         @Override
         public boolean accepts(org.jboss.ejb3.vfs.spi.VirtualFile file)
         {
            try {
               return file.isLeaf() && file.getName().startsWith("test");
            }
            catch (IOException e) {
               throw new RuntimeException(e);
            }
         }
      };
   }

   private VirtualFile getRoot() throws Exception
   {
      VFS.init();
      final URL url = getResource("/vfs");
      final VirtualFile root = VFS.createNewRoot(url);
      return root;
   }
}
TOP

Related Classes of org.jboss.test.ejb3.vfs.impl.vfs2.VirtualFileFilterUnitTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.