Author: julien(a)jboss.com
Date: 2007-02-15 11:31:50 -0500 (Thu, 15 Feb 2007)
New Revision: 6301
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectIdTestCase.java
Log:
- test case for PortalObject.getChildren(int mask)
- implemented and tested PortalObjectId.compareTo(Object o)
Modified:
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2007-02-15
15:03:34 UTC (rev 6300)
+++
trunk/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2007-02-15
16:31:50 UTC (rev 6301)
@@ -424,6 +424,25 @@
return objectNode.toString();
}
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ {
+ return true;
+ }
+ if (obj instanceof PortalObjectImpl)
+ {
+ PortalObjectImpl that = (PortalObjectImpl)obj;
+ return getId().equals(that.getId());
+ }
+ return false;
+ }
+
+ public int hashCode()
+ {
+ return getId().hashCode();
+ }
+
/** Return the default child of this object based on the declared property that
specifies the default object name. */
protected PortalObject getDefaultChild()
{
Modified: trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java
===================================================================
--- trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java 2007-02-15
15:03:34 UTC (rev 6300)
+++ trunk/core/src/main/org/jboss/portal/core/model/portal/PortalObjectId.java 2007-02-15
16:31:50 UTC (rev 6301)
@@ -198,9 +198,25 @@
return hashCode.intValue();
}
+ /**
+ * Lexicographical order based implementation on the names atoms.
+ */
public int compareTo(Object o)
{
- throw new NotYetImplemented();
+ PortalObjectId that = (PortalObjectId)o;
+ int index = 0;
+ while (index < this.names.length && index < that.names.length)
+ {
+ String thisName = this.names[index];
+ String thatName = that.names[index];
+ int order = thisName.compareTo(thatName);
+ if (order != 0)
+ {
+ return order;
+ }
+ index++;
+ }
+ return that.names.length - this.names.length;
}
/**
Modified:
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java 2007-02-15
15:03:34 UTC (rev 6300)
+++
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectContainerTestCase.java 2007-02-15
16:31:50 UTC (rev 6301)
@@ -41,11 +41,16 @@
import org.jboss.portal.common.test.TestParametrization;
import org.jboss.portal.common.test.junit.JUnitAdapter;
import org.jboss.portal.common.test.junit.POJOJUnitTest;
+import org.jboss.portal.common.junit.TransactionAssert;
+import org.jboss.portal.common.util.CollectionBuilder;
import org.jboss.portal.WindowState;
import org.jboss.portal.Mode;
import java.net.URL;
import java.util.Collections;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Comparator;
/**
* Portal Object Container Test Cases based on the microcontainer architecture
@@ -126,23 +131,15 @@
/** todo same with a transaction wrapping the start method */
public void testRootNodeCreation() throws Exception
{
- hibernate.openSession();
- assertTrue(hibernate.commitTransaction());
-
- //
- hibernate.openSession();
+ TransactionAssert.beginTransaction();
PortalObject root = container.getRootObject();
assertNotNull(root);
- assertTrue(hibernate.commitTransaction());
+ TransactionAssert.commitTransaction();
}
public void testCRUD() throws Exception
{
- hibernate.openSession();
- assertTrue(hibernate.commitTransaction());
-
- //
- hibernate.openSession();
+ TransactionAssert.beginTransaction();
PortalContainer ctx = (PortalContainer)container.getRootObject();
Portal portal = ctx.createPortal("default");
PortalObjectId portalId = portal.getId();
@@ -180,10 +177,10 @@
assertNotNull(windowId);
assertEquals(page, window.getParent());
assertEquals(window, page.getChild("default"));
- assertTrue(hibernate.commitTransaction());
+ TransactionAssert.commitTransaction();
//
- hibernate.openSession();
+ TransactionAssert.beginTransaction();
PortalObject portalIdObject = container.getObject(portalId);
assertNotNull(portalIdObject);
assertTrue(portalIdObject instanceof Portal);
@@ -196,10 +193,10 @@
assertNotNull(windowIdObject);
assertTrue(windowIdObject instanceof Window);
assertEquals(windowId, windowIdObject.getId());
- assertTrue(hibernate.commitTransaction());
+ TransactionAssert.commitTransaction();
//
- hibernate.openSession();
+ TransactionAssert.beginTransaction();
ctx = (PortalContainer)container.getRootObject();
assertNotNull(ctx);
portal = ctx.getPortal("default");
@@ -211,28 +208,63 @@
window = page.getWindow("default");
assertNotNull(window);
assertEquals(windowId, window.getId());
- assertTrue(hibernate.commitTransaction());
+ TransactionAssert.commitTransaction();
//
- hibernate.openSession();
+ TransactionAssert.beginTransaction();
ctx = (PortalContainer)container.getRootObject();
assertNotNull(ctx);
ctx.destroyChild("default");
portal = ctx.getPortal("default");
assertNull(portal);
- assertTrue(hibernate.commitTransaction());
+ TransactionAssert.commitTransaction();
//
- hibernate.openSession();
+ TransactionAssert.beginTransaction();
ctx = (PortalContainer)container.getRootObject();
portal = ctx.getPortal("default");
assertNull(portal);
- assertTrue(hibernate.commitTransaction());
+ TransactionAssert.commitTransaction();
}
public void testGetChildren() throws Exception
{
-
+ TransactionAssert.beginTransaction();
+ PortalContainer ctx = (PortalContainer)container.getRootObject();
+ Portal portal_1 = ctx.createPortal("1");
+ Page page_1_1 = portal_1.createPage("1");
+ Page page_1_2 = portal_1.createPage("2");
+ Page page_1_1_1 = page_1_1.createPage("1");
+ Window window_1_1_2 = page_1_1.createWindow("2", ContentType.PORTLET,
"uri");
+ Page page_1_1_3 = page_1_1.createPage("3");
+ Window window_1_1_4 = page_1_1.createWindow("4", ContentType.PORTLET,
"uri");
+ TransactionAssert.commitTransaction();
+
+ //
+ TransactionAssert.beginTransaction();
+ PortalObject o_1 = container.getRootObject().getChild("1");
+ PortalObject o_1_1 = o_1.getChild("1");
+ PortalObject o_1_2 = o_1.getChild("2");
+ PortalObject o_1_1_1 = o_1_1.getChild("1");
+ PortalObject o_1_1_2 = o_1_1.getChild("2");
+ PortalObject o_1_1_3 = o_1_1.getChild("3");
+ PortalObject o_1_1_4 = o_1_1.getChild("4");
+ List l1 = new ArrayList(o_1_1.getChildren());
+ Collections.sort(l1, new PortalObjectComparator());
+ assertEquals(new
CollectionBuilder().add(o_1_1_1).add(o_1_1_2).add(o_1_1_3).add(o_1_1_4).toArrayList(),
l1);
+ List l2 = new ArrayList(o_1_1.getChildren(PortalObject.PAGE_MASK));
+ Collections.sort(l2, new PortalObjectComparator());
+ assertEquals(new CollectionBuilder().add(o_1_1_1).add(o_1_1_3).toArrayList(), l2);
+ List l3 = new ArrayList(o_1_1.getChildren(PortalObject.WINDOW_MASK));
+ Collections.sort(l3, new PortalObjectComparator());
+ assertEquals(new CollectionBuilder().add(o_1_1_2).add(o_1_1_4).toArrayList(), l3);
+ List l4 = new ArrayList(o_1_1.getChildren(0));
+ Collections.sort(l4, new PortalObjectComparator());
+ assertEquals(new CollectionBuilder().toArrayList(), l4);
+ List l5 = new ArrayList(o_1_1.getChildren(PortalObject.PORTAL_MASK));
+ Collections.sort(l5, new PortalObjectComparator());
+ assertEquals(new CollectionBuilder().toArrayList(), l5);
+ TransactionAssert.commitTransaction();
}
public void testRecreate() throws Exception
@@ -240,7 +272,7 @@
PortalObjectId defaultId = new PortalObjectId(new String[]{"default"});
//
- hibernate.openSession();
+ TransactionAssert.beginTransaction();
PortalContainer ctx = (PortalContainer)container.getRootObject();
Portal portal = ctx.createPortal("default");
assertNotNull(portal);
@@ -257,7 +289,8 @@
object = container.getObject(defaultId);
assertNotNull(object);
- assertTrue(hibernate.commitTransaction());
+ //
+ TransactionAssert.commitTransaction();
}
/**
@@ -269,7 +302,7 @@
PortalObjectId defaultId = new PortalObjectId(new String[]{"portal"});
//
- hibernate.openSession();
+ TransactionAssert.beginTransaction();
PortalContainer ctx = (PortalContainer)container.getRootObject();
Portal portal = ctx.createPortal("portal");
portal.setDeclaredProperty("portalname", "portalvalue");
@@ -284,10 +317,10 @@
ContentState contentState = content.getState();
assertNotNull(contentState);
contentState.setProperty("content.abc", "def");
- assertTrue(hibernate.commitTransaction());
+ TransactionAssert.commitTransaction();
//
- hibernate.openSession();
+ TransactionAssert.beginTransaction();
ctx = (PortalContainer)container.getRootObject();
portal = (Portal)container.getObject(defaultId);
portal = (Portal)portal.copy(ctx, "copy", true);
@@ -308,7 +341,7 @@
contentState = content.getState();
assertNotNull(contentState);
assertEquals("def", contentState.getProperty("content.abc"));
- assertTrue(hibernate.commitTransaction());
+ TransactionAssert.commitTransaction();
}
// private void constructPortalObjects() throws Exception
@@ -320,4 +353,14 @@
// Page page = portal.createPage("default");
// assertNotNull(page);
// }
+
+ private static class PortalObjectComparator implements Comparator
+ {
+ public int compare(Object o1, Object o2)
+ {
+ PortalObject po1 = (PortalObject)o1;
+ PortalObject po2 = (PortalObject)o2;
+ return po1.getId().compareTo(po2.getId());
+ }
+ }
}
Modified:
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectIdTestCase.java
===================================================================
---
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectIdTestCase.java 2007-02-15
15:03:34 UTC (rev 6300)
+++
trunk/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectIdTestCase.java 2007-02-15
16:31:50 UTC (rev 6301)
@@ -163,6 +163,15 @@
assertTrue(new PortalObjectId(new String[]{"a","b"}).equals(new
PortalObjectId(new String[]{"a","b"})));
}
+ public void testComparable()
+ {
+ assertTrue(new PortalObjectId(new String[]{"a"}).compareTo(new
PortalObjectId(new String[]{"a"})) == 0);
+ assertTrue(new PortalObjectId(new String[]{"a"}).compareTo(new
PortalObjectId(new String[]{"b"})) < 0);
+ assertTrue(new PortalObjectId(new String[]{"b"}).compareTo(new
PortalObjectId(new String[]{"a"})) > 0);
+ assertTrue(new PortalObjectId(new String[]{"a"}).compareTo(new
PortalObjectId(new String[]{"a","b"})) > 0);
+ assertTrue(new PortalObjectId(new
String[]{"a","b"}).compareTo(new PortalObjectId(new
String[]{"a"})) < 0);
+ }
+
public void testIterator()
{
ExtendedAssert.assertEquals(new Object[]{}, Tools.toArray(new PortalObjectId(new
String[]{}).names()));