Search in sources :

Example 1 with Publication

use of org.eclipse.mylyn.docs.epub.core.Publication in project mylyn.docs by eclipse.

the class TestEPUB method testPackFileFileExists.

/**
 * Test method for {@link org.eclipse.mylyn.docs.epub.core.EPUB#pack(java.io.File, java.io.File)} .
 * <ul>
 * <li>Exception shall be thrown if working folder already exist.</li>
 * </ul>
 *
 * @throws Exception
 */
@Test
public final void testPackFileFileExists() throws Exception {
    File workingFolder = File.createTempFile("epub_", null);
    EPUB epub = new EPUB();
    Publication oebps = new OPSPublication();
    epub.add(oebps);
    try {
        epub.pack(epubFile, workingFolder);
        fail();
    } catch (Exception e) {
    }
}
Also used : EPUB(org.eclipse.mylyn.docs.epub.core.EPUB) Publication(org.eclipse.mylyn.docs.epub.core.Publication) OPSPublication(org.eclipse.mylyn.docs.epub.core.OPSPublication) OPSPublication(org.eclipse.mylyn.docs.epub.core.OPSPublication) RootFile(org.eclipse.mylyn.docs.epub.ocf.RootFile) File(java.io.File) IOException(java.io.IOException) Test(org.junit.Test)

Example 2 with Publication

use of org.eclipse.mylyn.docs.epub.core.Publication in project mylyn.docs by eclipse.

the class TestEPUB method testPackFileFile.

/**
 * Test method for {@link org.eclipse.mylyn.docs.epub.core.EPUB#pack(java.io.File, java.io.File)} .
 * <ul>
 * <li>Work folder shall exist when job is done.</li>
 * <li>Work folder shall contain EPUB artifacts.</li>
 * <li>Exception shall be thrown if working folder already exist.</li>
 * </ul>
 *
 * @throws Exception
 */
@Test
public final void testPackFileFile() throws Exception {
    EPUB epub = new EPUB();
    Publication oebps = new OPSPublication();
    oebps.addItem(new File("testdata/plain-page.xhtml"));
    epub.add(oebps);
    epub.pack(epubFile, epubFolder);
    // Make sure all required files are present
    File metaFolder = new File(epubFolder.getAbsolutePath() + File.separator + "META-INF");
    assertEquals(true, metaFolder.exists());
    assertEquals(true, metaFolder.isDirectory());
    File containerFile = new File(epubFolder.getAbsolutePath() + File.separator + "META-INF" + File.separator + "container.xml");
    assertEquals(true, containerFile.exists());
    assertEquals(false, containerFile.isDirectory());
    File oebpsFolder = new File(epubFolder.getAbsolutePath() + File.separator + "OEBPS");
    assertEquals(true, oebpsFolder.exists());
    assertEquals(true, oebpsFolder.isDirectory());
}
Also used : EPUB(org.eclipse.mylyn.docs.epub.core.EPUB) Publication(org.eclipse.mylyn.docs.epub.core.Publication) OPSPublication(org.eclipse.mylyn.docs.epub.core.OPSPublication) OPSPublication(org.eclipse.mylyn.docs.epub.core.OPSPublication) RootFile(org.eclipse.mylyn.docs.epub.ocf.RootFile) File(java.io.File) Test(org.junit.Test)

Example 3 with Publication

use of org.eclipse.mylyn.docs.epub.core.Publication in project mylyn.docs by eclipse.

the class TestEPUB method testAddOPSPublication.

/**
 * Test method for {@link org.eclipse.mylyn.docs.epub.core.EPUB#add(org.eclipse.mylyn.docs.epub.core.Publication)} .
 * <ul>
 * <li>Container shall hold more than one OPS publication</li>
 * <li>OPS structures shall follow naming conventions.</li>
 * <li>OPS MIME-type shall be correct</li>
 * <li>Rootfile object shall be correct.</li>
 * </ul>
 *
 * @throws Exception
 */
@Test
public final void testAddOPSPublication() throws Exception {
    EPUB epub = new EPUB();
    Publication oebps1 = new OPSPublication();
    Publication oebps2 = new OPSPublication();
    epub.add(oebps1);
    epub.add(oebps2);
    Container container = epub.getContainer();
    RootFiles rootfiles = container.getRootfiles();
    EList<RootFile> files = rootfiles.getRootfiles();
    assertEquals(true, files.get(0).getFullPath().equals("OEBPS/content.opf"));
    assertEquals(true, files.get(1).getFullPath().equals("OEBPS_1/content.opf"));
    assertEquals(true, files.get(0).getMediaType().equals("application/oebps-package+xml"));
    assertEquals(true, files.get(1).getMediaType().equals("application/oebps-package+xml"));
    assertEquals(true, files.get(0).getPublication() == oebps1);
    assertEquals(true, files.get(1).getPublication() == oebps2);
}
Also used : Container(org.eclipse.mylyn.docs.epub.ocf.Container) EPUB(org.eclipse.mylyn.docs.epub.core.EPUB) Publication(org.eclipse.mylyn.docs.epub.core.Publication) OPSPublication(org.eclipse.mylyn.docs.epub.core.OPSPublication) RootFiles(org.eclipse.mylyn.docs.epub.ocf.RootFiles) OPSPublication(org.eclipse.mylyn.docs.epub.core.OPSPublication) RootFile(org.eclipse.mylyn.docs.epub.ocf.RootFile) Test(org.junit.Test)

