module.setTitle("mytitle");
module.setSplashPackage("org.codehaus.enunciate.samples.docs.pckg1");
EnunciateConfiguration config = new EnunciateConfiguration(Arrays.asList((DeploymentModule) module));
config.setExcludeUnreferencedClasses(false);
config.setIncludeReferencedClasses(false);
Enunciate enunciate = new Enunciate(getAllJavaFiles(getSamplesDir()));
enunciate.setConfig(config);
enunciate.setTarget(Enunciate.Target.BUILD);
enunciate.setRuntimeClasspath(getInAPTClasspath());
module.setBase(enunciate.createTempDir().getAbsolutePath());
ClientLibraryArtifact artifact1 = new ClientLibraryArtifact("module1", "1", "lib1") {
@Override
public void exportTo(File file, Enunciate enunciate) throws IOException {
//no-op
}
};
artifact1.setDescription("my <b>marked up</b> description for artifact 1");
NamedFileArtifact file = new NamedFileArtifact(null, null, new File("1.1.xml"));
file.setDescription("my description 1.1");
artifact1.addArtifact(file);
file = new NamedFileArtifact(null, null, new File("1.2.xml"));
file.setDescription("my description 1.2");
artifact1.addArtifact(file);
ClientLibraryArtifact artifact2 = new ClientLibraryArtifact("module2", "2", "lib2") {
@Override
public void exportTo(File file, Enunciate enunciate) throws IOException {
//no-op
}
};
artifact2.setDescription("my <b>marked up</b> description for artifact 2");
file = new NamedFileArtifact(null, null, new File("2.1.xml"));
file.setDescription("my description 2.1");
artifact2.addArtifact(file);
file = new NamedFileArtifact(null, null, new File("2.2.xml"));
file.setDescription("my description 2.2");
artifact2.addArtifact(file);
enunciate.addArtifact(artifact1);
enunciate.addArtifact(artifact2);
enunciate.execute();
File docsXml = new File(enunciate.getGenerateDir(), "docs/docs.xml");
DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
builderFactory.setValidating(false);
DocumentBuilder builder = builderFactory.newDocumentBuilder();
builder.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
if (String.valueOf(systemId).endsWith("xhtml1-transitional.dtd")) {
return new InputSource(TestGenerateDocsXml.this.getClass().getResourceAsStream("xhtml1-transitional.dtd"));
}
else if (String.valueOf(systemId).endsWith("xhtml-special.ent")) {
return new InputSource(TestGenerateDocsXml.this.getClass().getResourceAsStream("xhtml-special.ent"));
}
else if (String.valueOf(systemId).endsWith("xhtml-lat1.ent")) {
return new InputSource(TestGenerateDocsXml.this.getClass().getResourceAsStream("xhtml-lat1.ent"));
}
else if (String.valueOf(systemId).endsWith("xhtml-symbol.ent")) {
return new InputSource(TestGenerateDocsXml.this.getClass().getResourceAsStream("xhtml-symbol.ent"));
}
return null;
}
});
Document document = builder.parse(docsXml);
XPath xpath = XPathFactory.newInstance().newXPath();
assertEquals("Here is some package documentation. <child>text</child>", xpath.evaluate("/api-docs/documentation", document).trim());
assertEquals("myco", xpath.evaluate("/api-docs/@copyright", document).trim());
String packageDocsXPath = "/api-docs/packages/package[@id='%s']/documentation";
assertEquals("Here is some package documentation. <child>text</child>", xpath.evaluate(String.format(packageDocsXPath, "org.codehaus.enunciate.samples.docs.pckg1"), document).trim());
assertEquals("Here is some more package documentation.", xpath.evaluate(String.format(packageDocsXPath, "org.codehaus.enunciate.samples.docs.pckg2"), document).trim());
String packageTagsXPath = "/api-docs/packages/package[@id='%s']/tag[@name='%s']";
assertEquals("sometag value", xpath.evaluate(String.format(packageTagsXPath, "org.codehaus.enunciate.samples.docs.pckg2", "sometag"), document).trim());
String typeDocsXPath = "/api-docs/data/schema[@namespace='%s']/types/type[@id='%s']/documentation";
assertEquals("Text for EnumOne", xpath.evaluate(String.format(typeDocsXPath, "urn:pckg1", "org.codehaus.enunciate.samples.docs.pckg1.EnumOne"), document).trim());
//todo: more testing of the docs xml...
File libsXml = new File(enunciate.getGenerateDir(), "docs/downloads.xml");
document = builder.parse(libsXml);
String libDescriptionXPath = "/downloads/download[@name='%s']/description";
assertEquals("my <b>marked up</b> description for artifact 1", xpath.evaluate(String.format(libDescriptionXPath, "lib1"), document).trim());
assertEquals("my <b>marked up</b> description for artifact 2", xpath.evaluate(String.format(libDescriptionXPath, "lib2"), document).trim());
String fileDescriptionXPath = "/downloads/download[@name='%s']/files/file[@name='%s']";
assertEquals("my description 1.1", xpath.evaluate(String.format(fileDescriptionXPath, "lib1", "1.1.xml"), document).trim());
assertEquals("my description 1.2", xpath.evaluate(String.format(fileDescriptionXPath, "lib1", "1.2.xml"), document).trim());
assertEquals("my description 2.1", xpath.evaluate(String.format(fileDescriptionXPath, "lib2", "2.1.xml"), document).trim());
assertEquals("my description 2.2", xpath.evaluate(String.format(fileDescriptionXPath, "lib2", "2.2.xml"), document).trim());
//todo: more testing of the downloads xml...
File indexHtml = new File(enunciate.getBuildDir(), "docs/index.html");
assertTrue(indexHtml.exists());
//todo: more testing of the generated HTML...
}