1 package net.javacoding.jspider.functional.specific.model; 2 3 import junit.framework.TestCase; 4 import net.javacoding.jspider.JSpider; 5 import net.javacoding.jspider.api.model.Folder; 6 import net.javacoding.jspider.mockobjects.plugin.JUnitEventSink; 7 import net.javacoding.jspider.core.util.config.ConfigurationFactory; 8 import net.javacoding.jspider.core.util.config.JSpiderConfiguration; 9 import net.javacoding.jspider.core.util.URLUtil; 10 import net.javacoding.jspider.core.storage.Storage; 11 import net.javacoding.jspider.functional.TestingConstants; 12 13 import java.net.URL ; 14 15 19 public class ModelTest extends TestCase { 20 21 public static final String 22 tree[][] = { 23 {"testcases", "specific", "model"}, 24 {"testcases", "specific", "model", "test1"}, 25 {"testcases", "specific", "model", "test2"} 26 }; 27 28 public static final int 29 resourceCount[][] = { 30 {0, 0, 1 }, 31 {0, 0, 1, 1}, 32 {0, 0, 1, 2} 33 }; 34 35 protected JUnitEventSink sink; 36 protected JSpiderConfiguration config; 37 38 41 public ModelTest ( ) { 42 super ( "ParseTest "); 43 } 44 45 49 protected void setUp() throws Exception { 50 System.err.println("setUp"); 51 config = ConfigurationFactory.getConfiguration(ConfigurationFactory.CONFIG_UNITTEST); 52 sink = JUnitEventSink.getInstance(); 53 } 54 55 59 protected void tearDown() throws Exception { 60 System.err.println("tearDown"); 61 ConfigurationFactory.cleanConfiguration(); 62 sink.reset(); 63 } 64 65 68 public void testSimpleParse ( ) throws Exception { 69 70 URL url = new URL ( "http://" + TestingConstants.HOST + "/testcases/specific/model/index.html" ); 71 72 JSpider jspider = new JSpider ( url ); 73 jspider.start ( ); 74 Storage storage = jspider.getContext().getStorage(); 75 testFolders ( storage ); 76 } 77 78 79 public void testFolders ( Storage storage ) throws Exception { 80 for (int i = 0; i < tree.length; i++) { 81 String [] folders = tree[i]; 82 Folder[] rootFolders = storage.getSiteDAO().find(URLUtil.normalize(new URL ("http", TestingConstants.HOST, ""))).getRootFolders(); 83 ensureFolders(i, rootFolders, folders, 0); 84 85 } 89 } 90 91 public void ensureFolders ( int treeIndex, Folder[] currentLevel, String [] folderNames, int index ) { 92 String name = folderNames[index]; 93 94 Folder foundFolder = null; 95 for (int i = 0; i < currentLevel.length; i++) { 96 Folder folder = currentLevel[i]; 97 if ( folder.getName().equals(name)){ 98 foundFolder = folder; 99 assertEquals("folder " + name + " reported wrong number of resources", resourceCount[treeIndex][index], folder.getResources().length); 100 } 101 } 102 assertNotNull("folder " + name + " not found", foundFolder); 103 104 if ( (index+1) < folderNames.length ) { 105 ensureFolders(treeIndex, foundFolder.getFolders(), folderNames, index+1); 106 } 107 } 108 109 } | Popular Tags |