KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > classreader > TestClassfileLoaderPermissiveDispatcher


1 /*
2  * Copyright (c) 2001-2005, Jean Tessier
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Jean Tessier nor the names of his contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

32
33 package com.jeantessier.classreader;
34
35 import java.io.*;
36 import java.util.*;
37
38 public class TestClassfileLoaderPermissiveDispatcher extends TestClassfileLoader {
39     public static final String JavaDoc TEST_FILENAME = "classes" + File.separator + "test.class";
40
41     private ClassfileLoader loader;
42
43     protected void setUp() throws Exception JavaDoc {
44         super.setUp();
45         
46         loader = new TransientClassfileLoader(new PermissiveDispatcher());
47         loader.addLoadListener(this);
48     }
49
50     public void testOneFile() {
51         String JavaDoc filename = TEST_FILENAME;
52         assertTrue(filename + " missing", new File(filename).exists());
53         
54         loader.load(Collections.singleton(filename));
55
56         assertEquals("Begin Session", 1, getBeginSessionEvents().size());
57         assertEquals("Begin Group", 1, getBeginGroupEvents().size());
58         assertEquals("Begin File", 1, getBeginFileEvents().size());
59         assertEquals("Begin Classfile", 1, getBeginClassfileEvents().size());
60         assertEquals("End Classfile", 1, getEndClassfileEvents().size());
61         assertEquals("End File", 1, getEndFileEvents().size());
62         assertEquals("End Group", 1, getEndGroupEvents().size());
63         assertEquals("End Session", 1, getEndSessionEvents().size());
64
65         assertEquals("Group size", 1, ((LoadEvent) getBeginGroupEvents().getFirst()).getSize());
66     }
67
68     public void testOneLevelZip() {
69         String JavaDoc filename = TEST_DIR + File.separator + "onelevel.zip";
70         assertTrue(filename + " missing", new File(filename).exists());
71         
72         loader.load(Collections.singleton(filename));
73
74         assertEquals("Begin Session", 1, getBeginSessionEvents().size());
75         assertEquals("Begin Group", 1, getBeginGroupEvents().size());
76         assertEquals("Begin File", 38, getBeginFileEvents().size());
77         assertEquals("Begin Classfile", 17, getBeginClassfileEvents().size());
78         assertEquals("End Classfile", 17, getEndClassfileEvents().size());
79         assertEquals("End File", 38, getEndFileEvents().size());
80         assertEquals("End Group", 1, getEndGroupEvents().size());
81         assertEquals("End Session", 1, getEndSessionEvents().size());
82
83         assertEquals("Group size", 38, ((LoadEvent) getBeginGroupEvents().getFirst()).getSize());
84     }
85
86     public void testOneLevelJar() {
87         String JavaDoc filename = TEST_DIR + File.separator + "onelevel.jar";
88         assertTrue(filename + " missing", new File(filename).exists());
89         
90         loader.load(Collections.singleton(filename));
91
92         assertEquals("Begin Session", 1, getBeginSessionEvents().size());
93         assertEquals("Begin Group", 1, getBeginGroupEvents().size());
94         assertEquals("Begin File", 40, getBeginFileEvents().size());
95         assertEquals("Begin Classfile", 17, getBeginClassfileEvents().size());
96         assertEquals("End Classfile", 17, getEndClassfileEvents().size());
97         assertEquals("End File", 40, getEndFileEvents().size());
98         assertEquals("End Group", 1, getEndGroupEvents().size());
99         assertEquals("End Session", 1, getEndSessionEvents().size());
100
101         assertEquals("Group size", 40, ((LoadEvent) getBeginGroupEvents().getFirst()).getSize());
102     }
103     
104     public void testOneLevelMiscellaneous() {
105         String JavaDoc filename = TEST_DIR + File.separator + "onelevel.mis";
106         assertTrue(filename + " missing", new File(filename).exists());
107         
108         loader.load(Collections.singleton(filename));
109
110         assertEquals("Begin Session", 1, getBeginSessionEvents().size());
111         assertEquals("Begin Group", 1, getBeginGroupEvents().size());
112         assertEquals("Begin File", 38, getBeginFileEvents().size());
113         assertEquals("Begin Classfile", 17, getBeginClassfileEvents().size());
114         assertEquals("End Classfile", 17, getEndClassfileEvents().size());
115         assertEquals("End File", 38, getEndFileEvents().size());
116         assertEquals("End Group", 1, getEndGroupEvents().size());
117         assertEquals("End Session", 1, getEndSessionEvents().size());
118     }
119
120     public void testTwoLevelZip() {
121         String JavaDoc filename = TEST_DIR + File.separator + "twolevel.zip";
122         assertTrue(filename + " missing", new File(filename).exists());
123         
124         loader.load(Collections.singleton(filename));
125
126         assertEquals("Begin Session", 1, getBeginSessionEvents().size());
127         assertEquals("Begin Group", 2, getBeginGroupEvents().size());
128         assertEquals("Begin File", 39, getBeginFileEvents().size());
129         assertEquals("Begin Classfile", 17, getBeginClassfileEvents().size());
130         assertEquals("End Classfile", 17, getEndClassfileEvents().size());
131         assertEquals("End File", 39, getEndFileEvents().size());
132         assertEquals("End Group", 2, getEndGroupEvents().size());
133         assertEquals("End Session", 1, getEndSessionEvents().size());
134     }
135
136     public void testTwoLevelJar() {
137         String JavaDoc filename = TEST_DIR + File.separator + "twolevel.jar";
138         assertTrue(filename + " missing", new File(filename).exists());
139         
140         loader.load(Collections.singleton(filename));
141
142         assertEquals("Begin Session", 1, getBeginSessionEvents().size());
143         assertEquals("Begin Group", 2, getBeginGroupEvents().size());
144         assertEquals("Begin File", 41, getBeginFileEvents().size());
145         assertEquals("Begin Classfile", 17, getBeginClassfileEvents().size());
146         assertEquals("End Classfile", 17, getEndClassfileEvents().size());
147         assertEquals("End File", 41, getEndFileEvents().size());
148         assertEquals("End Group", 2, getEndGroupEvents().size());
149         assertEquals("End Session", 1, getEndSessionEvents().size());
150     }
151     
152     public void testTwoLevelMiscellaneous() {
153         String JavaDoc filename = TEST_DIR + File.separator + "twolevel.mis";
154         assertTrue(filename + " missing", new File(filename).exists());
155         
156         loader.load(Collections.singleton(filename));
157
158         assertEquals("Begin Session", 1, getBeginSessionEvents().size());
159         assertEquals("Begin Group", 2, getBeginGroupEvents().size());
160         assertEquals("Begin File", 39, getBeginFileEvents().size());
161         assertEquals("Begin Classfile", 17, getBeginClassfileEvents().size());
162         assertEquals("End Classfile", 17, getEndClassfileEvents().size());
163         assertEquals("End File", 39, getEndFileEvents().size());
164         assertEquals("End Group", 2, getEndGroupEvents().size());
165         assertEquals("End Session", 1, getEndSessionEvents().size());
166     }
167 }
168
Popular Tags