001: /*
002: * J A V A C O M M U N I T Y P R O C E S S
003: *
004: * J S R 9 4
005: *
006: * Test Compatability Kit
007: *
008: */
009: package org.jcp.jsr94.tck;
010:
011: // java imports
012: import java.io.BufferedWriter;
013: import java.io.File;
014: import java.io.FileInputStream;
015: import java.io.FileOutputStream;
016: import java.io.FileWriter;
017: import java.io.IOException;
018: import java.net.URL;
019: import java.util.zip.ZipEntry;
020: import java.util.zip.ZipOutputStream;
021:
022: import junit.framework.Test;
023: import junit.framework.TestSuite;
024:
025: import org.drools.jsr94.rules.Jsr94FactHandle;
026: import org.jcp.jsr94.tck.admin.LocalRuleExecutionSetProviderTest;
027: import org.jcp.jsr94.tck.admin.RuleAdministrationExceptionTest;
028: import org.jcp.jsr94.tck.admin.RuleAdministratorTest;
029: import org.jcp.jsr94.tck.admin.RuleExecutionSetCreateExceptionTest;
030: import org.jcp.jsr94.tck.admin.RuleExecutionSetDeregistrationExceptionTest;
031: import org.jcp.jsr94.tck.admin.RuleExecutionSetRegisterExceptionTest;
032: import org.jcp.jsr94.tck.admin.RuleExecutionSetTest;
033: import org.jcp.jsr94.tck.admin.RuleTest;
034:
035: /**
036: * Run all the test suites in the Test Compatability Kit.
037: * Output is directed to System.out (textui).
038: */
039: public class AllTests extends TestSuite {
040:
041: public static Test suite() {
042: setTckConf();
043:
044: final TestSuite suite = new TestSuite(
045: "JSR 94 Test Compatability Kit");
046: suite.addTestSuite(ApiSignatureTest.class);
047: suite.addTestSuite(ClassLoaderTest.class);
048: suite.addTestSuite(ConfigurationExceptionTest.class);
049: suite.addTestSuite(HandleTest.class);
050: suite.addTestSuite(InvalidHandleExceptionTest.class);
051: suite.addTestSuite(InvalidRuleSessionExceptionTest.class);
052: suite.addTestSuite(ObjectFilterTest.class);
053: suite.addTestSuite(RuleExceptionTest.class);
054: suite.addTestSuite(RuleExecutionExceptionTest.class);
055: suite.addTestSuite(RuleExecutionSetMetadataTest.class);
056: suite.addTestSuite(RuleExecutionSetNotFoundExceptionTest.class);
057: suite.addTestSuite(RuleRuntimeTest.class);
058: suite.addTestSuite(RuleServiceProviderManagerTest.class);
059: suite.addTestSuite(RuleServiceProviderTest.class);
060: suite.addTestSuite(RuleSessionCreateExceptionTest.class);
061: suite.addTestSuite(RuleSessionTest.class);
062: suite
063: .addTestSuite(RuleSessionTypeUnsupportedExceptionTest.class);
064: suite.addTestSuite(StatefulRuleSessionTest.class);
065: suite.addTestSuite(StatelessRuleSessionTest.class);
066: suite.addTestSuite(LocalRuleExecutionSetProviderTest.class);
067: suite.addTestSuite(RuleAdministrationExceptionTest.class);
068: suite.addTestSuite(RuleAdministratorTest.class);
069: suite.addTestSuite(RuleExecutionSetCreateExceptionTest.class);
070: // suite.addTestSuite(RuleExecutionSetProviderTest.class);
071: suite.addTestSuite(RuleExecutionSetRegisterExceptionTest.class);
072: suite.addTestSuite(RuleExecutionSetTest.class);
073: suite
074: .addTestSuite(RuleExecutionSetDeregistrationExceptionTest.class);
075: suite.addTestSuite(RuleTest.class);
076: return suite;
077: }
078:
079: /**
080: * Because the tck.conf relies on directory paths that are not universally the same from eclipse, maven
081: * and ant this method create a tck.conf on the fly with the correct locations, it also create a jar
082: * on the fly which it uses as the jar url location.
083: *
084: */
085: private static void setTckConf() {
086: File jarFile = null;
087: ZipOutputStream zos = null;
088: File rootDirectory = null;
089: try {
090: jarFile = File.createTempFile("drools-jsr94", ".jar");
091:
092: URL url = Jsr94FactHandle.class
093: .getResource("Jsr94FactHandle.class");
094: rootDirectory = new File(url.getFile()).getParentFile()
095: .getParentFile().getParentFile().getParentFile();
096:
097: zos = new ZipOutputStream(new FileOutputStream(jarFile));
098: zipDir(rootDirectory, zos);
099: } catch (Exception e) {
100: e.printStackTrace();
101: } finally {
102: if (zos != null) {
103: try {
104: zos.close();
105: } catch (IOException e) {
106: }
107: }
108: }
109:
110: String conf = "";
111: conf += "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
112: conf += "<tck-configuration>\n";
113: conf += "<test-factory>org.jcp.jsr94.tck.util.TestFactory</test-factory>\n";
114: conf += "<rule-service-provider>org.drools.jsr94.rules.RuleServiceProviderImpl</rule-service-provider>\n";
115: conf += "<rule-service-provider-jar-url>file://"
116: + jarFile.getAbsolutePath()
117: + "</rule-service-provider-jar-url>\n";
118:
119: URL url = AllTests.class.getResource("AllTests.class");
120: String setLocation = new File(url.getFile()).getParentFile()
121: .getAbsolutePath().replaceAll("\\\\", "/");
122: // the tck needs an asbolute path, with no drive letters
123: if (setLocation.charAt(1) == ':') {
124: setLocation = setLocation.substring(2);
125: }
126: conf += "<rule-execution-set-location>" + setLocation
127: + "</rule-execution-set-location>\n";
128: conf += "</tck-configuration>";
129:
130: url = AllTests.class.getResource("tck.conf");
131: File tckConf = new File(url.getFile());
132: BufferedWriter buffWriter = null;
133: try {
134: FileWriter fileWriter = new FileWriter(tckConf);
135: buffWriter = new BufferedWriter(fileWriter);
136: buffWriter.write(conf);
137: } catch (IOException e) {
138: e.printStackTrace();
139: } finally {
140: try {
141: buffWriter.close();
142: } catch (IOException e) {
143: e.printStackTrace();
144: }
145: }
146:
147: System.setProperty("jsr94.tck.configuration", tckConf
148: .getParent());
149:
150: }
151:
152: public static void zipDir(File zipDir, ZipOutputStream zos) {
153: try {
154: String[] dirList = zipDir.list();
155: byte[] readBuffer = new byte[2156];
156: int bytesIn = 0;
157: for (int i = 0; i < dirList.length; i++) {
158: File f = new File(zipDir, dirList[i]);
159: if (f.isDirectory()) {
160: zipDir(f, zos);
161: continue;
162: }
163: FileInputStream fis = new FileInputStream(f);
164: ZipEntry anEntry = new ZipEntry(f.getPath());
165: zos.putNextEntry(anEntry);
166: while ((bytesIn = fis.read(readBuffer)) != -1) {
167: zos.write(readBuffer, 0, bytesIn);
168: }
169: fis.close();
170: }
171: } catch (Exception e) {
172: e.printStackTrace();
173: }
174: }
175: }
|