Author: nbelaevski
Date: 2010-04-06 12:32:09 -0400 (Tue, 06 Apr 2010)
New Revision: 16739
Added:
root/framework/trunk/impl/src/test/java/org/richfaces/context/ComponentMatcherNodeTest.java
root/framework/trunk/impl/src/test/java/org/richfaces/context/IdParserTest.java
Modified:
root/framework/trunk/impl/src/main/java/org/richfaces/context/ComponentMatcherNode.java
root/framework/trunk/impl/src/main/java/org/richfaces/context/IdParser.java
Log:
https://jira.jboss.org/jira/browse/RF-7856
Modified:
root/framework/trunk/impl/src/main/java/org/richfaces/context/ComponentMatcherNode.java
===================================================================
---
root/framework/trunk/impl/src/main/java/org/richfaces/context/ComponentMatcherNode.java 2010-04-06
16:21:28 UTC (rev 16738)
+++
root/framework/trunk/impl/src/main/java/org/richfaces/context/ComponentMatcherNode.java 2010-04-06
16:32:09 UTC (rev 16739)
@@ -48,11 +48,64 @@
private Set<String> subtreeIds;
- protected Map<String, ComponentMatcherNode> getChildrenMap(boolean isPattern)
{
+ void setParentNode(ComponentMatcherNode parentNode) {
+ this.parentNode = parentNode;
+ }
+
+ void incrementKidPatternNodesCounter() {
+ if (kidPatternNodesCounter == 0 && !isPatternNode()) {
+ ComponentMatcherNode parentNode = getParentNode();
+ if (parentNode != null) {
+ parentNode.incrementKidPatternNodesCounter();
+ }
+ }
+
+ kidPatternNodesCounter++;
+ }
+
+ void decrementKidPatternNodesCounter() {
+ kidPatternNodesCounter--;
+
+ if (kidPatternNodesCounter == 0 && !isPatternNode()) {
+ ComponentMatcherNode parentNode = getParentNode();
+ if (parentNode != null) {
+ parentNode.decrementKidPatternNodesCounter();
+ }
+ }
+ }
+
+ void setHasParentPatternNode(boolean hasParentPatternNode) {
+ this.hasParentPatternNode = hasParentPatternNode;
+
+ if (!isPatternNode()) {
+ if (idChildren != null) {
+ for (ComponentMatcherNode child : idChildren.values()) {
+ child.setHasParentPatternNode(hasParentPatternNode);
+ }
+ }
+
+ if (patternChildren != null) {
+ for (ComponentMatcherNode child : patternChildren.values()) {
+ child.setHasParentPatternNode(hasParentPatternNode);
+ }
+ }
+ }
+ }
+
+ boolean matches(String shortId) {
+ if (isPatternNode()) {
+ //TODO - modify when real patterns will be supported
+ return true;
+ } else {
+ return source.equals(shortId);
+ }
+ }
+
+ Map<String, ComponentMatcherNode> getChildrenMap(boolean isPattern) {
return isPattern ? patternChildren : idChildren;
}
- protected Map<String, ComponentMatcherNode> getOrCreateChildrenMap(boolean
isPattern) {
+ Map<String, ComponentMatcherNode> getOrCreateChildrenMap(boolean isPattern) {
if (isPattern) {
if (patternChildren == null) {
patternChildren = new HashMap<String, ComponentMatcherNode>(1);
@@ -80,19 +133,6 @@
return parentNode;
}
- public void setParentNode(ComponentMatcherNode parentNode) {
- this.parentNode = parentNode;
- }
-
- public boolean matches(String shortId) {
- if (isPatternNode()) {
- //TODO - modify when real patterns will be supported
- return true;
- } else {
- return source.equals(shortId);
- }
- }
-
public ComponentMatcherNode getMatchedChild(String shortId) {
ComponentMatcherNode node = null;
if (idChildren != null) {
@@ -120,34 +160,40 @@
return null;
}
- public void addChild(ComponentMatcherNode node) {
- node.setParentNode(this);
+ public void addChild(ComponentMatcherNode child) {
+ child.setParentNode(this);
- boolean isPatternNode = node.isPatternNode();
- Map<String, ComponentMatcherNode> childrenMap =
getOrCreateChildrenMap(isPatternNode);
- if (childrenMap.put(node.getSource(), node) == null) {
- if (isPatternNode) {
- increaseKidPatternNodesCounter();
- }
+ Map<String, ComponentMatcherNode> childrenMap =
getOrCreateChildrenMap(child.isPatternNode());
- if (isPatternNode || this.hasParentPatternNode()) {
- node.setHasParentPatternNode(true);
- }
+ ComponentMatcherNode previousNode = childrenMap.get(child.getSource());
+ if (previousNode != null) {
+ removeChild(previousNode);
}
+
+ childrenMap.put(child.getSource(), child);
+
+ if (child.isPatternNode() || child.hasKidPatternNodes()) {
+ incrementKidPatternNodesCounter();
+ }
+
+ if (isPatternNode() || this.hasParentPatternNode()) {
+ child.setHasParentPatternNode(true);
+ }
}
- public void removeChild(ComponentMatcherNode node) {
- boolean isPatternNode = node.isPatternNode();
- Map<String, ComponentMatcherNode> childrenMap =
getChildrenMap(isPatternNode);
+ public void removeChild(ComponentMatcherNode child) {
+ Map<String, ComponentMatcherNode> childrenMap =
getChildrenMap(child.isPatternNode());
if (childrenMap != null) {
- if (node.getParentNode() == this) {
- node.setParentNode(null);
- node.setHasParentPatternNode(false);
- if (childrenMap.remove(node.getSource()) != null) {
- if (isPatternNode) {
- decreaseKidPatternNodesCounter();
- }
+ if (child.getParentNode() == this) {
+ child.setParentNode(null);
+ child.setHasParentPatternNode(false);
+ childrenMap.remove(child.getSource());
+
+ if (child.isPatternNode() || child.hasKidPatternNodes()) {
+ decrementKidPatternNodesCounter();
}
+ } else {
+ //TODO - ?
}
}
}
@@ -164,22 +210,6 @@
return patternChildren != null && !patternChildren.isEmpty();
}
- public void increaseKidPatternNodesCounter() {
- kidPatternNodesCounter++;
- ComponentMatcherNode parentNode = getParentNode();
- if (parentNode != null) {
- parentNode.increaseKidPatternNodesCounter();
- }
- }
-
- public void decreaseKidPatternNodesCounter() {
- kidPatternNodesCounter--;
- ComponentMatcherNode parentNode = getParentNode();
- if (parentNode != null) {
- parentNode.decreaseKidPatternNodesCounter();
- }
- }
-
public boolean hasKidPatternNodes() {
return kidPatternNodesCounter > 0;
}
@@ -196,10 +226,6 @@
return added;
}
- public void setHasParentPatternNode(boolean hasParentPatternNode) {
- this.hasParentPatternNode = hasParentPatternNode;
- }
-
public boolean hasParentPatternNode() {
return hasParentPatternNode;
}
Modified: root/framework/trunk/impl/src/main/java/org/richfaces/context/IdParser.java
===================================================================
--- root/framework/trunk/impl/src/main/java/org/richfaces/context/IdParser.java 2010-04-06
16:21:28 UTC (rev 16738)
+++ root/framework/trunk/impl/src/main/java/org/richfaces/context/IdParser.java 2010-04-06
16:32:09 UTC (rev 16739)
@@ -21,6 +21,11 @@
*/
package org.richfaces.context;
+/**
+ * Helper class for parsing ids.
+ *
+ * @author Nick Belaevski
+ */
final class IdParser {
private boolean isInShortId = true;
@@ -51,6 +56,23 @@
this.isInShortId = true;
}
+ /**
+ * <p>
+ * Finds shortId that satisfies the following conditions:
+ * </p>
+ *
+ * <code>
+ * nextIdx(c) := { return id.indexOf(c, idx) }
+ * </code>
+
+ * <p></p>
+ *
+ * <code>
+ * shortId := id.substring(idx, Math.min(nextIdx(namingContainerSeparator),
nextIdx(subComponentSeparator)))
+ * </code>
+ *
+ * @return
+ */
private String findNextInShortId() {
String segment = null;
boolean found = false;
@@ -78,6 +100,22 @@
return segment;
}
+ /**
+ * <p>
+ * Finds fullId that satisfies the following conditions:
+ * </p>
+ *
+ * <code>
+ * nextIdx(c) := { return id.indexOf(c, idx) }
+ * </code>
+
+ * <p></p>
+ *
+ * <code>
+ * fullId := id.substring(idx, nextIdx(namingContainerSeparator))
+ * </code>
+ * @return
+ */
private String findNextInFullId() {
String segment = null;
int index = id.indexOf(namingContainerSeparator, idx);
Added:
root/framework/trunk/impl/src/test/java/org/richfaces/context/ComponentMatcherNodeTest.java
===================================================================
---
root/framework/trunk/impl/src/test/java/org/richfaces/context/ComponentMatcherNodeTest.java
(rev 0)
+++
root/framework/trunk/impl/src/test/java/org/richfaces/context/ComponentMatcherNodeTest.java 2010-04-06
16:32:09 UTC (rev 16739)
@@ -0,0 +1,337 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.context;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Map;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ComponentMatcherNodeTest {
+
+ private ComponentMatcherNode rootNode;
+
+ @Before
+ public void setUp() throws Exception {
+ rootNode = new ComponentMatcherNode();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ rootNode = null;
+ }
+
+ private ComponentMatcherNode createNode(String source, boolean isPattern) {
+ ComponentMatcherNode node = new ComponentMatcherNode();
+ node.setSource(source);
+ node.setPatternNode(isPattern);
+
+ return node;
+ }
+
+ @Test
+ public void testIdChild() throws Exception {
+ ComponentMatcherNode idNode = createNode("table", false);
+
+ assertNull(rootNode.getChild("table", false));
+ assertNull(rootNode.getChild("table2", false));
+
+ rootNode.addChild(idNode);
+
+ assertSame(rootNode, idNode.getParentNode());
+ assertNotNull(rootNode.getIdChildren());
+ assertTrue(rootNode.hasDirectIdChildren());
+ assertTrue(rootNode.hasDirectChildren());
+ assertFalse(rootNode.hasDirectPatternChildren());
+ assertFalse(rootNode.hasKidPatternNodes());
+
+ assertSame(idNode, rootNode.getChild("table", false));
+ assertSame(idNode, rootNode.getMatchedChild("table"));
+
+ assertNull(rootNode.getChild("table2", false));
+ assertNull(rootNode.getChild("xChild", false));
+ assertNull(rootNode.getMatchedChild("xChild"));
+
+ ComponentMatcherNode id2Node = createNode("table2", false);
+ rootNode.addChild(id2Node);
+ assertSame(idNode, rootNode.getChild("table", false));
+ assertSame(id2Node, rootNode.getChild("table2", false));
+ assertSame(id2Node, rootNode.getMatchedChild("table2"));
+
+ rootNode.removeChild(idNode);
+ rootNode.removeChild(id2Node);
+
+ assertNull(idNode.getParentNode());
+ assertFalse(rootNode.hasDirectIdChildren());
+ assertFalse(rootNode.hasDirectChildren());
+ assertFalse(rootNode.hasDirectPatternChildren());
+ assertFalse(rootNode.hasKidPatternNodes());
+
+ assertNull(rootNode.getChild("table", false));
+ assertNull(rootNode.getMatchedChild("table"));
+ }
+
+ @Test
+ public void testMarkAddedRemoved() throws Exception {
+ ComponentMatcherNode idNode = createNode("table", false);
+ ComponentMatcherNode patternNode = createNode("*", true);
+
+ assertFalse(idNode.isAdded());
+ assertFalse(patternNode.isAdded());
+
+ rootNode.addChild(idNode);
+ assertFalse(idNode.isAdded());
+ assertFalse(rootNode.isAdded());
+
+ idNode.markAdded();
+ assertSame(idNode, rootNode.getChild("table", false));
+ assertTrue(idNode.isAdded());
+ assertFalse(rootNode.isAdded());
+
+ idNode.markRemoved();
+ assertSame(idNode, rootNode.getChild("table", false));
+ assertFalse(idNode.isAdded());
+ assertFalse(rootNode.isAdded());
+
+ rootNode.addChild(patternNode);
+ assertFalse(patternNode.isAdded());
+ assertFalse(rootNode.isAdded());
+
+ patternNode.markAdded();
+ assertSame(patternNode, rootNode.getChild("*", true));
+ assertTrue(patternNode.isAdded());
+ assertFalse(rootNode.isAdded());
+
+ patternNode.markRemoved();
+ assertSame(patternNode, rootNode.getChild("*", true));
+ assertFalse(patternNode.isAdded());
+ assertFalse(rootNode.isAdded());
+ }
+
+ @Test
+ public void testPatternChild() throws Exception {
+ ComponentMatcherNode patternNode = createNode("*", true);
+
+ assertNull(rootNode.getChild("*", true));
+
+ rootNode.addChild(patternNode);
+
+ assertSame(rootNode, patternNode.getParentNode());
+ assertNotNull(rootNode.getPatternChildren());
+ assertFalse(rootNode.hasDirectIdChildren());
+ assertTrue(rootNode.hasDirectChildren());
+ assertTrue(rootNode.hasDirectPatternChildren());
+ assertTrue(rootNode.hasKidPatternNodes());
+
+ assertSame(patternNode, rootNode.getChild("*", true));
+ assertSame(patternNode, rootNode.getMatchedChild("anyId"));
+ assertSame(patternNode, rootNode.getMatchedChild("justAnotherId"));
+
+ rootNode.removeChild(patternNode);
+ assertNull(patternNode.getParentNode());
+ assertFalse(rootNode.hasDirectIdChildren());
+ assertFalse(rootNode.hasDirectChildren());
+ assertFalse(rootNode.hasDirectPatternChildren());
+ assertFalse(rootNode.hasKidPatternNodes());
+
+ assertNull(rootNode.getChild("*", true));
+ assertNull(rootNode.getMatchedChild("anyId"));
+ assertNull(rootNode.getMatchedChild("justAnotherId"));
+ }
+
+ private boolean hasPatternParent(ComponentMatcherNode node) {
+ ComponentMatcherNode pNode = node;
+ while ((pNode = pNode.getParentNode()) != null) {
+ if (pNode.isPatternNode()) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private boolean hasPatternKids(Map<String, ComponentMatcherNode> nodesMap) {
+ if (nodesMap == null) {
+ return false;
+ }
+
+ for (ComponentMatcherNode node : nodesMap.values()) {
+ if (node.isPatternNode()) {
+ return true;
+ }
+
+ if (hasPatternKids(node.getIdChildren())) {
+ return true;
+ }
+
+ if (hasPatternKids(node.getPatternChildren())) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private boolean hasPatternKids(ComponentMatcherNode node) {
+ if (hasPatternKids(node.getIdChildren())) {
+ return true;
+ }
+
+ if (hasPatternKids(node.getPatternChildren())) {
+ return true;
+ }
+
+ return false;
+ }
+
+ private void verifyNodeChildren(Map<String, ComponentMatcherNode> nodesMap) {
+ if (nodesMap != null) {
+ for (ComponentMatcherNode childNode : nodesMap.values()) {
+ verifyNode(childNode);
+ }
+ }
+ }
+
+ private void verifyNode(ComponentMatcherNode node) {
+ assertTrue(hasPatternParent(node) == node.hasParentPatternNode());
+ assertTrue(hasPatternKids(node) == node.hasKidPatternNodes());
+
+ verifyNodeChildren(node.getIdChildren());
+ verifyNodeChildren(node.getPatternChildren());
+ }
+
+ @Test
+ public void testAddChild() throws Exception {
+ verifyNode(rootNode);
+
+ ComponentMatcherNode tableNode = createNode("table", false);
+ rootNode.addChild(tableNode);
+ verifyNode(rootNode);
+ assertSame(tableNode, rootNode.getChild("table", false));
+ assertSame(tableNode, rootNode.getMatchedChild("table"));
+
+ ComponentMatcherNode tablePatternNode = createNode("table-*", true);
+ rootNode.addChild(tablePatternNode);
+ verifyNode(rootNode);
+ assertSame(tablePatternNode, rootNode.getChild("table-*", true));
+ assertSame(tablePatternNode, rootNode.getMatchedChild("anyChild"));
+
+ ComponentMatcherNode rowNode = createNode("row", false);
+ tableNode.addChild(rowNode);
+ verifyNode(rootNode);
+ assertSame(rowNode, tableNode.getChild("row", false));
+ assertSame(rowNode, tableNode.getMatchedChild("row"));
+
+ ComponentMatcherNode cellPatternNode = createNode("cell-*", true);
+ rowNode.addChild(cellPatternNode);
+ verifyNode(rootNode);
+ assertSame(cellPatternNode, rowNode.getChild("cell-*", true));
+ assertSame(cellPatternNode, rowNode.getMatchedChild("anyCell"));
+
+ ComponentMatcherNode secondRowNode = createNode("row", false);
+ tablePatternNode.addChild(secondRowNode);
+ verifyNode(rootNode);
+ assertSame(secondRowNode, tablePatternNode.getChild("row", false));
+ assertSame(secondRowNode, tablePatternNode.getMatchedChild("row"));
+
+ ComponentMatcherNode secondCellPatternNode = createNode("cell-*",
true);
+ secondRowNode.addChild(secondCellPatternNode);
+ verifyNode(rootNode);
+ assertSame(secondCellPatternNode, secondRowNode.getChild("cell-*",
true));
+ assertSame(secondCellPatternNode,
secondRowNode.getMatchedChild("anyCell"));
+ }
+
+ @Test
+ public void testRemoveChild() throws Exception {
+ ComponentMatcherNode tableNode = createNode("table", false);
+ rootNode.addChild(tableNode);
+
+ ComponentMatcherNode tablePatternNode = createNode("table-*", true);
+ rootNode.addChild(tablePatternNode);
+
+ ComponentMatcherNode rowNode = createNode("row", false);
+ tableNode.addChild(rowNode);
+
+ ComponentMatcherNode cellPatternNode = createNode("cell-*", true);
+ rowNode.addChild(cellPatternNode);
+
+ ComponentMatcherNode secondRowNode = createNode("row", false);
+ tablePatternNode.addChild(secondRowNode);
+
+ ComponentMatcherNode secondCellPatternNode = createNode("cell-*",
true);
+ secondRowNode.addChild(secondCellPatternNode);
+
+ verifyNode(rootNode);
+
+ assertSame(secondCellPatternNode, secondRowNode.getChild("cell-*",
true));
+ assertSame(secondCellPatternNode,
secondRowNode.getMatchedChild("anyCell"));
+ secondRowNode.removeChild(secondCellPatternNode);
+ assertNull(secondRowNode.getChild("cell-*", true));
+ assertNull(secondRowNode.getMatchedChild("anyCell"));
+
+ verifyNode(rootNode);
+
+ assertSame(rowNode, tableNode.getChild("row", false));
+ assertSame(rowNode, tableNode.getMatchedChild("row"));
+ tableNode.removeChild(rowNode);
+ assertNull(tableNode.getChild("row", false));
+ assertNull(tableNode.getMatchedChild("row"));
+
+ verifyNode(rootNode);
+
+ assertSame(secondRowNode, tablePatternNode.getChild("row", false));
+ assertSame(secondRowNode, tablePatternNode.getMatchedChild("row"));
+ tablePatternNode.removeChild(secondRowNode);
+ assertNull(tablePatternNode.getChild("row", false));
+ assertNull(tablePatternNode.getMatchedChild("row"));
+
+ verifyNode(rootNode);
+
+ assertSame(tablePatternNode, rootNode.getChild("table-*", true));
+ assertSame(tablePatternNode, rootNode.getMatchedChild("anyChild"));
+ rootNode.removeChild(tablePatternNode);
+ assertNull(rootNode.getChild("table-*", true));
+ assertNull(rootNode.getMatchedChild("anyChild"));
+
+ verifyNode(rootNode);
+
+ assertSame(tableNode, rootNode.getChild("table", false));
+ assertSame(tableNode, rootNode.getMatchedChild("table"));
+ rootNode.removeChild(tableNode);
+ assertNull(rootNode.getChild("table", false));
+ assertNull(rootNode.getMatchedChild("table"));
+
+ verifyNode(rootNode);
+ }
+}
Added: root/framework/trunk/impl/src/test/java/org/richfaces/context/IdParserTest.java
===================================================================
--- root/framework/trunk/impl/src/test/java/org/richfaces/context/IdParserTest.java
(rev 0)
+++
root/framework/trunk/impl/src/test/java/org/richfaces/context/IdParserTest.java 2010-04-06
16:32:09 UTC (rev 16739)
@@ -0,0 +1,196 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.context;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class IdParserTest {
+
+ private IdParser idParser;
+
+ @Before
+ public void setUp() throws Exception {
+ idParser = new IdParser(':', '@');
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ idParser = null;
+ }
+
+ @Test
+ public void testEmptyString() throws Exception {
+ idParser.setId("");
+
+ String segment;
+
+ segment = idParser.nextSegment();
+ assertEquals("", segment);
+ assertFalse(idParser.containsSubComponentSeparator());
+ assertNull(idParser.nextSegment());
+ }
+
+ @Test
+ public void testSimpleId() throws Exception {
+ idParser.setId("simpleId");
+
+ String segment;
+
+ segment = idParser.nextSegment();
+ assertEquals("simpleId", segment);
+ assertFalse(idParser.containsSubComponentSeparator());
+ assertNull(idParser.nextSegment());
+ }
+
+ @Test
+ public void testSubComponentId() throws Exception {
+ idParser.setId("table@head");
+
+ String segment;
+
+ segment = idParser.nextSegment();
+ assertEquals("table", segment);
+ assertFalse(idParser.containsSubComponentSeparator());
+
+ segment = idParser.nextSegment();
+ assertEquals("table@head", segment);
+ assertTrue(idParser.containsSubComponentSeparator());
+
+ assertNull(idParser.nextSegment());
+ }
+
+ @Test
+ public void testSeries() throws Exception {
+ idParser.setId("form:table:0:nestedTable@body");
+
+ String segment;
+
+ segment = idParser.nextSegment();
+ assertEquals("form", segment);
+ assertFalse(idParser.containsSubComponentSeparator());
+
+ segment = idParser.nextSegment();
+ assertEquals("table", segment);
+ assertFalse(idParser.containsSubComponentSeparator());
+
+ segment = idParser.nextSegment();
+ assertEquals("0", segment);
+ assertFalse(idParser.containsSubComponentSeparator());
+
+ segment = idParser.nextSegment();
+ assertEquals("nestedTable", segment);
+ assertFalse(idParser.containsSubComponentSeparator());
+
+ segment = idParser.nextSegment();
+ assertEquals("nestedTable@body", segment);
+ assertTrue(idParser.containsSubComponentSeparator());
+
+ assertNull(idParser.nextSegment());
+
+ idParser.setId("myBigTable@header");
+
+ segment = idParser.nextSegment();
+ assertEquals("myBigTable", segment);
+ assertFalse(idParser.containsSubComponentSeparator());
+
+ segment = idParser.nextSegment();
+ assertEquals("myBigTable@header", segment);
+ assertTrue(idParser.containsSubComponentSeparator());
+
+ assertNull(idParser.nextSegment());
+
+ idParser.setId("tree:0-12-28:node@status:table:10:tab@label");
+
+ segment = idParser.nextSegment();
+ assertEquals("tree", segment);
+ assertFalse(idParser.containsSubComponentSeparator());
+
+ segment = idParser.nextSegment();
+ assertEquals("0-12-28", segment);
+ assertFalse(idParser.containsSubComponentSeparator());
+
+ segment = idParser.nextSegment();
+ assertEquals("node", segment);
+ assertFalse(idParser.containsSubComponentSeparator());
+
+ segment = idParser.nextSegment();
+ assertEquals("node@status", segment);
+ assertTrue(idParser.containsSubComponentSeparator());
+
+ segment = idParser.nextSegment();
+ assertEquals("table", segment);
+ assertFalse(idParser.containsSubComponentSeparator());
+
+ segment = idParser.nextSegment();
+ assertEquals("10", segment);
+ assertFalse(idParser.containsSubComponentSeparator());
+
+ segment = idParser.nextSegment();
+ assertEquals("tab", segment);
+ assertFalse(idParser.containsSubComponentSeparator());
+
+ segment = idParser.nextSegment();
+ assertEquals("tab@label", segment);
+ assertTrue(idParser.containsSubComponentSeparator());
+
+ assertNull(idParser.nextSegment());
+ }
+
+ @Test
+ public void testNestedSubcomponents() throws Exception {
+ //TODO - review this test - behavior is not clear for now
+
+ idParser.setId("form:table@head@x-head:child");
+
+ String segment;
+
+ segment = idParser.nextSegment();
+ assertEquals("form", segment);
+ assertFalse(idParser.containsSubComponentSeparator());
+
+ segment = idParser.nextSegment();
+ assertEquals("table", segment);
+ assertFalse(idParser.containsSubComponentSeparator());
+
+ segment = idParser.nextSegment();
+ assertEquals("table@head@x-head", segment);
+ assertTrue(idParser.containsSubComponentSeparator());
+
+ segment = idParser.nextSegment();
+ assertEquals("child", segment);
+ assertFalse(idParser.containsSubComponentSeparator());
+
+ assertNull(idParser.nextSegment());
+ }
+}