diff options
Diffstat (limited to 'org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocServletTest.java')
-rw-r--r-- | org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocServletTest.java | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocServletTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocServletTest.java index ebd5a0529..42b2e85a4 100644 --- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocServletTest.java +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/remote/TocServletTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2015 IBM Corporation and others. + * Copyright (c) 2009, 2016 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,6 +11,8 @@ *******************************************************************************/ package org.eclipse.ua.tests.help.remote; +import static org.junit.Assert.assertEquals; + import java.io.InputStream; import java.net.URL; import java.util.ArrayList; @@ -19,51 +21,56 @@ import java.util.List; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; -import junit.framework.TestCase; - import org.eclipse.help.internal.base.BaseHelpSystem; import org.eclipse.help.internal.entityresolver.LocalEntityResolver; import org.eclipse.help.internal.server.WebappManager; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; -public class TocServletTest extends TestCase { - +public class TocServletTest { + private int mode; - @Override - protected void setUp() throws Exception { + @Before + public void setUp() throws Exception { BaseHelpSystem.ensureWebappRunning(); mode = BaseHelpSystem.getMode(); BaseHelpSystem.setMode(BaseHelpSystem.MODE_INFOCENTER); } - - @Override - protected void tearDown() throws Exception { + + @After + public void tearDown() throws Exception { BaseHelpSystem.setMode(mode); } + @Test public void testTocServletContainsUAToc() throws Exception { Node root = getTocContributions("en"); Element[] UARoot = findContributionById(root, "/org.eclipse.ua.tests/data/help/toc/root.xml"); assertEquals(1, UARoot.length); } + @Test public void testTocServletContainsFilteredToc() throws Exception { Node root = getTocContributions("en"); Element[] UARoot = findContributionById(root, "/org.eclipse.ua.tests/data/help/toc/filteredToc/toc.xml"); assertEquals(1, UARoot.length); } - + + @Test public void testTocServletContainsUnlinkedToc() throws Exception { Node root = getTocContributions("en"); Element[] UARoot = findContributionById(root, "/org.eclipse.ua.tests/data/help/toc/filteredToc/nonPrimaryToc.xml"); assertEquals(1, UARoot.length); } - + + @Test public void testReadEnToc() throws Exception { Node root = getTocContributions("en"); Element[] uaRoot = findContributionById(root, "/org.eclipse.ua.tests/data/help/search/toc.xml"); @@ -76,8 +83,9 @@ public class TocServletTest extends TestCase { assertEquals(1, topicEn.length); Element[] topicDe = findChildren(topicSearch[0], "topic", "label", "testde.html"); assertEquals(0, topicDe.length); - } - + } + + @Test public void testReadDeToc() throws Exception { Node root = getTocContributions("de"); Element[] uaRoot = findContributionById(root, "/org.eclipse.ua.tests/data/help/search/toc.xml"); @@ -91,11 +99,11 @@ public class TocServletTest extends TestCase { Element[] topicDe = findChildren(topicSearch[0], "topic", "label", "testde.html"); assertEquals(1, topicDe.length); } - + private Element[] findContributionById(Node root, String id) { return findChildren(root, "tocContribution", "id", id); } - + private Element[] findChildren(Node parent, String childKind, String attributeName, String attributeValue) { NodeList contributions = parent.getChildNodes(); List<Node> results = new ArrayList<Node>(); @@ -104,14 +112,14 @@ public class TocServletTest extends TestCase { if (next instanceof Element) { Element nextElement = (Element)next; if ( childKind.equals(nextElement.getTagName()) && attributeValue.equals(nextElement.getAttribute(attributeName))) { - - results.add(next); + + results.add(next); } } } return results.toArray(new Element[results.size()]); } - + protected Node getTocContributions( String locale) throws Exception { @@ -127,5 +135,5 @@ public class TocServletTest extends TestCase { assertEquals("tocContributions", root.getNodeName()); return root; } - + } |