[jboss-svn-commits] JBL Code SVN: r16935 - in labs/jbossrules/trunk/drools-jbrms/src: main/java/org/drools/brms/client/rpc and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Nov 30 05:57:52 EST 2007
Author: michael.neale at jboss.com
Date: 2007-11-30 05:57:51 -0500 (Fri, 30 Nov 2007)
New Revision: 16935
Added:
labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/ScenarioRunResult.java
labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/builder/ScenarioAssembler.java
Modified:
labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/qa/ScenarioWidget.java
labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RepositoryService.java
labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RepositoryServiceAsync.java
labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/ServiceImplementation.java
labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/builder/BRMSPackageBuilder.java
labs/jbossrules/trunk/drools-jbrms/src/test/java/org/drools/brms/server/ServiceImplementationTest.java
Log:
JBRULES-1271 scenario test runner now integrated
Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/qa/ScenarioWidget.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/qa/ScenarioWidget.java 2007-11-30 10:56:48 UTC (rev 16934)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/qa/ScenarioWidget.java 2007-11-30 10:57:51 UTC (rev 16935)
@@ -1011,7 +1011,7 @@
}
data.setWidget(i, 1, new Label(v.ruleName + ":"));
- data.getFlexCellFormatter().setAlignment(i, 0, HasHorizontalAlignment.ALIGN_RIGHT, HasVerticalAlignment.ALIGN_MIDDLE);
+ data.getFlexCellFormatter().setAlignment(i, 1, HasHorizontalAlignment.ALIGN_RIGHT, HasVerticalAlignment.ALIGN_MIDDLE);
final ListBox b = new ListBox();
Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RepositoryService.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RepositoryService.java 2007-11-30 10:56:48 UTC (rev 16934)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RepositoryService.java 2007-11-30 10:57:51 UTC (rev 16935)
@@ -18,6 +18,7 @@
import org.drools.brms.client.modeldriven.SuggestionCompletionEngine;
+import org.drools.brms.client.modeldriven.testing.Scenario;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.SerializableException;
@@ -317,4 +318,13 @@
*/
public String[] listRulesInPackage(String packageName) throws SerializableException;
+ /**
+ *
+ * @param packageName The package name the scenario is to be run in.
+ * @param scenario The scenario to run.
+ * @return The scenario, with the results fields populated.
+ * @throws SerializableException
+ */
+ public ScenarioRunResult runScenario(String packageUUID, Scenario scenario) throws SerializableException;
+
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RepositoryServiceAsync.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RepositoryServiceAsync.java 2007-11-30 10:56:48 UTC (rev 16934)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RepositoryServiceAsync.java 2007-11-30 10:57:51 UTC (rev 16935)
@@ -32,47 +32,48 @@
extends
RemoteService {
- /** Generated by AsyncInterfaceGenerator hackery */
- public void loadChildCategories(java.lang.String p0, AsyncCallback cb);
- public void loadRuleListForCategories(java.lang.String p0, AsyncCallback cb);
- public void loadTableConfig(java.lang.String p0, AsyncCallback cb);
- public void createCategory(java.lang.String p0, java.lang.String p1, java.lang.String p2, AsyncCallback cb);
- public void createNewRule(java.lang.String p0, java.lang.String p1, java.lang.String p2, java.lang.String p3, java.lang.String p4, AsyncCallback cb);
- public void deleteUncheckedRule(java.lang.String p0, java.lang.String p1, AsyncCallback cb);
- public void exportRepository(AsyncCallback cb);
- public void clearRulesRepository(AsyncCallback cb);
- public void listPackages(AsyncCallback cb);
- public void loadRuleAsset(java.lang.String p0, AsyncCallback cb);
- public void loadAssetHistory(java.lang.String p0, AsyncCallback cb);
- public void loadArchivedAssets(AsyncCallback cb);
- public void checkinVersion(org.drools.brms.client.rpc.RuleAsset p0, AsyncCallback cb);
- public void restoreVersion(java.lang.String p0, java.lang.String p1, java.lang.String p2, AsyncCallback cb);
- public void createPackage(java.lang.String p0, java.lang.String p1, AsyncCallback cb);
- public void loadPackageConfig(java.lang.String p0, AsyncCallback cb);
- public void savePackage(org.drools.brms.client.rpc.PackageConfigData p0, AsyncCallback cb);
- public void listAssets(java.lang.String p0, String[] p1, int p2, int p3, AsyncCallback cb);
- public void listStates(AsyncCallback cb);
- public void createState(java.lang.String p0, AsyncCallback cb);
- public void changeState(java.lang.String p0, java.lang.String p1, boolean p2, AsyncCallback cb);
- public void changeAssetPackage(java.lang.String p0, java.lang.String p1, java.lang.String p2, AsyncCallback cb);
- public void copyAsset(java.lang.String p0, java.lang.String p1, java.lang.String p2, AsyncCallback cb);
- public void copyPackage(java.lang.String p0, java.lang.String p1, AsyncCallback cb);
- public void listSnapshots(java.lang.String p0, AsyncCallback cb);
- public void createPackageSnapshot(java.lang.String p0, java.lang.String p1, boolean p2, java.lang.String p3, AsyncCallback cb);
- public void copyOrRemoveSnapshot(java.lang.String p0, java.lang.String p1, boolean p2, java.lang.String p3, AsyncCallback cb);
- public void quickFindAsset(java.lang.String p0, int p1, boolean p2, AsyncCallback cb);
- public void removeCategory(java.lang.String p0, AsyncCallback cb);
- public void loadSuggestionCompletionEngine(java.lang.String p0, AsyncCallback cb);
- public void buildPackage(java.lang.String p0, java.lang.String p1, boolean p2, AsyncCallback cb);
- public void buildPackageSource(java.lang.String p0, AsyncCallback cb);
- public void buildAssetSource(org.drools.brms.client.rpc.RuleAsset p0, AsyncCallback cb);
- public void buildAsset(org.drools.brms.client.rpc.RuleAsset p0, AsyncCallback cb);
- public void renameAsset(java.lang.String p0, java.lang.String p1, AsyncCallback cb);
- public void archiveAsset(java.lang.String p0, boolean p1, AsyncCallback cb);
- public void removeAsset(java.lang.String p0, AsyncCallback cb);
- public void renamePackage(java.lang.String p0, java.lang.String p1, AsyncCallback cb);
- public void rebuildSnapshots(AsyncCallback cb);
- public void listRulesInPackage(java.lang.String p0, AsyncCallback cb);
+ /** Generated by AsyncInterfaceGenerator hackery */
+ public void loadChildCategories(java.lang.String p0, AsyncCallback cb);
+ public void loadRuleListForCategories(java.lang.String p0, AsyncCallback cb);
+ public void loadTableConfig(java.lang.String p0, AsyncCallback cb);
+ public void createCategory(java.lang.String p0, java.lang.String p1, java.lang.String p2, AsyncCallback cb);
+ public void createNewRule(java.lang.String p0, java.lang.String p1, java.lang.String p2, java.lang.String p3, java.lang.String p4, AsyncCallback cb);
+ public void deleteUncheckedRule(java.lang.String p0, java.lang.String p1, AsyncCallback cb);
+ public void exportRepository(AsyncCallback cb);
+ public void clearRulesRepository(AsyncCallback cb);
+ public void listPackages(AsyncCallback cb);
+ public void loadRuleAsset(java.lang.String p0, AsyncCallback cb);
+ public void loadAssetHistory(java.lang.String p0, AsyncCallback cb);
+ public void loadArchivedAssets(AsyncCallback cb);
+ public void checkinVersion(org.drools.brms.client.rpc.RuleAsset p0, AsyncCallback cb);
+ public void restoreVersion(java.lang.String p0, java.lang.String p1, java.lang.String p2, AsyncCallback cb);
+ public void createPackage(java.lang.String p0, java.lang.String p1, AsyncCallback cb);
+ public void loadPackageConfig(java.lang.String p0, AsyncCallback cb);
+ public void savePackage(org.drools.brms.client.rpc.PackageConfigData p0, AsyncCallback cb);
+ public void listAssets(java.lang.String p0, String[] p1, int p2, int p3, AsyncCallback cb);
+ public void listStates(AsyncCallback cb);
+ public void createState(java.lang.String p0, AsyncCallback cb);
+ public void changeState(java.lang.String p0, java.lang.String p1, boolean p2, AsyncCallback cb);
+ public void changeAssetPackage(java.lang.String p0, java.lang.String p1, java.lang.String p2, AsyncCallback cb);
+ public void copyAsset(java.lang.String p0, java.lang.String p1, java.lang.String p2, AsyncCallback cb);
+ public void copyPackage(java.lang.String p0, java.lang.String p1, AsyncCallback cb);
+ public void listSnapshots(java.lang.String p0, AsyncCallback cb);
+ public void createPackageSnapshot(java.lang.String p0, java.lang.String p1, boolean p2, java.lang.String p3, AsyncCallback cb);
+ public void copyOrRemoveSnapshot(java.lang.String p0, java.lang.String p1, boolean p2, java.lang.String p3, AsyncCallback cb);
+ public void quickFindAsset(java.lang.String p0, int p1, boolean p2, AsyncCallback cb);
+ public void removeCategory(java.lang.String p0, AsyncCallback cb);
+ public void loadSuggestionCompletionEngine(java.lang.String p0, AsyncCallback cb);
+ public void buildPackage(java.lang.String p0, java.lang.String p1, boolean p2, AsyncCallback cb);
+ public void buildPackageSource(java.lang.String p0, AsyncCallback cb);
+ public void buildAssetSource(org.drools.brms.client.rpc.RuleAsset p0, AsyncCallback cb);
+ public void buildAsset(org.drools.brms.client.rpc.RuleAsset p0, AsyncCallback cb);
+ public void renameAsset(java.lang.String p0, java.lang.String p1, AsyncCallback cb);
+ public void archiveAsset(java.lang.String p0, boolean p1, AsyncCallback cb);
+ public void removeAsset(java.lang.String p0, AsyncCallback cb);
+ public void renamePackage(java.lang.String p0, java.lang.String p1, AsyncCallback cb);
+ public void rebuildSnapshots(AsyncCallback cb);
+ public void listRulesInPackage(java.lang.String p0, AsyncCallback cb);
+ public void runScenario(java.lang.String p0, org.drools.brms.client.modeldriven.testing.Scenario p1, AsyncCallback cb);
}
\ No newline at end of file
Added: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/ScenarioRunResult.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/ScenarioRunResult.java (rev 0)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/ScenarioRunResult.java 2007-11-30 10:57:51 UTC (rev 16935)
@@ -0,0 +1,25 @@
+package org.drools.brms.client.rpc;
+
+import org.drools.brms.client.modeldriven.testing.Scenario;
+
+import com.google.gwt.user.client.rpc.IsSerializable;
+
+/**
+ * This is essentially a "Either" class.
+ * It will either be a list of rule compiler errors (should it have to compile), or the scenario run results.
+ * @author Michael Neale
+ */
+public class ScenarioRunResult implements IsSerializable {
+
+ public ScenarioRunResult() {}
+
+
+ public BuilderResult[] errors;
+ public Scenario scenario;
+ public ScenarioRunResult(BuilderResult[] errors, Scenario scenario) {
+
+ this.errors = errors;
+ this.scenario = scenario;
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/ScenarioRunResult.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/ServiceImplementation.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/ServiceImplementation.java 2007-11-30 10:56:48 UTC (rev 16934)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/ServiceImplementation.java 2007-11-30 10:57:51 UTC (rev 16935)
@@ -27,20 +27,21 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.jar.JarInputStream;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.jcr.ItemExistsException;
-import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
-import javax.jcr.ValueFormatException;
-import javax.jcr.lock.LockException;
-import javax.jcr.nodetype.ConstraintViolationException;
-import javax.jcr.version.VersionException;
import org.apache.log4j.Logger;
+import org.drools.RuleBase;
+import org.drools.RuleBaseFactory;
+import org.drools.base.ClassTypeResolver;
import org.drools.brms.client.common.AssetFormats;
import org.drools.brms.client.modeldriven.SuggestionCompletionEngine;
import org.drools.brms.client.modeldriven.testing.Scenario;
@@ -50,6 +51,7 @@
import org.drools.brms.client.rpc.PackageConfigData;
import org.drools.brms.client.rpc.RepositoryService;
import org.drools.brms.client.rpc.RuleAsset;
+import org.drools.brms.client.rpc.ScenarioRunResult;
import org.drools.brms.client.rpc.SnapshotInfo;
import org.drools.brms.client.rpc.TableConfig;
import org.drools.brms.client.rpc.TableDataResult;
@@ -64,6 +66,8 @@
import org.drools.brms.server.util.BRMSSuggestionCompletionLoader;
import org.drools.brms.server.util.MetaDataMapper;
import org.drools.brms.server.util.TableDisplayHandler;
+import org.drools.common.DroolsObjectInputStream;
+import org.drools.common.InternalWorkingMemory;
import org.drools.compiler.DrlParser;
import org.drools.compiler.DroolsParserException;
import org.drools.compiler.PackageBuilderConfiguration;
@@ -79,6 +83,7 @@
import org.drools.repository.RulesRepositoryException;
import org.drools.repository.StateItem;
import org.drools.repository.VersionableItem;
+import org.drools.rule.Package;
import org.drools.testframework.ScenarioRunner;
import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.In;
@@ -108,6 +113,9 @@
private static final Logger log = Logger.getLogger( ServiceImplementation.class );
private MetaDataMapper metaDataMapper = new MetaDataMapper();
+ /** Used for a simple cache of binary packages to avoid serialization from the database */
+ static Map<String, RuleBase> ruleBaseCache = Collections.synchronizedMap(new HashMap<String, RuleBase>());
+
@WebRemote
@Restrict("#{identity.loggedIn}")
public String[] loadChildCategories(String categoryPath) {
@@ -377,7 +385,9 @@
if (!(asset.metaData.format.equals(AssetFormats.TEST_SCENARIO))
||
asset.metaData.format.equals(AssetFormats.ENUMERATION)) {
- repoAsset.getPackage().updateBinaryUpToDate(false);
+ PackageItem pkg = repoAsset.getPackage();
+ pkg.updateBinaryUpToDate(false);
+ this.ruleBaseCache.remove(pkg.getUUID());
}
@@ -549,6 +559,7 @@
item.updateDescription( data.description );
item.archiveItem( data.archived );
item.updateBinaryUpToDate(false);
+ this.ruleBaseCache.remove(data.uuid);
item.checkin( data.description );
BRMSSuggestionCompletionLoader loader = new BRMSSuggestionCompletionLoader();
@@ -822,12 +833,11 @@
out.flush();
out.close();
- item.updateBinaryUpToDate(true);
-
+ updateBinaryPackage(packageUUID, item, asm);
repository.save();
- } catch (IOException e) {
+ } catch (Exception e) {
log.error( e );
- throw new SerializableException(e.getMessage());
+ throw new DetailedSerializableException("An error occurred building the package.", e.getMessage());
}
@@ -836,8 +846,16 @@
}
}
+ private void updateBinaryPackage(String packageUUID, PackageItem item,
+ ContentPackageAssembler asm) throws Exception {
+ item.updateBinaryUpToDate(true);
+ RuleBase rb = RuleBaseFactory.newRuleBase();
+ rb.addPackage(asm.getBinaryPackage());
+ this.ruleBaseCache.put(packageUUID, rb);
+ }
+
private BuilderResult[] generateBuilderResults(ContentPackageAssembler asm) {
BuilderResult[] result = new BuilderResult[asm.getErrors().size()];
for ( int i = 0; i < result.length; i++ ) {
@@ -1007,9 +1025,66 @@
}
}
+ @WebRemote
+ @Restrict("#{identity.loggedIn}")
+ public ScenarioRunResult runScenario(String packageUUID, Scenario scenario)
+ throws SerializableException {
+ PackageItem item = this.repository.loadPackageByUUID(packageUUID);
+ if (item.isBinaryUpToDate() && this.ruleBaseCache.containsKey(packageUUID)) {
+ return runScenario(packageUUID, scenario, item);
+ } else {
+ //we have to build the package, and try again.
+ if (item.isBinaryUpToDate()) {
+ this.ruleBaseCache.put(packageUUID, loadRuleBase(item));
+ return runScenario(packageUUID, scenario, item);
+ } else {
+ BuilderResult[] errs = this.buildPackage(packageUUID, null, false);
+ if (errs == null || errs.length == 0) {
+ this.ruleBaseCache.put(packageUUID, loadRuleBase(item));
+ return runScenario(packageUUID, scenario, item);
+ } else {
+ return new ScenarioRunResult(errs, null);
+ }
+ }
+ }
+ }
+ private RuleBase loadRuleBase(PackageItem item) throws DetailedSerializableException {
+ try {
+ RuleBase rb = RuleBaseFactory.newRuleBase();
+ DroolsObjectInputStream in = new DroolsObjectInputStream(new ByteArrayInputStream(item.getCompiledPackageBytes()));
+ Package bin = (Package) in.readObject();
+ in.close();
+ rb.addPackage(bin);
+ return rb;
+ } catch (ClassNotFoundException e) {
+ log.error(e);
+ throw new DetailedSerializableException("A required class was not found.", e.getMessage());
+ } catch (Exception e) {
+ log.error(e);
+ throw new DetailedSerializableException("Unable to load a rulebase.", e.getMessage());
+ }
+ }
+ private ScenarioRunResult runScenario(String packageUUID,
+ Scenario scenario, PackageItem item)
+ throws DetailedSerializableException {
+ RuleBase rb = ruleBaseCache.get(packageUUID);
+ Package bin = rb.getPackages()[0];
+ List<JarInputStream> jars = BRMSPackageBuilder.getJars(item);
+ ClassTypeResolver res = new ClassTypeResolver(bin.getImports(), BRMSPackageBuilder.createClassLoader(jars));
+ try {
+ new ScenarioRunner(scenario, res, (InternalWorkingMemory) rb.newStatefulSession());
+ return new ScenarioRunResult(null, scenario);
+ } catch (ClassNotFoundException e) {
+ log.error(e);
+ throw new DetailedSerializableException("Unable to load a required class.", e.getMessage());
+ }
+ }
+
+
+
}
\ No newline at end of file
Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/builder/BRMSPackageBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/builder/BRMSPackageBuilder.java 2007-11-30 10:56:48 UTC (rev 16934)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/builder/BRMSPackageBuilder.java 2007-11-30 10:57:51 UTC (rev 16935)
@@ -61,7 +61,33 @@
* using the given classpath.
*/
public static BRMSPackageBuilder getInstance(List<JarInputStream> classpath) {
- ClassLoader parentClassLoader = Thread.currentThread().getContextClassLoader();
+ MapBackedClassLoader loader = createClassLoader(classpath);
+
+
+ // See if we can find a packagebuilder.conf
+ // We do this manually here, as we cannot rely on PackageBuilder doing this correctly
+ // note this chainedProperties already checks System properties too
+ ChainedProperties chainedProperties = new ChainedProperties( BRMSPackageBuilder.class.getClassLoader(), // pass this as it searches currentThread anyway
+ "packagebuilder.conf",
+ false ); // false means it ignores any default values
+
+ // the default compiler. This is nominally JANINO but can be overridden by setting drools.dialect.java.compiler to ECLIPSE
+ Properties properties = new Properties();
+ properties.setProperty( "drools.dialect.java.compiler",
+ chainedProperties.getProperty( "drools.dialect.java.compiler", "JANINO" ) );
+ PackageBuilderConfiguration pkgConf = new PackageBuilderConfiguration( properties );
+ pkgConf.setClassLoader( loader );
+
+ return new BRMSPackageBuilder( pkgConf );
+
+ }
+
+ /**
+ * For a given list of Jars, create a class loader.
+ */
+ public static MapBackedClassLoader createClassLoader(
+ List<JarInputStream> classpath) {
+ ClassLoader parentClassLoader = Thread.currentThread().getContextClassLoader();
if ( parentClassLoader == null ) {
parentClassLoader = BRMSPackageBuilder.class.getClassLoader();
}
@@ -97,26 +123,9 @@
} catch ( IOException e ) {
throw new RulesRepositoryException( e );
}
+ return loader;
+ }
-
- // See if we can find a packagebuilder.conf
- // We do this manually here, as we cannot rely on PackageBuilder doing this correctly
- // note this chainedProperties already checks System properties too
- ChainedProperties chainedProperties = new ChainedProperties( BRMSPackageBuilder.class.getClassLoader(), // pass this as it searches currentThread anyway
- "packagebuilder.conf",
- false ); // false means it ignores any default values
-
- // the default compiler. This is nominally JANINO but can be overridden by setting drools.dialect.java.compiler to ECLIPSE
- Properties properties = new Properties();
- properties.setProperty( "drools.dialect.java.compiler",
- chainedProperties.getProperty( "drools.dialect.java.compiler", "JANINO" ) );
- PackageBuilderConfiguration pkgConf = new PackageBuilderConfiguration( properties );
- pkgConf.setClassLoader( loader );
-
- return new BRMSPackageBuilder( pkgConf );
-
- }
-
/**
* This will return the preferred compiler, according to the System property
* drools.compiler (JANINO|ECLIPSE) - default is JANINO due to classpath issues
Added: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/builder/ScenarioAssembler.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/builder/ScenarioAssembler.java (rev 0)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/builder/ScenarioAssembler.java 2007-11-30 10:57:51 UTC (rev 16935)
@@ -0,0 +1,29 @@
+package org.drools.brms.server.builder;
+
+import java.util.List;
+import java.util.jar.JarInputStream;
+
+import org.drools.RuleBase;
+import org.drools.RuleBaseFactory;
+import org.drools.base.ClassTypeResolver;
+import org.drools.brms.client.modeldriven.testing.Scenario;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.repository.PackageItem;
+import org.drools.rule.Package;
+import org.drools.testframework.ScenarioRunner;
+
+public class ScenarioAssembler {
+
+
+ public ScenarioAssembler(PackageItem item, Package pkg, Scenario sc) {
+ List<JarInputStream> jars = BRMSPackageBuilder.getJars(item);
+ ClassTypeResolver res = new ClassTypeResolver(pkg.getImports(), BRMSPackageBuilder.createClassLoader(jars));
+
+// RuleBase rb = RuleBaseFactory.newRuleBase();
+// rb.addPackage(pkg);
+// InternalWorkingMemory iwm = (InternalWorkingMemory) rb.newStatefulSession();
+//
+// ScenarioRunner runner = new ScenarioRunner(sc, res, iwm);
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/builder/ScenarioAssembler.java
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: labs/jbossrules/trunk/drools-jbrms/src/test/java/org/drools/brms/server/ServiceImplementationTest.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/test/java/org/drools/brms/server/ServiceImplementationTest.java 2007-11-30 10:56:48 UTC (rev 16934)
+++ labs/jbossrules/trunk/drools-jbrms/src/test/java/org/drools/brms/server/ServiceImplementationTest.java 2007-11-30 10:57:51 UTC (rev 16935)
@@ -38,12 +38,20 @@
import org.drools.brms.client.modeldriven.brl.ISingleFieldConstraint;
import org.drools.brms.client.modeldriven.brl.RuleModel;
import org.drools.brms.client.modeldriven.brl.SingleFieldConstraint;
+import org.drools.brms.client.modeldriven.testing.ExecutionTrace;
+import org.drools.brms.client.modeldriven.testing.FactData;
+import org.drools.brms.client.modeldriven.testing.FieldData;
+import org.drools.brms.client.modeldriven.testing.Scenario;
+import org.drools.brms.client.modeldriven.testing.VerifyFact;
+import org.drools.brms.client.modeldriven.testing.VerifyField;
+import org.drools.brms.client.modeldriven.testing.VerifyRuleFired;
import org.drools.brms.client.rpc.BuilderResult;
import org.drools.brms.client.rpc.DetailedSerializableException;
import org.drools.brms.client.rpc.PackageConfigData;
import org.drools.brms.client.rpc.RepositoryService;
import org.drools.brms.client.rpc.RuleAsset;
import org.drools.brms.client.rpc.RuleContentText;
+import org.drools.brms.client.rpc.ScenarioRunResult;
import org.drools.brms.client.rpc.SnapshotInfo;
import org.drools.brms.client.rpc.TableConfig;
import org.drools.brms.client.rpc.TableDataResult;
@@ -66,1685 +74,1433 @@
public class ServiceImplementationTest extends TestCase {
- public void testCategory() throws Exception {
- //ServiceImpl impl = new ServiceImpl(new RulesRepository(SessionHelper.getSession()));
+ public void testCategory() throws Exception {
+ // ServiceImpl impl = new ServiceImpl(new
+ // RulesRepository(SessionHelper.getSession()));
- RepositoryService impl = getService();
+ RepositoryService impl = getService();
- String[] originalCats = impl.loadChildCategories( "/" );
+ String[] originalCats = impl.loadChildCategories("/");
- Boolean result = impl.createCategory( "/",
- "TopLevel1",
- "a description" );
- assertTrue( result.booleanValue() );
+ Boolean result = impl.createCategory("/", "TopLevel1", "a description");
+ assertTrue(result.booleanValue());
- result = impl.createCategory( "/",
- "TopLevel2",
- "a description" );
- assertTrue( result.booleanValue() );
+ result = impl.createCategory("/", "TopLevel2", "a description");
+ assertTrue(result.booleanValue());
- String[] cats = impl.loadChildCategories( "/" );
- assertTrue( cats.length == originalCats.length + 2 );
+ String[] cats = impl.loadChildCategories("/");
+ assertTrue(cats.length == originalCats.length + 2);
- result = impl.createCategory( "",
- "Top3",
- "description" );
- assertTrue( result.booleanValue() );
+ result = impl.createCategory("", "Top3", "description");
+ assertTrue(result.booleanValue());
- result = impl.createCategory( null,
- "Top4",
- "description" );
- assertTrue( result.booleanValue() );
+ result = impl.createCategory(null, "Top4", "description");
+ assertTrue(result.booleanValue());
- }
+ }
- public void testDeleteUnversionedRule() throws Exception {
- ServiceImplementation impl = getService();
+ public void testDeleteUnversionedRule() throws Exception {
+ ServiceImplementation impl = getService();
- impl.repository.loadDefaultPackage();
- impl.repository.createPackage( "anotherPackage",
- "woot" );
+ impl.repository.loadDefaultPackage();
+ impl.repository.createPackage("anotherPackage", "woot");
- CategoryItem cat = impl.repository.loadCategory( "/" );
- cat.addCategory( "testDeleteUnversioned",
- "yeah" );
+ CategoryItem cat = impl.repository.loadCategory("/");
+ cat.addCategory("testDeleteUnversioned", "yeah");
- String uuid = impl.createNewRule( "test Delete Unversioned",
- "a description",
- "testDeleteUnversioned",
- "anotherPackage",
- "txt" );
- assertNotNull( uuid );
- assertFalse( "".equals( uuid ) );
+ String uuid = impl.createNewRule("test Delete Unversioned",
+ "a description", "testDeleteUnversioned", "anotherPackage",
+ "txt");
+ assertNotNull(uuid);
+ assertFalse("".equals(uuid));
- AssetItem localItem = impl.repository.loadAssetByUUID( uuid );
+ AssetItem localItem = impl.repository.loadAssetByUUID(uuid);
-// String drl = "package org.drools.repository\n\ndialect 'mvel'\n\n" +
-// "rule Rule1 \n when \n AssetItem(description != null) \n then \n System.out.println(\"yeah\");\nend";
-// RuleBase rb = RuleBaseLoader.getInstance().loadFromReader(new StringReader(drl));
-// rb.newStatelessSession().execute(localItem);
+ // String drl = "package org.drools.repository\n\ndialect 'mvel'\n\n" +
+ // "rule Rule1 \n when \n AssetItem(description != null) \n then \n
+ // System.out.println(\"yeah\");\nend";
+ // RuleBase rb = RuleBaseLoader.getInstance().loadFromReader(new
+ // StringReader(drl));
+ // rb.newStatelessSession().execute(localItem);
- assertEquals( "test Delete Unversioned",
- localItem.getName() );
+ assertEquals("test Delete Unversioned", localItem.getName());
- localItem.remove();
- impl.repository.save();
+ localItem.remove();
+ impl.repository.save();
- try {
- localItem = impl.repository.loadAssetByUUID( uuid );
- fail();
- } catch ( Exception e ) {
- }
- }
+ try {
+ localItem = impl.repository.loadAssetByUUID(uuid);
+ fail();
+ } catch (Exception e) {
+ }
+ }
- public void testAddRuleAndListPackages() throws Exception {
- //ServiceImpl impl = new ServiceImpl(new RulesRepository(SessionHelper.getSession()));
+ public void testAddRuleAndListPackages() throws Exception {
+ // ServiceImpl impl = new ServiceImpl(new
+ // RulesRepository(SessionHelper.getSession()));
- ServiceImplementation impl = getService();
+ ServiceImplementation impl = getService();
- impl.repository.loadDefaultPackage();
- impl.repository.createPackage( "another",
- "woot" );
+ impl.repository.loadDefaultPackage();
+ impl.repository.createPackage("another", "woot");
- CategoryItem cat = impl.repository.loadCategory( "/" );
- cat.addCategory( "testAddRule",
- "yeah" );
+ CategoryItem cat = impl.repository.loadCategory("/");
+ cat.addCategory("testAddRule", "yeah");
- String result = impl.createNewRule( "test AddRule",
- "a description",
- "testAddRule",
- "another",
- "txt" );
- assertNotNull( result );
- assertFalse( "".equals( result ) );
+ String result = impl.createNewRule("test AddRule", "a description",
+ "testAddRule", "another", "txt");
+ assertNotNull(result);
+ assertFalse("".equals(result));
- PackageConfigData[] packages = impl.listPackages();
- assertTrue( packages.length > 0 );
+ PackageConfigData[] packages = impl.listPackages();
+ assertTrue(packages.length > 0);
- boolean found = false;
- for ( int i = 0; i < packages.length; i++ ) {
- if ( packages[i].name.equals( "another" ) ) {
- found = true;
- }
- }
+ boolean found = false;
+ for (int i = 0; i < packages.length; i++) {
+ if (packages[i].name.equals("another")) {
+ found = true;
+ }
+ }
- assertTrue( found );
+ assertTrue(found);
- assertFalse( packages[0].uuid == null );
- assertFalse( packages[0].uuid.equals( "" ) );
+ assertFalse(packages[0].uuid == null);
+ assertFalse(packages[0].uuid.equals(""));
- //just for performance testing with scaling up numbers of rules
- // for (int i=1; i <= 1000; i++) {
- // impl.createNewRule( "somerule_" + i, "description",
- // "testAddRule", "another", "drl" );
- // }
+ // just for performance testing with scaling up numbers of rules
+ // for (int i=1; i <= 1000; i++) {
+ // impl.createNewRule( "somerule_" + i, "description",
+ // "testAddRule", "another", "drl" );
+ // }
- result = impl.createNewRule( "testDTSample",
- "a description",
- "testAddRule",
- "another",
- AssetFormats.DECISION_SPREADSHEET_XLS );
- AssetItem dtItem = impl.repository.loadAssetByUUID( result );
- assertNotNull( dtItem.getBinaryContentAsBytes() );
- assertTrue( dtItem.getBinaryContentAttachmentFileName().endsWith( ".xls" ) );
- }
+ result = impl
+ .createNewRule("testDTSample", "a description", "testAddRule",
+ "another", AssetFormats.DECISION_SPREADSHEET_XLS);
+ AssetItem dtItem = impl.repository.loadAssetByUUID(result);
+ assertNotNull(dtItem.getBinaryContentAsBytes());
+ assertTrue(dtItem.getBinaryContentAttachmentFileName().endsWith(".xls"));
+ }
- public void testAttemptDupeRule() throws Exception {
- ServiceImplementation impl = getService();
- CategoryItem cat = impl.repository.loadCategory( "/" );
- cat.addCategory( "testAttemptDupeRule",
- "yeah" );
+ public void testAttemptDupeRule() throws Exception {
+ ServiceImplementation impl = getService();
+ CategoryItem cat = impl.repository.loadCategory("/");
+ cat.addCategory("testAttemptDupeRule", "yeah");
- impl.repository.createPackage( "dupes",
- "yeah" );
+ impl.repository.createPackage("dupes", "yeah");
- impl.createNewRule( "testAttemptDupeRule",
- "ya",
- "testAttemptDupeRule",
- "dupes",
- "rule" );
+ impl.createNewRule("testAttemptDupeRule", "ya", "testAttemptDupeRule",
+ "dupes", "rule");
+ String uuid = impl.createNewRule("testAttemptDupeRule", "ya",
+ "testAttemptDupeRule", "dupes", "rule");
+ assertEquals("DUPLICATE", uuid);
- String uuid = impl.createNewRule( "testAttemptDupeRule",
- "ya",
- "testAttemptDupeRule",
- "dupes",
- "rule" );
- assertEquals("DUPLICATE", uuid);
+ }
- }
+ public void testRuleTableLoad() throws Exception {
+ ServiceImplementation impl = getService();
+ TableConfig conf = impl
+ .loadTableConfig(TableDisplayHandler.DEFAULT_TABLE_TEMPLATE);
+ assertNotNull(conf.headers);
- public void testRuleTableLoad() throws Exception {
- ServiceImplementation impl = getService();
- TableConfig conf = impl.loadTableConfig( TableDisplayHandler.DEFAULT_TABLE_TEMPLATE );
- assertNotNull( conf.headers );
+ CategoryItem cat = impl.repository.loadCategory("/");
+ cat.addCategory("testRuleTableLoad", "yeah");
- CategoryItem cat = impl.repository.loadCategory( "/" );
- cat.addCategory( "testRuleTableLoad",
- "yeah" );
+ impl.repository.createPackage("testRuleTableLoad", "yeah");
+ impl.createNewRule("testRuleTableLoad", "ya", "testRuleTableLoad",
+ "testRuleTableLoad", "rule");
+ impl.createNewRule("testRuleTableLoad2", "ya", "testRuleTableLoad",
+ "testRuleTableLoad", "rule");
- impl.repository.createPackage( "testRuleTableLoad",
- "yeah" );
- impl.createNewRule( "testRuleTableLoad",
- "ya",
- "testRuleTableLoad",
- "testRuleTableLoad",
- "rule" );
- impl.createNewRule( "testRuleTableLoad2",
- "ya",
- "testRuleTableLoad",
- "testRuleTableLoad",
- "rule" );
+ TableDataResult result = impl
+ .loadRuleListForCategories("testRuleTableLoad");
+ assertEquals(2, result.data.length);
- TableDataResult result = impl.loadRuleListForCategories( "testRuleTableLoad" );
- assertEquals( 2,
- result.data.length );
+ String key = result.data[0].id;
+ assertFalse(key.startsWith("testRule"));
- String key = result.data[0].id;
- assertFalse( key.startsWith( "testRule" ) );
+ assertEquals(result.data[0].format, "rule");
+ assertTrue(result.data[0].values[0].startsWith("rule"));
+ }
- assertEquals( result.data[0].format,
- "rule" );
- assertTrue( result.data[0].values[0].startsWith( "rule" ) );
- }
+ public void testDateFormatting() throws Exception {
+ Calendar cal = Calendar.getInstance();
+ TableDisplayHandler handler = new TableDisplayHandler(
+ TableDisplayHandler.DEFAULT_TABLE_TEMPLATE);
+ String fmt = handler.formatDate(cal);
+ assertNotNull(fmt);
- public void testDateFormatting() throws Exception {
- Calendar cal = Calendar.getInstance();
- TableDisplayHandler handler = new TableDisplayHandler( TableDisplayHandler.DEFAULT_TABLE_TEMPLATE );
- String fmt = handler.formatDate( cal );
- assertNotNull( fmt );
+ assertTrue(fmt.length() > 8);
+ }
- assertTrue( fmt.length() > 8 );
- }
+ public void testLoadRuleAsset() throws Exception {
+ ServiceImplementation impl = getService();
+ impl.repository.createPackage("testLoadRuleAsset", "desc");
+ impl.createCategory("", "testLoadRuleAsset", "this is a cat");
- public void testLoadRuleAsset() throws Exception {
- ServiceImplementation impl = getService();
- impl.repository.createPackage( "testLoadRuleAsset",
- "desc" );
- impl.createCategory( "",
- "testLoadRuleAsset",
- "this is a cat" );
+ impl.createNewRule("testLoadRuleAsset", "description",
+ "testLoadRuleAsset", "testLoadRuleAsset", "drl");
- impl.createNewRule( "testLoadRuleAsset",
- "description",
- "testLoadRuleAsset",
- "testLoadRuleAsset",
- "drl" );
+ TableDataResult res = impl
+ .loadRuleListForCategories("testLoadRuleAsset");
+ assertEquals(1, res.data.length);
- TableDataResult res = impl.loadRuleListForCategories( "testLoadRuleAsset" );
- assertEquals( 1,
- res.data.length );
+ TableDataRow row = res.data[0];
+ String uuid = row.id;
- TableDataRow row = res.data[0];
- String uuid = row.id;
+ RuleAsset asset = impl.loadRuleAsset(uuid);
+ assertNotNull(asset);
- RuleAsset asset = impl.loadRuleAsset( uuid );
- assertNotNull( asset );
+ assertEquals(uuid, asset.uuid);
- assertEquals( uuid,
- asset.uuid );
+ assertEquals("description", asset.metaData.description);
- assertEquals( "description",
- asset.metaData.description );
+ assertNotNull(asset.content);
+ assertTrue(asset.content instanceof RuleContentText);
+ assertEquals("testLoadRuleAsset", asset.metaData.name);
+ assertEquals("testLoadRuleAsset", asset.metaData.title);
+ assertEquals("testLoadRuleAsset", asset.metaData.packageName);
+ assertEquals("drl", asset.metaData.format);
+ assertNotNull(asset.metaData.createdDate);
- assertNotNull( asset.content );
- assertTrue( asset.content instanceof RuleContentText );
- assertEquals( "testLoadRuleAsset",
- asset.metaData.name );
- assertEquals( "testLoadRuleAsset",
- asset.metaData.title );
- assertEquals( "testLoadRuleAsset",
- asset.metaData.packageName );
- assertEquals( "drl",
- asset.metaData.format );
- assertNotNull( asset.metaData.createdDate );
+ assertEquals(1, asset.metaData.categories.length);
+ assertEquals("testLoadRuleAsset", asset.metaData.categories[0]);
- assertEquals( 1,
- asset.metaData.categories.length );
- assertEquals( "testLoadRuleAsset",
- asset.metaData.categories[0] );
+ AssetItem rule = impl.repository.loadPackage("testLoadRuleAsset")
+ .loadAsset("testLoadRuleAsset");
+ impl.repository.createState("whee");
+ rule.updateState("whee");
+ rule.checkin("changed state");
+ asset = impl.loadRuleAsset(uuid);
- AssetItem rule = impl.repository.loadPackage( "testLoadRuleAsset" ).loadAsset( "testLoadRuleAsset" );
- impl.repository.createState( "whee" );
- rule.updateState( "whee" );
- rule.checkin( "changed state" );
- asset = impl.loadRuleAsset( uuid );
+ assertEquals("whee", asset.metaData.status);
+ assertEquals("changed state", asset.metaData.checkinComment);
- assertEquals( "whee",
- asset.metaData.status );
- assertEquals( "changed state",
- asset.metaData.checkinComment );
+ uuid = impl.createNewRule("testBRLFormatSugComp", "description",
+ "testLoadRuleAsset", "testLoadRuleAsset",
+ AssetFormats.BUSINESS_RULE);
+ asset = impl.loadRuleAsset(uuid);
+ assertTrue(asset.content instanceof RuleModel);
- uuid = impl.createNewRule( "testBRLFormatSugComp",
- "description",
- "testLoadRuleAsset",
- "testLoadRuleAsset",
- AssetFormats.BUSINESS_RULE );
- asset = impl.loadRuleAsset( uuid );
- assertTrue( asset.content instanceof RuleModel );
+ uuid = impl.createNewRule("testLoadRuleAssetBRL", "description",
+ "testLoadRuleAsset", "testLoadRuleAsset",
+ AssetFormats.DSL_TEMPLATE_RULE);
+ asset = impl.loadRuleAsset(uuid);
+ assertTrue(asset.content instanceof RuleContentText);
+ }
- uuid = impl.createNewRule( "testLoadRuleAssetBRL",
- "description",
- "testLoadRuleAsset",
- "testLoadRuleAsset",
- AssetFormats.DSL_TEMPLATE_RULE );
- asset = impl.loadRuleAsset( uuid );
- assertTrue( asset.content instanceof RuleContentText );
- }
+ public void testLoadAssetHistoryAndRestore() throws Exception {
+ ServiceImplementation impl = getService();
+ impl.repository.createPackage("testLoadAssetHistory", "desc");
+ impl.createCategory("", "testLoadAssetHistory", "this is a cat");
- public void testLoadAssetHistoryAndRestore() throws Exception {
- ServiceImplementation impl = getService();
- impl.repository.createPackage( "testLoadAssetHistory",
- "desc" );
- impl.createCategory( "",
- "testLoadAssetHistory",
- "this is a cat" );
+ String uuid = impl.createNewRule("testLoadAssetHistory", "description",
+ "testLoadAssetHistory", "testLoadAssetHistory", "drl");
+ RuleAsset asset = impl.loadRuleAsset(uuid);
+ impl.checkinVersion(asset); // 1
+ asset = impl.loadRuleAsset(uuid);
+ impl.checkinVersion(asset); // 2
+ asset = impl.loadRuleAsset(uuid);
+ impl.checkinVersion(asset); // HEAD
- String uuid = impl.createNewRule( "testLoadAssetHistory",
- "description",
- "testLoadAssetHistory",
- "testLoadAssetHistory",
- "drl" );
- RuleAsset asset = impl.loadRuleAsset( uuid );
- impl.checkinVersion( asset ); //1
- asset = impl.loadRuleAsset( uuid );
- impl.checkinVersion( asset ); //2
- asset = impl.loadRuleAsset( uuid );
- impl.checkinVersion( asset ); //HEAD
+ TableDataResult result = impl.loadAssetHistory(uuid);
+ assertNotNull(result);
+ TableDataRow[] rows = result.data;
+ assertEquals(2, rows.length);
+ assertFalse(rows[0].id.equals(uuid));
+ assertFalse(rows[1].id.equals(uuid));
- TableDataResult result = impl.loadAssetHistory( uuid );
- assertNotNull( result );
- TableDataRow[] rows = result.data;
- assertEquals( 2,
- rows.length );
- assertFalse( rows[0].id.equals( uuid ) );
- assertFalse( rows[1].id.equals( uuid ) );
+ RuleAsset old = impl.loadRuleAsset(rows[0].id);
+ RuleAsset newer = impl.loadRuleAsset(rows[1].id);
+ assertFalse(old.metaData.versionNumber == newer.metaData.versionNumber);
- RuleAsset old = impl.loadRuleAsset( rows[0].id );
- RuleAsset newer = impl.loadRuleAsset( rows[1].id );
- assertFalse( old.metaData.versionNumber == newer.metaData.versionNumber );
+ RuleAsset head = impl.loadRuleAsset(uuid);
- RuleAsset head = impl.loadRuleAsset( uuid );
+ long oldVersion = old.metaData.versionNumber;
+ assertFalse(oldVersion == head.metaData.versionNumber);
- long oldVersion = old.metaData.versionNumber;
- assertFalse( oldVersion == head.metaData.versionNumber );
+ impl.restoreVersion(old.uuid, head.uuid, "this was cause of a mistake");
- impl.restoreVersion( old.uuid,
- head.uuid,
- "this was cause of a mistake" );
+ RuleAsset newHead = impl.loadRuleAsset(uuid);
- RuleAsset newHead = impl.loadRuleAsset( uuid );
+ assertEquals("this was cause of a mistake",
+ newHead.metaData.checkinComment);
- assertEquals( "this was cause of a mistake",
- newHead.metaData.checkinComment );
+ }
- }
+ public void testCheckin() throws Exception {
+ RepositoryService serv = getService();
- public void testCheckin() throws Exception {
- RepositoryService serv = getService();
+ serv.listPackages();
- serv.listPackages();
+ serv
+ .createCategory("/", "testCheckinCategory",
+ "this is a description");
+ serv.createCategory("/", "testCheckinCategory2",
+ "this is a description");
+ serv.createCategory("testCheckinCategory", "deeper", "description");
- serv.createCategory( "/",
- "testCheckinCategory",
- "this is a description" );
- serv.createCategory( "/",
- "testCheckinCategory2",
- "this is a description" );
- serv.createCategory( "testCheckinCategory",
- "deeper",
- "description" );
+ String uuid = serv.createNewRule("testChecking",
+ "this is a description", "testCheckinCategory",
+ RulesRepository.DEFAULT_PACKAGE, "drl");
- String uuid = serv.createNewRule( "testChecking",
- "this is a description",
- "testCheckinCategory",
- RulesRepository.DEFAULT_PACKAGE,
- "drl" );
+ RuleAsset asset = serv.loadRuleAsset(uuid);
- RuleAsset asset = serv.loadRuleAsset( uuid );
+ assertNotNull(asset.metaData.lastModifiedDate);
- assertNotNull( asset.metaData.lastModifiedDate );
+ asset.metaData.coverage = "boo";
+ asset.content = new RuleContentText();
+ ((RuleContentText) asset.content).content = "yeah !";
- asset.metaData.coverage = "boo";
- asset.content = new RuleContentText();
- ((RuleContentText) asset.content).content = "yeah !";
+ Date start = new Date();
+ Thread.sleep(100);
- Date start = new Date();
- Thread.sleep( 100 );
+ String uuid2 = serv.checkinVersion(asset);
+ assertEquals(uuid, uuid2);
- String uuid2 = serv.checkinVersion( asset );
- assertEquals( uuid,
- uuid2 );
+ RuleAsset asset2 = serv.loadRuleAsset(uuid);
+ assertNotNull(asset2.metaData.lastModifiedDate);
+ assertTrue(asset2.metaData.lastModifiedDate.after(start));
- RuleAsset asset2 = serv.loadRuleAsset( uuid );
- assertNotNull( asset2.metaData.lastModifiedDate );
- assertTrue( asset2.metaData.lastModifiedDate.after( start ) );
+ assertEquals("boo", asset2.metaData.coverage);
+ assertEquals(1, asset2.metaData.versionNumber);
- assertEquals( "boo",
- asset2.metaData.coverage );
- assertEquals( 1,
- asset2.metaData.versionNumber );
+ assertEquals("yeah !", ((RuleContentText) asset2.content).content);
- assertEquals( "yeah !",
- ((RuleContentText) asset2.content).content );
+ asset2.metaData.coverage = "ya";
+ asset2.metaData.checkinComment = "checked in";
- asset2.metaData.coverage = "ya";
- asset2.metaData.checkinComment = "checked in";
+ String cat = asset2.metaData.categories[0];
+ asset2.metaData.categories = new String[3];
+ asset2.metaData.categories[0] = cat;
+ asset2.metaData.categories[1] = "testCheckinCategory2";
+ asset2.metaData.categories[2] = "testCheckinCategory/deeper";
- String cat = asset2.metaData.categories[0];
- asset2.metaData.categories = new String[3];
- asset2.metaData.categories[0] = cat;
- asset2.metaData.categories[1] = "testCheckinCategory2";
- asset2.metaData.categories[2] = "testCheckinCategory/deeper";
+ serv.checkinVersion(asset2);
- serv.checkinVersion( asset2 );
+ asset2 = serv.loadRuleAsset(uuid);
+ assertEquals("ya", asset2.metaData.coverage);
+ assertEquals(2, asset2.metaData.versionNumber);
+ assertEquals("checked in", asset2.metaData.checkinComment);
+ assertEquals(3, asset2.metaData.categories.length);
+ assertEquals("testCheckinCategory", asset2.metaData.categories[0]);
+ assertEquals("testCheckinCategory2", asset2.metaData.categories[1]);
+ assertEquals("testCheckinCategory/deeper",
+ asset2.metaData.categories[2]);
- asset2 = serv.loadRuleAsset( uuid );
- assertEquals( "ya",
- asset2.metaData.coverage );
- assertEquals( 2,
- asset2.metaData.versionNumber );
- assertEquals( "checked in",
- asset2.metaData.checkinComment );
- assertEquals( 3,
- asset2.metaData.categories.length );
- assertEquals( "testCheckinCategory",
- asset2.metaData.categories[0] );
- assertEquals( "testCheckinCategory2",
- asset2.metaData.categories[1] );
- assertEquals( "testCheckinCategory/deeper",
- asset2.metaData.categories[2] );
+ // now lets try a concurrent edit of an asset.
+ // asset3 will be loaded and edited, and then asset2 will try to
+ // clobber, it, which should fail.
+ // as it is optimistically locked.
+ RuleAsset asset3 = serv.loadRuleAsset(asset2.uuid);
+ asset3.metaData.subject = "new sub";
+ serv.checkinVersion(asset3);
- //now lets try a concurrent edit of an asset.
- //asset3 will be loaded and edited, and then asset2 will try to clobber, it, which should fail.
- //as it is optimistically locked.
- RuleAsset asset3 = serv.loadRuleAsset( asset2.uuid );
- asset3.metaData.subject = "new sub";
- serv.checkinVersion( asset3 );
+ asset3 = serv.loadRuleAsset(asset2.uuid);
+ assertFalse(asset3.metaData.versionNumber == asset2.metaData.versionNumber);
- asset3 = serv.loadRuleAsset( asset2.uuid );
- assertFalse( asset3.metaData.versionNumber == asset2.metaData.versionNumber );
+ String result = serv.checkinVersion(asset2);
+ assertTrue(result.startsWith("ERR"));
+ System.err.println(result.substring(5));
- String result = serv.checkinVersion( asset2 );
- assertTrue(result.startsWith("ERR"));
- System.err.println(result.substring(5));
+ }
+ public void testArchivePackage() throws Exception {
+ ServiceImplementation impl = getService();
- }
+ PackageConfigData[] pkgs = impl.listPackages();
- public void testArchivePackage() throws Exception {
- ServiceImplementation impl = getService();
+ String uuid = impl.createPackage("testCreateArchivedPackage",
+ "this is a new package");
+ PackageItem item = impl.repository
+ .loadPackage("testCreateArchivedPackage");
+ item.archiveItem(true);
+ assertEquals(pkgs.length, impl.listPackages().length);
+ }
- PackageConfigData[] pkgs = impl.listPackages();
+ public void testCreatePackage() throws Exception {
+ ServiceImplementation impl = getService();
+ PackageConfigData[] pkgs = impl.listPackages();
+ String uuid = impl.createPackage("testCreatePackage",
+ "this is a new package");
+ assertNotNull(uuid);
- String uuid = impl.createPackage( "testCreateArchivedPackage",
- "this is a new package" );
- PackageItem item = impl.repository.loadPackage( "testCreateArchivedPackage" );
- item.archiveItem( true );
- assertEquals( pkgs.length,
- impl.listPackages().length );
- }
+ PackageItem item = impl.repository.loadPackage("testCreatePackage");
+ assertNotNull(item);
+ assertEquals("this is a new package", item.getDescription());
- public void testCreatePackage() throws Exception {
- ServiceImplementation impl = getService();
- PackageConfigData[] pkgs = impl.listPackages();
- String uuid = impl.createPackage( "testCreatePackage",
- "this is a new package" );
- assertNotNull( uuid );
+ assertEquals(pkgs.length + 1, impl.listPackages().length);
- PackageItem item = impl.repository.loadPackage( "testCreatePackage" );
- assertNotNull( item );
- assertEquals( "this is a new package",
- item.getDescription() );
+ PackageConfigData conf = impl.loadPackageConfig(uuid);
+ assertEquals("this is a new package", conf.description);
+ assertNotNull(conf.lastModified);
- assertEquals( pkgs.length + 1,
- impl.listPackages().length );
+ pkgs = impl.listPackages();
- PackageConfigData conf = impl.loadPackageConfig( uuid );
- assertEquals( "this is a new package",
- conf.description );
- assertNotNull( conf.lastModified );
+ impl.copyPackage("testCreatePackage", "testCreatePackage_COPY");
- pkgs = impl.listPackages();
+ assertEquals(pkgs.length + 1, impl.listPackages().length);
+ try {
+ impl.copyPackage("testCreatePackage", "testCreatePackage_COPY");
+ } catch (RulesRepositoryException e) {
+ assertNotNull(e.getMessage());
+ }
+ }
- impl.copyPackage( "testCreatePackage",
- "testCreatePackage_COPY" );
+ public void testLoadPackageConfig() throws Exception {
+ ServiceImplementation impl = getService();
+ PackageItem it = impl.repository.loadDefaultPackage();
+ String uuid = it.getUUID();
+ it.updateCoverage("xyz");
+ it.updateExternalURI("ext");
+ it.updateHeader("header");
+ impl.repository.save();
- assertEquals( pkgs.length + 1,
- impl.listPackages().length );
- try {
- impl.copyPackage( "testCreatePackage",
- "testCreatePackage_COPY" );
- } catch ( RulesRepositoryException e ) {
- assertNotNull( e.getMessage() );
- }
- }
+ PackageConfigData data = impl.loadPackageConfig(uuid);
+ assertNotNull(data);
- public void testLoadPackageConfig() throws Exception {
- ServiceImplementation impl = getService();
- PackageItem it = impl.repository.loadDefaultPackage();
- String uuid = it.getUUID();
- it.updateCoverage( "xyz" );
- it.updateExternalURI( "ext" );
- it.updateHeader( "header" );
- impl.repository.save();
+ assertEquals(RulesRepository.DEFAULT_PACKAGE, data.name);
+ assertEquals("header", data.header);
+ assertEquals("ext", data.externalURI);
- PackageConfigData data = impl.loadPackageConfig( uuid );
- assertNotNull( data );
+ assertNotNull(data.uuid);
+ assertFalse(data.isSnapshot);
- assertEquals( RulesRepository.DEFAULT_PACKAGE,
- data.name );
- assertEquals( "header",
- data.header );
- assertEquals( "ext",
- data.externalURI );
+ assertNotNull(data.dateCreated);
+ Date original = data.lastModified;
- assertNotNull( data.uuid );
- assertFalse( data.isSnapshot );
+ Thread.sleep(100);
- assertNotNull( data.dateCreated );
- Date original = data.lastModified;
+ impl.createPackageSnapshot(RulesRepository.DEFAULT_PACKAGE,
+ "TEST SNAP 2.0", false, "ya");
+ PackageItem loaded = impl.repository.loadPackageSnapshot(
+ RulesRepository.DEFAULT_PACKAGE, "TEST SNAP 2.0");
- Thread.sleep( 100 );
+ data = impl.loadPackageConfig(loaded.getUUID());
+ assertTrue(data.isSnapshot);
+ assertEquals("TEST SNAP 2.0", data.snapshotName);
+ assertFalse(original.equals(data.lastModified));
+ assertEquals("ya", data.checkinComment);
+ }
- impl.createPackageSnapshot( RulesRepository.DEFAULT_PACKAGE,
- "TEST SNAP 2.0",
- false,
- "ya" );
- PackageItem loaded = impl.repository.loadPackageSnapshot( RulesRepository.DEFAULT_PACKAGE,
- "TEST SNAP 2.0" );
+ public void testPackageConfSave() throws Exception {
+ RepositoryService impl = getService();
+ String uuid = impl.createPackage("testPackageConfSave", "a desc");
+ PackageConfigData data = impl.loadPackageConfig(uuid);
- data = impl.loadPackageConfig( loaded.getUUID() );
- assertTrue( data.isSnapshot );
- assertEquals( "TEST SNAP 2.0",
- data.snapshotName );
- assertFalse( original.equals( data.lastModified ) );
- assertEquals( "ya",
- data.checkinComment );
- }
+ data.description = "new desc";
+ data.header = "wa";
+ data.externalURI = "new URI";
- public void testPackageConfSave() throws Exception {
- RepositoryService impl = getService();
- String uuid = impl.createPackage( "testPackageConfSave",
- "a desc" );
- PackageConfigData data = impl.loadPackageConfig( uuid );
+ ValidatedResponse res = impl.savePackage(data);
+ assertNotNull(res);
+ assertTrue(res.hasErrors);
+ assertNotNull(res.errorMessage);
- data.description = "new desc";
- data.header = "wa";
- data.externalURI = "new URI";
+ data = impl.loadPackageConfig(uuid);
+ assertEquals("new desc", data.description);
+ assertEquals("wa", data.header);
+ assertEquals("new URI", data.externalURI);
- ValidatedResponse res = impl.savePackage( data );
- assertNotNull( res );
- assertTrue( res.hasErrors );
- assertNotNull( res.errorMessage );
+ data.header = "";
+ res = impl.savePackage(data);
+ if (res.hasErrors) {
+ System.out
+ .println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
+ System.out.println(res.errorMessage);
+ System.out
+ .println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
- data = impl.loadPackageConfig( uuid );
- assertEquals( "new desc",
- data.description );
- assertEquals( "wa",
- data.header );
- assertEquals( "new URI",
- data.externalURI );
+ }
- data.header = "";
- res = impl.savePackage( data );
- if ( res.hasErrors ) {
- System.out.println( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" );
- System.out.println( res.errorMessage );
- System.out.println( "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" );
+ assertFalse(res.hasErrors);
+ }
- }
+ public void testListByFormat() throws Exception {
+ RepositoryService impl = getService();
+ String cat = "testListByFormat";
+ impl.createCategory("/", cat, "ya");
+ String pkgUUID = impl.createPackage("testListByFormat",
+ "used for listing by format.");
- assertFalse( res.hasErrors );
- }
+ String uuid = impl.createNewRule("testListByFormat", "x", cat,
+ "testListByFormat", "testListByFormat");
+ String uuid2 = impl.createNewRule("testListByFormat2", "x", cat,
+ "testListByFormat", "testListByFormat");
+ String uuid3 = impl.createNewRule("testListByFormat3", "x", cat,
+ "testListByFormat", "testListByFormat");
+ String uuid4 = impl.createNewRule("testListByFormat4", "x", cat,
+ "testListByFormat", "testListByFormat");
- public void testListByFormat() throws Exception {
- RepositoryService impl = getService();
- String cat = "testListByFormat";
- impl.createCategory( "/",
- cat,
- "ya" );
- String pkgUUID = impl.createPackage( "testListByFormat",
- "used for listing by format." );
+ TableDataResult res = impl.listAssets(pkgUUID, arr("testListByFormat"),
+ -1, 0);
+ assertEquals(4, res.data.length);
+ assertEquals(uuid, res.data[0].id);
+ assertEquals("testListByFormat", res.data[0].values[0]);
- String uuid = impl.createNewRule( "testListByFormat",
- "x",
- cat,
- "testListByFormat",
- "testListByFormat" );
- String uuid2 = impl.createNewRule( "testListByFormat2",
- "x",
- cat,
- "testListByFormat",
- "testListByFormat" );
- String uuid3 = impl.createNewRule( "testListByFormat3",
- "x",
- cat,
- "testListByFormat",
- "testListByFormat" );
- String uuid4 = impl.createNewRule( "testListByFormat4",
- "x",
- cat,
- "testListByFormat",
- "testListByFormat" );
+ res = impl.listAssets(pkgUUID, arr("testListByFormat"), 4, 0);
+ assertEquals(4, res.data.length);
- TableDataResult res = impl.listAssets( pkgUUID,
- arr( "testListByFormat" ),
- -1,
- 0 );
- assertEquals( 4,
- res.data.length );
- assertEquals( uuid,
- res.data[0].id );
- assertEquals( "testListByFormat",
- res.data[0].values[0] );
+ res = impl.listAssets(pkgUUID, arr("testListByFormat"), 2, 0);
+ assertEquals(2, res.data.length);
+ assertEquals(uuid, res.data[0].id);
- res = impl.listAssets( pkgUUID,
- arr( "testListByFormat" ),
- 4,
- 0 );
- assertEquals( 4,
- res.data.length );
+ res = impl.listAssets(pkgUUID, arr("testListByFormat"), 2, 2);
+ assertEquals(2, res.data.length);
+ assertEquals(uuid3, res.data[0].id);
- res = impl.listAssets( pkgUUID,
- arr( "testListByFormat" ),
- 2,
- 0 );
- assertEquals( 2,
- res.data.length );
- assertEquals( uuid,
- res.data[0].id );
+ uuid = impl.createNewRule("testListByFormat5", "x", cat,
+ "testListByFormat", "otherFormat");
- res = impl.listAssets( pkgUUID,
- arr( "testListByFormat" ),
- 2,
- 2 );
- assertEquals( 2,
- res.data.length );
- assertEquals( uuid3,
- res.data[0].id );
+ res = impl.listAssets(pkgUUID, arr("otherFormat"), 40, 0);
+ assertEquals(1, res.data.length);
+ assertEquals(uuid, res.data[0].id);
- uuid = impl.createNewRule( "testListByFormat5",
- "x",
- cat,
- "testListByFormat",
- "otherFormat" );
+ res = impl.listAssets(pkgUUID, new String[] { "otherFormat",
+ "testListByFormat" }, 40, 0);
+ assertEquals(5, res.data.length);
- res = impl.listAssets( pkgUUID,
- arr( "otherFormat" ),
- 40,
- 0 );
- assertEquals( 1,
- res.data.length );
- assertEquals( uuid,
- res.data[0].id );
+ TableDataResult result = impl.quickFindAsset("testListByForma", 5,
+ false);
+ assertEquals(5, result.data.length);
- res = impl.listAssets( pkgUUID,
- new String[]{"otherFormat", "testListByFormat"},
- 40,
- 0 );
- assertEquals( 5,
- res.data.length );
+ assertNotNull(result.data[0].id);
+ assertTrue(result.data[0].values[0].startsWith("testListByFormat"));
- TableDataResult result = impl.quickFindAsset( "testListByForma",
- 5,
- false );
- assertEquals( 5,
- result.data.length );
+ result = impl.quickFindAsset("testListByForma", 3, false);
+ assertEquals(4, result.data.length);
- assertNotNull( result.data[0].id );
- assertTrue( result.data[0].values[0].startsWith( "testListByFormat" ) );
+ assertEquals("MORE", result.data[3].id);
- result = impl.quickFindAsset( "testListByForma",
- 3,
- false );
- assertEquals( 4,
- result.data.length );
+ }
- assertEquals( "MORE",
- result.data[3].id );
+ public String[] arr(String s) {
+ return new String[] { s };
+ }
- }
+ public void testStatus() throws Exception {
+ RepositoryService impl = getService();
+ String uuid = impl.createState("testStatus1");
+ assertNotNull(uuid);
- public String[] arr(String s) {
- return new String[]{s};
- }
+ String[] states = impl.listStates();
+ assertTrue(states.length > 0);
- public void testStatus() throws Exception {
- RepositoryService impl = getService();
- String uuid = impl.createState( "testStatus1" );
- assertNotNull( uuid );
+ impl.createState("testStatus2");
+ String[] states2 = impl.listStates();
+ assertEquals(states.length + 1, states2.length);
- String[] states = impl.listStates();
- assertTrue( states.length > 0 );
+ int match = 0;
+ for (int i = 0; i < states2.length; i++) {
+ if (states2[i].equals("testStatus2")) {
+ match++;
+ } else if (states2[i].equals("testStatus1")) {
+ match++;
+ }
+ }
- impl.createState( "testStatus2" );
- String[] states2 = impl.listStates();
- assertEquals( states.length + 1,
- states2.length );
+ assertEquals(2, match);
- int match = 0;
- for ( int i = 0; i < states2.length; i++ ) {
- if ( states2[i].equals( "testStatus2" ) ) {
- match++;
- } else if ( states2[i].equals( "testStatus1" ) ) {
- match++;
- }
- }
+ String packagUUID = impl.createPackage("testStatus", "description");
+ String ruleUUID = impl.createNewRule("testStatus", "desc", null,
+ "testStatus", "drl");
+ String ruleUUID2 = impl.createNewRule("testStatus2", "desc", null,
+ "testStatus", "drl");
+ impl.createState("testState");
- assertEquals( 2,
- match );
+ RuleAsset asset = impl.loadRuleAsset(ruleUUID);
+ assertEquals(StateItem.DRAFT_STATE_NAME, asset.metaData.status);
+ impl.changeState(ruleUUID, "testState", false);
+ asset = impl.loadRuleAsset(ruleUUID);
+ assertEquals("testState", asset.metaData.status);
+ asset = impl.loadRuleAsset(ruleUUID2);
+ assertEquals(StateItem.DRAFT_STATE_NAME, asset.metaData.status);
- String packagUUID = impl.createPackage( "testStatus",
- "description" );
- String ruleUUID = impl.createNewRule( "testStatus",
- "desc",
- null,
- "testStatus",
- "drl" );
- String ruleUUID2 = impl.createNewRule( "testStatus2",
- "desc",
- null,
- "testStatus",
- "drl" );
- impl.createState( "testState" );
+ impl.createState("testState2");
+ impl.changeState(packagUUID, "testState2", true);
- RuleAsset asset = impl.loadRuleAsset( ruleUUID );
- assertEquals( StateItem.DRAFT_STATE_NAME,
- asset.metaData.status );
- impl.changeState( ruleUUID,
- "testState",
- false );
- asset = impl.loadRuleAsset( ruleUUID );
- assertEquals( "testState",
- asset.metaData.status );
- asset = impl.loadRuleAsset( ruleUUID2 );
- assertEquals( StateItem.DRAFT_STATE_NAME,
- asset.metaData.status );
+ PackageConfigData pkg = impl.loadPackageConfig(packagUUID);
+ assertEquals("testState2", pkg.state);
- impl.createState( "testState2" );
- impl.changeState( packagUUID,
- "testState2",
- true );
+ asset = impl.loadRuleAsset(ruleUUID2);
+ assertEquals("testState2", asset.metaData.status);
- PackageConfigData pkg = impl.loadPackageConfig( packagUUID );
- assertEquals( "testState2",
- pkg.state );
+ impl.checkinVersion(asset);
+ asset = impl.loadRuleAsset(asset.uuid);
+ assertEquals("testState2", asset.metaData.status);
- asset = impl.loadRuleAsset( ruleUUID2 );
- assertEquals( "testState2",
- asset.metaData.status );
+ }
- impl.checkinVersion( asset );
- asset = impl.loadRuleAsset( asset.uuid );
- assertEquals( "testState2",
- asset.metaData.status );
+ public void testMovePackage() throws Exception {
+ RepositoryService impl = getService();
+ String[] cats = impl.loadChildCategories("/");
+ if (cats.length == 0) {
+ impl.createCategory("/", "la", "d");
+ }
+ String sourcePkgId = impl.createPackage("sourcePackage", "description");
+ String destPkgId = impl.createPackage("targetPackage", "description");
- }
+ String cat = impl.loadChildCategories("/")[0];
- public void testMovePackage() throws Exception {
- RepositoryService impl = getService();
- String[] cats = impl.loadChildCategories( "/" );
- if ( cats.length == 0 ) {
- impl.createCategory( "/",
- "la",
- "d" );
- }
- String sourcePkgId = impl.createPackage( "sourcePackage",
- "description" );
- String destPkgId = impl.createPackage( "targetPackage",
- "description" );
+ String uuid = impl.createNewRule("testMovePackage", "desc", cat,
+ "sourcePackage", "drl");
- String cat = impl.loadChildCategories( "/" )[0];
+ TableDataResult res = impl.listAssets(destPkgId,
+ new String[] { "drl" }, 2, 0);
+ assertEquals(0, res.data.length);
- String uuid = impl.createNewRule( "testMovePackage",
- "desc",
- cat,
- "sourcePackage",
- "drl" );
+ impl.changeAssetPackage(uuid, "targetPackage", "yeah");
+ res = impl.listAssets(destPkgId, new String[] { "drl" }, 2, 0);
- TableDataResult res = impl.listAssets( destPkgId,
- new String[]{"drl"},
- 2,
- 0 );
- assertEquals( 0,
- res.data.length );
+ assertEquals(1, res.data.length);
- impl.changeAssetPackage( uuid,
- "targetPackage",
- "yeah" );
- res = impl.listAssets( destPkgId,
- new String[]{"drl"},
- 2,
- 0 );
+ res = impl.listAssets(sourcePkgId, new String[] { "drl" }, 2, 0);
- assertEquals( 1,
- res.data.length );
+ assertEquals(0, res.data.length);
- res = impl.listAssets( sourcePkgId,
- new String[]{"drl"},
- 2,
- 0 );
+ }
- assertEquals( 0,
- res.data.length );
+ public void testCopyAsset() throws Exception {
+ RepositoryService impl = getService();
+ impl.createCategory("/", "templates", "ya");
+ String uuid = impl.createNewRule("testCopyAsset", "", "templates",
+ RulesRepository.DEFAULT_PACKAGE, "drl");
+ String uuid2 = impl.copyAsset(uuid, RulesRepository.DEFAULT_PACKAGE,
+ "testCopyAsset2");
+ assertNotSame(uuid, uuid2);
- }
+ RuleAsset asset = impl.loadRuleAsset(uuid2);
+ assertNotNull(asset);
+ assertEquals(RulesRepository.DEFAULT_PACKAGE,
+ asset.metaData.packageName);
+ assertEquals("testCopyAsset2", asset.metaData.name);
+ }
- public void testCopyAsset() throws Exception {
- RepositoryService impl = getService();
- impl.createCategory( "/",
- "templates",
- "ya" );
- String uuid = impl.createNewRule( "testCopyAsset",
- "",
- "templates",
- RulesRepository.DEFAULT_PACKAGE,
- "drl" );
- String uuid2 = impl.copyAsset( uuid,
- RulesRepository.DEFAULT_PACKAGE,
- "testCopyAsset2" );
- assertNotSame( uuid,
- uuid2 );
+ public void testSnapshot() throws Exception {
+ RepositoryService impl = getService();
+ impl.createCategory("/", "snapshotTesting", "y");
+ impl.createPackage("testSnapshot", "d");
+ String uuid = impl.createNewRule("testSnapshotRule", "",
+ "snapshotTesting", "testSnapshot", "drl");
- RuleAsset asset = impl.loadRuleAsset( uuid2 );
- assertNotNull( asset );
- assertEquals( RulesRepository.DEFAULT_PACKAGE,
- asset.metaData.packageName );
- assertEquals( "testCopyAsset2",
- asset.metaData.name );
- }
+ impl.createPackageSnapshot("testSnapshot", "X", false, "ya");
+ SnapshotInfo[] snaps = impl.listSnapshots("testSnapshot");
+ assertEquals(1, snaps.length);
+ assertEquals("X", snaps[0].name);
+ assertEquals("ya", snaps[0].comment);
+ assertNotNull(snaps[0].uuid);
+ PackageConfigData confSnap = impl.loadPackageConfig(snaps[0].uuid);
+ assertEquals("testSnapshot", confSnap.name);
- public void testSnapshot() throws Exception {
- RepositoryService impl = getService();
- impl.createCategory( "/",
- "snapshotTesting",
- "y" );
- impl.createPackage( "testSnapshot",
- "d" );
- String uuid = impl.createNewRule( "testSnapshotRule",
- "",
- "snapshotTesting",
- "testSnapshot",
- "drl" );
+ impl.createPackageSnapshot("testSnapshot", "Y", false, "we");
+ assertEquals(2, impl.listSnapshots("testSnapshot").length);
+ impl.createPackageSnapshot("testSnapshot", "X", true, "we");
+ assertEquals(2, impl.listSnapshots("testSnapshot").length);
- impl.createPackageSnapshot( "testSnapshot",
- "X",
- false,
- "ya" );
- SnapshotInfo[] snaps = impl.listSnapshots( "testSnapshot" );
- assertEquals( 1,
- snaps.length );
- assertEquals( "X",
- snaps[0].name );
- assertEquals( "ya",
- snaps[0].comment );
- assertNotNull( snaps[0].uuid );
- PackageConfigData confSnap = impl.loadPackageConfig( snaps[0].uuid );
- assertEquals( "testSnapshot",
- confSnap.name );
+ impl.copyOrRemoveSnapshot("testSnapshot", "X", false, "Q");
+ assertEquals(3, impl.listSnapshots("testSnapshot").length);
- impl.createPackageSnapshot( "testSnapshot",
- "Y",
- false,
- "we" );
- assertEquals( 2,
- impl.listSnapshots( "testSnapshot" ).length );
- impl.createPackageSnapshot( "testSnapshot",
- "X",
- true,
- "we" );
- assertEquals( 2,
- impl.listSnapshots( "testSnapshot" ).length );
+ try {
+ impl.copyOrRemoveSnapshot("testSnapshot", "X", false, "");
+ fail("should not be able to copy snapshot to empty detination");
+ } catch (SerializableException e) {
+ assertNotNull(e.getMessage());
+ }
- impl.copyOrRemoveSnapshot( "testSnapshot",
- "X",
- false,
- "Q" );
- assertEquals( 3,
- impl.listSnapshots( "testSnapshot" ).length );
+ impl.copyOrRemoveSnapshot("testSnapshot", "X", true, null);
+ assertEquals(2, impl.listSnapshots("testSnapshot").length);
- try {
- impl.copyOrRemoveSnapshot( "testSnapshot",
- "X",
- false,
- "" );
- fail( "should not be able to copy snapshot to empty detination" );
- } catch ( SerializableException e ) {
- assertNotNull( e.getMessage() );
- }
+ }
- impl.copyOrRemoveSnapshot( "testSnapshot",
- "X",
- true,
- null );
- assertEquals( 2,
- impl.listSnapshots( "testSnapshot" ).length );
+ public void testSnapshotRebuild() throws Exception {
- }
+ ServiceImplementation impl = getService();
+ RulesRepository repo = impl.repository;
- public void testSnapshotRebuild() throws Exception {
+ // get rid of other snapshot crap
+ Iterator pkit = repo.listPackages();
+ while (pkit.hasNext()) {
+ PackageItem pkg = (PackageItem) pkit.next();
+ String[] snaps = repo.listPackageSnapshots(pkg.getName());
+ for (String snapName : snaps) {
+ repo.removePackageSnapshot(pkg.getName(), snapName);
+ }
+ }
+ PackageItem pkg = repo.createPackage("testSnapshotRebuild", "");
+ pkg.updateHeader("import java.util.List");
+ repo.save();
+ AssetItem item = pkg.addAsset("anAsset", "");
+ item.updateFormat(AssetFormats.DRL);
+ item
+ .updateContent(" rule abc \n when \n then \n System.out.println(42); \n end");
+ item.checkin("");
- ServiceImplementation impl = getService();
- RulesRepository repo = impl.repository;
+ BuilderResult[] res = impl.buildPackage(pkg.getUUID(), "", true);
+ assertNull(res);
+ impl.createPackageSnapshot("testSnapshotRebuild", "SNAP", false, "");
- //get rid of other snapshot crap
- Iterator pkit = repo.listPackages();
- while(pkit.hasNext()) {
- PackageItem pkg = (PackageItem) pkit.next();
- String[] snaps = repo.listPackageSnapshots( pkg.getName() );
- for ( String snapName : snaps ) {
- repo.removePackageSnapshot( pkg.getName(), snapName );
- }
- }
+ PackageItem snap = repo.loadPackageSnapshot("testSnapshotRebuild",
+ "SNAP");
+ long snapTime = snap.getLastModified().getTimeInMillis();
+ Thread.sleep(100);
- PackageItem pkg = repo.createPackage( "testSnapshotRebuild", "" );
- pkg.updateHeader( "import java.util.List" );
- repo.save();
+ impl.rebuildSnapshots();
- AssetItem item = pkg.addAsset( "anAsset", "" );
- item.updateFormat( AssetFormats.DRL );
- item.updateContent( " rule abc \n when \n then \n System.out.println(42); \n end");
- item.checkin( "" );
+ PackageItem snap_ = repo.loadPackageSnapshot("testSnapshotRebuild",
+ "SNAP");
+ long newTime = snap_.getLastModified().getTimeInMillis();
- BuilderResult[] res = impl.buildPackage( pkg.getUUID(), "", true );
- assertNull(res);
+ assertTrue(newTime > snapTime);
+ item.updateContent("garbage");
+ item.checkin("");
- impl.createPackageSnapshot( "testSnapshotRebuild", "SNAP", false, "");
+ impl.createPackageSnapshot("testSnapshotRebuild", "SNAP2", false, "");
- PackageItem snap = repo.loadPackageSnapshot( "testSnapshotRebuild", "SNAP" );
- long snapTime = snap.getLastModified().getTimeInMillis();
+ try {
+ impl.rebuildSnapshots();
+ } catch (DetailedSerializableException e) {
+ assertNotNull(e.getMessage());
+ assertNotNull(e.getLongDescription());
+ }
- Thread.sleep( 100 );
+ }
- impl.rebuildSnapshots();
+ public void testRemoveCategory() throws Exception {
+ RepositoryService impl = getService();
+ String[] children = impl.loadChildCategories("/");
+ impl.createCategory("/", "testRemoveCategory", "foo");
+ impl.removeCategory("testRemoveCategory");
+ String[] _children = impl.loadChildCategories("/");
+ assertEquals(children.length, _children.length);
- PackageItem snap_ = repo.loadPackageSnapshot( "testSnapshotRebuild", "SNAP" );
- long newTime = snap_.getLastModified().getTimeInMillis();
+ }
- assertTrue(newTime > snapTime);
+ public void testRemoveAsset() throws Exception {
+ RepositoryService impl = getService();
+ String cat = "testRemoveAsset";
+ impl.createCategory("/", cat, "ya");
+ String pkgUUID = impl.createPackage("testRemoveAsset", "");
+ String uuid = impl.createNewRule("testRemoveAsset", "x", cat,
+ "testRemoveAsset", "testRemoveAsset");
- item.updateContent( "garbage" );
- item.checkin( "" );
+ String uuid2 = impl.createNewRule("testRemoveAsset2", "x", cat,
+ "testRemoveAsset", "testRemoveAsset");
- impl.createPackageSnapshot( "testSnapshotRebuild", "SNAP2", false, "");
+ String uuid3 = impl.createNewRule("testRemoveAsset3", "x", cat,
+ "testRemoveAsset", "testRemoveAsset");
+ String uuid4 = impl.createNewRule("testRemoveAsset4", "x", cat,
+ "testRemoveAsset", "testRemoveAsset");
- try {
- impl.rebuildSnapshots();
- } catch (DetailedSerializableException e) {
- assertNotNull(e.getMessage());
- assertNotNull(e.getLongDescription());
- }
+ TableDataResult res = impl.listAssets(pkgUUID, arr("testRemoveAsset"),
+ -1, 0);
+ assertEquals(4, res.data.length);
- }
+ impl.removeAsset(uuid4);
+ res = impl.listAssets(pkgUUID, arr("testRemoveAsset"), -1, 0);
+ assertEquals(3, res.data.length);
+ }
- public void testRemoveCategory() throws Exception {
+ public void testArchiveAsset() throws Exception {
+ RepositoryService impl = getService();
+ String cat = "testArchiveAsset";
+ impl.createCategory("/", cat, "ya");
+ String pkgUUID = impl.createPackage("testArchiveAsset", "");
- RepositoryService impl = getService();
- String[] children = impl.loadChildCategories( "/" );
- impl.createCategory( "/",
- "testRemoveCategory",
- "foo" );
+ String uuid = impl.createNewRule("testArchiveAsset", "x", cat,
+ "testArchiveAsset", "testArchiveAsset");
- impl.removeCategory( "testRemoveCategory" );
- String[] _children = impl.loadChildCategories( "/" );
- assertEquals( children.length,
- _children.length );
+ String uuid2 = impl.createNewRule("testArchiveAsset2", "x", cat,
+ "testArchiveAsset", "testArchiveAsset");
- }
+ String uuid3 = impl.createNewRule("testArchiveAsset3", "x", cat,
+ "testArchiveAsset", "testArchiveAsset");
+ String uuid4 = impl.createNewRule("testArchiveAsset4", "x", cat,
+ "testArchiveAsset", "testArchiveAsset");
- public void testRemoveAsset() throws Exception {
- RepositoryService impl = getService();
- String cat = "testRemoveAsset";
- impl.createCategory( "/",
- cat,
- "ya" );
- String pkgUUID = impl.createPackage( "testRemoveAsset",
- "" );
+ TableDataResult res = impl.listAssets(pkgUUID, arr("testArchiveAsset"),
+ -1, 0);
+ assertEquals(4, res.data.length);
- String uuid = impl.createNewRule( "testRemoveAsset",
- "x",
- cat,
- "testRemoveAsset",
- "testRemoveAsset" );
+ impl.archiveAsset(uuid4, true);
- String uuid2 = impl.createNewRule( "testRemoveAsset2",
- "x",
- cat,
- "testRemoveAsset",
- "testRemoveAsset" );
+ res = impl.listAssets(pkgUUID, arr("testArchiveAsset"), -1, 0);
+ assertEquals(3, res.data.length);
- String uuid3 = impl.createNewRule( "testRemoveAsset3",
- "x",
- cat,
- "testRemoveAsset",
- "testRemoveAsset" );
- String uuid4 = impl.createNewRule( "testRemoveAsset4",
- "x",
- cat,
- "testRemoveAsset",
- "testRemoveAsset" );
+ impl.archiveAsset(uuid4, false);
- TableDataResult res = impl.listAssets( pkgUUID,
- arr( "testRemoveAsset" ),
- -1,
- 0 );
- assertEquals( 4,
- res.data.length );
+ res = impl.listAssets(pkgUUID, arr("testArchiveAsset"), -1, 0);
+ assertEquals(4, res.data.length);
- impl.removeAsset( uuid4 );
+ }
- res = impl.listAssets( pkgUUID,
- arr( "testRemoveAsset" ),
- -1,
- 0 );
- assertEquals( 3,
- res.data.length );
- }
+ public void testLoadSuggestionCompletionEngine() throws Exception {
+ RepositoryService impl = getService();
+ String uuid = impl.createPackage("testSuggestionComp", "x");
+ PackageConfigData conf = impl.loadPackageConfig(uuid);
+ conf.header = "import java.util.List";
+ SuggestionCompletionEngine eng = impl
+ .loadSuggestionCompletionEngine("testSuggestionComp");
+ assertNotNull(eng);
- public void testArchiveAsset() throws Exception {
- RepositoryService impl = getService();
- String cat = "testArchiveAsset";
- impl.createCategory( "/",
- cat,
- "ya" );
- String pkgUUID = impl.createPackage( "testArchiveAsset",
- "" );
+ }
- String uuid = impl.createNewRule( "testArchiveAsset",
- "x",
- cat,
- "testArchiveAsset",
- "testArchiveAsset" );
+ /**
+ * This will test creating a package, check it compiles, and can exectute
+ * rules, then take a snapshot, and check that it reports errors.
+ */
+ public void testBinaryPackageCompileAndExecute() throws Exception {
+ ServiceImplementation impl = getService();
+ RulesRepository repo = impl.repository;
- String uuid2 = impl.createNewRule( "testArchiveAsset2",
- "x",
- cat,
- "testArchiveAsset",
- "testArchiveAsset" );
+ // create our package
+ PackageItem pkg = repo.createPackage("testBinaryPackageCompile", "");
+ pkg.updateHeader("import org.drools.Person");
+ AssetItem rule1 = pkg.addAsset("rule_1", "");
+ rule1.updateFormat(AssetFormats.DRL);
+ rule1
+ .updateContent("rule 'rule1' \n when \np : Person() \n then \np.setAge(42); \n end");
+ rule1.checkin("");
+ repo.save();
- String uuid3 = impl.createNewRule( "testArchiveAsset3",
- "x",
- cat,
- "testArchiveAsset",
- "testArchiveAsset" );
- String uuid4 = impl.createNewRule( "testArchiveAsset4",
- "x",
- cat,
- "testArchiveAsset",
- "testArchiveAsset" );
+ BuilderResult[] results = impl.buildPackage(pkg.getUUID(), null, true);
+ assertNull(results);
- TableDataResult res = impl.listAssets( pkgUUID,
- arr( "testArchiveAsset" ),
- -1,
- 0 );
- assertEquals( 4,
- res.data.length );
+ pkg = repo.loadPackage("testBinaryPackageCompile");
+ byte[] binPackage = pkg.getCompiledPackageBytes();
- impl.archiveAsset( uuid4, true );
+ assertNotNull(binPackage);
- res = impl.listAssets( pkgUUID,
- arr( "testArchiveAsset" ),
- -1,
- 0 );
- assertEquals( 3,
- res.data.length );
+ ByteArrayInputStream bin = new ByteArrayInputStream(binPackage);
+ ObjectInputStream in = new DroolsObjectInputStream(bin);
+ Package binPkg = (Package) in.readObject();
- impl.archiveAsset( uuid4, false );
+ assertNotNull(binPkg);
+ assertTrue(binPkg.isValid());
- res = impl.listAssets( pkgUUID,
- arr( "testArchiveAsset" ),
- -1,
- 0 );
- assertEquals( 4,
- res.data.length );
+ Person p = new Person();
- }
+ BinaryRuleBaseLoader loader = new BinaryRuleBaseLoader();
+ loader.addPackage(new ByteArrayInputStream(binPackage));
+ RuleBase rb = loader.getRuleBase();
+ StatelessSession sess = rb.newStatelessSession();
+ sess.execute(p);
+ assertEquals(42, p.getAge());
+ impl.createPackageSnapshot("testBinaryPackageCompile", "SNAP1", false,
+ "");
- public void testLoadSuggestionCompletionEngine() throws Exception {
- RepositoryService impl = getService();
- String uuid = impl.createPackage( "testSuggestionComp",
- "x" );
- PackageConfigData conf = impl.loadPackageConfig( uuid );
- conf.header = "import java.util.List";
+ rule1
+ .updateContent("rule 'rule1' \n when p:PersonX() \n then System.err.println(42); \n end");
+ rule1.checkin("");
- SuggestionCompletionEngine eng = impl.loadSuggestionCompletionEngine( "testSuggestionComp" );
- assertNotNull( eng );
+ results = impl.buildPackage(pkg.getUUID(), null, true);
+ assertNotNull(results);
+ assertEquals(1, results.length);
+ assertEquals(rule1.getName(), results[0].assetName);
+ assertEquals(AssetFormats.DRL, results[0].assetFormat);
+ assertNotNull(results[0].message);
+ assertEquals(rule1.getUUID(), results[0].uuid);
- }
+ pkg = repo.loadPackageSnapshot("testBinaryPackageCompile", "SNAP1");
+ results = impl.buildPackage(pkg.getUUID(), null, true);
+ assertNull(results);
- /**
- * This will test creating a package, check it compiles, and can exectute rules,
- * then take a snapshot, and check that it reports errors.
- */
- public void testBinaryPackageCompileAndExecute() throws Exception {
- ServiceImplementation impl = getService();
- RulesRepository repo = impl.repository;
+ }
- //create our package
- PackageItem pkg = repo.createPackage( "testBinaryPackageCompile",
- "" );
- pkg.updateHeader( "import org.drools.Person" );
- AssetItem rule1 = pkg.addAsset( "rule_1",
- "" );
- rule1.updateFormat( AssetFormats.DRL );
- rule1.updateContent( "rule 'rule1' \n when \np : Person() \n then \np.setAge(42); \n end" );
- rule1.checkin( "" );
- repo.save();
+ /**
+ * This will test creating a package with a BRL rule, check it compiles, and
+ * can exectute rules, then take a snapshot, and check that it reports
+ * errors.
+ */
+ public void testBinaryPackageCompileAndExecuteWithBRXML() throws Exception {
+ ServiceImplementation impl = getService();
+ RulesRepository repo = impl.repository;
- BuilderResult[] results = impl.buildPackage( pkg.getUUID(), null, true );
- assertNull( results );
+ // create our package
+ PackageItem pkg = repo.createPackage("testBinaryPackageCompileBRL", "");
+ pkg.updateHeader("import org.drools.Person");
+ AssetItem rule2 = pkg.addAsset("rule2", "");
+ rule2.updateFormat(AssetFormats.BUSINESS_RULE);
- pkg = repo.loadPackage( "testBinaryPackageCompile" );
- byte[] binPackage = pkg.getCompiledPackageBytes();
+ RuleModel model = new RuleModel();
+ model.name = "rule2";
+ FactPattern pattern = new FactPattern("Person");
- assertNotNull( binPackage );
+ SingleFieldConstraint con = new SingleFieldConstraint();
+ con.constraintValueType = ISingleFieldConstraint.TYPE_PREDICATE;
+ con.value = "name soundslike 'foobar'";
+ pattern.addConstraint(con);
- ByteArrayInputStream bin = new ByteArrayInputStream( binPackage );
- ObjectInputStream in = new DroolsObjectInputStream( bin );
- Package binPkg = (Package) in.readObject();
+ pattern.boundName = "p";
+ ActionSetField action = new ActionSetField("p");
+ ActionFieldValue value = new ActionFieldValue("age", "42",
+ SuggestionCompletionEngine.TYPE_NUMERIC);
+ action.addFieldValue(value);
- assertNotNull( binPkg );
- assertTrue( binPkg.isValid() );
+ model.addLhsItem(pattern);
+ model.addRhsItem(action);
- Person p = new Person();
+ rule2.updateContent(BRXMLPersistence.getInstance().marshal(model));
+ rule2.checkin("");
+ repo.save();
- BinaryRuleBaseLoader loader = new BinaryRuleBaseLoader();
- loader.addPackage( new ByteArrayInputStream( binPackage ) );
- RuleBase rb = loader.getRuleBase();
+ BuilderResult[] results = impl.buildPackage(pkg.getUUID(), null, true);
+ if (results != null) {
+ for (int i = 0; i < results.length; i++) {
+ System.err.println(results[i].message);
+ }
+ }
+ assertNull(results);
- StatelessSession sess = rb.newStatelessSession();
- sess.execute( p );
- assertEquals( 42,
- p.getAge() );
+ pkg = repo.loadPackage("testBinaryPackageCompileBRL");
+ byte[] binPackage = pkg.getCompiledPackageBytes();
- impl.createPackageSnapshot( "testBinaryPackageCompile",
- "SNAP1",
- false,
- "" );
+ // Here is where we write it out if needed... UNCOMMENT if needed for
+ // the binary test
+ // FileOutputStream out = new
+ // FileOutputStream("/Users/michaelneale/RepoBinPackage.pkg");
+ // out.write( binPackage );
+ // out.flush();
+ // out.close();
- rule1.updateContent( "rule 'rule1' \n when p:PersonX() \n then System.err.println(42); \n end" );
- rule1.checkin( "" );
+ assertNotNull(binPackage);
- results = impl.buildPackage( pkg.getUUID(), null, true );
- assertNotNull( results );
- assertEquals( 1,
- results.length );
- assertEquals( rule1.getName(),
- results[0].assetName );
- assertEquals( AssetFormats.DRL,
- results[0].assetFormat );
- assertNotNull( results[0].message );
- assertEquals( rule1.getUUID(),
- results[0].uuid );
+ ByteArrayInputStream bin = new ByteArrayInputStream(binPackage);
+ ObjectInputStream in = new DroolsObjectInputStream(bin);
+ Package binPkg = (Package) in.readObject();
- pkg = repo.loadPackageSnapshot( "testBinaryPackageCompile",
- "SNAP1" );
- results = impl.buildPackage( pkg.getUUID(), null, true );
- assertNull( results );
+ assertNotNull(binPkg);
+ assertTrue(binPkg.isValid());
- }
+ // and this shows off the "soundex" thing...
+ Person p = new Person("fubar");
+ BinaryRuleBaseLoader loader = new BinaryRuleBaseLoader();
+ loader.addPackage(new ByteArrayInputStream(binPackage));
+ RuleBase rb = loader.getRuleBase();
- /**
- * This will test creating a package with a BRL rule, check it compiles, and can exectute rules,
- * then take a snapshot, and check that it reports errors.
- */
- public void testBinaryPackageCompileAndExecuteWithBRXML() throws Exception {
- ServiceImplementation impl = getService();
- RulesRepository repo = impl.repository;
+ StatelessSession sess = rb.newStatelessSession();
+ sess.execute(p);
+ assertEquals(42, p.getAge());
- //create our package
- PackageItem pkg = repo.createPackage( "testBinaryPackageCompileBRL",
- "" );
- pkg.updateHeader( "import org.drools.Person" );
- AssetItem rule2 = pkg.addAsset( "rule2",
- "" );
- rule2.updateFormat( AssetFormats.BUSINESS_RULE );
+ impl.createPackageSnapshot("testBinaryPackageCompileBRL", "SNAP1",
+ false, "");
- RuleModel model = new RuleModel();
- model.name = "rule2";
- FactPattern pattern = new FactPattern( "Person" );
+ pattern.factType = "PersonX";
+ rule2.updateContent(BRXMLPersistence.getInstance().marshal(model));
+ rule2.checkin("");
+ results = impl.buildPackage(pkg.getUUID(), null, true);
+ assertNotNull(results);
+ assertTrue(results.length > 0);
+ // assertEquals(2, results.length);
+ assertEquals(rule2.getName(), results[0].assetName);
+ assertEquals(AssetFormats.BUSINESS_RULE, results[0].assetFormat);
+ assertNotNull(results[0].message);
+ assertEquals(rule2.getUUID(), results[0].uuid);
- SingleFieldConstraint con = new SingleFieldConstraint();
- con.constraintValueType = ISingleFieldConstraint.TYPE_PREDICATE;
- con.value = "name soundslike 'foobar'";
- pattern.addConstraint( con );
+ pkg = repo.loadPackageSnapshot("testBinaryPackageCompileBRL", "SNAP1");
+ results = impl.buildPackage(pkg.getUUID(), null, true);
+ assertNull(results);
+ // check that the rule name in the model is being set
+ AssetItem asset2 = pkg.addAsset("testSetRuleName", "");
+ asset2.updateFormat(AssetFormats.BUSINESS_RULE);
+ asset2.checkin("");
- pattern.boundName = "p";
- ActionSetField action = new ActionSetField( "p" );
- ActionFieldValue value = new ActionFieldValue( "age",
- "42",
- SuggestionCompletionEngine.TYPE_NUMERIC );
- action.addFieldValue( value );
+ RuleModel model2 = new RuleModel();
+ assertNull(model2.name);
+ RuleAsset asset = impl.loadRuleAsset(asset2.getUUID());
+ asset.content = model2;
- model.addLhsItem( pattern );
- model.addRhsItem( action );
+ impl.checkinVersion(asset);
- rule2.updateContent( BRXMLPersistence.getInstance().marshal( model ) );
- rule2.checkin( "" );
- repo.save();
+ asset = impl.loadRuleAsset(asset2.getUUID());
- BuilderResult[] results = impl.buildPackage( pkg.getUUID(), null, true );
- if ( results != null ) {
- for ( int i = 0; i < results.length; i++ ) {
- System.err.println( results[i].message );
- }
- }
- assertNull( results );
+ model2 = (RuleModel) asset.content;
+ assertNotNull(model2);
+ assertNotNull(model2.name);
+ assertEquals(asset2.getName(), model2.name);
- pkg = repo.loadPackage( "testBinaryPackageCompileBRL" );
- byte[] binPackage = pkg.getCompiledPackageBytes();
+ }
- //Here is where we write it out if needed... UNCOMMENT if needed for the binary test
-// FileOutputStream out = new FileOutputStream("/Users/michaelneale/RepoBinPackage.pkg");
-// out.write( binPackage );
-// out.flush();
-// out.close();
+ /**
+ * this loads up a precompile binary package. If this fails, then it means
+ * it needs to be updated. It gets the package form the BRL example above.
+ */
+ public void IGNORE_testLoadAndExecBinary() throws Exception {
+ Person p = new Person("fubar");
+ BinaryRuleBaseLoader loader = new BinaryRuleBaseLoader();
+ loader.addPackage(this.getClass().getResourceAsStream(
+ "/RepoBinPackage.pkg"));
+ RuleBase rb = loader.getRuleBase();
+ StatelessSession sess = rb.newStatelessSession();
+ sess.execute(p);
+ assertEquals(42, p.getAge());
+ }
- assertNotNull( binPackage );
+ public void testPackageSource() throws Exception {
+ ServiceImplementation impl = getService();
+ RulesRepository repo = impl.repository;
- ByteArrayInputStream bin = new ByteArrayInputStream( binPackage );
- ObjectInputStream in = new DroolsObjectInputStream( bin );
- Package binPkg = (Package) in.readObject();
+ // create our package
+ PackageItem pkg = repo.createPackage("testPackageSource", "");
+ pkg.updateHeader("import org.goo.Ber");
+ AssetItem rule1 = pkg.addAsset("rule_1", "");
+ rule1.updateFormat(AssetFormats.DRL);
+ rule1
+ .updateContent("rule 'rule1' \n when p:Person() \n then p.setAge(42); \n end");
+ rule1.checkin("");
+ repo.save();
- assertNotNull( binPkg );
- assertTrue( binPkg.isValid() );
+ AssetItem func = pkg.addAsset("funky", "");
+ func.updateFormat(AssetFormats.FUNCTION);
+ func.updateContent("this is a func");
+ func.checkin("");
- //and this shows off the "soundex" thing...
- Person p = new Person("fubar");
+ String drl = impl.buildPackageSource(pkg.getUUID());
+ assertNotNull(drl);
- BinaryRuleBaseLoader loader = new BinaryRuleBaseLoader();
- loader.addPackage( new ByteArrayInputStream( binPackage ) );
- RuleBase rb = loader.getRuleBase();
+ assertTrue(drl.indexOf("import org.goo.Ber") > -1);
+ assertTrue(drl.indexOf("package testPackageSource") > -1);
+ assertTrue(drl.indexOf("rule 'rule1'") > -1);
+ assertTrue(drl.indexOf("this is a func") > -1);
+ assertTrue(drl.indexOf("this is a func") < drl.indexOf("rule 'rule1'"));
+ assertTrue(drl.indexOf("package testPackageSource") < drl
+ .indexOf("this is a func"));
+ assertTrue(drl.indexOf("package testPackageSource") < drl
+ .indexOf("import org.goo.Ber"));
- StatelessSession sess = rb.newStatelessSession();
- sess.execute( p );
- assertEquals( 42,
- p.getAge() );
+ AssetItem dsl = pkg.addAsset("MyDSL", "");
+ dsl.updateFormat(AssetFormats.DSL);
+ dsl
+ .updateContent("[when]This is foo=bar()\n[then]do something=yeahMan();");
+ dsl.checkin("");
- impl.createPackageSnapshot( "testBinaryPackageCompileBRL",
- "SNAP1",
- false,
- "" );
+ AssetItem asset = pkg.addAsset("MyDSLRule", "");
+ asset.updateFormat(AssetFormats.DSL_TEMPLATE_RULE);
+ asset.updateContent("when \n This is foo \n then \n do something");
+ asset.checkin("");
- pattern.factType = "PersonX";
- rule2.updateContent( BRXMLPersistence.getInstance().marshal( model ) );
- rule2.checkin( "" );
+ drl = impl.buildPackageSource(pkg.getUUID());
+ assertNotNull(drl);
- results = impl.buildPackage( pkg.getUUID(), null, true );
- assertNotNull( results );
- assertTrue( results.length > 0 );
- //assertEquals(2, results.length);
- assertEquals( rule2.getName(),
- results[0].assetName );
- assertEquals( AssetFormats.BUSINESS_RULE,
- results[0].assetFormat );
- assertNotNull( results[0].message );
- assertEquals( rule2.getUUID(),
- results[0].uuid );
+ assertTrue(drl.indexOf("import org.goo.Ber") > -1);
+ assertTrue(drl.indexOf("This is foo") == -1);
+ assertTrue(drl.indexOf("do something") == -1);
+ assertTrue(drl.indexOf("bar()") > 0);
+ assertTrue(drl.indexOf("yeahMan();") > 0);
- pkg = repo.loadPackageSnapshot( "testBinaryPackageCompileBRL",
- "SNAP1" );
- results = impl.buildPackage( pkg.getUUID(), null, true );
- assertNull( results );
+ }
- //check that the rule name in the model is being set
- AssetItem asset2 = pkg.addAsset( "testSetRuleName",
- "" );
- asset2.updateFormat( AssetFormats.BUSINESS_RULE );
- asset2.checkin( "" );
+ public void testAssetSource() throws Exception {
+ ServiceImplementation impl = getService();
+ RulesRepository repo = impl.repository;
- RuleModel model2 = new RuleModel();
- assertNull( model2.name );
- RuleAsset asset = impl.loadRuleAsset( asset2.getUUID() );
- asset.content = model2;
+ // create our package
+ PackageItem pkg = repo.createPackage("testAssetSource", "");
+ AssetItem asset = pkg.addAsset("testRule", "");
+ asset.updateFormat(AssetFormats.DRL);
+ asset.updateContent("rule 'n' \n when Foo() then bar(); \n end");
+ asset.checkin("");
+ repo.save();
- impl.checkinVersion( asset );
+ RuleAsset rule = impl.loadRuleAsset(asset.getUUID());
+ String drl = impl.buildAssetSource(rule);
+ assertEquals("rule 'n' \n when Foo() then bar(); \n end", drl);
- asset = impl.loadRuleAsset( asset2.getUUID() );
+ asset = pkg.addAsset("DT", "");
+ asset.updateFormat(AssetFormats.DECISION_SPREADSHEET_XLS);
+ asset.updateBinaryContentAttachment(this.getClass()
+ .getResourceAsStream("/SampleDecisionTable.xls"));
+ asset.checkin("");
- model2 = (RuleModel) asset.content;
- assertNotNull( model2 );
- assertNotNull( model2.name );
- assertEquals( asset2.getName(),
- model2.name );
+ rule = impl.loadRuleAsset(asset.getUUID());
+ drl = impl.buildAssetSource(rule);
+ assertNotNull(drl);
+ assertTrue(drl.indexOf("rule") > -1);
+ assertTrue(drl.indexOf("policy: Policy") > -1);
- }
+ AssetItem dsl = pkg.addAsset("MyDSL", "");
+ dsl.updateFormat(AssetFormats.DSL);
+ dsl
+ .updateContent("[when]This is foo=bar()\n[then]do something=yeahMan();");
+ dsl.checkin("");
- /**
- * this loads up a precompile binary package. If this fails,
- * then it means it needs to be updated. It gets the package form the BRL example above.
- */
- public void IGNORE_testLoadAndExecBinary() throws Exception {
- Person p = new Person("fubar");
- BinaryRuleBaseLoader loader = new BinaryRuleBaseLoader();
- loader.addPackage( this.getClass().getResourceAsStream( "/RepoBinPackage.pkg" ) );
- RuleBase rb = loader.getRuleBase();
- StatelessSession sess = rb.newStatelessSession();
- sess.execute( p );
- assertEquals( 42,
- p.getAge() );
- }
+ asset = pkg.addAsset("MyDSLRule", "");
+ asset.updateFormat(AssetFormats.DSL_TEMPLATE_RULE);
+ asset.updateContent("when \n This is foo \n then \n do something");
+ asset.checkin("");
- public void testPackageSource() throws Exception {
- ServiceImplementation impl = getService();
- RulesRepository repo = impl.repository;
+ rule = impl.loadRuleAsset(asset.getUUID());
+ drl = impl.buildAssetSource(rule);
+ assertNotNull(drl);
+ assertTrue(drl.indexOf("This is foo") == -1);
+ assertTrue(drl.indexOf("do something") == -1);
+ assertTrue(drl.indexOf("bar()") > -1);
+ assertTrue(drl.indexOf("yeahMan();") > -1);
- //create our package
- PackageItem pkg = repo.createPackage( "testPackageSource",
- "" );
- pkg.updateHeader( "import org.goo.Ber" );
- AssetItem rule1 = pkg.addAsset( "rule_1",
- "" );
- rule1.updateFormat( AssetFormats.DRL );
- rule1.updateContent( "rule 'rule1' \n when p:Person() \n then p.setAge(42); \n end" );
- rule1.checkin( "" );
- repo.save();
+ rule = impl.loadRuleAsset(repo.copyAsset(asset.getUUID(),
+ "testAssetSource", "newRuleName"));
+ // System.err.println(((RuleContentText)rule.content).content);
+ drl = impl.buildAssetSource(rule);
+ assertNotNull(drl);
+ assertTrue(drl.indexOf("newRuleName") > 0);
- AssetItem func = pkg.addAsset( "funky",
- "" );
- func.updateFormat( AssetFormats.FUNCTION );
- func.updateContent( "this is a func" );
- func.checkin( "" );
+ }
- String drl = impl.buildPackageSource( pkg.getUUID() );
- assertNotNull( drl );
+ public void testBuildAsset() throws Exception {
+ ServiceImplementation impl = getService();
+ RulesRepository repo = impl.repository;
- assertTrue( drl.indexOf( "import org.goo.Ber" ) > -1 );
- assertTrue( drl.indexOf( "package testPackageSource" ) > -1 );
- assertTrue( drl.indexOf( "rule 'rule1'" ) > -1 );
- assertTrue( drl.indexOf( "this is a func" ) > -1 );
- assertTrue( drl.indexOf( "this is a func" ) < drl.indexOf( "rule 'rule1'" ) );
- assertTrue( drl.indexOf( "package testPackageSource" ) < drl.indexOf( "this is a func" ) );
- assertTrue( drl.indexOf( "package testPackageSource" ) < drl.indexOf( "import org.goo.Ber" ) );
+ // create our package
+ PackageItem pkg = repo.createPackage("testBuildAsset", "");
+ AssetItem model = pkg.addAsset("MyModel", "");
+ model.updateFormat(AssetFormats.MODEL);
+ model.updateBinaryContentAttachment(this.getClass()
+ .getResourceAsStream("/billasurf.jar"));
+ model.checkin("");
- AssetItem dsl = pkg.addAsset( "MyDSL",
- "" );
- dsl.updateFormat( AssetFormats.DSL );
- dsl.updateContent( "[when]This is foo=bar()\n[then]do something=yeahMan();" );
- dsl.checkin( "" );
+ pkg.updateHeader("import com.billasurf.Person");
- AssetItem asset = pkg.addAsset( "MyDSLRule",
- "" );
- asset.updateFormat( AssetFormats.DSL_TEMPLATE_RULE );
- asset.updateContent( "when \n This is foo \n then \n do something" );
- asset.checkin( "" );
+ AssetItem asset = pkg.addAsset("testRule", "");
+ asset.updateFormat(AssetFormats.DRL);
+ asset
+ .updateContent("rule 'MyGoodRule' \n when Person() then System.err.println(42); \n end");
+ asset.checkin("");
+ repo.save();
- drl = impl.buildPackageSource( pkg.getUUID() );
- assertNotNull( drl );
+ RuleAsset rule = impl.loadRuleAsset(asset.getUUID());
- assertTrue( drl.indexOf( "import org.goo.Ber" ) > -1 );
- assertTrue( drl.indexOf( "This is foo" ) == -1 );
- assertTrue( drl.indexOf( "do something" ) == -1 );
- assertTrue( drl.indexOf( "bar()" ) > 0 );
- assertTrue( drl.indexOf( "yeahMan();" ) > 0 );
+ // check its all OK
+ BuilderResult[] result = impl.buildAsset(rule);
+ assertNull(result);
- }
+ // try it with a bad rule
+ RuleContentText text = new RuleContentText();
+ text.content = "rule 'MyBadRule' \n when Personx() then System.err.println(42); \n end";
+ rule.content = text;
- public void testAssetSource() throws Exception {
- ServiceImplementation impl = getService();
- RulesRepository repo = impl.repository;
+ result = impl.buildAsset(rule);
+ assertNotNull(result);
+ assertNotNull(result[0].message);
+ assertEquals(AssetFormats.DRL, result[0].assetFormat);
- //create our package
- PackageItem pkg = repo.createPackage( "testAssetSource",
- "" );
- AssetItem asset = pkg.addAsset( "testRule",
- "" );
- asset.updateFormat( AssetFormats.DRL );
- asset.updateContent( "rule 'n' \n when Foo() then bar(); \n end" );
- asset.checkin( "" );
- repo.save();
+ // now mix in a DSL
+ AssetItem dsl = pkg.addAsset("MyDSL", "");
+ dsl.updateFormat(AssetFormats.DSL);
+ dsl
+ .updateContent("[when]There is a person=Person()\n[then]print out 42=System.err.println(42);");
+ dsl.checkin("");
- RuleAsset rule = impl.loadRuleAsset( asset.getUUID() );
- String drl = impl.buildAssetSource( rule );
- assertEquals( "rule 'n' \n when Foo() then bar(); \n end",
- drl );
+ AssetItem dslRule = pkg.addAsset("dslRule", "");
+ dslRule.updateFormat(AssetFormats.DSL_TEMPLATE_RULE);
+ dslRule
+ .updateContent("when \n There is a person \n then \n print out 42");
+ dslRule.checkin("");
- asset = pkg.addAsset( "DT",
- "" );
- asset.updateFormat( AssetFormats.DECISION_SPREADSHEET_XLS );
- asset.updateBinaryContentAttachment( this.getClass().getResourceAsStream( "/SampleDecisionTable.xls" ) );
- asset.checkin( "" );
+ rule = impl.loadRuleAsset(dslRule.getUUID());
- rule = impl.loadRuleAsset( asset.getUUID() );
- drl = impl.buildAssetSource( rule );
- assertNotNull( drl );
- assertTrue( drl.indexOf( "rule" ) > -1 );
- assertTrue( drl.indexOf( "policy: Policy" ) > -1 );
+ result = impl.buildAsset(rule);
+ assertNull(result);
- AssetItem dsl = pkg.addAsset( "MyDSL",
- "" );
- dsl.updateFormat( AssetFormats.DSL );
- dsl.updateContent( "[when]This is foo=bar()\n[then]do something=yeahMan();" );
- dsl.checkin( "" );
+ asset = pkg.addAsset("someEnumThing", "");
+ asset.updateFormat(AssetFormats.ENUMERATION);
+ asset.updateContent("goober boy");
+ asset.checkin("");
+ result = impl.buildAsset(impl.loadRuleAsset(asset.getUUID()));
+ assertFalse(result.length == 0);
- asset = pkg.addAsset( "MyDSLRule",
- "" );
- asset.updateFormat( AssetFormats.DSL_TEMPLATE_RULE );
- asset.updateContent( "when \n This is foo \n then \n do something" );
- asset.checkin( "" );
+ }
+ public void testBuildAssetBRXMLAndCopy() throws Exception {
+ ServiceImplementation impl = getService();
+ RulesRepository repo = impl.repository;
- rule = impl.loadRuleAsset( asset.getUUID() );
- drl = impl.buildAssetSource( rule );
- assertNotNull( drl );
- assertTrue( drl.indexOf( "This is foo" ) == -1 );
- assertTrue( drl.indexOf( "do something" ) == -1 );
- assertTrue( drl.indexOf( "bar()" ) > -1 );
- assertTrue( drl.indexOf( "yeahMan();" ) > -1 );
+ // create our package
+ PackageItem pkg = repo.createPackage("testBuildAssetBRL", "");
+ AssetItem model = pkg.addAsset("MyModel", "");
+ model.updateFormat(AssetFormats.MODEL);
+ model.updateBinaryContentAttachment(this.getClass()
+ .getResourceAsStream("/billasurf.jar"));
+ model.checkin("");
+ pkg.updateHeader("import com.billasurf.Person");
+ impl.createCategory("/", "brl", "");
- rule = impl.loadRuleAsset( repo.copyAsset( asset.getUUID(), "testAssetSource", "newRuleName" ) );
- //System.err.println(((RuleContentText)rule.content).content);
- drl = impl.buildAssetSource( rule );
- assertNotNull( drl );
- assertTrue( drl.indexOf( "newRuleName" ) > 0 );
+ String uuid = impl.createNewRule("testBRL", "", "brl",
+ "testBuildAssetBRL", AssetFormats.BUSINESS_RULE);
- }
+ RuleAsset rule = impl.loadRuleAsset(uuid);
+ RuleModel m = (RuleModel) rule.content;
+ assertNotNull(m);
+ m.name = "testBRL";
- public void testBuildAsset() throws Exception {
- ServiceImplementation impl = getService();
- RulesRepository repo = impl.repository;
+ FactPattern p = new FactPattern("Person");
+ p.boundName = "p";
+ SingleFieldConstraint con = new SingleFieldConstraint();
+ con.fieldName = "name";
+ con.value = "mark";
+ con.operator = "==";
+ con.constraintValueType = SingleFieldConstraint.TYPE_LITERAL;
- //create our package
- PackageItem pkg = repo.createPackage( "testBuildAsset",
- "" );
- AssetItem model = pkg.addAsset( "MyModel",
- "" );
- model.updateFormat( AssetFormats.MODEL );
- model.updateBinaryContentAttachment( this.getClass().getResourceAsStream( "/billasurf.jar" ) );
- model.checkin( "" );
+ p.addConstraint(con);
- pkg.updateHeader( "import com.billasurf.Person" );
+ m.addLhsItem(p);
- AssetItem asset = pkg.addAsset( "testRule",
- "" );
- asset.updateFormat( AssetFormats.DRL );
- asset.updateContent( "rule 'MyGoodRule' \n when Person() then System.err.println(42); \n end" );
- asset.checkin( "" );
- repo.save();
+ ActionSetField set = new ActionSetField("p");
+ ActionFieldValue f = new ActionFieldValue("name", "42-ngoo",
+ SuggestionCompletionEngine.TYPE_STRING);
+ set.addFieldValue(f);
- RuleAsset rule = impl.loadRuleAsset( asset.getUUID() );
+ m.addRhsItem(set);
- //check its all OK
- BuilderResult[] result = impl.buildAsset( rule );
- assertNull( result );
+ impl.checkinVersion(rule);
- //try it with a bad rule
- RuleContentText text = new RuleContentText();
- text.content = "rule 'MyBadRule' \n when Personx() then System.err.println(42); \n end";
- rule.content = text;
+ // check its all OK
+ BuilderResult[] result = impl.buildAsset(rule);
+ if (result != null) {
+ for (int i = 0; i < result.length; i++) {
+ System.err.println(result[i].message);
+ }
+ }
+ assertNull(result);
- result = impl.buildAsset( rule );
- assertNotNull( result );
- assertNotNull( result[0].message );
- assertEquals( AssetFormats.DRL,
- result[0].assetFormat );
+ List assets = iteratorToList(pkg.getAssets());
+ assertEquals(2, assets.size());
+ // now lets copy...
+ String newUUID = impl.copyAsset(rule.uuid, rule.metaData.packageName,
+ "ruleName2");
- //now mix in a DSL
- AssetItem dsl = pkg.addAsset( "MyDSL",
- "" );
- dsl.updateFormat( AssetFormats.DSL );
- dsl.updateContent( "[when]There is a person=Person()\n[then]print out 42=System.err.println(42);" );
- dsl.checkin( "" );
+ assets = iteratorToList(pkg.getAssets());
+ assertEquals(3, assets.size());
+ RuleAsset asset = impl.loadRuleAsset(newUUID);
- AssetItem dslRule = pkg.addAsset( "dslRule",
- "" );
- dslRule.updateFormat( AssetFormats.DSL_TEMPLATE_RULE );
- dslRule.updateContent( "when \n There is a person \n then \n print out 42" );
- dslRule.checkin( "" );
+ String pkgSource = impl.buildPackageSource(pkg.getUUID());
- rule = impl.loadRuleAsset( dslRule.getUUID() );
+ assertTrue(pkgSource.indexOf("ruleName2") > 0);
+ assertTrue(impl.buildAssetSource(asset).indexOf("ruleName2") > 0);
+ assertTrue(impl.buildAssetSource(asset).indexOf("testBRL") == -1);
- result = impl.buildAsset( rule );
- assertNull( result );
+ // RuleModel model2 = (RuleModel) asset.content;
+ // assertEquals("ruleName2", model2.name);
- asset = pkg.addAsset( "someEnumThing", "" );
- asset.updateFormat( AssetFormats.ENUMERATION );
- asset.updateContent( "goober boy" );
- asset.checkin( "" );
- result = impl.buildAsset( impl.loadRuleAsset( asset.getUUID() ) );
- assertFalse(result.length == 0);
+ }
- }
+ private List iteratorToList(Iterator assets) {
+ List result = new ArrayList();
+ while (assets.hasNext()) {
+ result.add(assets.next());
- public void testBuildAssetBRXMLAndCopy() throws Exception {
- ServiceImplementation impl = getService();
- RulesRepository repo = impl.repository;
+ }
+ return result;
+ }
- //create our package
- PackageItem pkg = repo.createPackage( "testBuildAssetBRL",
- "" );
- AssetItem model = pkg.addAsset( "MyModel",
- "" );
- model.updateFormat( AssetFormats.MODEL );
- model.updateBinaryContentAttachment( this.getClass().getResourceAsStream( "/billasurf.jar" ) );
- model.checkin( "" );
+ public void testBuildAssetWithPackageConfigError() throws Exception {
+ ServiceImplementation impl = getService();
+ RulesRepository repo = impl.repository;
- pkg.updateHeader( "import com.billasurf.Person" );
- impl.createCategory( "/",
- "brl",
- "" );
+ PackageItem pkg = repo.createPackage(
+ "testBuildAssetWithPackageConfigError", "");
+ // AssetItem model = pkg.addAsset( "MyModel", "" );
+ // model.updateFormat( AssetFormats.MODEL );
+ // model.updateBinaryContentAttachment(
+ // this.getClass().getResourceAsStream( "/billasurf.jar" ) );
+ // model.checkin( "" );
- String uuid = impl.createNewRule( "testBRL",
- "",
- "brl",
- "testBuildAssetBRL",
- AssetFormats.BUSINESS_RULE );
+ // pkg.updateHeader( "import com.billasurf.Person" );
- RuleAsset rule = impl.loadRuleAsset( uuid );
+ AssetItem asset = pkg.addAsset("testRule", "");
+ asset.updateFormat(AssetFormats.DRL);
+ asset.updateContent("rule 'MyGoodRule' \n when \n then \n end");
+ asset.checkin("");
+ repo.save();
- RuleModel m = (RuleModel) rule.content;
- assertNotNull( m );
- m.name = "testBRL";
+ RuleAsset rule = impl.loadRuleAsset(asset.getUUID());
- FactPattern p = new FactPattern( "Person" );
- p.boundName = "p";
- SingleFieldConstraint con = new SingleFieldConstraint();
- con.fieldName = "name";
- con.value = "mark";
- con.operator = "==";
- con.constraintValueType = SingleFieldConstraint.TYPE_LITERAL;
+ // check its all OK
+ BuilderResult[] result = impl.buildAsset(rule);
+ if (!(result == null)) {
+ System.err.println(result[0].assetName + " " + result[0].message);
+ }
+ assertNull(result);
- p.addConstraint( con );
+ pkg.updateHeader("importxxxx");
+ repo.save();
+ result = impl.buildAsset(rule);
+ assertNotNull(result);
- m.addLhsItem( p );
+ assertEquals(1, result.length);
+ assertEquals("package", result[0].assetFormat);
+ assertNotNull(result[0].message);
- ActionSetField set = new ActionSetField( "p" );
- ActionFieldValue f = new ActionFieldValue( "name",
- "42-ngoo",
- SuggestionCompletionEngine.TYPE_STRING );
- set.addFieldValue( f );
+ }
- m.addRhsItem( set );
+ public void testRuleNameList() throws Exception {
+ ServiceImplementation impl = getService();
+ RulesRepository repo = impl.repository;
- impl.checkinVersion( rule );
+ // create our package
+ PackageItem pkg = repo.createPackage("testRuleNameList", "");
+ pkg.updateHeader("import org.goo.Ber");
+ AssetItem rule1 = pkg.addAsset("rule_1", "");
+ rule1.updateFormat(AssetFormats.DRL);
+ rule1
+ .updateContent("rule 'rule1' \n when p:Person() \n then p.setAge(42); \n end");
+ rule1.checkin("");
+ repo.save();
- //check its all OK
- BuilderResult[] result = impl.buildAsset( rule );
- if ( result != null ) {
- for ( int i = 0; i < result.length; i++ ) {
- System.err.println( result[i].message );
- }
- }
- assertNull( result );
+ AssetItem rule2 = pkg.addAsset("rule_2", "");
+ rule2.updateFormat(AssetFormats.DRL);
+ rule2
+ .updateContent("rule 'rule2' \n when p:Person() \n then p.setAge(42); \n end");
+ rule2.checkin("");
+ repo.save();
+ String[] list = impl.listRulesInPackage(pkg.getName());
+ assertEquals(2, list.length);
+ assertEquals("rule1", list[0]);
+ assertEquals("rule2", list[1]);
- List assets = iteratorToList(pkg.getAssets());
- assertEquals(2, assets.size());
- //now lets copy...
- String newUUID = impl.copyAsset( rule.uuid, rule.metaData.packageName, "ruleName2" );
+ }
+ /**
+ * This idea of this is to not compile packages more then we have to.
+ */
+ public void testBinaryUpToDate() throws Exception {
+ ServiceImplementation impl = getService();
+ RulesRepository repo = impl.repository;
- assets = iteratorToList(pkg.getAssets());
- assertEquals(3, assets.size());
- RuleAsset asset = impl.loadRuleAsset( newUUID );
+ // create our package
+ PackageItem pkg = repo.createPackage("testBinaryPackageUpToDate", "");
+ assertFalse(pkg.isBinaryUpToDate());
+ pkg.updateHeader("import org.drools.Person");
+ AssetItem rule1 = pkg.addAsset("rule_1", "");
+ rule1.updateFormat(AssetFormats.DRL);
+ rule1
+ .updateContent("rule 'rule1' \n when \np : Person() \n then \np.setAge(42); \n end");
+ rule1.checkin("");
+ repo.save();
- String pkgSource = impl.buildPackageSource( pkg.getUUID() );
+ assertFalse(pkg.isBinaryUpToDate());
+ assertFalse(impl.ruleBaseCache.containsKey(pkg.getUUID()));
+ impl.ruleBaseCache.remove("XXX");
- assertTrue(pkgSource.indexOf( "ruleName2" ) > 0);
- assertTrue(impl.buildAssetSource( asset ).indexOf( "ruleName2" ) > 0);
- assertTrue(impl.buildAssetSource( asset ).indexOf( "testBRL" ) == -1);
+ BuilderResult[] results = impl.buildPackage(pkg.getUUID(), null, true);
+ assertNull(results);
+ pkg = repo.loadPackage("testBinaryPackageUpToDate");
+ byte[] binPackage = pkg.getCompiledPackageBytes();
-// RuleModel model2 = (RuleModel) asset.content;
-// assertEquals("ruleName2", model2.name);
+ assertNotNull(binPackage);
- }
+ assertTrue(pkg.getNode().getProperty("drools:binaryUpToDate")
+ .getBoolean());
+ assertTrue(pkg.isBinaryUpToDate());
+ assertTrue(impl.ruleBaseCache.containsKey(pkg.getUUID()));
- private List iteratorToList(Iterator assets) {
- List result = new ArrayList();
- while ( assets.hasNext() ) {
- result.add( assets.next() );
+ RuleAsset asset = impl.loadRuleAsset(rule1.getUUID());
+ impl.checkinVersion(asset);
- }
- return result;
- }
+ assertFalse(pkg.getNode().getProperty("drools:binaryUpToDate")
+ .getBoolean());
+ assertFalse(impl.ruleBaseCache.containsKey(pkg.getUUID()));
- public void testBuildAssetWithPackageConfigError() throws Exception {
- ServiceImplementation impl = getService();
- RulesRepository repo = impl.repository;
+ impl.buildPackage(pkg.getUUID(), null, false);
- PackageItem pkg = repo.createPackage( "testBuildAssetWithPackageConfigError",
- "" );
- // AssetItem model = pkg.addAsset( "MyModel", "" );
- // model.updateFormat( AssetFormats.MODEL );
- // model.updateBinaryContentAttachment( this.getClass().getResourceAsStream( "/billasurf.jar" ) );
- // model.checkin( "" );
+ assertTrue(pkg.getNode().getProperty("drools:binaryUpToDate")
+ .getBoolean());
+ assertTrue(impl.ruleBaseCache.containsKey(pkg.getUUID()));
- // pkg.updateHeader( "import com.billasurf.Person" );
+ PackageConfigData config = impl.loadPackageConfig(pkg.getUUID());
+ impl.savePackage(config);
- AssetItem asset = pkg.addAsset( "testRule",
- "" );
- asset.updateFormat( AssetFormats.DRL );
- asset.updateContent( "rule 'MyGoodRule' \n when \n then \n end" );
- asset.checkin( "" );
- repo.save();
+ assertFalse(pkg.getNode().getProperty("drools:binaryUpToDate")
+ .getBoolean());
+ assertFalse(pkg.isBinaryUpToDate());
+ impl.buildPackage(pkg.getUUID(), null, false);
+ assertTrue(pkg.getNode().getProperty("drools:binaryUpToDate")
+ .getBoolean());
+ assertTrue(pkg.isBinaryUpToDate());
- RuleAsset rule = impl.loadRuleAsset( asset.getUUID() );
+ }
- //check its all OK
- BuilderResult[] result = impl.buildAsset( rule );
- if ( !(result == null) ) {
- System.err.println( result[0].assetName + " " + result[0].message );
- }
- assertNull( result );
+ public void testRunScenario() throws Exception {
+ ServiceImplementation impl = getService();
+ RulesRepository repo = impl.repository;
- pkg.updateHeader( "importxxxx" );
- repo.save();
- result = impl.buildAsset( rule );
- assertNotNull( result );
-
- assertEquals( 1,
- result.length );
- assertEquals( "package",
- result[0].assetFormat );
- assertNotNull( result[0].message );
-
- }
-
- public void testRuleNameList() throws Exception {
- ServiceImplementation impl = getService();
- RulesRepository repo = impl.repository;
-
- //create our package
- PackageItem pkg = repo.createPackage( "testRuleNameList",
- "" );
- pkg.updateHeader( "import org.goo.Ber" );
- AssetItem rule1 = pkg.addAsset( "rule_1",
- "" );
- rule1.updateFormat( AssetFormats.DRL );
- rule1.updateContent( "rule 'rule1' \n when p:Person() \n then p.setAge(42); \n end" );
- rule1.checkin( "" );
- repo.save();
-
- AssetItem rule2 = pkg.addAsset( "rule_2",
- "" );
- rule2.updateFormat( AssetFormats.DRL );
- rule2.updateContent( "rule 'rule2' \n when p:Person() \n then p.setAge(42); \n end" );
- rule2.checkin( "" );
+ PackageItem pkg = repo.createPackage("testScenarioRun", "");
+ pkg.updateHeader("import org.drools.Person");
+ AssetItem rule1 = pkg.addAsset("rule_1", "");
+ rule1.updateFormat(AssetFormats.DRL);
+ rule1
+ .updateContent("rule 'rule1' \n when \np : Person() \n then \np.setAge(42); \n end");
+ rule1.checkin("");
repo.save();
- String[] list = impl.listRulesInPackage(pkg.getName());
- assertEquals(2, list.length);
- assertEquals("rule1", list[0]);
- assertEquals("rule2", list[1]);
+ Scenario sc = new Scenario();
+ FactData person = new FactData();
+ person.name = "p";
+ person.type = "Person";
+ person.fieldData.add(new FieldData("age", "40"));
+ person.fieldData.add(new FieldData("name", "michael"));
- }
+ sc.fixtures.add(person);
+ sc.fixtures.add(new ExecutionTrace());
+ VerifyRuleFired vr = new VerifyRuleFired("rule1", 1, null);
+ sc.fixtures.add(vr);
+ VerifyFact vf = new VerifyFact();
+ vf.name = "p";
+ vf.fieldValues.add(new VerifyField("name", "michael", "=="));
+ vf.fieldValues.add(new VerifyField("age", "42", "=="));
+ sc.fixtures.add(vf);
- /**
- * This idea of this is to not compile packages more then we have to.
- */
- public void testBinaryUpToDate() throws Exception {
- ServiceImplementation impl = getService();
- RulesRepository repo = impl.repository;
+ ScenarioRunResult res = impl.runScenario(pkg.getUUID(), sc);
+ assertEquals(null, res.errors);
+ assertNotNull(res.scenario);
+ assertTrue(vf.wasSuccessful());
+ assertTrue(vr.wasSuccessful());
- //create our package
- PackageItem pkg = repo.createPackage( "testBinaryPackageUpToDate",
- "" );
- assertFalse(pkg.isBinaryUpToDate());
- pkg.updateHeader( "import org.drools.Person" );
- AssetItem rule1 = pkg.addAsset( "rule_1",
- "" );
- rule1.updateFormat( AssetFormats.DRL );
- rule1.updateContent( "rule 'rule1' \n when \np : Person() \n then \np.setAge(42); \n end" );
- rule1.checkin( "" );
- repo.save();
- BuilderResult[] results = impl.buildPackage( pkg.getUUID(), null, true );
- assertNull( results );
- pkg = repo.loadPackage( "testBinaryPackageUpToDate" );
- byte[] binPackage = pkg.getCompiledPackageBytes();
+ res = impl.runScenario(pkg.getUUID(), sc);
+ assertEquals(null, res.errors);
+ assertNotNull(res.scenario);
+ assertTrue(vf.wasSuccessful());
+ assertTrue(vr.wasSuccessful());
- assertNotNull( binPackage );
- assertTrue(pkg.getNode().getProperty("drools:binaryUpToDate").getBoolean());
+ impl.ruleBaseCache.clear();
+ res = impl.runScenario(pkg.getUUID(), sc);
+ assertEquals(null, res.errors);
+ assertNotNull(res.scenario);
+ assertTrue(vf.wasSuccessful());
+ assertTrue(vr.wasSuccessful());
- RuleAsset asset = impl.loadRuleAsset(rule1.getUUID());
- impl.checkinVersion(asset);
+ //BuilderResult[] results = impl.buildPackage(pkg.getUUID(), null, true);
+ //assertNull(results);
- assertFalse(pkg.getNode().getProperty("drools:binaryUpToDate").getBoolean());
+ }
- impl.buildPackage(pkg.getUUID(), null, false );
+ private ServiceImplementation getService() throws Exception {
+ ServiceImplementation impl = new ServiceImplementation();
- assertTrue(pkg.getNode().getProperty("drools:binaryUpToDate").getBoolean());
+ impl.repository = new RulesRepository(TestEnvironmentSessionHelper
+ .getSession());
+ return impl;
+ }
- PackageConfigData config = impl.loadPackageConfig(pkg.getUUID());
- impl.savePackage(config);
-
- assertFalse(pkg.getNode().getProperty("drools:binaryUpToDate").getBoolean());
- assertFalse(pkg.isBinaryUpToDate());
- impl.buildPackage(pkg.getUUID(), null, false );
- assertTrue(pkg.getNode().getProperty("drools:binaryUpToDate").getBoolean());
- assertTrue(pkg.isBinaryUpToDate());
-
-
- }
-
-
- private ServiceImplementation getService() throws Exception {
- ServiceImplementation impl = new ServiceImplementation();
-
- impl.repository = new RulesRepository( TestEnvironmentSessionHelper.getSession() );
- return impl;
- }
-
}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list