-
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.
- Loading branch information
1 parent
98506cf
commit 4fd9779
Showing
23 changed files
with
1,189 additions
and
1 deletion.
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
12 changes: 12 additions & 0 deletions
12
odf-core/src/test/java/org/openpreservation/odf/validation/rules/AbstractRuleTest.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,12 @@ | ||
package org.openpreservation.odf.validation.rules; | ||
|
||
import org.junit.Test; | ||
|
||
import nl.jqno.equalsverifier.EqualsVerifier; | ||
|
||
public class AbstractRuleTest { | ||
@Test | ||
public void testEqualsContract() { | ||
EqualsVerifier.forClass(AbstractRule.class).verify(); | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
odf-core/src/test/java/org/openpreservation/odf/validation/rules/ContentTest.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,94 @@ | ||
package org.openpreservation.odf.validation.rules; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertThrows; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.File; | ||
import java.nio.file.Paths; | ||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
import org.openpreservation.messages.MessageLog; | ||
import org.openpreservation.odf.fmt.TestFiles; | ||
import org.openpreservation.odf.pkg.OdfPackage; | ||
import org.openpreservation.odf.pkg.OdfPackages; | ||
import org.openpreservation.odf.pkg.PackageParser; | ||
import org.openpreservation.odf.validation.Rule; | ||
import org.openpreservation.odf.xml.OdfXmlDocument; | ||
|
||
import com.helger.commons.io.resource.URLResource; | ||
import com.helger.schematron.pure.SchematronResourcePure; | ||
import com.helger.schematron.svrl.AbstractSVRLMessage; | ||
import com.helger.schematron.svrl.SVRLHelper; | ||
import com.helger.schematron.svrl.jaxb.SchematronOutputType; | ||
|
||
public class ContentTest { | ||
@Test | ||
public void testGetInstance() { | ||
final SchematronResourcePure schematron = ((SchematronRule) Rules.odf7()).schematron; | ||
assertTrue(schematron.isValidSchematron()); | ||
} | ||
|
||
@Test | ||
public void testCheckNullXmlDoc() { | ||
Rule rule = Rules.odf7(); | ||
OdfXmlDocument nullDoc = null; | ||
assertThrows("UnsupportedOperationException expected", | ||
UnsupportedOperationException.class, | ||
() -> { | ||
rule.check(nullDoc); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testCheckNullPackage() { | ||
Rule rule = Rules.odf7(); | ||
OdfPackage nullPkg = null; | ||
assertThrows("NullPointerException expected", | ||
NullPointerException.class, | ||
() -> { | ||
rule.check(nullPkg); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testSchematronContentFail() throws Exception { | ||
final SchematronResourcePure schematron = ((SchematronRule) Rules.odf7()).schematron; | ||
final SchematronOutputType schResult = schematron.applySchematronValidationToSVRL(new URLResource(ClassLoader.getSystemResource("org/openpreservation/odf/fmt/xml/content.xml"))); | ||
assertNotNull(schResult); | ||
List<AbstractSVRLMessage> results = SVRLHelper.getAllFailedAssertionsAndSuccessfulReports(schResult); | ||
assertEquals(1, results.size()); | ||
} | ||
|
||
@Test | ||
public void testSchematronContentPass() throws Exception { | ||
final SchematronResourcePure schematron = ((SchematronRule) Rules.odf7()).schematron; | ||
final SchematronOutputType schResult = schematron.applySchematronValidationToSVRL(new URLResource(TestFiles.SCHEMATRON_CHECKER_XML)); | ||
assertNotNull(schResult); | ||
List<AbstractSVRLMessage> results = SVRLHelper.getAllFailedAssertionsAndSuccessfulReports(schResult); | ||
assertEquals(0, results.size()); | ||
} | ||
|
||
@Test | ||
public void testPackageContentFail() throws Exception { | ||
final Rule odf7 = Rules.odf7(); | ||
PackageParser parser = OdfPackages.getPackageParser(); | ||
OdfPackage pkg = parser.parsePackage(Paths.get(new File(TestFiles.EMPTY_ODS.toURI()).getAbsolutePath())); | ||
MessageLog messages = odf7.check(pkg); | ||
assertNotNull(messages); | ||
assertEquals(1, messages.getErrors().size()); | ||
assertEquals(1, messages.getMessages().values().stream().filter(m -> m.stream().filter(e -> e.getId().equals("ODF_7")).count() > 0).count()); | ||
} | ||
|
||
@Test | ||
public void testPackageContentPass() throws Exception { | ||
final Rule odf7 = Rules.odf7(); | ||
PackageParser parser = OdfPackages.getPackageParser(); | ||
OdfPackage pkg = parser.parsePackage(Paths.get(new File(TestFiles.SCHEMATRON_CHECKER_ODS.toURI()).getAbsolutePath())); | ||
MessageLog messages = odf7.check(pkg); | ||
assertNotNull(messages); | ||
assertEquals(0, messages.getErrors().size()); | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
...re/src/test/java/org/openpreservation/odf/validation/rules/DigitalSignaturesRuleTest.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,104 @@ | ||
package org.openpreservation.odf.validation.rules; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertThrows; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.nio.file.Paths; | ||
|
||
import org.junit.Test; | ||
import org.openpreservation.messages.MessageLog; | ||
import org.openpreservation.odf.fmt.TestFiles; | ||
import org.openpreservation.odf.pkg.OdfPackage; | ||
import org.openpreservation.odf.pkg.OdfPackages; | ||
import org.openpreservation.odf.pkg.PackageParser; | ||
import org.openpreservation.odf.validation.Rule; | ||
import org.openpreservation.odf.xml.OdfXmlDocument; | ||
|
||
import nl.jqno.equalsverifier.EqualsVerifier; | ||
|
||
public class DigitalSignaturesRuleTest { | ||
@Test | ||
public void testEqualsContract() { | ||
EqualsVerifier.forClass(DigitalSignaturesRule.class).verify(); | ||
} | ||
|
||
@Test | ||
public void testGetInstance() { | ||
Rule rule = DigitalSignaturesRule.getInstance(); | ||
assertNotNull("Returned Rule should not be null", rule); | ||
} | ||
|
||
@Test | ||
public void testCheckNullXmlDoc() { | ||
Rule rule = DigitalSignaturesRule.getInstance(); | ||
OdfXmlDocument nullDoc = null; | ||
assertThrows("UnsupportedOperationException expected", | ||
UnsupportedOperationException.class, | ||
() -> { | ||
rule.check(nullDoc); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testCheckNullPackage() { | ||
Rule rule = DigitalSignaturesRule.getInstance(); | ||
OdfPackage nullPkg = null; | ||
assertThrows("NullPointerException expected", | ||
NullPointerException.class, | ||
() -> { | ||
rule.check(nullPkg); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testCheckValidPackage() throws IOException, URISyntaxException { | ||
PackageParser parser = OdfPackages.getPackageParser(); | ||
OdfPackage pkg = parser.parsePackage(Paths.get(new File(TestFiles.EMPTY_ODS.toURI()).getAbsolutePath())); | ||
Rule rule = DigitalSignaturesRule.getInstance(); | ||
MessageLog results = rule.check(pkg); | ||
assertFalse("Valid Package should not return errors", results.hasErrors()); | ||
} | ||
|
||
@Test | ||
public void testCheckNotZipPackage() throws IOException, URISyntaxException { | ||
PackageParser parser = OdfPackages.getPackageParser(); | ||
OdfPackage pkg = parser.parsePackage(Paths.get(new File(TestFiles.EMPTY_FODS.toURI()).getAbsolutePath())); | ||
Rule rule = DigitalSignaturesRule.getInstance(); | ||
MessageLog results = rule.check(pkg); | ||
assertFalse("Document XML should NOT return errors", results.hasErrors()); | ||
} | ||
|
||
@Test | ||
public void testCheckNotWellFormedPackage() throws IOException, URISyntaxException { | ||
PackageParser parser = OdfPackages.getPackageParser(); | ||
OdfPackage pkg = parser.parsePackage(Paths.get(new File(TestFiles.BADLY_FORMED_PKG.toURI()).getAbsolutePath())); | ||
Rule rule = Rules.odf9(); | ||
MessageLog results = rule.check(pkg); | ||
assertFalse("Badly formed package does not contain digital signatures.", results.hasErrors()); | ||
} | ||
|
||
@Test | ||
public void testCheckInvalidPackage() throws IOException, URISyntaxException { | ||
PackageParser parser = OdfPackages.getPackageParser(); | ||
OdfPackage pkg = parser.parsePackage(Paths.get(new File(TestFiles.MIME_EXTRA_ODS.toURI()).getAbsolutePath())); | ||
Rule rule = DigitalSignaturesRule.getInstance(); | ||
MessageLog results = rule.check(pkg); | ||
assertFalse("Invalid extra headers for mimetype is OK.", results.hasErrors()); | ||
} | ||
|
||
@Test | ||
public void testCheckValidDsigPackage() throws IOException, URISyntaxException { | ||
PackageParser parser = OdfPackages.getPackageParser(); | ||
OdfPackage pkg = parser.parsePackage(Paths.get(new File(TestFiles.DSIG_VALID.toURI()).getAbsolutePath())); | ||
Rule rule = DigitalSignaturesRule.getInstance(); | ||
MessageLog results = rule.check(pkg); | ||
assertTrue("File contains valid digital signatures.", results.hasErrors()); | ||
assertEquals(1, results.getMessages().values().stream().filter(m -> m.stream().filter(e -> e.getId().equals("ODF_9")).count() > 0).count()); | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
odf-core/src/test/java/org/openpreservation/odf/validation/rules/EncryptionRuleTest.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,104 @@ | ||
package org.openpreservation.odf.validation.rules; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertThrows; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.nio.file.Paths; | ||
|
||
import org.junit.Test; | ||
import org.openpreservation.messages.MessageLog; | ||
import org.openpreservation.odf.fmt.TestFiles; | ||
import org.openpreservation.odf.pkg.OdfPackage; | ||
import org.openpreservation.odf.pkg.OdfPackages; | ||
import org.openpreservation.odf.pkg.PackageParser; | ||
import org.openpreservation.odf.validation.Rule; | ||
import org.openpreservation.odf.xml.OdfXmlDocument; | ||
|
||
import nl.jqno.equalsverifier.EqualsVerifier; | ||
|
||
public class EncryptionRuleTest { | ||
@Test | ||
public void testEqualsContract() { | ||
EqualsVerifier.forClass(EncryptionRule.class).verify(); | ||
} | ||
|
||
@Test | ||
public void testGetInstance() { | ||
Rule rule = EncryptionRule.getInstance(); | ||
assertNotNull("Returned Rule should not be null", rule); | ||
} | ||
|
||
@Test | ||
public void testCheckNullXmlDoc() { | ||
Rule rule = EncryptionRule.getInstance(); | ||
OdfXmlDocument nullDoc = null; | ||
assertThrows("UnsupportedOperationException expected", | ||
UnsupportedOperationException.class, | ||
() -> { | ||
rule.check(nullDoc); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testCheckNullPackage() { | ||
Rule rule = EncryptionRule.getInstance(); | ||
OdfPackage nullPkg = null; | ||
assertThrows("NullPointerException expected", | ||
NullPointerException.class, | ||
() -> { | ||
rule.check(nullPkg); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testCheckValidPackage() throws IOException, URISyntaxException { | ||
PackageParser parser = OdfPackages.getPackageParser(); | ||
OdfPackage pkg = parser.parsePackage(Paths.get(new File(TestFiles.EMPTY_ODS.toURI()).getAbsolutePath())); | ||
Rule rule = EncryptionRule.getInstance(); | ||
MessageLog results = rule.check(pkg); | ||
assertFalse("Valid Package should not return errors", results.hasErrors()); | ||
} | ||
|
||
@Test | ||
public void testCheckNotZipPackage() throws IOException, URISyntaxException { | ||
PackageParser parser = OdfPackages.getPackageParser(); | ||
OdfPackage pkg = parser.parsePackage(Paths.get(new File(TestFiles.EMPTY_FODS.toURI()).getAbsolutePath())); | ||
Rule rule = EncryptionRule.getInstance(); | ||
MessageLog results = rule.check(pkg); | ||
assertFalse("Document XML should NOT return errors", results.hasErrors()); | ||
} | ||
|
||
@Test | ||
public void testCheckNotWellFormedPackage() throws IOException, URISyntaxException { | ||
PackageParser parser = OdfPackages.getPackageParser(); | ||
OdfPackage pkg = parser.parsePackage(Paths.get(new File(TestFiles.BADLY_FORMED_PKG.toURI()).getAbsolutePath())); | ||
Rule rule = Rules.odf1(); | ||
MessageLog results = rule.check(pkg); | ||
assertFalse("Badly formed package does not contain digital signatures.", results.hasErrors()); | ||
} | ||
|
||
@Test | ||
public void testCheckInvalidPackage() throws IOException, URISyntaxException { | ||
PackageParser parser = OdfPackages.getPackageParser(); | ||
OdfPackage pkg = parser.parsePackage(Paths.get(new File(TestFiles.MIME_EXTRA_ODS.toURI()).getAbsolutePath())); | ||
Rule rule = EncryptionRule.getInstance(); | ||
MessageLog results = rule.check(pkg); | ||
assertFalse("Invalid extra headers for mimetype is OK.", results.hasErrors()); | ||
} | ||
|
||
@Test | ||
public void testCheckValidEncryptedPackage() throws IOException, URISyntaxException { | ||
PackageParser parser = OdfPackages.getPackageParser(); | ||
OdfPackage pkg = parser.parsePackage(Paths.get(new File(TestFiles.ENCRYPTED_PASSWORDS.toURI()).getAbsolutePath())); | ||
Rule rule = EncryptionRule.getInstance(); | ||
MessageLog results = rule.check(pkg); | ||
assertTrue("File contains valid digital signatures.", results.hasErrors()); | ||
assertEquals(5, results.getMessages().values().stream().filter(m -> m.stream().filter(e -> e.getId().equals("ODF_1")).count() > 0).count()); | ||
} | ||
} |
Oops, something went wrong.