Search in sources :

Example 1 with JavaDocToc

use of org.eclipse.linuxtools.internal.javadocs.ui.JavaDocToc in project linuxtools by eclipse.

the class CheckJavadoc method testHelpTopic.

/**
 * 	Create a valid topic file given the sample Javadoc files provided
 *  in the /javadoc_root directory.
 *  @throws IOException
 * 	@result  A valid topic will be created with the proper href and label.
 *           Additionally this topic will be enabled correctly and will
 *           contain no child topics (subtopics).
 */
@Test
public void testHelpTopic() throws IOException {
    // Get current directory and append our test doc directory to it.
    // Set plugin preferences to read/detect Javadocs from this directory
    // instead.
    String testDocLoc = "/javadoc_root";
    String dir = FileLocator.toFileURL(this.getClass().getResource(testDocLoc)).getPath();
    IPath wsRoot = new Path(dir);
    IPreferenceStore ps = JavaDocPlugin.getDefault().getPreferenceStore();
    ps.setValue(PreferenceConstants.JAVADOCS_DIRECTORY, wsRoot.toOSString());
    JavaDocToc toc = new JavaDocToc();
    // Get topics array
    ITopic[] topics = toc.getTopics();
    // Verify we have the test topic, in this case jnr-unixsocket
    assertTrue(topics.length > 0);
    assertTrue(topics.length == 1);
    // Set topics and check labels
    ITopic topicJnr = topics[0];
    // $NON-NLS-1$
    assertTrue(topicJnr.getLabel().startsWith("jnr-unixsocket"));
    // Get subtopics for each topic, should be 0 since
    // Javadocs directories are only one level deep
    ITopic[] subtopicsJnr = topicJnr.getSubtopics();
    assertTrue(subtopicsJnr.length == 0);
    IUAElement[] elementsJnr = topicJnr.getChildren();
    assertTrue(elementsJnr.length == 0);
    // Get hrefs and check for correctness according to Plugin-ID
    // relative path
    String hrefApache = topicJnr.getHref();
    assertEquals(hrefApache, // $NON-NLS-1$
    "org.eclipse.linuxtools.javadocs/jnr-unixsocket/index.html");
    // Check to make sure topics are enables (should always be true)
    // regardless of input
    assertTrue(topicJnr.isEnabled(null));
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) JavaDocToc(org.eclipse.linuxtools.internal.javadocs.ui.JavaDocToc) ITopic(org.eclipse.help.ITopic) IPath(org.eclipse.core.runtime.IPath) IUAElement(org.eclipse.help.IUAElement) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) Test(org.junit.Test)

Aggregations

IPath (org.eclipse.core.runtime.IPath)1 Path (org.eclipse.core.runtime.Path)1 ITopic (org.eclipse.help.ITopic)1 IUAElement (org.eclipse.help.IUAElement)1 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)1 JavaDocToc (org.eclipse.linuxtools.internal.javadocs.ui.JavaDocToc)1 Test (org.junit.Test)1