KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > javacoding > jspider > functional > specific > model > ModelTest


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 JavaDoc;
14
15 /**
16  * $Id: ModelTest.java,v 1.1 2003/04/10 16:19:23 vanrogu Exp $
17  * @todo elaborate to check better
18  */

19 public class ModelTest extends TestCase {
20
21     public static final String JavaDoc
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     /**
39      * Public constructor giving a name to the test.
40      */

41     public ModelTest ( ) {
42         super ( "ParseTest ");
43     }
44
45     /**
46      * JUnit's overridden setUp method
47      * @throws java.lang.Exception in case something fails during setup
48      */

49     protected void setUp() throws Exception JavaDoc {
50         System.err.println("setUp");
51         config = ConfigurationFactory.getConfiguration(ConfigurationFactory.CONFIG_UNITTEST);
52         sink = JUnitEventSink.getInstance();
53     }
54
55     /**
56      * JUnit's overridden tearDown method
57      * @throws java.lang.Exception in case something fails during tearDown
58      */

59     protected void tearDown() throws Exception JavaDoc {
60         System.err.println("tearDown");
61         ConfigurationFactory.cleanConfiguration();
62         sink.reset();
63     }
64
65     /**
66      * Test a simple parse.
67      */

68     public void testSimpleParse ( ) throws Exception JavaDoc {
69
70         URL JavaDoc url = new URL JavaDoc ( "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 JavaDoc {
80         for (int i = 0; i < tree.length; i++) {
81             String JavaDoc[] folders = tree[i];
82             Folder[] rootFolders = storage.getSiteDAO().find(URLUtil.normalize(new URL JavaDoc("http", TestingConstants.HOST, ""))).getRootFolders();
83             ensureFolders(i, rootFolders, folders, 0);
84
85             //email
86
//refs
87
//resources
88
}
89     }
90
91     public void ensureFolders ( int treeIndex, Folder[] currentLevel, String JavaDoc[] folderNames, int index ) {
92         String JavaDoc 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