You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@labs.apache.org by si...@apache.org on 2008/09/16 16:31:05 UTC
svn commit: r695904 [2/2] - in /labs/magma/trunk/foundation-beans-view: ./
src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/magma/ src/main/java/org/apache/magma/view/
src/main/java/org/apache/magma/vi...
Added: labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/BeanViewTreeTest.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/BeanViewTreeTest.java?rev=695904&view=auto
==============================================================================
--- labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/BeanViewTreeTest.java (added)
+++ labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/BeanViewTreeTest.java Tue Sep 16 07:31:00 2008
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.view;
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import org.apache.magma.beans.BeanData;
+import org.apache.magma.beans.PropertyInfo;
+import org.apache.magma.view.tree.HiddenNode;
+import org.apache.magma.view.tree.Node;
+import org.apache.magma.view.tree.SimpleViewFilter;
+import org.apache.magma.view.tree.ViewCustomizer;
+import org.apache.magma.view.tree.Zone;
+
+import org.junit.Test;
+
+
+public class BeanViewTreeTest {
+ @Test
+ public void simpleTree() throws Exception {
+ ViewBean bean = new ViewBean();
+ BeanData data = bean.beanData();
+ Node root = data.getViewTree();
+ assertNotNull(root);
+ simpleCheck(data, root, null);
+ }
+
+
+ private void simpleCheck(BeanData data, Node root, String parented) {
+ for (String prop : data.getPropertyNames()) {
+ PropertyInfo property = data.getProperty(prop);
+ if (property.getViewSettings() != null) {
+ String id = (parented != null ? parented + "-" : "") + property.getName();
+ Node propnode = root.findById(id);
+ assertNotNull("Could not find the node " + id, propnode);
+ String label = property.getViewSettings().getLabel();
+ if (label != null && label.length() > 0) {
+ Zone zone = propnode.getZone(Side.OutsideLeft);
+ assertNotNull("Cannot find label zone for " + property.getName() + " aside " + propnode, zone);
+ List<Node> nodes = zone.getNodes();
+ assertTrue(nodes.size() > 0);
+ Node node = nodes.get(0);
+ assertEquals(propnode.getId() + "-label", node.getId());
+ }
+ }
+ }
+ }
+
+
+ @Test
+ public void filters() throws Exception {
+ ViewCustomizer flt = new SimpleViewFilter("basictest", "+another", "-age");
+ ViewBean bean = new ViewBean();
+ BeanData data = bean.beanData();
+ Node root = data.getViewTree(flt);
+ assertNotNull(root);
+ for (String prop : data.getPropertyNames()) {
+ PropertyInfo property = data.getProperty(prop);
+ if (property.getViewSettings() != null) {
+ Node propnode = root.findById(property.getName());
+ if (property.getName().equals("age")) {
+ assertNotNull("Age should be here, even if filtered", propnode);
+ assertEquals(HiddenNode.class, propnode.getClass());
+ } else if (property.getName().equals("another")) {
+ assertNotNull(propnode);
+ simpleCheck(data, propnode, "another");
+ } else {
+ assertNotNull(propnode);
+ String label = property.getViewSettings().getLabel();
+ if (label != null && label.length() > 0) {
+ Zone zone = propnode.getZone(Side.OutsideLeft);
+ assertNotNull("Cannot find label zone for " + property.getName(), zone);
+ List<Node> nodes = zone.getNodes();
+ assertTrue(nodes.size() > 0);
+ Node node = nodes.get(0);
+ assertEquals(prop + "-label", node.getId());
+ }
+ }
+ }
+ }
+
+ }
+
+}
Added: labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/InBeanViewSettingsTest.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/InBeanViewSettingsTest.java?rev=695904&view=auto
==============================================================================
--- labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/InBeanViewSettingsTest.java (added)
+++ labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/InBeanViewSettingsTest.java Tue Sep 16 07:31:00 2008
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.view;
+
+import org.apache.magma.beans.BeanData;
+import org.apache.magma.beans.PropertyInfo;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+
+public class InBeanViewSettingsTest {
+
+
+ @Test
+ public void beanViews() throws Exception {
+ ViewBean bean = new ViewBean();
+ BeanData data = bean.beanData();
+ PropertyInfo ageinfo = data.getProperty("age");
+ ViewSettings settings = ageinfo.getViewSettings();
+ assertNotNull(settings);
+ assertEquals("Insert age", settings.getLabel());
+ assertEquals(3.0f, settings.getOrdinal().getOrder(), 0);
+ assertEquals("You must be at least 13 years old", settings.getTip());
+ }
+
+ @Test
+ public void beansList() throws Exception {
+ ViewBean bean = new ViewBean();
+ BeanData data = bean.beanData();
+ PropertyInfo ageinfo = data.getProperty("age");
+ ViewSettings settings = ageinfo.getViewListSettings();
+ assertNull(settings);
+ PropertyInfo nameinfo = data.getProperty("name");
+ settings = nameinfo.getViewListSettings();
+ assertNotNull(settings);
+ assertEquals("Insert name", settings.getLabel());
+ assertEquals(1.0f, settings.getOrdinal().getOrder(), 0);
+ }
+
+}
Added: labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/ToUserTest.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/ToUserTest.java?rev=695904&view=auto
==============================================================================
--- labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/ToUserTest.java (added)
+++ labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/ToUserTest.java Tue Sep 16 07:31:00 2008
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.view;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+
+public class ToUserTest {
+
+ @Test
+ public void treeToUser() throws Exception {
+ ViewBean b = new ViewBean();
+ b.setName("A");
+ b.setSurname("B");
+ b.setAge(3);
+
+ String touser = b.toUser();
+ assertEquals("A B 3", touser.trim());
+
+ b.setName("X");
+ b.setSurname("Y");
+ b.setAge(1);
+
+ touser = b.toUser();
+ assertEquals("X Y 1", touser.trim());
+ }
+
+}
Added: labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/ViewBean.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/ViewBean.java?rev=695904&view=auto
==============================================================================
--- labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/ViewBean.java (added)
+++ labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/ViewBean.java Tue Sep 16 07:31:00 2008
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.view;
+
+import org.apache.magma.beans.MagmaBean;
+
+@MagmaBean
+public class ViewBean {
+
+ private String name;
+ private String surname;
+ private int age;
+ private ViewBean another;
+
+ @View(label="Insert name")
+ @Order(1)
+ @Listed
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @View(label="Insert surname")
+ @Order(2)
+ @Listed
+ public String getSurname() {
+ return surname;
+ }
+ public void setSurname(String surname) {
+ this.surname = surname;
+ }
+
+ @View(label="Insert age", tip="You must be at least 13 years old")
+ @Order(3)
+ public int getAge() {
+ return age;
+ }
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ @View(label="Brother")
+ @Order(4)
+ @Listed
+ public ViewBean getAnother() {
+ return another;
+ }
+ public void setAnother(ViewBean another) {
+ this.another = another;
+ }
+
+}
Added: labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/tree/CreatingTreeTest.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/tree/CreatingTreeTest.java?rev=695904&view=auto
==============================================================================
--- labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/tree/CreatingTreeTest.java (added)
+++ labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/tree/CreatingTreeTest.java Tue Sep 16 07:31:00 2008
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.view.tree;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import org.apache.magma.view.Side;
+import org.apache.magma.view.ViewSettings;
+import org.apache.magma.view.ZoneSetting;
+
+import org.junit.Test;
+public class CreatingTreeTest {
+
+ @Test
+ public void createSimple() throws Exception {
+ Node root = new Node("root");
+
+ ViewSettings node1view = new ViewSettings();
+ ZoneSetting node1set = new ZoneSetting();
+ node1set.setSide(Side.Bottom);
+ node1set.setShared(false);
+ node1view.setZone(node1set);
+
+ ViewSettings node2view = new ViewSettings();
+ ZoneSetting node2set = new ZoneSetting();
+ node2set.setSide(Side.Bottom);
+ node2set.setShared(false);
+ node2view.setZone(node2set);
+
+ ViewSettings node3view = new ViewSettings();
+ ZoneSetting node3set = new ZoneSetting();
+ node3set.setSide(Side.Bottom);
+ node3set.setShared(true);
+ node3view.setZone(node3set);
+
+ ViewSettings node4view = new ViewSettings();
+ ZoneSetting node4set = new ZoneSetting();
+ node4set.setSide(Side.Bottom);
+ node4set.setShared(true);
+ node4view.setZone(node4set);
+
+ root.addSubnode(new Node("node1", node1view));
+ root.addSubnode(new Node("node2", node2view));
+ root.addSubnode(new Node("node3", node3view));
+ root.addSubnode(new Node("node4", node4view));
+
+ root.validate();
+
+ Zone zone = root.getZone(Side.Bottom);
+ assertEquals(4, zone.getNodes().size());
+
+ assertEquals("node1", zone.getNodes().get(0).getId());
+ assertEquals("node2", zone.getNodes().get(1).getId());
+ assertEquals("node3", zone.getNodes().get(2).getId());
+ assertEquals("node4", zone.getNodes().get(3).getId());
+ }
+
+ @Test
+ public void findById() throws Exception {
+ ViewSettings node1view = new ViewSettings();
+ ZoneSetting node1set = new ZoneSetting();
+ node1set.setSide(Side.Bottom);
+ node1set.setShared(false);
+ node1view.setZone(node1set);
+
+ ViewSettings node2view = new ViewSettings();
+ ZoneSetting node2set = new ZoneSetting();
+ node2set.setSide(Side.InsideLeft);
+ node2set.setShared(false);
+ node2view.setZone(node2set);
+
+ ViewSettings node3view = new ViewSettings();
+ ZoneSetting node3set = new ZoneSetting();
+ node3set.setSide(Side.InsideLeft);
+ node3set.setShared(true);
+ node3view.setZone(node3set);
+
+ ViewSettings node4view = new ViewSettings();
+ ZoneSetting node4set = new ZoneSetting();
+ node4set.setSide(Side.InsideLeft);
+ node4set.setShared(true);
+ node4view.setZone(node4set);
+
+ Node root = new Node("root");
+ Node node1 = new Node("node1", node1view);
+ root.addSubnode(node1);
+ Node node2 = new Node("node2", node2view);
+ node1.addSubnode(node2);
+ Node node3 = new Node("node3", node3view);
+ node2.addSubnode(node3);
+ Node node4 = new Node("node4", node4view);
+ node2.addSubnode(node4);
+
+ Node found = null;
+ found = root.findById("node1");
+ assertNotNull(found);
+ assertSame(node1, found);
+ found = root.findById("node2");
+ assertNotNull(found);
+ assertSame(node2, found);
+ found = root.findById("node3");
+ assertNotNull(found);
+ assertSame(node3, found);
+ found = root.findById("node4");
+ assertNotNull(found);
+ assertSame(node4, found);
+
+ found = node2.findById("node1");
+ assertNull(found);
+ found = node2.findById("root");
+ assertNull(found);
+
+ }
+}
Added: labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/tree/DeCamelCaseTest.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/tree/DeCamelCaseTest.java?rev=695904&view=auto
==============================================================================
--- labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/tree/DeCamelCaseTest.java (added)
+++ labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/tree/DeCamelCaseTest.java Tue Sep 16 07:31:00 2008
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.view.tree;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.experimental.theories.DataPoint;
+import org.junit.experimental.theories.Theories;
+import org.junit.experimental.theories.Theory;
+import org.junit.runner.RunWith;
+
+@RunWith(Theories.class)
+public class DeCamelCaseTest {
+
+ @DataPoint public static String[]
+ set0 = {"",""},
+ set0b = {"__",""},
+ set1 = {"simpleCasedField", "simple cased field"},
+ set2 = {"nocasefield", "nocasefield"},
+ set3 = {"thisHasURI", "this has URI"},
+ set4 = {"URIAtBeginning", "URI at beginning"},
+ set5 = {"andURIInTheMiddle", "and URI in the middle"},
+ set6 = {"people_coming_from_c", "people coming from c"},
+ set6b = {"people__coming$$_from_c", "people coming from c"},
+ set7 = {"mixing2Things", "mixing 2 things"},
+ set8 = {"mixing22Things", "mixing 22 things"},
+ set8b = {"200", "200"}, // While 200 is not a valid java identifier, set200 and get200 are :)
+ set8c = {"200Names", "200 names"},
+ set9 = {"testForI18N", "test for I18N"},
+ set10 = {"testForI18NLikeStuff", "test for I18N like stuff"};
+
+ @Theory public void convert(String[] vals) {
+ String deCamelCase = ViewUtils.deCamelCase(vals[0]);
+ //System.out.println("Testing " + vals[0] + " -> " + deCamelCase);
+ assertEquals(vals[1], deCamelCase);
+ }
+
+}
Added: labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/tree/ZoneTest.java
URL: http://svn.apache.org/viewvc/labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/tree/ZoneTest.java?rev=695904&view=auto
==============================================================================
--- labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/tree/ZoneTest.java (added)
+++ labs/magma/trunk/foundation-beans-view/src/test/java/org/apache/magma/view/tree/ZoneTest.java Tue Sep 16 07:31:00 2008
@@ -0,0 +1,307 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.magma.view.tree;
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+import java.util.Random;
+import java.util.Set;
+
+import org.apache.magma.view.OrdinalConstraint;
+import org.apache.magma.view.OrdinalSetting;
+import org.apache.magma.view.Side;
+import org.apache.magma.view.ViewSettings;
+import org.apache.magma.view.ZoneSetting;
+
+import org.junit.Test;
+
+public class ZoneTest {
+
+ private static final int TEST_SIZE = 50;
+ private static final Random rnd = new Random();
+
+ @Test
+ public void testValidateWithFixedOrders() {
+ Node root = new Node("root");
+ Zone z = new Zone(Side.Top, root);
+ root.addZone(z);
+
+ for (int i = 0; i < TEST_SIZE; i++) {
+ OrdinalSetting ord = new OrdinalSetting();
+ ord.setOrder(i + 1);
+ ViewSettings vs = new ViewSettings();
+ vs.setOrdinal(ord);
+ Node sub = new Node("sub" + i, vs);
+ z.addNode(sub);
+ }
+
+ root.validate();
+
+ List<Node> nodes = z.getNodes();
+ checkOrder(nodes);
+
+ }
+
+ private void checkOrder(List<Node> nodes) {
+ assertNotNull(nodes);
+ assertEquals(TEST_SIZE, nodes.size());
+ for (int i = 0; i < TEST_SIZE; i++) {
+ assertEquals("sub" + i, nodes.get(i).getId());
+ }
+ }
+
+ @Test
+ public void testValidateWithAfters() {
+ Node root = new Node("root");
+ Zone z = new Zone(Side.Top, root);
+ root.addZone(z);
+
+ int[] positions = new int[TEST_SIZE];
+ for (int i = 0; i < positions.length; i++) {
+ positions[i] = i;
+ }
+ for (int i = 0; i < positions.length; i++) {
+ int tmp = positions[i];
+ int rndPos = rnd.nextInt(positions.length);
+ positions[i] = positions[rndPos];
+ positions[rndPos] = tmp;
+ }
+
+ OrdinalSetting ord = new OrdinalSetting();
+ ViewSettings vs = new ViewSettings();
+ vs.setOrdinal(ord);
+ Node sub = new Node("sub0", vs);
+ z.addNode(sub);
+ for (int i = 1; i < positions.length; i++) {
+ ord = new OrdinalSetting();
+ ord.addConstraint(new OrdinalConstraint(false, "sub" + (i - 1)));
+ vs = new ViewSettings();
+ vs.setOrdinal(ord);
+ sub = new Node("sub" + i, vs);
+ z.addNode(sub);
+ }
+ root.validate();
+
+ List<Node> nodes = z.getNodes();
+ checkOrder(nodes);
+ }
+
+ @Test
+ public void testValidateWithBeforeAndAfter() {
+ Node root = new Node("root");
+ Zone z = new Zone(Side.Top, root);
+ root.addZone(z);
+
+ int[] positions = new int[TEST_SIZE];
+ for (int i = 0; i < positions.length; i++) {
+ positions[i] = i;
+ }
+ for (int i = 0; i < positions.length; i++) {
+ int tmp = positions[i];
+ int rndPos = rnd.nextInt(positions.length);
+ positions[i] = positions[rndPos];
+ positions[rndPos] = tmp;
+ }
+
+ OrdinalSetting ord = new OrdinalSetting();
+ ViewSettings vs = new ViewSettings();
+ vs.setOrdinal(ord);
+ Node sub = new Node("sub0", vs);
+ z.addNode(sub);
+ for (int i = 1; i < positions.length; i++) {
+ ord = new OrdinalSetting();
+ if (i % 2 == 0) {
+ ord.addConstraint(new OrdinalConstraint(true, "sub" + (i + 1)));
+ } else {
+ ord.addConstraint(new OrdinalConstraint(false, "sub" + (i - 1)));
+ }
+ vs = new ViewSettings();
+ vs.setOrdinal(ord);
+ sub = new Node("sub" + i, vs);
+ z.addNode(sub);
+ }
+ root.validate();
+
+ List<Node> nodes = z.getNodes();
+ checkOrder(nodes);
+ }
+
+
+ @Test
+ public void testValidateWithNoAnchorPoint() {
+ Node root = new Node("root");
+ Zone z = new Zone(Side.Top, root);
+ root.addZone(z);
+ for (int i = 0; i < TEST_SIZE; i++) {
+ OrdinalSetting ord = new OrdinalSetting();
+ ord.addConstraint(new OrdinalConstraint(false, "sub" + (i - 1)));
+ ViewSettings vs = new ViewSettings();
+ vs.setOrdinal(ord);
+ Node sub = new Node("sub" + i, vs);
+ z.addNode(sub);
+ }
+
+ root.validate();
+
+ List<Node> nodes = z.getNodes();
+ checkOrder(nodes);
+ }
+
+ @Test
+ public void testValidateWithBefores() {
+ Node root = new Node("root");
+ Zone z = new Zone(Side.Top, root);
+ root.addZone(z);
+
+ int[] positions = new int[TEST_SIZE];
+ for (int i = 0; i < positions.length; i++) {
+ positions[i] = i;
+ }
+ for (int i = 0; i < positions.length; i++) {
+ int tmp = positions[i];
+ int rndPos = rnd.nextInt(positions.length);
+ positions[i] = positions[rndPos];
+ positions[rndPos] = tmp;
+ }
+
+ OrdinalSetting ord = new OrdinalSetting();
+ ViewSettings vs = new ViewSettings();
+ Node sub = null;
+ for (int i = 0; i < positions.length - 1; i++) {
+ ord = new OrdinalSetting();
+ ord.addConstraint(new OrdinalConstraint(true, "sub" + (i + 1)));
+ vs = new ViewSettings();
+ vs.setOrdinal(ord);
+ sub = new Node("sub" + i, vs);
+ z.addNode(sub);
+ }
+ vs = new ViewSettings();
+ sub = new Node("sub" + (positions.length - 1), vs);
+ z.addNode(sub);
+
+
+ root.validate();
+
+ List<Node> nodes = z.getNodes();
+ checkOrder(nodes);
+ }
+
+ @Test
+ public void testFindById() {
+ Node root = new Node("root");
+ Zone z = new Zone(Side.Top, root);
+ root.addZone(z);
+ Node sub = new Node("sub");
+ z.addNode(sub);
+
+ Node found = z.findById("sub");
+ assertNotNull(found);
+ assertSame(sub, found);
+
+ found = z.findById("notpresent");
+ assertNull(found);
+ }
+
+ @Test
+ public void singleSlice() throws Exception {
+ Node root = new Node("root");
+ Zone z = new Zone(Side.Top, root);
+ root.addZone(z);
+
+ for (int i = 0; i < TEST_SIZE; i++) {
+ OrdinalSetting ord = new OrdinalSetting();
+ ord.setOrder(i + 1);
+ ZoneSetting zs = new ZoneSetting();
+ zs.setShared(true);
+ ViewSettings vs = new ViewSettings();
+ vs.setOrdinal(ord);
+ vs.setZone(zs);
+ z.addNode(new Node("sub" + i, vs));
+ }
+
+ root.validate();
+
+ assertEquals(1, z.getSlices());
+ List<Node> nodes = z.getSliceNodes(0);
+ checkOrder(nodes);
+ }
+
+ @Test
+ public void ownSlice() throws Exception {
+ Node root = new Node("root");
+ Zone z = new Zone(Side.Top, root);
+ root.addZone(z);
+
+ for (int i = 0; i < TEST_SIZE; i++) {
+ OrdinalSetting ord = new OrdinalSetting();
+ ord.setOrder(i + 1);
+ ZoneSetting zs = new ZoneSetting();
+ zs.setShared(false);
+ ViewSettings vs = new ViewSettings();
+ vs.setOrdinal(ord);
+ vs.setZone(zs);
+ z.addNode(new Node("sub" + i, vs));
+ }
+
+ root.validate();
+
+ assertEquals(TEST_SIZE, z.getSlices());
+ for (int i = 0; i < TEST_SIZE; i++) {
+ List<Node> nodes = z.getSliceNodes(0);
+ assertEquals(1, nodes.size());
+ }
+
+ }
+
+ @Test
+ public void sliceInPairs() throws Exception {
+ Node root = new Node("root");
+ Zone z = new Zone(Side.Top, root);
+ root.addZone(z);
+
+ int slices = 0;
+ for (int i = 0; i < TEST_SIZE; i++) {
+ OrdinalSetting ord = new OrdinalSetting();
+ ord.setOrder(i + 1);
+ ZoneSetting zs = new ZoneSetting();
+ zs.setShared(i % 3 != 0);
+ if (i % 3 == 0) slices += 2;
+ ViewSettings vs = new ViewSettings();
+ vs.setOrdinal(ord);
+ vs.setZone(zs);
+ z.addNode(new Node("sub" + i, vs));
+ }
+
+ root.validate();
+
+ assertEquals(slices, z.getSlices());
+ // Not checking the last one cause could contain one instead of two just because there are odd numbers
+ for (int i = 0; i < slices - 1; i++) {
+ List<Node> nodes = z.getSliceNodes(i);
+ if (i % 2 == 0) {
+ assertEquals("Failed on slice " + i, 1, nodes.size());
+ } else {
+ assertEquals("Failed on slice " + i, 2, nodes.size());
+ }
+ }
+
+ Set<Node> allNodes = root.getAllNodes();
+ assertEquals(TEST_SIZE + 1, allNodes.size());
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org