Example 4 with Publication

use of org.eclipse.mylyn.docs.epub.core.Publication in project mylyn.docs by eclipse.

the class TestEPUB method testPackFile.

/**
 * Test method for {@link org.eclipse.mylyn.docs.epub.core.EPUB#pack(java.io.File)}.
 * <ul>
 * <li>Temporary folder shall not exist when job is done.</li>
 * </ul>
 *
 * @throws Exception
 */
@Test
public final void testPackFile() throws Exception {
    EPUB epub = new EPUB();
    Publication oebps = new OPSPublication();
    oebps.addItem(new File("testdata/plain-page.xhtml"));
    epub.add(oebps);
    File drawing = new File("testdata/drawing.svg");
    epub.add(drawing, "image/svg+xml");
    File tempFolder = epub.pack(epubFile);
    assertEquals(false, tempFolder.exists());
}
Also used : EPUB(org.eclipse.mylyn.docs.epub.core.EPUB) Publication(org.eclipse.mylyn.docs.epub.core.Publication) OPSPublication(org.eclipse.mylyn.docs.epub.core.OPSPublication) OPSPublication(org.eclipse.mylyn.docs.epub.core.OPSPublication) RootFile(org.eclipse.mylyn.docs.epub.ocf.RootFile) File(java.io.File) Test(org.junit.Test)

Example 5 with Publication

use of org.eclipse.mylyn.docs.epub.core.Publication in project mylyn.docs by eclipse.

the class TestEPUB method testUnpackFileFile.

/**
 * Test method for {@link org.eclipse.mylyn.docs.epub.core.EPUB#unpack(java.io.File, java.io.File)} .
 *
 * @throws Exception
 */
@Test
public final void testUnpackFileFile() throws Exception {
    // First pack the EPUB
    EPUB epub = new EPUB();
    Publication oebps = new OPSPublication();
    oebps.addItem(new File("testdata/plain-page.xhtml"));
    epub.add(oebps);
    epub.pack(epubFile, epubFolder);
    deleteFolder(epubFolder);
    // Then check for some contents when unpacked
    EPUB epub2 = new EPUB();
    epub2.unpack(epubFile, epubFolder);
    // Make sure all required files are present
    File metaFolder = new File(epubFolder.getAbsolutePath() + File.separator + "META-INF");
    assertEquals(true, metaFolder.exists());
    assertEquals(true, metaFolder.isDirectory());
    File containerFile = new File(epubFolder.getAbsolutePath() + File.separator + "META-INF" + File.separator + "container.xml");
    assertEquals(true, containerFile.exists());
    assertEquals(false, containerFile.isDirectory());
    File oebpsFolder = new File(epubFolder.getAbsolutePath() + File.separator + "OEBPS");
    assertEquals(true, oebpsFolder.exists());
    assertEquals(true, oebpsFolder.isDirectory());
}
Also used : EPUB(org.eclipse.mylyn.docs.epub.core.EPUB) Publication(org.eclipse.mylyn.docs.epub.core.Publication) OPSPublication(org.eclipse.mylyn.docs.epub.core.OPSPublication) OPSPublication(org.eclipse.mylyn.docs.epub.core.OPSPublication) RootFile(org.eclipse.mylyn.docs.epub.ocf.RootFile) File(java.io.File) Test(org.junit.Test)

Aggregations

OPSPublication (org.eclipse.mylyn.docs.epub.core.OPSPublication)16 Publication (org.eclipse.mylyn.docs.epub.core.Publication)16 Test (org.junit.Test)16 File (java.io.File)15 EPUB (org.eclipse.mylyn.docs.epub.core.EPUB)15 RootFile (org.eclipse.mylyn.docs.epub.ocf.RootFile)9 NavPoint (org.eclipse.mylyn.docs.epub.ncx.NavPoint)2 Ncx (org.eclipse.mylyn.docs.epub.ncx.Ncx)2 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 Meta (org.eclipse.mylyn.docs.epub.ncx.Meta)1 Container (org.eclipse.mylyn.docs.epub.ocf.Container)1 RootFiles (org.eclipse.mylyn.docs.epub.ocf.RootFiles)1