1 17 18 19 20 package org.apache.lenya.cms.publication; 21 22 import java.io.IOException ; 23 24 import javax.xml.parsers.ParserConfigurationException ; 25 import javax.xml.transform.TransformerException ; 26 27 import junit.framework.TestCase; 28 29 import org.xml.sax.SAXException ; 30 31 public class DefaultSiteTreeTest extends TestCase { 32 33 private DefaultSiteTree siteTree = null; 34 35 39 public DefaultSiteTreeTest(String test) { 40 super(test); 41 } 42 43 49 public static void main(String [] args) { 50 junit.textui.TestRunner.run(DefaultSiteTreeTest.class); 51 } 52 53 56 protected void setUp() throws Exception { 57 super.setUp(); 58 siteTree = new DefaultSiteTree("testTree.xml"); 59 Label label = new Label("Foo", "en"); 60 Label[] fooLabels = { label }; 61 siteTree.addNode("/foo", fooLabels, true, null, null, false); 62 label = new Label("Home", "en"); 63 Label[] homeLabels = { label }; 64 siteTree.addNode("/index", homeLabels, true, null, null, false); 65 label = new Label("Bar", "en"); 66 Label label_de = new Label("Stab", "de"); 67 Label[] barLabels = { label, label_de }; 68 siteTree.addNode("/foo/bar", barLabels, true, "http://exact.biz", "suffix", true); 69 label = new Label("Lala", "en"); 70 Label[] lalaLabels = { label }; 71 siteTree.addNode("/foo/lala", lalaLabels, true, null, null, false); 72 } 73 74 77 protected void tearDown() throws Exception { 78 super.tearDown(); 79 } 80 81 84 final public void testDefaultSiteTreeString() { 85 } 87 88 91 final public void testDefaultSiteTreeFile() { 92 } 94 95 100 final public void testAddNodeStringStringLabelArray() throws SiteTreeException { 101 Label label = new Label("Tutorial", null); 102 Label[] labels = { label }; 103 104 siteTree.addNode("/foo", "tutorial", labels); 105 SiteTreeNode node = siteTree.getNode("/foo/tutorial"); 106 assertNotNull(node); 107 assertEquals(node.getId(), "tutorial"); 108 } 109 110 113 final public void testAddNodeSiteTreeNode() { 114 } 116 117 122 final public void testAddNodeStringLabelArrayStringStringboolean() throws SiteTreeException { 123 Label label1 = new Label("Doh", "en"); 124 Label label2 = new Label("Ding", "en"); 125 Label[] labels = { label1, label2}; 126 127 siteTree.addNode("/foo/ding", labels, true, null, null, false); 128 129 assertNotNull(siteTree.getNode("/foo/ding")); 130 assertEquals(siteTree.getNode("/foo/ding").getId(), "ding"); 131 } 132 133 138 final public void testAddNodeStringStringLabelArrayStringStringboolean() throws SiteTreeException { 139 Label label1 = new Label("Doh", "en"); 140 Label label2 = new Label("Ding", "en"); 141 Label[] labels = { label1, label2}; 142 143 siteTree.addNode("/foo", "baz", labels, true, null, null, false); 144 145 assertNotNull(siteTree.getNode("/foo/baz")); 146 assertEquals(siteTree.getNode("/foo/baz").getId(), "baz"); 147 } 148 149 154 final public void testAddLabel() throws SiteTreeException { 155 Label label = new Label("Tutorial", null); 156 Label[] labels = null; 157 158 siteTree.addLabel("/foo/bar", label); 159 labels = siteTree.getNode("/foo/bar").getLabels(); 160 assertEquals(labels.length, 3); 161 label = siteTree.getNode("/foo/bar").getLabel(""); 162 assertNotNull(label); 163 assertEquals(label.getLabel(), "Tutorial"); 164 } 165 166 170 final public void testRemoveLabel() { 171 assertEquals(siteTree.getNode("/foo/bar").getLabels().length, 2); 172 173 Label label = new Label("Stab", "de"); 174 siteTree.removeLabel("/foo/bar", label); 175 assertEquals(siteTree.getNode("/foo/bar").getLabels().length, 1); 176 177 assertEquals(siteTree.getNode("/foo/bar").getLabels()[0], new Label("Bar", "en")); 178 179 siteTree.addLabel("/foo/bar", label); 180 assertEquals(siteTree.getNode("/foo/bar").getLabels().length, 2); 181 } 182 183 188 final public void testRemoveNode() throws SiteTreeException { 189 Label label1 = new Label("Hi", "en"); 190 Label label2 = new Label("Ho", "en"); 191 Label[] labels1 = { label1, label2}; 192 193 siteTree.addNode("/hi", labels1, true, null, null, false); 194 195 Label[] labels2 = { label1, label2}; 196 197 siteTree.addNode("/hi/ho", labels2, true, null, null, false); 198 199 assertNotNull(siteTree.getNode("/hi/ho")); 200 201 siteTree.removeNode("/hi"); 202 203 assertNull(siteTree.getNode("/hi/ho")); 204 assertNull(siteTree.getNode("/hi")); 205 } 206 207 211 final public void testGetNode() { 212 assertNotNull(siteTree.getNode("/foo/bar")); 213 214 assertNull(siteTree.getNode("/foo/baz")); 215 } 216 217 221 final public void testSave() { 222 } 224 225 232 final public void testMoveUp() throws SiteTreeException, IOException , TransformerException { 233 siteTree.moveUp("/foo/lala"); 234 siteTree.save(); 235 assertNotNull(siteTree.getNode("/foo/lala")); 236 } 237 238 245 final public void testMoveDown() throws SiteTreeException, IOException , TransformerException { 246 siteTree.moveDown("/foo"); 247 siteTree.save(); 248 assertNotNull(siteTree.getNode("/foo")); 249 } 250 251 260 final public void testImportSubtree() throws ParserConfigurationException , SAXException , SiteTreeException, IOException , TransformerException { 261 DefaultSiteTree newSiteTree = new DefaultSiteTree("importedTree.xml"); 262 Label label = new Label("root", "en"); 263 Label[] rootLabels = { label }; 264 newSiteTree.addNode("/root", rootLabels, true, null, null, false); 265 label = new Label("foo", "en"); 266 Label[] fooLabels = { label }; 267 newSiteTree.addNode("/root/foo", fooLabels, true, null, null, false); 268 label = new Label("subtree", "en"); 269 Label[] subtreeLabels = { label }; 270 newSiteTree.addNode("/root/subtree", subtreeLabels, true, "http://exact.biz", "suffix", true); 271 label = new Label("child", "en"); 272 Label[] childLabels = { label }; 273 newSiteTree.addNode("/root/subtree/child", childLabels, true, null, null, false); 274 SiteTreeNode node=newSiteTree.getNode("/root/subtree"); 275 assertNotNull(node); 276 SiteTreeNode parentNode=siteTree.getNode("/foo/lala"); 277 assertNotNull(parentNode); 278 siteTree.importSubtree(parentNode,node, "subtree", null); 279 siteTree.save(); 280 assertNotNull(siteTree.getNode("/foo/lala/subtree")); 281 assertNotNull(siteTree.getNode("/foo/lala/subtree/child")); 282 } 283 } 284 | Popular Tags |