[jboss-svn-commits] JBL Code SVN: r10880 - in labs/jbossrules/trunk/drools-jbrms/src: main/java/org/drools/brms/client/ruleeditor and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Apr 10 22:59:39 EDT 2007
Author: fmeyer
Date: 2007-04-10 22:59:39 -0400 (Tue, 10 Apr 2007)
New Revision: 10880
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/RepositoryServiceAsync.java
labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RuleAsset.java
labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/ActionToolbar.java
labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/RuleViewer.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/contenthandler/ContentHandler.java
labs/jbossrules/trunk/drools-jbrms/src/test/java/org/drools/brms/server/ServiceImplementationTest.java
Log:
JBRULES-676 Delete action for a newly created asset
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-04-11 00:32:17 UTC (rev 10879)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RepositoryService.java 2007-04-11 02:59:39 UTC (rev 10880)
@@ -42,6 +42,10 @@
*/
public String createNewRule(String ruleName, String description, String initialCategory, String initialPackage, String format) throws SerializableException;
+
+ public void deleteUncheckedRule(String ruleName, String initialPackage);
+
+
/**
* This returns a list of packages where rules may be added.
* Only the UUID and the name need to be populated.
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-04-11 00:32:17 UTC (rev 10879)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RepositoryServiceAsync.java 2007-04-11 02:59:39 UTC (rev 10880)
@@ -21,6 +21,7 @@
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 listPackages(AsyncCallback cb);
public void loadRuleAsset(java.lang.String p0, AsyncCallback cb);
public void loadAssetHistory(java.lang.String p0, AsyncCallback cb);
@@ -32,13 +33,13 @@
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 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 quickFindAsset, 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 changeState(java.lang.String p0, java.lang.String p1, boolean p2, AsyncCallback cb);
}
Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RuleAsset.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RuleAsset.java 2007-04-11 00:32:17 UTC (rev 10879)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/rpc/RuleAsset.java 2007-04-11 02:59:39 UTC (rev 10880)
@@ -17,5 +17,8 @@
public String uuid;
public boolean archived = false;
+ public long getVersionNumber() {
+ return metaData.versionNumber;
+ }
}
Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/ActionToolbar.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/ActionToolbar.java 2007-04-11 00:32:17 UTC (rev 10879)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/ActionToolbar.java 2007-04-11 02:59:39 UTC (rev 10880)
@@ -50,12 +50,13 @@
final Command checkin,
final Command archiv,
final Command minimiseMaximise,
- boolean readOnly) {
+ final Command delete, boolean readOnly) {
this.metaData = asset.metaData;
this.checkinAction = checkin;
this.uuid = asset.uuid;
this.archiveAction = archiv;
+ this.deleteAction = delete;
this.state = new HTML();
String status = metaData.status;
@@ -139,21 +140,24 @@
});
saveControls.add(archive);
- Button delete = new Button("Delete");
- delete.addClickListener(new ClickListener() {
- public void onClick(Widget w) {
- YesNoDialog diag = new YesNoDialog("Are you sure about archive this Item?", new Command() {
- public void execute() {
- metaData.checkinComment = "Archived Item on $date";
- deleteAction.execute();
- }
- });
- diag.setPopupPosition(Window.getClientWidth() / 2, Window.getClientHeight() / 2);
- diag.show();
- }
- });
- saveControls.add(delete);
-
+ if (this.metaData.versionNumber == 0) {
+ Button delete = new Button( "Delete" );
+ delete.addClickListener( new ClickListener() {
+ public void onClick(Widget w) {
+ YesNoDialog diag = new YesNoDialog( "Are you sure about delete this unversioned Item?",
+ new Command() {
+ public void execute() {
+ metaData.checkinComment = "Archived Item on $date";
+ deleteAction.execute();
+ }
+ } );
+ diag.setPopupPosition( Window.getClientWidth() / 2,
+ Window.getClientHeight() / 2 );
+ diag.show();
+ }
+ } );
+ saveControls.add( delete );
+ }
HorizontalPanel windowControls = new HorizontalPanel();
Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/RuleViewer.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/RuleViewer.java 2007-04-11 00:32:17 UTC (rev 10879)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/client/ruleeditor/RuleViewer.java 2007-04-11 02:59:39 UTC (rev 10880)
@@ -1,7 +1,9 @@
package org.drools.brms.client.ruleeditor;
import org.drools.brms.client.common.ErrorPopup;
+import org.drools.brms.client.common.InfoPopup;
import org.drools.brms.client.common.LoadingPopup;
+import org.drools.brms.client.rpc.MetaData;
import org.drools.brms.client.rpc.RepositoryServiceFactory;
import org.drools.brms.client.rpc.RuleAsset;
@@ -74,6 +76,8 @@
}
});
+
+ Command deleteCommand = null;
//metaWidget.setWidth( "100%" );
@@ -90,7 +94,7 @@
formatter.setWidth( 0,
1,
"30%" );
-
+
//and now the action widgets (checkin/close etc).
toolbar = new ActionToolbar( asset,
new Command() {
@@ -108,6 +112,11 @@
zoomIntoAsset();
}
},
+ new Command() {
+ public void execute() {
+ doDelete();
+ }
+ },
readOnly);
toolbar.setCloseCommand( new Command() {
public void execute() {
@@ -135,8 +144,20 @@
layout.setWidget( 2,
0,
doco );
-
}
+
+ void doDelete() {
+ RepositoryServiceFactory.getService().deleteUncheckedRule( this.asset.uuid , this.asset.metaData.packageName, new AsyncCallback() {
+
+ public void onFailure(Throwable err) {
+ ErrorPopup.showMessage( err.getMessage() );
+ }
+
+ public void onSuccess(Object o) {
+ closeCommand.execute();
+ }
+ });
+ }
/**
* This responds to the checkin command.
@@ -164,13 +185,8 @@
ErrorPopup.showMessage( "Failed to check in the item. Please contact your system administrator." );
return;
}
-
refreshDataAndView( );
-
}
-
-
-
});
}
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-04-11 00:32:17 UTC (rev 10879)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/ServiceImplementation.java 2007-04-11 02:59:39 UTC (rev 10880)
@@ -122,7 +122,15 @@
}
}
-
+
+
+ @WebRemote
+ public void deleteUncheckedRule(String uuid, String initialPackage) {
+ AssetItem asset = repository.loadAssetByUUID( uuid );
+ asset.remove();
+ repository.save();
+ }
+
/**
* For some format types, we add some sugar by adding a new template.
*/
@@ -587,7 +595,6 @@
} catch (RulesRepositoryException e) {
throw new SerializableException( e.getMessage() );
}
-
}
@WebRemote
@@ -603,9 +610,4 @@
}
}
-
-
-
-
-
}
Modified: labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/contenthandler/ContentHandler.java
===================================================================
--- labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/contenthandler/ContentHandler.java 2007-04-11 00:32:17 UTC (rev 10879)
+++ labs/jbossrules/trunk/drools-jbrms/src/main/java/org/drools/brms/server/contenthandler/ContentHandler.java 2007-04-11 02:59:39 UTC (rev 10880)
@@ -54,7 +54,6 @@
public static ContentHandler getHandler(String format) {
-
ContentHandler h = (ContentHandler) handlers.get( format );
if (h == null) throw new IllegalArgumentException("Unable to handle the content type: " + format);
return h;
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-04-11 00:32:17 UTC (rev 10879)
+++ labs/jbossrules/trunk/drools-jbrms/src/test/java/org/drools/brms/server/ServiceImplementationTest.java 2007-04-11 02:59:39 UTC (rev 10880)
@@ -30,17 +30,13 @@
public class ServiceImplementationTest extends TestCase {
-
-
- public void testCategory() throws Exception {
+ public void testCategory() throws Exception {
//ServiceImpl impl = new ServiceImpl(new RulesRepository(SessionHelper.getSession()));
-
-
RepositoryService impl = getService();
-
+
String[] originalCats = impl.loadChildCategories( "/" );
-
+
Boolean result = impl.createCategory( "/",
"TopLevel1",
"a description" );
@@ -50,570 +46,814 @@
"TopLevel2",
"a description" );
assertTrue( result.booleanValue() );
-
+
String[] cats = impl.loadChildCategories( "/" );
assertTrue( cats.length == originalCats.length + 2 );
+
+ result = impl.createCategory( "",
+ "Top3",
+ "description" );
+ assertTrue( result.booleanValue() );
+
+ result = impl.createCategory( null,
+ "Top4",
+ "description" );
+ assertTrue( result.booleanValue() );
+
+ }
+
+ public void testDeleteUnversionedRule() throws Exception {
+ ServiceImplementation impl = getService();
+
+ impl.repository.loadDefaultPackage();
+ impl.repository.createPackage( "anotherPackage",
+ "woot" );
+
+ 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 ) );
- result = impl.createCategory( "", "Top3", "description" );
- assertTrue(result.booleanValue());
+ AssetItem localItem = impl.repository.loadAssetByUUID( uuid );
+ assertEquals( "test Delete Unversioned", localItem.getName() );
- result = impl.createCategory( null, "Top4", "description" );
- assertTrue(result.booleanValue());
+ localItem.remove();
+ impl.repository.save();
+ try {
+ localItem = impl.repository.loadAssetByUUID( uuid );
+ fail();
+ } catch (Exception e ) {
+ }
+ }
+ public void testAddRuleAndListPackages() throws Exception {
+ //ServiceImpl impl = new ServiceImpl(new RulesRepository(SessionHelper.getSession()));
+
+ ServiceImplementation impl = getService();
+
+ impl.repository.loadDefaultPackage();
+ impl.repository.createPackage( "another",
+ "woot" );
+
+ 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 ) );
+
+ 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;
+ }
+ }
+
+ assertTrue( found );
+
+ 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" );
+ // }
}
-
- public void testAddRuleAndListPackages() throws Exception {
- //ServiceImpl impl = new ServiceImpl(new RulesRepository(SessionHelper.getSession()));
-
- ServiceImplementation impl = getService();
-
- impl.repository.loadDefaultPackage();
- impl.repository.createPackage( "another", "woot" );
-
-
- 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 ));
-
- 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;
- }
- }
-
- assertTrue(found);
-
- 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" );
-// }
- }
- public void testAttemptDupeRule() throws Exception {
- ServiceImplementation impl = getService();
- CategoryItem cat = impl.repository.loadCategory( "/" );
- cat.addCategory( "testAttemptDupeRule", "yeah" );
-
- impl.repository.createPackage("dupes", "yeah");
-
- impl.createNewRule( "testAttemptDupeRule", "ya", "testAttemptDupeRule", "dupes", "rule" );
-
- try {
- impl.createNewRule( "testAttemptDupeRule", "ya", "testAttemptDupeRule", "dupes", "rule" );
- fail("should not allow duplicates.");
- } catch (SerializableException e) {
- assertNotNull(e.getMessage());
- }
-
- }
-
- public void testRuleTableLoad() throws Exception {
- ServiceImplementation impl = getService();
- TableConfig conf = impl.loadTableConfig( AssetItemListViewer.RULE_LIST_TABLE_ID );
- assertNotNull(conf.headers);
-
- 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" );
+ public void testAttemptDupeRule() throws Exception {
+ ServiceImplementation impl = getService();
+ CategoryItem cat = impl.repository.loadCategory( "/" );
+ cat.addCategory( "testAttemptDupeRule",
+ "yeah" );
- TableDataResult result = impl.loadRuleListForCategories( "testRuleTableLoad" );
- assertEquals(2, result.data.length);
-
- String key = result.data[0].id;
- assertFalse(key.startsWith( "testRule" ));
-
- assertEquals(result.data[0].format, "rule");
- assertTrue(result.data[0].values[0].startsWith( "testRule" ));
-
-
-
- }
-
- public void testDateFormatting() throws Exception {
- Calendar cal = Calendar.getInstance();
- TableDisplayHandler handler = new TableDisplayHandler();
- String fmt = handler.formatDate( cal );
- assertNotNull(fmt);
-
- assertTrue(fmt.length() > 8);
- }
-
- 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" );
-
- TableDataResult res = impl.loadRuleListForCategories( "testLoadRuleAsset" );
- assertEquals(1, res.data.length);
-
- TableDataRow row = res.data[0];
- String uuid = row.id;
-
+ impl.repository.createPackage( "dupes",
+ "yeah" );
-
- RuleAsset asset = impl.loadRuleAsset( uuid );
- assertNotNull(asset);
-
- assertEquals(uuid, asset.uuid);
-
- 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);
-
- 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 );
-
- assertEquals("whee", asset.metaData.status);
- assertEquals("changed state", asset.metaData.checkinComment);
-
-
- uuid = impl.createNewRule( "testBRXMLFormatSugComp", "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);
- }
-
- 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
- impl.checkinVersion( asset ); //2
- 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 ));
-
- 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 );
-
- long oldVersion = old.metaData.versionNumber;
- assertFalse(oldVersion == head.metaData.versionNumber );
-
- impl.restoreVersion( old.uuid, head.uuid, "this was cause of a mistake" );
-
- RuleAsset newHead = impl.loadRuleAsset( uuid );
-
-
- assertEquals("this was cause of a mistake", newHead.metaData.checkinComment);
-
-
- }
-
-
-
- public void testCheckin() throws Exception {
- RepositoryService serv = getService();
-
- serv.listPackages();
-
- 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", "default", "drl" );
-
- RuleAsset asset = serv.loadRuleAsset( uuid );
-
- assertNotNull(asset.metaData.lastModifiedDate);
-
- asset.metaData.coverage = "boo";
- asset.content = new RuleContentText();
- ((RuleContentText) asset.content).content = "yeah !";
-
- Date start = new Date();
- Thread.sleep( 100 );
-
- String uuid2 = serv.checkinVersion( asset );
- assertEquals(uuid, uuid2);
-
- 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("yeah !", ((RuleContentText) asset2.content).content);
-
- 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";
-
- 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]);
+ impl.createNewRule( "testAttemptDupeRule",
+ "ya",
+ "testAttemptDupeRule",
+ "dupes",
+ "rule" );
-
- }
-
-
- public void testArchivePackage() throws Exception {
- ServiceImplementation impl = getService();
-
- PackageConfigData[] pkgs = impl.listPackages();
-
- 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 );
- }
-
- public void testCreatePackage() throws Exception {
- ServiceImplementation impl = getService();
- PackageConfigData[] pkgs = impl.listPackages();
- String uuid = impl.createPackage( "testCreatePackage", "this is a new package" );
- assertNotNull( uuid );
-
- PackageItem item = impl.repository.loadPackage( "testCreatePackage" );
- assertNotNull(item);
- assertEquals("this is a new package", item.getDescription());
-
-
-
- assertEquals(pkgs.length + 1, impl.listPackages().length);
-
- PackageConfigData conf = impl.loadPackageConfig( uuid );
- assertEquals("this is a new package", conf.description);
- assertNotNull(conf.lastModified);
- }
-
- 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();
-
- PackageConfigData data = impl.loadPackageConfig( uuid );
- assertNotNull(data);
-
- assertEquals("default", data.name);
- assertEquals("header", data.header);
- assertEquals("ext", data.externalURI);
-
- assertNotNull(data.uuid);
-
- }
-
- public void testPackageConfSave() throws Exception {
- RepositoryService impl = getService();
- String uuid = impl.createPackage( "testPackageConfSave", "a desc" );
- PackageConfigData data = impl.loadPackageConfig( uuid );
-
- data.description = "new desc";
- data.header = "wa";
- data.externalURI = "new URI";
-
-
- ValidatedResponse res = impl.savePackage( data );
- assertNotNull(res);
- assertTrue(res.hasErrors);
- assertNotNull(res.errorMessage);
-
- 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("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
-
- }
+ try {
+ impl.createNewRule( "testAttemptDupeRule",
+ "ya",
+ "testAttemptDupeRule",
+ "dupes",
+ "rule" );
+ fail( "should not allow duplicates." );
+ } catch ( SerializableException e ) {
+ assertNotNull( e.getMessage() );
+ }
- 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." );
-
- 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" );
+ }
- 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"), 4, 0 );
- assertEquals(4, res.data.length);
+ public void testRuleTableLoad() throws Exception {
+ ServiceImplementation impl = getService();
+ TableConfig conf = impl.loadTableConfig( AssetItemListViewer.RULE_LIST_TABLE_ID );
+ assertNotNull( conf.headers );
- 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"), 2, 2 );
- assertEquals(2, res.data.length);
- assertEquals(uuid3, res.data[0].id);
-
-
- uuid = impl.createNewRule( "testListByFormat5", "x", cat, "testListByFormat", "otherFormat" );
-
- res = impl.listAssets( pkgUUID, arr("otherFormat"), 40, 0 );
- assertEquals(1, res.data.length);
- assertEquals(uuid, res.data[0].id);
+ CategoryItem cat = impl.repository.loadCategory( "/" );
+ cat.addCategory( "testRuleTableLoad",
+ "yeah" );
- res = impl.listAssets( pkgUUID, new String[] {"otherFormat", "testListByFormat"}, 40, 0 );
- assertEquals(5, res.data.length);
-
+ impl.repository.createPackage( "testRuleTableLoad",
+ "yeah" );
+ impl.createNewRule( "testRuleTableLoad",
+ "ya",
+ "testRuleTableLoad",
+ "testRuleTableLoad",
+ "rule" );
+ impl.createNewRule( "testRuleTableLoad2",
+ "ya",
+ "testRuleTableLoad",
+ "testRuleTableLoad",
+ "rule" );
- TableDataResult result = impl.quickFindAsset( "testListByForma", 5, false );
- assertEquals(5, result.data.length);
-
- assertNotNull(result.data[0].id);
- assertTrue(result.data[0].values[0].startsWith( "testListByFormat" ));
-
- 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);
-
- String[] states = impl.listStates();
- assertTrue(states.length > 0);
-
- impl.createState( "testStatus2" );
- String[] states2 = impl.listStates();
- assertEquals(states.length + 1, states2.length);
-
- int match = 0;
- for ( int i = 0; i < states2.length; i++ ) {
- if (states2[i].equals( "testStatus2" )) {
- match++;
- } else if (states2[i].equals( "testStatus1" )) {
- match++;
- }
- }
-
- assertEquals(2, match);
-
+ TableDataResult result = impl.loadRuleListForCategories( "testRuleTableLoad" );
+ assertEquals( 2,
+ result.data.length );
- 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" );
-
- 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);
-
-
-
- impl.createState( "testState2" );
- impl.changeState( packagUUID, "testState2", true );
-
- PackageConfigData pkg = impl.loadPackageConfig( packagUUID );
- assertEquals("testState2", pkg.state);
-
- 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];
-
- String uuid = impl.createNewRule( "testMovePackage", "desc", cat, "sourcePackage", "drl" );
-
- TableDataResult res = impl.listAssets( destPkgId, new String[] {"drl"}, 2, 0 );
- assertEquals(0, res.data.length);
-
-
- impl.changeAssetPackage( uuid, "targetPackage", "yeah" );
- res = impl.listAssets( destPkgId, new String[] {"drl"}, 2, 0 );
-
- assertEquals(1, 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", "default", "drl" );
- String uuid2 = impl.copyAsset( uuid, "default", "testCopyAsset2" );
- assertNotSame( uuid, uuid2 );
-
- RuleAsset asset = impl.loadRuleAsset( uuid2 );
- assertNotNull(asset);
- assertEquals("default", asset.metaData.packageName);
- assertEquals("testCopyAsset2", asset.metaData.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", "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.createPackageSnapshot( "testSnapshot", "Y", false, "we" );
- assertEquals(2, impl.listSnapshots( "testSnapshot" ).length);
- impl.createPackageSnapshot( "testSnapshot", "X", true, "we" );
- assertEquals(2, impl.listSnapshots( "testSnapshot" ).length);
-
- impl.copyOrRemoveSnapshot( "testSnapshot", "X", false, "Q" );
- assertEquals(3, 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 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);
-
-
- }
-
- 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);
-
- }
-
- private ServiceImplementation getService() throws Exception {
- ServiceImplementation impl = new ServiceImplementation();
- impl.repository = new RulesRepository( TestEnvironmentSessionHelper.getSession() );
- return impl;
- }
-
-
+ String key = result.data[0].id;
+ assertFalse( key.startsWith( "testRule" ) );
+
+ assertEquals( result.data[0].format,
+ "rule" );
+ assertTrue( result.data[0].values[0].startsWith( "testRule" ) );
+ }
+
+ public void testDateFormatting() throws Exception {
+ Calendar cal = Calendar.getInstance();
+ TableDisplayHandler handler = new TableDisplayHandler();
+ String fmt = handler.formatDate( cal );
+ assertNotNull( fmt );
+
+ assertTrue( fmt.length() > 8 );
+ }
+
+ 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" );
+
+ TableDataResult res = impl.loadRuleListForCategories( "testLoadRuleAsset" );
+ assertEquals( 1,
+ res.data.length );
+
+ TableDataRow row = res.data[0];
+ String uuid = row.id;
+
+ RuleAsset asset = impl.loadRuleAsset( uuid );
+ assertNotNull( asset );
+
+ assertEquals( uuid,
+ asset.uuid );
+
+ 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 );
+
+ 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 );
+
+ assertEquals( "whee",
+ asset.metaData.status );
+ assertEquals( "changed state",
+ asset.metaData.checkinComment );
+
+ uuid = impl.createNewRule( "testBRXMLFormatSugComp",
+ "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 );
+ }
+
+ 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
+ impl.checkinVersion( asset ); //2
+ 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 ) );
+
+ 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 );
+
+ long oldVersion = old.metaData.versionNumber;
+ assertFalse( oldVersion == head.metaData.versionNumber );
+
+ impl.restoreVersion( old.uuid,
+ head.uuid,
+ "this was cause of a mistake" );
+
+ RuleAsset newHead = impl.loadRuleAsset( uuid );
+
+ assertEquals( "this was cause of a mistake",
+ newHead.metaData.checkinComment );
+
+ }
+
+ public void testCheckin() throws Exception {
+ RepositoryService serv = getService();
+
+ serv.listPackages();
+
+ 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",
+ "default",
+ "drl" );
+
+ RuleAsset asset = serv.loadRuleAsset( uuid );
+
+ assertNotNull( asset.metaData.lastModifiedDate );
+
+ asset.metaData.coverage = "boo";
+ asset.content = new RuleContentText();
+ ((RuleContentText) asset.content).content = "yeah !";
+
+ Date start = new Date();
+ Thread.sleep( 100 );
+
+ String uuid2 = serv.checkinVersion( asset );
+ assertEquals( uuid,
+ uuid2 );
+
+ 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( "yeah !",
+ ((RuleContentText) asset2.content).content );
+
+ 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";
+
+ 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] );
+
+ }
+
+ public void testArchivePackage() throws Exception {
+ ServiceImplementation impl = getService();
+
+ PackageConfigData[] pkgs = impl.listPackages();
+
+ 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 );
+ }
+
+ public void testCreatePackage() throws Exception {
+ ServiceImplementation impl = getService();
+ PackageConfigData[] pkgs = impl.listPackages();
+ String uuid = impl.createPackage( "testCreatePackage",
+ "this is a new package" );
+ assertNotNull( uuid );
+
+ PackageItem item = impl.repository.loadPackage( "testCreatePackage" );
+ assertNotNull( item );
+ assertEquals( "this is a new package",
+ item.getDescription() );
+
+ assertEquals( pkgs.length + 1,
+ impl.listPackages().length );
+
+ PackageConfigData conf = impl.loadPackageConfig( uuid );
+ assertEquals( "this is a new package",
+ conf.description );
+ assertNotNull( conf.lastModified );
+ }
+
+ 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();
+
+ PackageConfigData data = impl.loadPackageConfig( uuid );
+ assertNotNull( data );
+
+ assertEquals( "default",
+ data.name );
+ assertEquals( "header",
+ data.header );
+ assertEquals( "ext",
+ data.externalURI );
+
+ assertNotNull( data.uuid );
+
+ }
+
+ public void testPackageConfSave() throws Exception {
+ RepositoryService impl = getService();
+ String uuid = impl.createPackage( "testPackageConfSave",
+ "a desc" );
+ PackageConfigData data = impl.loadPackageConfig( uuid );
+
+ data.description = "new desc";
+ data.header = "wa";
+ data.externalURI = "new URI";
+
+ ValidatedResponse res = impl.savePackage( data );
+ assertNotNull( res );
+ assertTrue( res.hasErrors );
+ assertNotNull( res.errorMessage );
+
+ 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." );
+
+ 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" );
+
+ 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" ),
+ 4,
+ 0 );
+ assertEquals( 4,
+ res.data.length );
+
+ 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" ),
+ 2,
+ 2 );
+ assertEquals( 2,
+ res.data.length );
+ assertEquals( uuid3,
+ res.data[0].id );
+
+ uuid = impl.createNewRule( "testListByFormat5",
+ "x",
+ cat,
+ "testListByFormat",
+ "otherFormat" );
+
+ res = impl.listAssets( pkgUUID,
+ arr( "otherFormat" ),
+ 40,
+ 0 );
+ assertEquals( 1,
+ res.data.length );
+ assertEquals( uuid,
+ res.data[0].id );
+
+ res = impl.listAssets( pkgUUID,
+ new String[]{"otherFormat", "testListByFormat"},
+ 40,
+ 0 );
+ assertEquals( 5,
+ res.data.length );
+
+ TableDataResult result = impl.quickFindAsset( "testListByForma",
+ 5,
+ false );
+ assertEquals( 5,
+ result.data.length );
+
+ assertNotNull( result.data[0].id );
+ assertTrue( result.data[0].values[0].startsWith( "testListByFormat" ) );
+
+ 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 );
+
+ String[] states = impl.listStates();
+ assertTrue( states.length > 0 );
+
+ impl.createState( "testStatus2" );
+ String[] states2 = impl.listStates();
+ assertEquals( states.length + 1,
+ states2.length );
+
+ int match = 0;
+ for ( int i = 0; i < states2.length; i++ ) {
+ if ( states2[i].equals( "testStatus2" ) ) {
+ match++;
+ } else if ( states2[i].equals( "testStatus1" ) ) {
+ match++;
+ }
+ }
+
+ assertEquals( 2,
+ 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" );
+
+ 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 );
+
+ impl.createState( "testState2" );
+ impl.changeState( packagUUID,
+ "testState2",
+ true );
+
+ PackageConfigData pkg = impl.loadPackageConfig( packagUUID );
+ assertEquals( "testState2",
+ pkg.state );
+
+ 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];
+
+ String uuid = impl.createNewRule( "testMovePackage",
+ "desc",
+ cat,
+ "sourcePackage",
+ "drl" );
+
+ TableDataResult res = impl.listAssets( destPkgId,
+ new String[]{"drl"},
+ 2,
+ 0 );
+ assertEquals( 0,
+ res.data.length );
+
+ impl.changeAssetPackage( uuid,
+ "targetPackage",
+ "yeah" );
+ res = impl.listAssets( destPkgId,
+ new String[]{"drl"},
+ 2,
+ 0 );
+
+ assertEquals( 1,
+ 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",
+ "default",
+ "drl" );
+ String uuid2 = impl.copyAsset( uuid,
+ "default",
+ "testCopyAsset2" );
+ assertNotSame( uuid,
+ uuid2 );
+
+ RuleAsset asset = impl.loadRuleAsset( uuid2 );
+ assertNotNull( asset );
+ assertEquals( "default",
+ asset.metaData.packageName );
+ assertEquals( "testCopyAsset2",
+ asset.metaData.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",
+ "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.createPackageSnapshot( "testSnapshot",
+ "Y",
+ false,
+ "we" );
+ assertEquals( 2,
+ impl.listSnapshots( "testSnapshot" ).length );
+ impl.createPackageSnapshot( "testSnapshot",
+ "X",
+ true,
+ "we" );
+ assertEquals( 2,
+ impl.listSnapshots( "testSnapshot" ).length );
+
+ impl.copyOrRemoveSnapshot( "testSnapshot",
+ "X",
+ false,
+ "Q" );
+ assertEquals( 3,
+ 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 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 );
+
+ }
+
+ 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 );
+
+ }
+
+ private ServiceImplementation getService() throws Exception {
+ ServiceImplementation impl = new ServiceImplementation();
+ impl.repository = new RulesRepository( TestEnvironmentSessionHelper.getSession() );
+ return impl;
+ }
+
}
More information about the jboss-svn-commits
mailing list