From: <jbo...@li...> - 2006-01-06 07:25:45
|
Author: mic...@jb... Date: 2006-01-06 02:25:19 -0500 (Fri, 06 Jan 2006) New Revision: 2006 Added: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/AttachmentPersistTest.java trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java Removed: trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/AttachmentFile.hbm.xml trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/db/AttachmentPersistTest.java trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/db/RulePersistenceTest.java trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/db/RuleSetPersistenceTest.java Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/MetaData.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetAttachment.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetVersionInfo.java trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleDef.hbm.xml trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetAttachment.hbm.xml trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetDef.hbm.xml trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetVersionInfo.hbm.xml trunk/labs/jbossrules/drools-repository/src/test/resources/hibernate.cfg.xml Log: pre weekend commit Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/MetaData.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/MetaData.java 2006-01-06 07:19:01 UTC (rev 2005) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/MetaData.java 2006-01-06 07:25:19 UTC (rev 2006) @@ -4,9 +4,12 @@ import java.util.Date; /** + * MetaData for rule assets. + * * This is based on the <a href="http://dublincore.org/documents/dces/"> Dublin * Core</a> specification. Not * all of these fields will be used by everyone. They should only be used for classification. + * An alternative approach is to use the free form "tagging" of Rule assets. */ public class MetaData implements @@ -130,7 +133,12 @@ this.title = title; } - public MetaData copy(){ + /** + * This is used for versioning. + * MetaData itself is not versioned, but copies of it are taken when + * other assets are versioned. + */ + MetaData copy(){ MetaData copy = new MetaData(); copy.contributor = this.contributor; copy.coverage = this.coverage; Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java 2006-01-06 07:19:01 UTC (rev 2005) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleDef.java 2006-01-06 07:25:19 UTC (rev 2006) @@ -7,6 +7,9 @@ public class RuleDef extends Persistent { + + private static final long serialVersionUID = -677781085801764266L; + private String name; private long versionNumber; private String content; @@ -19,21 +22,10 @@ private String documentation; private Date effectiveDate; private Date expiryDate; - private boolean deleted; - public boolean isDeleted(){ - return deleted; - } - - public void setDeleted(boolean deleted){ - this.deleted = deleted; - } - - - /** * Use tagging to aid with searching and sorting of large numbers of rules. * Tags should not effect the versioning of the rules. @@ -58,16 +50,10 @@ this.name = name; this.content = content; this.versionNumber = 1; - this.head = true; this.tags = new HashSet(); } - /** - * This little cheat tells the repo that this - * rule is at the head of versions. - */ - private boolean head; + - public String getContent(){ return content; } @@ -100,12 +86,7 @@ public void setCheckedOutBy(String checkOutBy){ this.checkedOutBy = checkOutBy; } - public boolean isHead(){ - return head; - } - public void setHead(boolean isHead){ - this.head = isHead; - } + public String getVersionComment(){ return versionComment; } @@ -115,7 +96,7 @@ public long getVersionNumber(){ return this.versionNumber; } - private void setVersionNumber(long versionNumber){ + void setVersionNumber(long versionNumber){ this.versionNumber = versionNumber; } public String getDocumentation(){ @@ -150,7 +131,9 @@ return this; } - /** return a list of tags as Strings */ + /** return a list of tags as Strings. Tags are stored as Tag objects, + * but are essentially strings. + */ public String[] listTags() { String[] tagList = new String[tags.size()]; @@ -163,14 +146,24 @@ return tagList; } - public RuleDef createNewVersion() { -// if (this.checkedOut) { -// throw new RuleRepositoryLockException("Rule is checked out by " + this.checkedOutBy); -// } + /** + * Copy the tags. It is allowable to reuse the same Tag identities. + */ + private Set copyTags() { + Set newTags = new HashSet(); + for ( Iterator iter = this.tags.iterator(); iter.hasNext(); ) { + Tag tag = (Tag) iter.next(); + newTags.add(tag); + } + return newTags; + } + + /** + * This is used for versioning. + */ + RuleDef copy() { RuleDef newVersion = new RuleDef(); newVersion.content = this.content; - this.head = false; - newVersion.head = true; newVersion.documentation = documentation; newVersion.effectiveDate = this.effectiveDate; newVersion.expiryDate = this.expiryDate; @@ -179,39 +172,8 @@ } newVersion.name = this.name; newVersion.status = ""; - newVersion.tags = this.copyTags(); - newVersion.versionNumber = this.versionNumber + 1; + newVersion.tags = this.copyTags(); return newVersion; } - - - - private Set copyTags() { - Set newTags = new HashSet(); - for ( Iterator iter = this.tags.iterator(); iter.hasNext(); ) { - Tag tag = (Tag) iter.next(); - newTags.add(tag); - } - return newTags; - } - - - -// public boolean equals(Object arg){ -// if (arg.getClass() != this.getClass()) return false; -// RuleDef other = (RuleDef) arg; -// return (other.versionNumber == this.versionNumber -// && other.name.equals(this.name)); -// } -// -// -// -// public int hashCode(){ -// int result = this.name.hashCode(); -// return new Long(versionNumber).hashCode() + 27 * result; -// } - - - } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetAttachment.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetAttachment.java 2006-01-06 07:19:01 UTC (rev 2005) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetAttachment.java 2006-01-06 07:25:19 UTC (rev 2006) @@ -1,35 +1,47 @@ package org.drools.repository; -import java.util.HashSet; -import java.util.Set; /** - * A RuleSetAttachment contains a ruleset that is stored in a non-normalised format. + * A RuleSetAttachment may contain a ruleset that is stored in a non-normalised format. * An attachment may be a spreadsheet for instance. Or it may be a HTML document and a properties file. - * An "attachment" will contain one or more AttachmentFiles, which actually wraps the content. + * It can even be a plain old DRL file. * - * These are versioned along with the ruleset (with optional per save versioning). + * Attachments can also be miscellanious files, such as test scripts or documentation. The deployer will + * use the typeOfAttachment property to work out what to do with it. * + * These are versioned along with the ruleset (with per save versioning as well). + * * @author <a href="mailto:mic...@gm..."> Michael Neale</a> * */ public class RuleSetAttachment extends Persistent { + + private static final long serialVersionUID = 7474038734785975202L; + + + private byte[] content; + private String originalFileName; + private String typeOfAttachment; - private Set attachments = new HashSet(); + private String name; private long versionNumber = 1; public RuleSetAttachment(String typeOfAttachment, - String name){ + String name, + byte[] content, + String originalFileName ) { super(); this.typeOfAttachment = typeOfAttachment; this.name = name; + this.content = content; + this.originalFileName = originalFileName; } - public RuleSetAttachment() { + RuleSetAttachment() { } public String getName(){ @@ -42,22 +54,6 @@ } - public Set getAttachments(){ - return attachments; - } - - - private void setAttachments(Set attachments){ - this.attachments = attachments; - } - - - public RuleSetAttachment addFile(AttachmentFile file) { - this.attachments.add(file); - return this; - } - - public String getTypeOfAttachment(){ return typeOfAttachment; } @@ -69,9 +65,25 @@ return versionNumber; } - public void setVersionNumber(long versionNumber){ + void setVersionNumber(long versionNumber){ this.versionNumber = versionNumber; } + + public byte[] getContent(){ + return content; + } + + public void setContent(byte[] content){ + this.content = content; + } + + public String getOriginalFileName(){ + return originalFileName; + } + + public void setOriginalFileName(String originalFileName){ + this.originalFileName = originalFileName; + } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java 2006-01-06 07:19:01 UTC (rev 2005) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetDef.java 2006-01-06 07:25:19 UTC (rev 2006) @@ -1,6 +1,9 @@ package org.drools.repository; +import java.util.ArrayList; import java.util.HashSet; +import java.util.Iterator; +import java.util.List; import java.util.Set; /** @@ -8,11 +11,9 @@ * The workingVersionNumber drives what version of rules will be included in this ruleset. * Changing this number will mean that different versions of ruledefs are loaded etc. * - * * @author <a href="mailto:mic...@gm..."> Michael Neale</a> - * */ -public class RuleSetDef extends Persistent { +public class RuleSetDef extends Persistent implements Comparable { private static final long serialVersionUID = 608068118653708104L; private String name; @@ -21,13 +22,14 @@ private Set tags; private long workingVersionNumber; private Set versionHistory; - private RuleSetAttachment attachment; + private Set attachments; public RuleSetDef(String name, MetaData meta) { this.name = name; this.metaData = meta; this.tags = new HashSet(); this.rules = new HashSet(); + this.attachments = new HashSet(); this.workingVersionNumber = 1; } @@ -38,16 +40,7 @@ RuleSetDef() { } - public RuleSetAttachment getAttachment(){ - return attachment; - } - - public void setAttachment(RuleSetAttachment attachment){ - this.attachment = attachment; - } - - public Set getVersionHistory(){ return versionHistory; } @@ -57,23 +50,49 @@ this.versionHistory = versionHistory; } + /** + * This adds a rule to the ruleset. + * + * If the rule already has an Id, and it is a different version number, then + * it will be copied for this ruleset. + * If it has the same version number, then it will be shared. + */ public RuleSetDef addRule(RuleDef rule) { - this.rules.add(rule); + if (rule.getId() == null) { + rule.setVersionNumber(this.workingVersionNumber); + this.rules.add(rule); + } else if (rule.getVersionNumber() == this.workingVersionNumber) { + this.rules.add(rule); + } else { + RuleDef copy = rule.copy(); + copy.setVersionNumber(this.workingVersionNumber); + this.rules.add(copy); + } return this; } + public RuleSetDef addAttachment(RuleSetAttachment attachmentFile) { + attachmentFile.setVersionNumber(this.workingVersionNumber); + this.attachments.add(attachmentFile); + return this; + } + public MetaData getMetaData(){ return metaData; } public void setMetaData(MetaData metaData){ this.metaData = metaData; } + + + /** The list of rules that are currently loaded for this ruleset */ public Set getRules(){ return rules; } private void setRules(Set rules){ this.rules = rules; } + public String getName(){ return name; } @@ -102,14 +121,84 @@ this.workingVersionNumber = workingVersionNumber; } - /** This method increments the version of the ruleset, creating a brand new version. + /** + * This method increments the working version of the ruleset, creating a brand new version. * This records the event in the version history. - * All rules and ruleset-attachments that are connected to this version of the ruleset are + * + * Typically you would call this method when you want to make a stable version of a rule set (lock in all + * the related assets) and then move on to an "editing" version. You can always switch back to a previous version + * of a rulebase. + * + * All rules and ruleset-attachments etc that are + * connected to this version of the ruleset are cloned with the new workingVersionNumber. + * + * This means that the previous state of the RuleSet is kept in tact (for instance, as a release of rules). + * Rules can then be edited, removed and so on without effecting any previous versions of rules and the ruleset. + * + * Previous rules can be retrieved by changing the value of workingVersionNumber. + * + * Note that further to this, rules themselves will be versioned on save (think of that versioning as + * "minor" versions, and this sort of ruleset versions as major versions). + * + * Ideally once a new version is created, the RuleSet should be stored and then loaded fresh, + * which will hide the non working versions of the rules. + * */ public void createNewVersion(String comment, String newStatus) { + this.workingVersionNumber++; + RuleSetVersionInfo newVersion = new RuleSetVersionInfo(); + newVersion.setStatus(newStatus); + newVersion.setVersionNumber(this.workingVersionNumber); + this.versionHistory.add(newVersion); + //as the Ids are null, copied objects + //will get a new identity, and have the new workingVersionNumber + + //now have to create new rules and add to the collection + createNewRuleVersions( comment ); + +// //create new attachment +// for ( Iterator iter = this.attachments.iterator(); iter.hasNext(); ) { +// RuleSetAttachment att = (RuleSetAttachment) iter.next(); +// //TODO: need too finish this. +// att.copy(); +// +// } + + //create new functions, app data and imports etc. + System.out.println("DON'T FORGET FUNCTIONS ETC !!"); + } + + private void createNewRuleVersions(String comment){ + for ( Iterator iter = this.rules.iterator(); iter.hasNext(); ) { + RuleDef old = (RuleDef) iter.next(); + RuleDef clone = (RuleDef) old.copy(); + clone.setVersionComment(comment); + clone.setVersionNumber(this.workingVersionNumber); + this.rules.add(clone); + } + } + public String toString() { + return "{ name=" + this.name + " , workingVersionNumber=" + this.workingVersionNumber + " }"; + } + + /** The name provides the natural ordering */ + public int compareTo(Object arg){ + if (arg instanceof RuleSetDef) { + return ((RuleSetDef) arg).name.compareTo(this.name); + } + return 0; + } + + public Set getAttachments(){ + return attachments; + } + + private void setAttachments(Set attachments){ + this.attachments = attachments; + } } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetVersionInfo.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetVersionInfo.java 2006-01-06 07:19:01 UTC (rev 2005) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/RuleSetVersionInfo.java 2006-01-06 07:25:19 UTC (rev 2006) @@ -13,9 +13,11 @@ * @author <a href="mailto:mic...@gm..."> Michael Neale</a> * */ -public class RuleSetVersionInfo extends Persistent { +public class RuleSetVersionInfo extends Persistent implements Comparable { - private String createdByUser; + + private static final long serialVersionUID = 53728327711138178L; + private Date createdOn = new Date(); private long versionNumber; private String versionComment; @@ -29,23 +31,15 @@ this.status = status; } - public RuleSetVersionInfo(String createdByUser, - long versionNumber, + public RuleSetVersionInfo(long versionNumber, String versionComment){ super(); - this.createdByUser = createdByUser; this.versionNumber = versionNumber; this.versionComment = versionComment; } RuleSetVersionInfo() {} - public String getCreatedByUser(){ - return createdByUser; - } - public void setCreatedByUser(String createdByUser){ - this.createdByUser = createdByUser; - } public Date getCreatedOn(){ return createdOn; } @@ -64,6 +58,21 @@ public void setVersionNumber(long versionNumber){ this.versionNumber = versionNumber; } + + /** The version number provides the natural ordering */ + public int compareTo(Object arg){ + if (arg instanceof RuleSetVersionInfo) { + RuleSetVersionInfo info = (RuleSetVersionInfo) arg; + if (info.versionNumber == this.versionNumber ) { + return 0; + } else if (info.versionNumber < this.versionNumber) { + return -1; + } else { + return 1; + } + } + return 0; + } Modified: trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java 2006-01-06 07:19:01 UTC (rev 2005) +++ trunk/labs/jbossrules/drools-repository/src/main/java/org/drools/repository/db/RepositoryImpl.java 2006-01-06 07:25:19 UTC (rev 2006) @@ -27,17 +27,6 @@ //DODGY METHODS START - public List listAllRules(boolean head) { - Session session = getSession(); - session.beginTransaction(); - List results = session - .createQuery("from RuleDef where head = :head") - .setBoolean("head", head).setMaxResults(1000) - .list(); - session.getTransaction().commit(); - return results; - } - public RuleDef loadRule(String ruleName, long versionNumber) { Session session = getSession(); session.beginTransaction(); Deleted: trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/AttachmentFile.hbm.xml =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/AttachmentFile.hbm.xml 2006-01-06 07:19:01 UTC (rev 2005) +++ trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/AttachmentFile.hbm.xml 2006-01-06 07:25:19 UTC (rev 2006) @@ -1,39 +0,0 @@ -<?xml version="1.0"?> -<!DOCTYPE hibernate-mapping PUBLIC - "-//Hibernate/Hibernate Mapping DTD 3.0//EN" - "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> - - -<hibernate-mapping> - - <class name="org.drools.repository.AttachmentFile" table="FILE_ATTACHMENTS"> - <id name="id" column="ATTACHMENT_ID"> - <generator class="native"/> - </id> - - <property name="content"/> - <property name="contentType" /> - <property name="originalFileName" /> -<!-- - <component name="metaData"> - <property name="title" /> - <property name="creator" /> - <property name="subject" /> - <property name="description" /> - <property name="publisher" /> - <property name="contributor" /> - <property name="dateCreated" /> - <property name="format" /> - <property name="source" /> - <property name="language" /> - <property name="relation" /> - <property name="coverage" /> - <property name="rights" /> - </component> - --> - - - - </class> - -</hibernate-mapping> \ No newline at end of file Modified: trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleDef.hbm.xml =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleDef.hbm.xml 2006-01-06 07:19:01 UTC (rev 2005) +++ trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleDef.hbm.xml 2006-01-06 07:25:19 UTC (rev 2006) @@ -21,8 +21,7 @@ <property name="documentation" /> <property name="effectiveDate" /> <property name="expiryDate" /> - <property name="head" /> - <property name="deleted" /> + <!-- want nothing to be lazy, no runtime proxies??? --> <!-- tags to aid with searching and management of rules --> Modified: trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetAttachment.hbm.xml =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetAttachment.hbm.xml 2006-01-06 07:19:01 UTC (rev 2005) +++ trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetAttachment.hbm.xml 2006-01-06 07:25:19 UTC (rev 2006) @@ -13,11 +13,8 @@ <property name="name" /> <property name="typeOfAttachment" /> - - <set name="attachments" table="RULESET_ATTACHMENT_FILES" lazy="false" cascade="all"> - <key column="RULESET_ATTACHMENT_ID"/> - <one-to-many class="org.drools.repository.AttachmentFile"/> - </set> + <property name="content" /> + <property name="originalFileName" /> </class> Modified: trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetDef.hbm.xml =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetDef.hbm.xml 2006-01-06 07:19:01 UTC (rev 2005) +++ trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetDef.hbm.xml 2006-01-06 07:25:19 UTC (rev 2006) @@ -50,13 +50,12 @@ <one-to-many class="org.drools.repository.RuleSetVersionInfo"/> </set> - <!-- we need only one ruleset attachment object. The files are attached to it as a - collection --> - <many-to-one name="attachment" column="RULESET_ATTACHMENT_ID" - class="org.drools.repository.RuleSetAttachment" - lazy="false" - cascade="all" - unique="true"/> + <set name="attachments" lazy="false" cascade="all"> + <key column="RULESET_ID"/> + <one-to-many class="org.drools.repository.RuleSetAttachment"/> + </set> + + </class> Modified: trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetVersionInfo.hbm.xml =================================================================== --- trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetVersionInfo.hbm.xml 2006-01-06 07:19:01 UTC (rev 2005) +++ trunk/labs/jbossrules/drools-repository/src/main/resources/org/drools/repository/RuleSetVersionInfo.hbm.xml 2006-01-06 07:25:19 UTC (rev 2006) @@ -15,7 +15,6 @@ <property name="versionNumber"/> <property name="versionComment"/> <property name="createdOn"/> - <property name="createdByUser"/> <property name="status" /> </class> Added: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/AttachmentPersistTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/AttachmentPersistTest.java 2006-01-06 07:19:01 UTC (rev 2005) +++ trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/AttachmentPersistTest.java 2006-01-06 07:25:19 UTC (rev 2006) @@ -0,0 +1,16 @@ +package org.drools.repository; + +import org.drools.repository.db.PersistentCase; +import org.drools.repository.db.RepositoryImpl; + +public class AttachmentPersistTest extends PersistentCase { + + public void testLoadSave() { + RuleSetAttachment at = new RuleSetAttachment("test","test", "test".getBytes(), "blah.xml" ); + RepositoryImpl repo = getRepo(); + repo.save(at); + RuleSetAttachment at2 = repo.loadAttachment("test"); + assertEquals("test", at2.getTypeOfAttachment()); + } + +} Property changes on: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/AttachmentPersistTest.java ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java 2006-01-06 07:19:01 UTC (rev 2005) +++ trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java 2006-01-06 07:25:19 UTC (rev 2006) @@ -0,0 +1,69 @@ +package org.drools.repository; + +import java.util.List; +import java.util.Set; + +import org.drools.repository.MetaData; +import org.drools.repository.RuleDef; +import org.drools.repository.db.PersistentCase; +import org.drools.repository.db.RepositoryImpl; + +public class RulePersistenceTest extends PersistentCase { + + public void testStoreNewRuleDef() throws Exception { + RepositoryImpl repo = getRepo(); + RuleDef def = repo.save(new RuleDef("myRule", "A rule")); + assertNotNull(def.getId()); + def = repo.save(new RuleDef("myRule2", "A rule2")); + def = new RuleDef("myRule3", "A rule3"); + def.addTag("tag1").addTag("tag2").addTag("HR"); + def = repo.save(def); + assertNotNull(def.getId()); + } + + + + public void testRetreieveRuleWithTags() { + RepositoryImpl repo = getRepo(); + RuleDef newRule = new RuleDef("my rule", "content"); + newRule.addTag("HR").addTag("SALARY"); + repo.save(newRule); + + RuleDef rule = repo.loadRule("my rule", 1); + assertNotNull(rule); + assertEquals("my rule", rule.getName()); + + Set tags = rule.getTags(); + assertEquals(2, tags.size()); + String[] tagList = rule.listTags(); + assertTrue(tagList[0].equals("HR") || tagList[0].equals("SALARY")); + + List rules = repo.findRulesByTag("HR"); + assertTrue(rules.size() > 0); + + } + + public void testRuleCopy() { + RepositoryImpl repo = getRepo(); + + RuleDef rule1 = new RuleDef("newVersionTest", "XXX"); + rule1.addTag("HR").addTag("BOO"); + + MetaData meta = new MetaData(); + meta.setCreator("Peter Jackson"); + rule1.setMetaData(meta); + + repo.save(rule1); + RuleDef ruleCopy = rule1.copy(); + assertEquals(null, ruleCopy.getId()); + assertEquals(2, ruleCopy.getTags().size()); + assertEquals("Peter Jackson", ruleCopy.getMetaData().getCreator()); + + } + + + + + + +} Property changes on: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RulePersistenceTest.java ___________________________________________________________________ Name: svn:eol-style + native Added: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java 2006-01-06 07:19:01 UTC (rev 2005) +++ trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java 2006-01-06 07:25:19 UTC (rev 2006) @@ -0,0 +1,89 @@ +package org.drools.repository; + +import java.util.HashSet; +import java.util.Set; + +import org.drools.repository.AttachmentFile; +import org.drools.repository.MetaData; +import org.drools.repository.RuleDef; +import org.drools.repository.RuleSetAttachment; +import org.drools.repository.RuleSetDef; +import org.drools.repository.RuleSetVersionInfo; +import org.drools.repository.db.PersistentCase; +import org.drools.repository.db.RepositoryImpl; + +public class RuleSetPersistenceTest extends PersistentCase { + + public void testLoadSaveRuleSet() { + MetaData meta = new MetaData(); + meta.setCreator("Michael Neale"); + meta.setRights("Unlimited"); + + RuleSetDef def = new RuleSetDef("my ruleset", meta); + def.addTag("ME"); + RepositoryImpl repo = getRepo(); + repo.save(def); + + RuleSetDef def2 = repo.loadRuleSet("my ruleset"); + assertEquals("my ruleset", def2.getName()); + assertEquals("Michael Neale", def2.getMetaData().getCreator()); + assertEquals(1, def2.getTags().size()); + + } + + public void testRuleSetWithRules() { + MetaData meta = new MetaData(); + meta.setCreator("Michael Neale"); + RuleSetDef ruleSet = new RuleSetDef("Uber 1", meta); + ruleSet.addRule(new RuleDef("UBER1Rule", "This is a rule")); + RuleDef def = new RuleDef("UBER2Rule", "this is also a rule"); + def.addTag("HR").addTag("BUS"); + ruleSet.addRule(def); + ruleSet.addTag("HR"); + + RepositoryImpl repo = getRepo(); + repo.save(ruleSet); + + RuleSetDef loaded = repo.loadRuleSet("Uber 1"); + assertEquals(2, loaded.getRules().size()); + + } + + public void testRuleSetWithAttachment() { + MetaData meta = new MetaData(); + meta.setCreator("Michael Neale - Uber pimp"); + RuleSetDef ruleSet = new RuleSetDef("Attachmate", meta); + + RuleSetAttachment attachment = new RuleSetAttachment("decision-table", + "my text file", + "content".getBytes(), + "file.txt"); + ruleSet.addAttachment(attachment); + + RepositoryImpl repo = getRepo(); + repo.save(ruleSet); + + RuleSetDef result = repo.loadRuleSet("Attachmate"); + assertEquals(1, result.getAttachments().size()); + RuleSetAttachment at2 = (RuleSetAttachment) result.getAttachments().iterator().next(); + assertEquals("file.txt", at2.getOriginalFileName()); + } + + public void testRuleSetWithVersionHistory() { + RuleSetDef def = new RuleSetDef("WithHistory", null); + Set history = new HashSet(); + RuleSetVersionInfo info = new RuleSetVersionInfo(1, "blah"); + + history.add(info); + RuleSetVersionInfo info2 = new RuleSetVersionInfo(2, "woo"); + history.add(info2); + + def.setVersionHistory(history); + RepositoryImpl repo = getRepo(); + repo.save(def); + + RuleSetDef def2 = repo.loadRuleSet("WithHistory"); + assertEquals(2, def2.getVersionHistory().size()); + } + +} Property changes on: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/RuleSetPersistenceTest.java ___________________________________________________________________ Name: svn:eol-style + native Deleted: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/db/AttachmentPersistTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/db/AttachmentPersistTest.java 2006-01-06 07:19:01 UTC (rev 2005) +++ trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/db/AttachmentPersistTest.java 2006-01-06 07:25:19 UTC (rev 2006) @@ -1,25 +0,0 @@ -package org.drools.repository.db; - -import org.drools.repository.AttachmentFile; -import org.drools.repository.RuleSetAttachment; - -public class AttachmentPersistTest extends PersistentCase { - - public void testLoadSave() { - RuleSetAttachment at = new RuleSetAttachment(); - at.setName("RS1"); - at.setTypeOfAttachment("DRL"); - - AttachmentFile file = new AttachmentFile("blah".getBytes(), "text", "blah.drl"); - at.addFile(file); - - RepositoryImpl repo = getRepo(); - repo.save(at); - - RuleSetAttachment at2 = repo.loadAttachment("RS1"); - assertEquals("DRL", at2.getTypeOfAttachment()); - - assertEquals(1, at2.getAttachments().size()); - } - -} Deleted: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/db/RulePersistenceTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/db/RulePersistenceTest.java 2006-01-06 07:19:01 UTC (rev 2005) +++ trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/db/RulePersistenceTest.java 2006-01-06 07:25:19 UTC (rev 2006) @@ -1,79 +0,0 @@ -package org.drools.repository.db; - -import java.util.List; -import java.util.Set; - -import org.drools.repository.MetaData; -import org.drools.repository.RuleDef; - -public class RulePersistenceTest extends PersistentCase { - - public void testStoreNewRuleDef() throws Exception { - RepositoryImpl repo = getRepo(); - RuleDef def = repo.save(new RuleDef("myRule", "A rule")); - assertNotNull(def.getId()); - def = repo.save(new RuleDef("myRule2", "A rule2")); - def = new RuleDef("myRule3", "A rule3"); - def.addTag("tag1").addTag("tag2").addTag("HR"); - def = repo.save(def); - assertNotNull(def.getId()); - } - - public void testListRules() { - RepositoryImpl repo = getRepo(); - repo.save(new RuleDef("blah", "blah")); - List list = repo.listAllRules(true); - assertTrue(list.size() > 0); - } - - public void testRetreieveRuleWithTags() { - RepositoryImpl repo = getRepo(); - RuleDef newRule = new RuleDef("my rule", "content"); - newRule.addTag("HR").addTag("SALARY"); - repo.save(newRule); - - RuleDef rule = repo.loadRule("my rule", 1); - assertNotNull(rule); - assertEquals("my rule", rule.getName()); - - Set tags = rule.getTags(); - assertEquals(2, tags.size()); - String[] tagList = rule.listTags(); - assertTrue(tagList[0].equals("HR") || tagList[0].equals("SALARY")); - - List rules = repo.findRulesByTag("HR"); - assertTrue(rules.size() > 0); - - } - - public void testNewVersionOfRule() { - RepositoryImpl repo = getRepo(); - - RuleDef rule1 = new RuleDef("newVersionTest", "XXX"); - MetaData meta = new MetaData(); - meta.setCreator("Peter Jackson"); - rule1.setMetaData(meta); - - repo.save(rule1); - - RuleDef rule2 = rule1.createNewVersion(); - rule2.addTag("PJ"); - - repo.save(rule2); - repo.save(rule1); - - RuleDef latest = repo.loadRule("newVersionTest", 2); - assertEquals("Peter Jackson", latest.getMetaData().getCreator()); - - List ruleHistory = repo.listRuleHistory("newVersionTest"); - assertEquals(2, ruleHistory.size()); - assertEquals(1, ((RuleDef) ruleHistory.get(0)).getVersionNumber()); - assertEquals(2, ((RuleDef) ruleHistory.get(1)).getVersionNumber()); - } - - - - - - -} Deleted: trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/db/RuleSetPersistenceTest.java =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/db/RuleSetPersistenceTest.java 2006-01-06 07:19:01 UTC (rev 2005) +++ trunk/labs/jbossrules/drools-repository/src/test/java/org/drools/repository/db/RuleSetPersistenceTest.java 2006-01-06 07:25:19 UTC (rev 2006) @@ -1,86 +0,0 @@ -package org.drools.repository.db; - -import java.util.HashSet; -import java.util.Set; - -import org.drools.repository.AttachmentFile; -import org.drools.repository.MetaData; -import org.drools.repository.RuleDef; -import org.drools.repository.RuleSetAttachment; -import org.drools.repository.RuleSetDef; -import org.drools.repository.RuleSetVersionInfo; - -public class RuleSetPersistenceTest extends PersistentCase { - - public void testLoadSaveRuleSet() { - MetaData meta = new MetaData(); - meta.setCreator("Michael Neale"); - meta.setRights("Unlimited"); - - RuleSetDef def = new RuleSetDef("my ruleset", meta); - def.addTag("ME"); - RepositoryImpl repo = getRepo(); - repo.save(def); - - RuleSetDef def2 = repo.loadRuleSet("my ruleset"); - assertEquals("my ruleset", def2.getName()); - assertEquals("Michael Neale", def2.getMetaData().getCreator()); - assertEquals(1, def2.getTags().size()); - - } - - public void testRuleSetWithRules() { - MetaData meta = new MetaData(); - meta.setCreator("Michael Neale"); - RuleSetDef ruleSet = new RuleSetDef("Uber 1", meta); - ruleSet.addRule(new RuleDef("UBER1Rule", "This is a rule")); - RuleDef def = new RuleDef("UBER2Rule", "this is also a rule"); - def.addTag("HR").addTag("BUS"); - ruleSet.addRule(def); - ruleSet.addTag("HR"); - - RepositoryImpl repo = getRepo(); - repo.save(ruleSet); - - RuleSetDef loaded = repo.loadRuleSet("Uber 1"); - assertEquals(2, loaded.getRules().size()); - - } - - public void testRuleSetWithAttachment() { - MetaData meta = new MetaData(); - meta.setCreator("Michael Neale - Uber pimp"); - RuleSetDef ruleSet = new RuleSetDef("Attachmate", meta); - - RuleSetAttachment attachment = new RuleSetAttachment("decision-table", "my text file"); - attachment.addFile(new AttachmentFile("blah,blah".getBytes(), "text", "nothing.csv")); - attachment.addFile(new AttachmentFile("boo,boo".getBytes(), "binary", "smeg.xls")); - ruleSet.setAttachment(attachment); - - RepositoryImpl repo = getRepo(); - repo.save(ruleSet); - - RuleSetDef result = repo.loadRuleSet("Attachmate"); - assertNotNull(result); - assertEquals("decision-table", result.getAttachment().getTypeOfAttachment()); - assertEquals(2, result.getAttachment().getAttachments().size()); - } - - public void testRuleSetWithVersionHistory() { - RuleSetDef def = new RuleSetDef("WithHistory", null); - Set history = new HashSet(); - RuleSetVersionInfo info = new RuleSetVersionInfo("Michael", 1, "blah"); - - history.add(info); - RuleSetVersionInfo info2 = new RuleSetVersionInfo("Michael", 2, "woo"); - history.add(info2); - - def.setVersionHistory(history); - RepositoryImpl repo = getRepo(); - repo.save(def); - - RuleSetDef def2 = repo.loadRuleSet("WithHistory"); - assertEquals(2, def2.getVersionHistory().size()); - } - -} Modified: trunk/labs/jbossrules/drools-repository/src/test/resources/hibernate.cfg.xml =================================================================== --- trunk/labs/jbossrules/drools-repository/src/test/resources/hibernate.cfg.xml 2006-01-06 07:19:01 UTC (rev 2005) +++ trunk/labs/jbossrules/drools-repository/src/test/resources/hibernate.cfg.xml 2006-01-06 07:25:19 UTC (rev 2006) @@ -37,7 +37,6 @@ <mapping resource="org/drools/repository/Tag.hbm.xml"/> <mapping resource="org/drools/repository/RuleSetDef.hbm.xml"/> <mapping resource="org/drools/repository/RuleSetAttachment.hbm.xml"/> - <mapping resource="org/drools/repository/AttachmentFile.hbm.xml"/> <mapping resource="org/drools/repository/RuleSetVersionInfo.hbm.xml"/> |