-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from openpreserve/test/validator
TEST: Validator tests
- Loading branch information
Showing
6 changed files
with
216 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
203 changes: 203 additions & 0 deletions
203
odf-core/src/test/java/org/openpreservation/odf/validation/ValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
package org.openpreservation.odf.validation; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertThrows; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import javax.xml.parsers.ParserConfigurationException; | ||
|
||
import org.junit.Test; | ||
import org.openpreservation.odf.fmt.TestFiles; | ||
import org.xml.sax.SAXException; | ||
|
||
public class ValidatorTest { | ||
|
||
@Test | ||
public void validateNullPath() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
Path nullPath = null; | ||
assertThrows("NullPointerException expected", | ||
NullPointerException.class, | ||
() -> { | ||
validator.validate(nullPath); | ||
}); | ||
} | ||
|
||
@Test | ||
public void validateNoSuchPath() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
Path noSuchFile = Paths.get("n0SuchDF1l3"); | ||
assertThrows("FileNotFoundException expected", | ||
FileNotFoundException.class, | ||
() -> { | ||
validator.validate(noSuchFile); | ||
}); | ||
} | ||
|
||
@Test | ||
public void validateDirPath() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
Path noSuchFile = Paths.get("."); | ||
assertThrows("IllegalArgumentException expected", | ||
IllegalArgumentException.class, | ||
() -> { | ||
validator.validate(noSuchFile); | ||
}); | ||
} | ||
|
||
@Test | ||
public void validatePath() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
ValidationReport report = validator.validate(new File(TestFiles.EMPTY_ODS.toURI()).toPath()); | ||
assertTrue("Package should be valid." , report.isValid()); | ||
} | ||
|
||
@Test | ||
public void validateNullFile() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
File nullFile = null; | ||
assertThrows("NullPointerException expected", | ||
NullPointerException.class, | ||
() -> { | ||
validator.validate(nullFile); | ||
}); | ||
} | ||
|
||
@Test | ||
public void validateFile() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
ValidationReport report = validator.validate(new File(TestFiles.EMPTY_ODS.toURI())); | ||
assertTrue("Package should be valid." , report.isValid()); | ||
} | ||
|
||
@Test | ||
public void validateEmpty() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
ValidationReport report = validator.validate(new File(TestFiles.EMPTY.toURI()).toPath()); | ||
assertFalse("Package should NOT be valid, spreadsheets only." , report.isValid()); | ||
assertEquals(1, report.getMessages().stream().filter(m -> m.getId().equals("DOC-1")).count()); | ||
} | ||
|
||
@Test | ||
public void validateNoMimeNoRoot() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
ValidationReport report = validator.validate(new File(TestFiles.NO_MIME_NO_ROOT_ODS.toURI()).toPath()); | ||
assertTrue("Package should be valid." , report.isValid()); | ||
} | ||
|
||
@Test | ||
public void validateDocXml() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
ValidationReport report = validator.validate(new File(TestFiles.EMPTY_FODS.toURI()).toPath()); | ||
assertTrue("Package should be valid." , report.isValid()); | ||
} | ||
|
||
@Test | ||
public void validateDocInvalidXml() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
ValidationReport report = validator.validate(new File(TestFiles.FLAT_NOT_VALID.toURI()).toPath()); | ||
assertFalse("Document should NOT be valid." , report.isValid()); | ||
assertEquals(1, report.getMessages().stream().filter(m -> m.getId().equals("XML-4")).count()); | ||
} | ||
|
||
@Test | ||
public void validateDocNotWellFormedXml() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
ValidationReport report = validator.validate(new File(TestFiles.FLAT_NOT_WF.toURI()).toPath()); | ||
assertFalse("Document should NOT be valid." , report.isValid()); | ||
assertEquals(1, report.getMessages().stream().filter(m -> m.getId().equals("DOC-1")).count()); | ||
assertEquals(1, report.getMessages().stream().filter(m -> m.getId().equals("XML-3")).count()); | ||
} | ||
|
||
@Test | ||
public void validateSpreadsheetNullPath() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
Path nullPath = null; | ||
assertThrows("NullPointerException expected", | ||
NullPointerException.class, | ||
() -> { | ||
validator.validateSpreadsheet(nullPath); | ||
}); | ||
} | ||
|
||
@Test | ||
public void validateSpreadsheetPath() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
ValidationReport report = validator.validateSpreadsheet(new File(TestFiles.EMPTY_ODS.toURI()).toPath()); | ||
assertTrue("Package should be valid." , report.isValid()); | ||
} | ||
|
||
@Test | ||
public void validateSpreadsheetNullFile() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
File nullFile = null; | ||
assertThrows("NullPointerException expected", | ||
NullPointerException.class, | ||
() -> { | ||
validator.validateSpreadsheet(nullFile); | ||
}); | ||
} | ||
|
||
@Test | ||
public void validateSpreadsheetFile() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
ValidationReport report = validator.validateSpreadsheet(new File(TestFiles.EMPTY_ODS.toURI())); | ||
assertTrue("Package should be valid." , report.isValid()); | ||
} | ||
|
||
@Test | ||
public void validateSingleFormatInvalid() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
ValidationReport report = validator.validateSpreadsheet(new File(TestFiles.DSIG_INVALID.toURI()).toPath()); | ||
assertFalse("Package should NOT be valid, spreadsheets only." , report.isValid()); | ||
assertEquals(1, report.getMessages().stream().filter(m -> m.getId().equals("DOC-7")).count()); | ||
} | ||
|
||
@Test | ||
public void validateSingleFormatEmpty() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
ValidationReport report = validator.validateSpreadsheet(new File(TestFiles.EMPTY.toURI()).toPath()); | ||
assertFalse("Package should NOT be valid, spreadsheets only." , report.isValid()); | ||
assertEquals(1, report.getMessages().stream().filter(m -> m.getId().equals("DOC-6")).count()); | ||
} | ||
|
||
@Test | ||
public void validateSingleFormatNoMimeNoRoot() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
ValidationReport report = validator.validateSpreadsheet(new File(TestFiles.NO_MIME_NO_ROOT_ODS.toURI()).toPath()); | ||
assertFalse("Package should NOT be valid, spreadsheets only." , report.isValid()); | ||
assertEquals(1, report.getMessages().stream().filter(m -> m.getId().equals("DOC-7")).count()); | ||
} | ||
|
||
@Test | ||
public void validateSingleFormatDocXml() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
ValidationReport report = validator.validateSpreadsheet(new File(TestFiles.EMPTY_FODS.toURI()).toPath()); | ||
assertTrue("Package should be valid." , report.isValid()); | ||
} | ||
|
||
@Test | ||
public void validateSpreadsheetDocInvalidXml() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
ValidationReport report = validator.validateSpreadsheet(new File(TestFiles.FLAT_NOT_VALID.toURI()).toPath()); | ||
assertFalse("Document should NOT be valid." , report.isValid()); | ||
assertEquals(1, report.getMessages().stream().filter(m -> m.getId().equals("XML-4")).count()); | ||
} | ||
|
||
@Test | ||
public void validateSpreadsheetDocNotWellFormedXml() throws ParserConfigurationException, IOException, SAXException, URISyntaxException { | ||
Validator validator = new Validator(); | ||
ValidationReport report = validator.validateSpreadsheet(new File(TestFiles.FLAT_NOT_WF.toURI()).toPath()); | ||
assertFalse("Document should NOT be valid." , report.isValid()); | ||
assertEquals(1, report.getMessages().stream().filter(m -> m.getId().equals("DOC-1")).count()); | ||
assertEquals(1, report.getMessages().stream().filter(m -> m.getId().equals("XML-3")).count()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters