in src/main/java/com/atlassian/uwc/exporters/MindtouchExporterTest.java [511:620]
public void testOutputPageData() {
File out = new File("tmp/exported_mindtouch_pages");
assertFalse(out.exists());
Vector<MindtouchPage> pages = new Vector<MindtouchPage>();
MindtouchPage page = new MindtouchPage("39", "Sandbox",
"<content type=\"text/html\" title=\"Sandbox\"><body>\n" +
"<p>Testing 123</p></body><body target=\"toc\"><em>No headers</em></body></content>",
"<tags count=\"0\" href=\"http://192.168.2.247/@api/deki/pages/39/tags\" />",
"<comments count=\"0\" totalcount=\"0\" href=\"http://192.168.2.247/@api/deki/pages/39/comments\" />",
"<files count=\"0\" href=\"http://192.168.2.247/@api/deki/pages/39/files\" />");
MindtouchPage child = new MindtouchPage("43", "Test Tags",
"<content type=\"text/html\" title=\"Test Tags\"><body>\n" +
"<p>This page will have tags associated with it that will need to be turned into labels</p></body><body target=\"toc\"><em>No headers</em></body></content>",
"<tags count=\"1\" href=\"http://192.168.2.247/@api/deki/pages/43/tags\">" +
"<tag value=\"test\" id=\"3\" href=\"http://192.168.2.247/@api/deki/site/tags/3\">" +
"<type>text</type><uri>http://192.168.2.247/Special:Tags?tag=test</uri><title>test</title>" +
"</tag>" +
"</tags>",
"<comments count=\"0\" totalcount=\"0\" href=\"http://192.168.2.247/@api/deki/pages/43/comments\" />",
"<files count=\"0\" href=\"http://192.168.2.247/@api/deki/pages/43/files\" />");
MindtouchPage attchild = new MindtouchPage("40", "Test Attachments",
"<content type=\"text/html\" title=\"Test Attachments\"><body>\n" +
"<p>We\'re going to have some attachments content.</p>\n" +
"<p>We need an image that\'s inline, a link to an attachment, and an attached file with no reference in the page.</p>\n" +
"<p>Inline:</p>\n" +
"<p><img alt=\"cow.jpg\" class=\"internal default\" src=\"http://192.168.2.247/@api/deki/files/1/=cow.jpg\" /></p>\n" +
"<p>Link:</p>\n" +
"<p><a rel=\"internal\" href=\"http://192.168.2.247/@api/deki/files/3/=abc.txt\" class=\"iconitext-16 ext-txt \">abc.txt</a></p>\n" +
"</body><body target=\"toc\"><em>No headers</em></body></content>",
"<tags count=\"0\" href=\"http://192.168.2.247/@api/deki/pages/40/tags\" />",
"<comments count=\"0\" totalcount=\"0\" href=\"http://192.168.2.247/@api/deki/pages/40/comments\" />",
"<files count=\"1\" href=\"http://192.168.2.247/@api/deki/pages/40/files\">" +
"<file id=\"3\" href=\"http://192.168.2.247/@api/deki/files/3/info\"><filename>abc.txt</filename><description>text file" +
"</description><contents type=\"text/plain\" size=\"11\" " +
"href=\"http://192.168.2.247/@api/deki/files/3/=abc.txt\" /><date.created>2009-09-30T20:20:11Z" +
"</date.created><user.createdby id=\"1\" href=\"http://192.168.2.247/@api/deki/users/1\">" +
"<nick>laura.kolker</nick><username>laura.kolker</username><email>laura.kolker@gmail.com</email>" +
"<hash.email>9ed3310b0d84b37fe658dce82b713c08</hash.email>" +
"<uri.gravatar>http://www.gravatar.com/avatar/9ed3310b0d84b37fe658dce82b713c08</uri.gravatar>" +
"</user.createdby><revisions count=\"1\" totalcount=\"1\"" +
" href=\"http://192.168.2.247/@api/deki/files/3/revisions\" />" +
"<page.parent id=\"40\" href=\"http://192.168.2.247/@api/deki/pages/40?redirects=0\">" +
"<uri.ui>http://192.168.2.247/Sandbox/Test_Attachments</uri.ui><title>Test Attachments</title>" +
"<path>Sandbox/Test_Attachments</path><namespace>main</namespace>" +
"</page.parent><properties count=\"1\" href=\"http://192.168.2.247/@api/deki/files/3/properties\">" +
"<property name=\"urn:deki.mindtouch.com#description\" href=\"http://192.168.2.247/@api/deki/files" +
"/3/properties/urn%253adeki.mindtouch.com%2523description/info\" " +
"etag=\"6.r1_ts2009-09-30T20:20:11Z\"><contents type=\"text/plain; charset=utf-8\" size=\"9\"" +
" href=\"http://192.168.2.247/@api/deki/files/3/properties/urn%253adeki.mindtouch.com%" +
"2523description\">text file</contents><date.modified>2009-09-30T20:20:11Z</date.modified>" +
"<user.modified id=\"1\" href=\"http://192.168.2.247/@api/deki/users/1\">" +
"<nick>laura.kolker</nick><username>laura.kolker</username><email>laura.kolker@gmail.com</email>" +
"<hash.email>9ed3310b0d84b37fe658dce82b713c08</hash.email><uri.gravatar>http" +
"://www.gravatar.com/avatar/9ed3310b0d84b37fe658dce82b713c08</uri.gravatar>" +
"</user.modified></property></properties></file></files>");
page.getSubpages().add(child);
page.getSubpages().add(attchild);
pages.add(page);
try {
tester.outputPageData(pages);
assertTrue(out.exists());
File[] outfiles = out.listFiles(new NoSvnFilter());
assertNotNull(outfiles);
assertEquals(2, outfiles.length);
int i = 0;
File[] children = null;
for (File outfile : outfiles) {
assertNotNull(outfile);
switch(i++) {
case 0:
assertEquals("39_Sandbox.xml", outfile.getName());
assertTrue(outfile.isFile());
break;
case 1:
assertEquals("39_Sandbox_subpages", outfile.getName());
assertTrue(outfile.isDirectory());
children = outfile.listFiles(new NoSvnFilter());
break;
}
}
//subpages
assertNotNull(children);
assertEquals(3, children.length);
for (File outchild : children) {
assertNotNull(outchild);
String name = outchild.getName();
assertTrue(name, "43_TestTags.xml".equals(name) ||
"40_TestAttachments.xml".equals(name) ||
"40_TestAttachments_attachments".equals(name));
if ("40_TestAttachments_attachments".equals(name)) {
assertTrue(outchild.isDirectory());
children = outchild.listFiles(new NoSvnFilter());
}
else assertTrue(outchild.isFile());
}
//attachments
assertNotNull(children);
assertEquals(1, children.length);
File attachment = children[0];
assertNotNull(attachment);
assertEquals("abc.txt", attachment.getName());
} finally {
tester.deleteDir(out);
}
}