Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Test Cleanup] First attempt #828

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@
<artifactId>jackson-mapper-asl</artifactId>
<version>1.9.12</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
Expand Down
18 changes: 6 additions & 12 deletions src/test/java/com/adobe/epubcheck/api/AbstractEpubCheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import java.util.LinkedList;
import java.util.List;

import com.adobe.epubcheck.api.*;
import com.adobe.epubcheck.util.*;
import org.junit.Before;

Expand All @@ -47,14 +48,12 @@

public abstract class AbstractEpubCheckTest
{

private String basepath;
List<MessageId> expectedWarnings = new LinkedList<MessageId>();
List<MessageId> expectedErrors = new LinkedList<MessageId>();
List<MessageId> expectedFatals = new LinkedList<MessageId>();
List<MessageId> expectedInfos = new LinkedList<MessageId>();
List<MessageId> expectedUsages = new LinkedList<MessageId>();

protected List<MessageId> expectedWarnings = new LinkedList<MessageId>();
protected List<MessageId> expectedErrors = new LinkedList<MessageId>();
protected List<MessageId> expectedFatals = new LinkedList<MessageId>();
protected List<MessageId> expectedInfos = new LinkedList<MessageId>();
protected List<MessageId> expectedUsages = new LinkedList<MessageId>();

protected AbstractEpubCheckTest(String basepath)
{
Expand Down Expand Up @@ -86,11 +85,6 @@ public void testValidateDocument(String fileName, String resultFile)
testValidateDocument(fileName, resultFile, null, false, false);
}

public void testValidateDocument(String fileName, String resultFile, boolean usage, boolean verbose)
{
testValidateDocument(fileName, resultFile, EPUBProfile.DEFAULT, usage, verbose);
}

public void testValidateDocument(String fileName, String resultFile, EPUBProfile profile, boolean usage,
boolean verbose)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
package com.adobe.epubcheck.test;
package com.adobe.epubcheck.api;

import com.adobe.epubcheck.api.EpubCheck;
import com.adobe.epubcheck.api.Report;
import com.adobe.epubcheck.test.CommonTestRunner;
import com.adobe.epubcheck.util.WriterReportImpl;
import org.junit.Assert;
import org.junit.Test;

import java.io.File;
import java.io.FileInputStream;
Expand All @@ -7,56 +14,68 @@
import java.net.URISyntaxException;
import java.net.URL;

import org.junit.Assert;
import org.junit.Test;

import com.adobe.epubcheck.api.EpubCheck;
import com.adobe.epubcheck.api.Report;
import com.adobe.epubcheck.util.WriterReportImpl;

/**
* Test the various constructors for the EpubCheck Object.
*/
public class api_Test
public class ApiConstructorsTest
{

/**
* Checking if the standard API constructor can take an epub and validate it.
*
* @throws Exception
*/
@Test
public void EpubCheck1_Test() throws Exception
public void StandardConstructorTest() throws Exception
{
File epub = getTestEpub();
EpubCheck check = new EpubCheck(epub);
Assert.assertEquals("The file should have generated errors.", 2, 2 & check.doValidate());
Assert.assertEquals("The file should have no errors.", 0, check.doValidate());
}

/**
* Checking if we can apply a PrintWriter to the constructor and get the expected output written
* to the supplied PrintWriter.
*
* @throws Exception
*/
@Test
public void EpubCheck_PrintWriter_Test() throws Exception
public void PrintWriterConstructorTest() throws Exception
{
try {
File epub = getTestEpub();
URL expectedUrl = common.class.getResource("api");
URL expectedUrl = this.getClass().getResource("");
String outputPath = new File(expectedUrl.toURI()).getAbsolutePath();

File actualResults = new File(outputPath + "/PrintWriter_Actual.txt");
File expectedResults = new File(outputPath + "/PrintWriter_Expected.txt");
FileOutputStream outputStream = new FileOutputStream(actualResults);
PrintWriter out = new PrintWriter(outputStream);
EpubCheck check = new EpubCheck(epub, out);
Assert.assertEquals("The file should have generated errors.", 2, 2 & check.doValidate());
Assert.assertEquals("The file should have no errors.", 0, check.doValidate());
out.flush();
outputStream.close();
out.close();
Assert.assertTrue("The resulting file doesn't exist.", actualResults.exists());
Assert.assertTrue("The expected file doesn't exist.", expectedResults.exists());
common.compareText(expectedResults, actualResults);
CommonTestRunner.compareText(expectedResults, actualResults);
} catch (URISyntaxException e) {
throw new IllegalStateException("Cannot find test file", e);
}
}

/**
* Checking if we can stream a epub to the constructor and use a Report object to
* summarize the output.
*
* @throws Exception
*/
@Test
public void EpubCheck_InputStream_Test() throws Exception
public void InputStreamConstructorTest() throws Exception
{
try {
File epub = getTestEpub();
URL expectedUrl = common.class.getResource("api");
URL expectedUrl = this.getClass().getResource("");
String outputPath = new File(expectedUrl.toURI()).getAbsolutePath();
File actualResults = new File(outputPath + "/InputStream_Actual.txt");
File expectedResults = new File(outputPath + "/InputStream_Expected.txt");
Expand All @@ -66,23 +85,24 @@ public void EpubCheck_InputStream_Test() throws Exception
FileInputStream epubStream = new FileInputStream(epub);
Report report = new WriterReportImpl(out, "Testing 123");
EpubCheck check = new EpubCheck(epubStream, report, epub.getPath());
Assert.assertEquals("The file should have generated errors.", 2, 2 & check.doValidate());
Assert.assertEquals("The file should have generated errors.", 0, check.doValidate());
out.flush();
outputStream.close();
out.close();
epubStream.close();
Assert.assertEquals("Errors reported", 0, report.getErrorCount());
Assert.assertTrue("The resulting file doesn't exist.", actualResults.exists());
Assert.assertTrue("The expected file doesn't exist.", expectedResults.exists());
common.compareText(expectedResults, actualResults);
CommonTestRunner.compareText(expectedResults, actualResults);
} catch (URISyntaxException e) {
throw new IllegalStateException("Cannot find test file", e);
}
}

private File getTestEpub()
private File getTestEpub() throws Exception
{
try {
URL inputUrl = common.class.getResource("../../../../30/epub/invalid/font_no_fallback.epub");
URL inputUrl = this.getClass().getResource("../../../../minimal-epub/30/minimal-epub-30.epub");
String inputPath = new File(inputUrl.toURI()).getAbsolutePath();
File epub = new File(inputPath);
Assert.assertTrue("Couldn't find resource: " + inputPath, epub.exists());
Expand Down
63 changes: 36 additions & 27 deletions src/test/java/com/adobe/epubcheck/api/Epub20CheckExpandedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import com.adobe.epubcheck.messages.MessageId;

@Deprecated
public class Epub20CheckExpandedTest extends AbstractEpubCheckTest
{

Expand All @@ -36,39 +37,60 @@ public Epub20CheckExpandedTest()
super("/20/expanded/");
}

/**
* This test will check that error is set if mimetype in the main package
* has a incorrect value.
*/
@Test
public void testValidateEPUBPLoremBasic()
public void validateEPUBMimetypeTest()
{
testValidateDocument("valid/lorem/lorem-basic", "valid/lorem/lorem-basic.txt");
Collections.addAll(expectedErrors, MessageId.PKG_007);
testValidateDocument("invalid/new/mimetype");
}


/**
* This test checks that we find paths that point to a local directory
* that is not present should be found.
*/
@Test
public void testValidateEPUBMimetype()
public void validateBadPathInNCXTest()
{
Collections.addAll(expectedErrors, MessageId.PKG_007);
testValidateDocument("invalid/lorem-mimetype", "invalid/lorem-mimetype.txt");
Collections.addAll(expectedErrors, MessageId.RSC_005);
testValidateDocument("invalid/new/badpath");
}

/**
* This test checks that a incorrect type should be flagged.
* Type used in this test is 'body'
*/
@Test
public void testValidateEPUBBadPathInNCX()
public void validateBadNcxPageTargetTypeTest()
{
Collections.addAll(expectedErrors, MessageId.RSC_005);
testValidateDocument("invalid/lorem-ncx-badpath");
testValidateDocument("invalid/new/pagetarget");
}

/**
* This is a test to check that we allow more than one entry in a epub navigation index.
* Also check that the allowed guide elements are present.
*/
@Test
public void testValidateEPUBBadNcxPageTargetType()
public void validateMultipleEntries()
{
Collections.addAll(expectedErrors, MessageId.RSC_005);
testValidateDocument("invalid/ncx-pagetarget-type");
testValidateDocument("valid/new/dual");
}

/**
* This test will validate that extra spaces either trailing or leading the
* string of an unique ID should be acceptable.
*
* Look at issue 163
*/
@Test
public void testValidateEPUBUidSpaces()
public void validateUniqueIDWithSpacesTest()
{
// ascertain that leading/trailing space in 2.0 id values is accepted
// issue 163
testValidateDocument("valid/lorem-uidspaces", "valid/lorem-uidspaces.txt");
testValidateDocument("valid/new/uid-with-spaces", "valid/new/uid-with-spaces.txt");
}

@Test
Expand All @@ -92,19 +114,6 @@ public void testValidateEPUB20_okFallback()
testValidateDocument("valid/fallbacks/", "valid/fallbacks.txt");
}

@Test
public void testValidateEPUB20_loremBasicDual()
{
testValidateDocument("valid/lorem-basic-dual/", "valid/lorem-basic-dual.txt");
}

@Test
public void testValidateEPUB20_guideWithNcx()
{
Collections.addAll(expectedErrors, MessageId.OPF_032);
testValidateDocument("valid/lorem-dual-guide/", "valid/lorem-dual-guide.txt");
}

@Test
public void testValidateEPUB20_guideBrokenLink()
{
Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/adobe/epubcheck/api/Epub20CheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import com.adobe.epubcheck.messages.MessageId;

@Deprecated
public class Epub20CheckTest extends AbstractEpubCheckTest
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import com.adobe.epubcheck.messages.MessageId;

@Deprecated
public class Epub30CheckExpandedTest extends AbstractEpubCheckTest
{

Expand Down
1 change: 1 addition & 0 deletions src/test/java/com/adobe/epubcheck/api/Epub30CheckTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

import com.adobe.epubcheck.messages.MessageId;

@Deprecated
public class Epub30CheckTest extends AbstractEpubCheckTest
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.adobe.epubcheck.messages.Message;
import com.adobe.epubcheck.util.FeatureEnum;

@Deprecated
public class LocalizationTest
{

Expand Down
Loading