001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.classreader;
034:
035: import java.io.*;
036: import java.util.*;
037:
038: public class TestClassfileLoaderPermissiveDispatcher extends
039: TestClassfileLoaderBase {
040: public static final String TEST_FILENAME = "classes"
041: + File.separator + "test.class";
042:
043: private ClassfileLoader loader;
044:
045: protected void setUp() throws Exception {
046: super .setUp();
047:
048: loader = new TransientClassfileLoader(
049: new PermissiveDispatcher());
050: loader.addLoadListener(this );
051: }
052:
053: public void testOneFile() {
054: String filename = TEST_FILENAME;
055: assertTrue(filename + " missing", new File(filename).exists());
056:
057: loader.load(Collections.singleton(filename));
058:
059: assertEquals("Begin Session", 1, getBeginSessionEvents().size());
060: assertEquals("Begin Group", 1, getBeginGroupEvents().size());
061: assertEquals("Begin File", 1, getBeginFileEvents().size());
062: assertEquals("Begin Classfile", 1, getBeginClassfileEvents()
063: .size());
064: assertEquals("End Classfile", 1, getEndClassfileEvents().size());
065: assertEquals("End File", 1, getEndFileEvents().size());
066: assertEquals("End Group", 1, getEndGroupEvents().size());
067: assertEquals("End Session", 1, getEndSessionEvents().size());
068:
069: assertEquals("Group size", 1, getBeginGroupEvents().getFirst()
070: .getSize());
071: }
072:
073: public void testOneLevelZip() {
074: String filename = TEST_DIR + File.separator + "onelevel.zip";
075: assertTrue(filename + " missing", new File(filename).exists());
076:
077: loader.load(Collections.singleton(filename));
078:
079: assertEquals("Begin Session", 1, getBeginSessionEvents().size());
080: assertEquals("Begin Group", 1, getBeginGroupEvents().size());
081: assertEquals("Begin File", 31, getBeginFileEvents().size());
082: assertEquals("Begin Classfile", 14, getBeginClassfileEvents()
083: .size());
084: assertEquals("End Classfile", 14, getEndClassfileEvents()
085: .size());
086: assertEquals("End File", 31, getEndFileEvents().size());
087: assertEquals("End Group", 1, getEndGroupEvents().size());
088: assertEquals("End Session", 1, getEndSessionEvents().size());
089:
090: assertEquals("Group size", 31, getBeginGroupEvents().getFirst()
091: .getSize());
092: }
093:
094: public void testOneLevelJar() {
095: String filename = TEST_DIR + File.separator + "onelevel.jar";
096: assertTrue(filename + " missing", new File(filename).exists());
097:
098: loader.load(Collections.singleton(filename));
099:
100: assertEquals("Begin Session", 1, getBeginSessionEvents().size());
101: assertEquals("Begin Group", 1, getBeginGroupEvents().size());
102: assertEquals("Begin File", 33, getBeginFileEvents().size());
103: assertEquals("Begin Classfile", 14, getBeginClassfileEvents()
104: .size());
105: assertEquals("End Classfile", 14, getEndClassfileEvents()
106: .size());
107: assertEquals("End File", 33, getEndFileEvents().size());
108: assertEquals("End Group", 1, getEndGroupEvents().size());
109: assertEquals("End Session", 1, getEndSessionEvents().size());
110:
111: assertEquals("Group size", 33, getBeginGroupEvents().getFirst()
112: .getSize());
113: }
114:
115: public void testOneLevelMiscellaneous() {
116: String filename = TEST_DIR + File.separator + "onelevel.mis";
117: assertTrue(filename + " missing", new File(filename).exists());
118:
119: loader.load(Collections.singleton(filename));
120:
121: assertEquals("Begin Session", 1, getBeginSessionEvents().size());
122: assertEquals("Begin Group", 1, getBeginGroupEvents().size());
123: assertEquals("Begin File", 31, getBeginFileEvents().size());
124: assertEquals("Begin Classfile", 14, getBeginClassfileEvents()
125: .size());
126: assertEquals("End Classfile", 14, getEndClassfileEvents()
127: .size());
128: assertEquals("End File", 31, getEndFileEvents().size());
129: assertEquals("End Group", 1, getEndGroupEvents().size());
130: assertEquals("End Session", 1, getEndSessionEvents().size());
131: }
132:
133: public void testTwoLevelZip() {
134: String filename = TEST_DIR + File.separator + "twolevel.zip";
135: assertTrue(filename + " missing", new File(filename).exists());
136:
137: loader.load(Collections.singleton(filename));
138:
139: assertEquals("Begin Session", 1, getBeginSessionEvents().size());
140: assertEquals("Begin Group", 2, getBeginGroupEvents().size());
141: assertEquals("Begin File", 32, getBeginFileEvents().size());
142: assertEquals("Begin Classfile", 14, getBeginClassfileEvents()
143: .size());
144: assertEquals("End Classfile", 14, getEndClassfileEvents()
145: .size());
146: assertEquals("End File", 32, getEndFileEvents().size());
147: assertEquals("End Group", 2, getEndGroupEvents().size());
148: assertEquals("End Session", 1, getEndSessionEvents().size());
149: }
150:
151: public void testTwoLevelJar() {
152: String filename = TEST_DIR + File.separator + "twolevel.jar";
153: assertTrue(filename + " missing", new File(filename).exists());
154:
155: loader.load(Collections.singleton(filename));
156:
157: assertEquals("Begin Session", 1, getBeginSessionEvents().size());
158: assertEquals("Begin Group", 2, getBeginGroupEvents().size());
159: assertEquals("Begin File", 34, getBeginFileEvents().size());
160: assertEquals("Begin Classfile", 14, getBeginClassfileEvents()
161: .size());
162: assertEquals("End Classfile", 14, getEndClassfileEvents()
163: .size());
164: assertEquals("End File", 34, getEndFileEvents().size());
165: assertEquals("End Group", 2, getEndGroupEvents().size());
166: assertEquals("End Session", 1, getEndSessionEvents().size());
167: }
168:
169: public void testTwoLevelMiscellaneous() {
170: String filename = TEST_DIR + File.separator + "twolevel.mis";
171: assertTrue(filename + " missing", new File(filename).exists());
172:
173: loader.load(Collections.singleton(filename));
174:
175: assertEquals("Begin Session", 1, getBeginSessionEvents().size());
176: assertEquals("Begin Group", 2, getBeginGroupEvents().size());
177: assertEquals("Begin File", 32, getBeginFileEvents().size());
178: assertEquals("Begin Classfile", 14, getBeginClassfileEvents()
179: .size());
180: assertEquals("End Classfile", 14, getEndClassfileEvents()
181: .size());
182: assertEquals("End File", 32, getEndFileEvents().size());
183: assertEquals("End Group", 2, getEndGroupEvents().size());
184: assertEquals("End Session", 1, getEndSessionEvents().size());
185: }
186: }
|