Author: chris.laprun(a)jboss.com
Date: 2009-01-24 07:07:08 -0500 (Sat, 24 Jan 2009)
New Revision: 12623
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/api/node/PortalNodeImpl.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectTestCase.java
Log:
- JBPORTAL-2281: we do always need ChildrenCollection after all...
- Added iterator tests.
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/api/node/PortalNodeImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/api/node/PortalNodeImpl.java 2009-01-23
19:19:51 UTC (rev 12622)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/api/node/PortalNodeImpl.java 2009-01-24
12:07:08 UTC (rev 12623)
@@ -1,6 +1,6 @@
/******************************************************************************
* JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * Copyright 2009, Red Hat Middleware, LLC, and individual *
* contributors as indicated by the @authors tag. See the *
* copyright.txt in the distribution for a full listing of *
* individual contributors. *
@@ -40,7 +40,6 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -169,7 +168,7 @@
}
public String getDisplayName(Locale locale)
- {
+ {
LocalizedString ldisplayName = object.getDisplayName();
if (ldisplayName != null)
{
@@ -179,7 +178,7 @@
return result;
}
}
-
+
// Lazily compute the display name
if (displayNameKey == null)
{
@@ -196,7 +195,7 @@
catch (MissingResourceException ignore)
{
}
-
+
if (bundle != null)
{
try
@@ -302,15 +301,15 @@
String orderProperty2S = (String)node2.getProperties().get(ORDER);
if (orderProperty1S != null && orderProperty2S == null)
- {
+ {
return -1;
}
else if (orderProperty1S == null && orderProperty2S != null)
- {
+ {
return 1;
}
else if (orderProperty1S != null && orderProperty2S != null)
- {
+ {
float orderProperty1 = -1;
float orderProperty2 = -1;
@@ -401,10 +400,8 @@
boolean allVisible = portalAuthorizationManager.checkPermission(new
PortalObjectPermission(objectNode.object.getId(),
PortalObjectPermission.VIEW_RECURSIVE_ACTION));
//
- for (Iterator<PortalObject> i = tmp.iterator(); i.hasNext();)
+ for (PortalObject childObject : tmp)
{
- PortalObject childObject = (PortalObject)i.next();
-
// It is visible if the parent has recursive view enabled
boolean visible = allVisible;
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2009-01-23
19:19:51 UTC (rev 12622)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/core/impl/model/portal/PortalObjectImpl.java 2009-01-24
12:07:08 UTC (rev 12623)
@@ -256,19 +256,26 @@
public int size()
{
- int count = 0;
-
- for (Object object : children.values())
+ if (mask != ALL_TYPES_MASK)
{
- ObjectNode childNode = (ObjectNode)object;
- PortalObjectImpl childObject = childNode.getObject();
- if (isMatchingMask(childObject, mask))
+ int count = 0;
+
+ for (Object object : children.values())
{
- count++;
+ ObjectNode childNode = (ObjectNode)object;
+ PortalObjectImpl childObject = childNode.getObject();
+ if (isMatchingMask(childObject, mask))
+ {
+ count++;
+ }
}
- }
- return count;
+ return count;
+ }
+ else
+ {
+ return children.size();
+ }
}
public Object[] toArray()
@@ -367,18 +374,10 @@
public Collection getChildren(int wantedMask)
{
- // if we want all the children, bypass ChildrenCollection
- if (wantedMask == ALL_TYPES_MASK)
- {
- return new TreeMap(objectNode.getChildren()).values();
- }
- else
- {
- // Correct eventually the mask
- final int mask = wantedMask & ALL_TYPES_MASK;
+ // Correct eventually the mask
+ final int mask = wantedMask & ALL_TYPES_MASK;
- return new ChildrenCollection(mask, objectNode.getChildren());
- }
+ return new ChildrenCollection(mask, objectNode.getChildren());
}
public String getListener()
Modified:
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectTestCase.java
===================================================================
---
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectTestCase.java 2009-01-23
19:19:51 UTC (rev 12622)
+++
branches/JBoss_Portal_Branch_2_7/core/src/main/org/jboss/portal/test/core/model/portal/PortalObjectTestCase.java 2009-01-24
12:07:08 UTC (rev 12623)
@@ -23,16 +23,15 @@
package org.jboss.portal.test.core.model.portal;
-import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.jboss.portal.common.junit.TransactionAssert;
+import org.jboss.portal.core.model.content.ContentType;
import org.jboss.portal.core.model.portal.Context;
+import org.jboss.portal.core.model.portal.DuplicatePortalObjectException;
+import org.jboss.portal.core.model.portal.NoSuchPortalObjectException;
+import org.jboss.portal.core.model.portal.Page;
import org.jboss.portal.core.model.portal.Portal;
-import org.jboss.portal.core.model.portal.Page;
import org.jboss.portal.core.model.portal.PortalObject;
-import org.jboss.portal.core.model.portal.DuplicatePortalObjectException;
-import org.jboss.portal.core.model.portal.NoSuchPortalObjectException;
-import org.jboss.portal.core.model.content.ContentType;
import java.util.Collection;
@@ -46,6 +45,7 @@
private Portal p_1;
private Page p_1_1;
private Page p_1_2;
+ private static final int A_INDEX = 65;
public static TestSuite suite() throws Exception
{
@@ -56,7 +56,7 @@
public void setUp() throws Exception
{
super.setUp();
-
+
TransactionAssert.beginTransaction();
root = container.getContext("");
p_1 = root.createPortal("1");
@@ -105,6 +105,48 @@
assertEquals(p_1_1, child.getParent());
}
+ public void testIterator() throws NoSuchPortalObjectException,
DuplicatePortalObjectException
+ {
+ Portal portal;
+ Page page;
+
+ TransactionAssert.beginTransaction();
+ root.destroyChild(p_1.getName());
+ char nbChildren = 20;
+ portal = root.createPortal("portal");
+ page = portal.createPage("page");
+
+ // create children, we need to convert the current index with Character.toString as
default ordering results in
+ // pa10 < pa2 and in test failure
+ for (char i = A_INDEX; i < nbChildren + A_INDEX; i++)
+ {
+ // convert current index into a letter
+ String letter = Character.toString(i);
+ page.createPage("pa" + letter);
+ page.createWindow("w" + letter, ContentType.PORTLET, "foo" +
letter);
+ }
+ TransactionAssert.commitTransaction();
+
+ Collection<PortalObject> children =
page.getChildren(PortalObject.PAGE_MASK);
+ assertNotNull(children);
+ char i = A_INDEX;
+ String name;
+ for (PortalObject child : children)
+ {
+ name = child.getName();
+ assertEquals("pa" + Character.toString(i++), name);
+ }
+
+ children = page.getChildren(PortalObject.WINDOW_MASK);
+ assertNotNull(children);
+ i = A_INDEX;
+ for (PortalObject child : children)
+ {
+ name = child.getName();
+ assertEquals("w" + Character.toString(i++), name);
+ }
+ }
+
/*public void testPerformanceGetChildren() throws DuplicatePortalObjectException,
NoSuchPortalObjectException
{
Portal portal;