001: package com.mockrunner.test.consistency;
002:
003: import java.io.File;
004: import java.io.FilenameFilter;
005: import java.net.URL;
006: import java.util.ArrayList;
007: import java.util.Arrays;
008: import java.util.List;
009:
010: import junit.framework.Test;
011: import junit.framework.TestSuite;
012:
013: import com.mockrunner.example.connector.AccountDAOTest;
014: import com.mockrunner.example.ejb.UserLoginSessionTest;
015: import com.mockrunner.example.jdbc.BookstoreTest;
016: import com.mockrunner.example.jms.StockQuotePublisherTest;
017: import com.mockrunner.example.servlet.RedirectServletTest;
018: import com.mockrunner.example.struts.AuthenticationActionTest;
019: import com.mockrunner.example.tag.TableEnumTagTest;
020: import com.mockrunner.gen.jar.MockrunnerJars;
021:
022: public class MockrunnerJarTestConfiguration {
023: public final static String RELEASE_DIR = "bin";
024: public final static String BUILD_DIR = "buildjdk1.6jee5";
025: public final static String LIB_DIR = "lib";
026: public final static String JDK13_DIR = "jdk1.3";
027: public final static String JDK14_DIR = "jdk1.4";
028: public final static String JDK15_DIR = "jdk1.5";
029: public final static String JDK16_DIR = "jdk1.6";
030: public final static String J2EE13_DIR = "j2ee1.3";
031: public final static String J2EE14_DIR = "j2ee1.4";
032: public final static String JEE5_DIR = "jee5";
033: public final static String THIRD_PARTY_DIR = "jar";
034:
035: public final static String ALL_REFERENCE_TEST = AllReferenceTests.class
036: .getName();
037: public final static String JDBC_REFERENCE_TEST = BookstoreTest.class
038: .getName();
039: public final static String EJB_REFERENCE_TEST = UserLoginSessionTest.class
040: .getName();
041: public final static String JMS_REFERENCE_TEST = StockQuotePublisherTest.class
042: .getName();
043: public final static String SERVLET_REFERENCE_TEST = RedirectServletTest.class
044: .getName();
045: public final static String STRUTS_REFERENCE_TEST = AuthenticationActionTest.class
046: .getName();
047: public final static String TAG_REFERENCE_TEST = TableEnumTagTest.class
048: .getName();
049: public final static String CONNECTOR_REFERENCE_TEST = AccountDAOTest.class
050: .getName();
051:
052: public Mapping[] createMappings() {
053: try {
054: List jdk13j2ee13Jars = getReleasedJars(JDK13_DIR,
055: J2EE13_DIR);
056: List jdk14j2ee13Jars = getReleasedJars(JDK14_DIR,
057: J2EE13_DIR);
058: List jdk14j2ee14Jars = getReleasedJars(JDK14_DIR,
059: J2EE14_DIR);
060: List jdk15j2ee13Jars = getReleasedJars(JDK15_DIR,
061: J2EE13_DIR);
062: List jdk15j2ee14Jars = getReleasedJars(JDK15_DIR,
063: J2EE14_DIR);
064: List jdk15jee5Jars = getReleasedJars(JDK15_DIR, JEE5_DIR);
065: List jdk16j2ee13Jars = getReleasedJars(JDK16_DIR,
066: J2EE13_DIR);
067: List jdk16j2ee14Jars = getReleasedJars(JDK16_DIR,
068: J2EE14_DIR);
069: List jdk16jee5Jars = getReleasedJars(JDK16_DIR, JEE5_DIR);
070: List jee5ThirdPartyJarURLs = getURLFromFileList(getThirdPartyJarsJEE5());
071: List j2ee14ThirdPartyJarURLs = getURLFromFileList(getThirdPartyJarsJ2EE14());
072: List j2ee13ThirdPartyJarURLs = getURLFromFileList(getThirdPartyJarsJ2EE13());
073: List jdk13j2ee13mappings = createMappings(jdk13j2ee13Jars,
074: j2ee13ThirdPartyJarURLs);
075: List jdk14j2ee13mappings = createMappings(jdk14j2ee13Jars,
076: j2ee13ThirdPartyJarURLs);
077: List jdk14j2ee14mappings = createMappings(jdk14j2ee14Jars,
078: j2ee14ThirdPartyJarURLs);
079: List jdk15j2ee13mappings = createMappings(jdk15j2ee13Jars,
080: j2ee13ThirdPartyJarURLs);
081: List jdk15j2ee14mappings = createMappings(jdk15j2ee14Jars,
082: j2ee14ThirdPartyJarURLs);
083: List jdk15jee5mappings = createMappings(jdk15jee5Jars,
084: jee5ThirdPartyJarURLs);
085: List jdk16j2ee13mappings = createMappings(jdk16j2ee13Jars,
086: j2ee13ThirdPartyJarURLs);
087: List jdk16j2ee14mappings = createMappings(jdk16j2ee14Jars,
088: j2ee14ThirdPartyJarURLs);
089: List jdk16jee5mappings = createMappings(jdk16jee5Jars,
090: jee5ThirdPartyJarURLs);
091: List resultList = new ArrayList();
092: resultList.addAll(jdk13j2ee13mappings);
093: resultList.addAll(jdk14j2ee13mappings);
094: resultList.addAll(jdk14j2ee14mappings);
095: resultList.addAll(jdk15j2ee13mappings);
096: resultList.addAll(jdk15j2ee14mappings);
097: resultList.addAll(jdk15jee5mappings);
098: resultList.addAll(jdk16j2ee13mappings);
099: resultList.addAll(jdk16j2ee14mappings);
100: resultList.addAll(jdk16jee5mappings);
101: return (Mapping[]) resultList
102: .toArray(new Mapping[resultList.size()]);
103: } catch (Exception exc) {
104: throw new RuntimeException(exc);
105: }
106: }
107:
108: private List createMappings(List jars, List thirdpartyJarURLs)
109: throws Exception {
110: List mappings = new ArrayList();
111: for (int ii = 0; ii < jars.size(); ii++) {
112: File currentFile = (File) jars.get(ii);
113: String name = currentFile.getName();
114: String referenceTest = getReferenceTest(name);
115: List urls = new ArrayList();
116: urls.add(currentFile.toURI().toURL());
117: urls.add(new File(BUILD_DIR).toURI().toURL());
118: urls.addAll(thirdpartyJarURLs);
119: Mapping currentMapping = new Mapping(referenceTest,
120: (URL[]) urls.toArray(new URL[urls.size()]));
121: mappings.add(currentMapping);
122: }
123: return mappings;
124: }
125:
126: private String getReferenceTest(String jarName) {
127: if (jarName.indexOf("servlet") > -1) {
128: return SERVLET_REFERENCE_TEST;
129: } else if (jarName.indexOf("tag") > -1) {
130: return TAG_REFERENCE_TEST;
131: } else if (jarName.indexOf("struts") > -1) {
132: return STRUTS_REFERENCE_TEST;
133: } else if (jarName.indexOf("jms") > -1) {
134: return JMS_REFERENCE_TEST;
135: } else if (jarName.indexOf("ejb") > -1) {
136: return EJB_REFERENCE_TEST;
137: } else if (jarName.indexOf("jdbc") > -1) {
138: return JDBC_REFERENCE_TEST;
139: } else if (jarName.indexOf("jca") > -1) {
140: return CONNECTOR_REFERENCE_TEST;
141: }
142: return ALL_REFERENCE_TEST;
143: }
144:
145: private List getURLFromFileList(List list) throws Exception {
146: List urlList = new ArrayList();
147: for (int ii = 0; ii < list.size(); ii++) {
148: File currentFile = (File) list.get(ii);
149: urlList.add(currentFile.toURI().toURL());
150: }
151: return urlList;
152: }
153:
154: public List getThirdPartyJarsJEE5() {
155: String jarDirName = getBaseDir() + THIRD_PARTY_DIR;
156: return new ArrayList(Arrays.asList(new File(jarDirName)
157: .listFiles(new JarFileFilter())));
158: }
159:
160: public List getThirdPartyJarsJ2EE14() {
161: List resultList = getThirdPartyJarsWithoutJEE5Jars();
162: String jarDirName = getBaseDir() + THIRD_PARTY_DIR
163: + File.separator + J2EE14_DIR;
164: resultList.addAll(Arrays.asList(new File(jarDirName)
165: .listFiles(new JarFileFilter())));
166: return resultList;
167: }
168:
169: public List getThirdPartyJarsJ2EE13() {
170: List resultList = getThirdPartyJarsWithoutJEE5Jars();
171: String jarDirName = getBaseDir() + THIRD_PARTY_DIR
172: + File.separator + J2EE13_DIR;
173: resultList.addAll(Arrays.asList(new File(jarDirName)
174: .listFiles(new JarFileFilter())));
175: return resultList;
176: }
177:
178: private List getThirdPartyJarsWithoutJEE5Jars() {
179: List fileList = getThirdPartyJarsJEE5();
180: List resultList = new ArrayList();
181: for (int ii = 0; ii < fileList.size(); ii++) {
182: File currentFile = (File) fileList.get(ii);
183: if (!isJEE5StandardInterfaceOrJEE5OnlyJar(currentFile)) {
184: resultList.add(currentFile);
185: }
186: }
187: return resultList;
188: }
189:
190: private boolean isJEE5StandardInterfaceOrJEE5OnlyJar(
191: File currentFile) {
192: if (MockrunnerJars.getStandardInterfaceJars().contains(
193: currentFile.getName()))
194: return true;
195: if (MockrunnerJars.getJEE5OnlyJars().contains(
196: currentFile.getName()))
197: return true;
198: return false;
199: }
200:
201: public List getReleasedJars(String jdkDir, String j2eeDir) {
202: String jarDirName = getBaseDir() + LIB_DIR + File.separator
203: + jdkDir + File.separator + j2eeDir;
204: return listFiles(jarDirName);
205: }
206:
207: private List listFiles(String jarDirName) {
208: File[] jarFiles = new File(jarDirName)
209: .listFiles(new JarFileFilter());
210: return Arrays.asList(jarFiles);
211: }
212:
213: private String getBaseDir() {
214: File releaseDir = new File(RELEASE_DIR);
215: String jarDirName = releaseDir.getAbsolutePath()
216: + File.separator;
217: return jarDirName + releaseDir.list()[0] + File.separator;
218: }
219:
220: private class JarFileFilter implements FilenameFilter {
221: public boolean accept(File dir, String name) {
222: if (name.endsWith(".jar"))
223: return true;
224: return false;
225: }
226: }
227:
228: public class Mapping {
229: private String testClass;
230: private URL[] urls;
231:
232: public Mapping(String testClass, URL[] urls) {
233: this .testClass = testClass;
234: this .urls = urls;
235: }
236:
237: public String getTestClass() {
238: return testClass;
239: }
240:
241: public URL[] getUrls() {
242: return urls;
243: }
244: }
245:
246: public static class AllReferenceTests {
247: public static Test suite() {
248: TestSuite suite = new TestSuite("AllReferenceTests");
249: suite.addTest(new TestSuite(BookstoreTest.class));
250: suite.addTest(new TestSuite(UserLoginSessionTest.class));
251: suite.addTest(new TestSuite(StockQuotePublisherTest.class));
252: suite.addTest(new TestSuite(RedirectServletTest.class));
253: suite
254: .addTest(new TestSuite(
255: AuthenticationActionTest.class));
256: suite.addTest(new TestSuite(TableEnumTagTest.class));
257: suite.addTest(new TestSuite(AccountDAOTest.class));
258: return suite;
259: }
260: }
261: }
|