[jboss-svn-commits] JBL Code SVN: r9254 - in labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin: test and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Feb 1 09:38:19 EST 2007


Author: mshaw
Date: 2007-02-01 09:38:19 -0500 (Thu, 01 Feb 2007)
New Revision: 9254

Added:
   labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/test/
   labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/test/TestingPlugin.java
   labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/test/test.drl
Modified:
   labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/wizards/GenerateRtlWizard.java
Log:


Added: labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/test/TestingPlugin.java
===================================================================
--- labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/test/TestingPlugin.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/test/TestingPlugin.java	2007-02-01 14:38:19 UTC (rev 9254)
@@ -0,0 +1,26 @@
+package org.drools.testing.plugin.test;
+
+import java.io.FileWriter;
+
+import junit.framework.TestCase;
+
+import org.drools.lang.descr.PackageDescr;
+import org.drools.testing.core.beans.Scenario;
+import org.drools.testing.core.beans.TestSuite;
+import org.drools.testing.core.main.Testing;
+import org.drools.testing.core.main.TransformerService;
+
+public class TestingPlugin extends TestCase {
+	
+	public void testGenerateRTL () throws Exception {
+		PackageDescr paDescr = TransformerService.parseDrl("/org/drools/testing/plugin/test/test.drl");
+		Testing testing = new Testing("The Test Test Suite", paDescr);
+		Scenario scenario = testing.generateScenario("Scenario One",paDescr.getRules());
+		testing.addScenarioToSuite(scenario);
+		TestSuite testSuite = testing.getTestSuite();
+		FileWriter out = new FileWriter("test.rtl");
+		testSuite.marshal(out);
+	}
+	
+	
+}

Added: labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/test/test.drl
===================================================================
--- labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/test/test.drl	                        (rev 0)
+++ labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/test/test.drl	2007-02-01 14:38:19 UTC (rev 9254)
@@ -0,0 +1,29 @@
+package org.drools.testing.core.rules
+import org.drools.testing.core.rules.model.Account;
+import org.drools.testing.core.rules.model.Person;
+
+rule rule1
+	when 
+		$acc : Account (status == "active", balance == 0)
+		$person : Person ( age < 60 )
+	then
+		$acc.setBalance(new Integer(0));
+		modify($acc);
+		System.out.println("firing rule1");
+end
+
+rule rule2
+	when
+		$acc : Account (status == "active", balance < 0)
+	then
+		$acc.setStatus("overdrawn");
+		modify($acc);
+		System.out.println("Your account is overdrawn. Balance: "+$acc.getBalance());	
+end
+
+rule rule3
+	when
+		$acc : Account (balance > 0)
+	then
+		System.out.println("The banks likes you.. so we're increasing our fees!");
+end							 
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/wizards/GenerateRtlWizard.java
===================================================================
--- labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/wizards/GenerateRtlWizard.java	2007-02-01 14:37:02 UTC (rev 9253)
+++ labs/jbossrules/trunk/drools-testing-plugin/src/org/drools/testing/plugin/wizards/GenerateRtlWizard.java	2007-02-01 14:38:19 UTC (rev 9254)
@@ -1,11 +1,17 @@
 package org.drools.testing.plugin.wizards;
 
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
 
 import org.drools.lang.descr.RuleDescr;
+import org.drools.testing.core.beans.Scenario;
+import org.drools.testing.core.beans.TestSuite;
+import org.drools.testing.core.exception.RuleTestLanguageException;
+import org.drools.testing.core.main.Testing;
 import org.drools.testing.plugin.wizards.model.RtlModel;
 import org.eclipse.core.resources.IContainer;
 import org.eclipse.core.resources.IFile;
@@ -29,6 +35,10 @@
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.ide.IDE;
+import org.exolab.castor.xml.MarshalException;
+import org.exolab.castor.xml.Marshaller;
+import org.exolab.castor.xml.ValidationException;
+import org.xml.sax.ContentHandler;
 
 /**
  * This is a sample new wizard. Its role is to create a new file 
@@ -126,16 +136,37 @@
 		}
 		IContainer container = (IContainer) resource;
 		final IFile file = container.getFile(new Path(fileName));
+		
 		try {
-			InputStream stream = openContentStream();
+			Testing testing = new Testing("The Test Test Suite", rtlModel.getPackageDescr());
+			Scenario scenario = testing.generateScenario("Scenario One",rtlModel.getPackageDescr().getRules());
+			testing.addScenarioToSuite(scenario);
+			TestSuite testSuite = testing.getTestSuite();
+			FileWriter out = new FileWriter(fileName);
+			ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+			Marshaller marshaller = new Marshaller(out);
+        	marshaller.setSuppressXSIType(true);
+        	marshaller.setSupressXMLDeclaration(true);
+        	marshaller.marshal(testSuite);   
+			InputStream stream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
 			if (file.exists()) {
 				file.setContents(stream, true, true, monitor);
 			} else {
 				file.create(stream, true, monitor);
 			}
 			stream.close();
+		}catch (RuleTestLanguageException e) {
+			throwCoreException(e.getMessage());
+			
 		} catch (IOException e) {
+			throwCoreException(e.getMessage());
+		}catch (MarshalException e) {
+			throwCoreException(e.getMessage());
+		}catch (ValidationException e) {
+			throwCoreException(e.getMessage());
 		}
+		
+		
 		monitor.worked(1);
 		monitor.setTaskName("Opening file for editing...");
 		getShell().getDisplay().asyncExec(new Runnable() {
@@ -153,7 +184,7 @@
 	}
 	
 	/**
-	 * We will initialize file contents with a sample text.
+	 * We will initialize file contents with the newly generated rtl scenario
 	 */
 
 	private InputStream openContentStream() {




More information about the jboss-svn-commits mailing list