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

Fix PersistenceUpdatesTest: correctly close and delete test file #31

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion owlapi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<version>2.4.0-SNAPSHOT</version>
</parent>
<artifactId>pellet-owlapi</artifactId>
<name>Pellet :: OWL API (ignazio1977 fork)</name>
<name>Pellet :: OWL API</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<artifactId>pellet-parent</artifactId>
<version>2.4.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Pellet :: Parent POM</name>
<name>Pellet</name>
<description>The Clark and Parsia Pellet OWL Reasoner</description>
<url>https://github.com/clarkparsia/pellet</url>
<licenses>
Expand Down Expand Up @@ -42,7 +42,7 @@
<properties>
<junit.version>4.11</junit.version>
<slf4j.version>1.7.5</slf4j.version>
<owlapi.version>[4.0.2,4.2)</owlapi.version>
<owlapi.version>4.2.7</owlapi.version>
<jena.version>2.13.0</jena.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,15 @@ public void testPersistenceRemoves(String inputOnt) throws IOException {
// at this point there should be a change to the ontology that is not applied yet to the classifier
// this should cause the save operation to fail

FileOutputStream fos = new FileOutputStream( testFile );
try {
FileOutputStream fos = new FileOutputStream( testFile );

IncrementalClassifierPersistence.save( modular, fos );
fail( "The incremental classifer must not allow itself to be persisted if there are any unapplied changes to the ontology" );

fos.close();
} catch( IllegalStateException e ) {
assertTrue( testFile.delete() );
// correct behavior
} finally {
fos.close();
assertTrue( testFile.delete() );
}

} finally {
Expand Down Expand Up @@ -155,17 +154,16 @@ public void testPersistenceAdds(String inputOnt) throws IOException {
// at this point there should be a change to the ontology that is not applied yet to the classifier
// this should cause the save operation to fail

FileOutputStream fos = new FileOutputStream( testFile );
try {
FileOutputStream fos = new FileOutputStream( testFile );

IncrementalClassifierPersistence.save( modular, fos );
fail( "The incremental classifer must not allow itself to be persisted if there are any unapplied changes to the ontology" );

fos.close();
} catch( IllegalStateException e ) {
assertTrue( testFile.delete() );
// correct behavior
}
} finally {
fos.close();
assertTrue( testFile.delete() );
}

modular.dispose();
} finally {
Expand Down Expand Up @@ -208,13 +206,15 @@ public void testAllowedUpdates(String inputOnt) throws IOException {
modular.classify();

// at this point, the ontology should be updated (despite the changes), and the save should succeed.

FileOutputStream fos = new FileOutputStream( testFile );

IncrementalClassifierPersistence.save( modular, fos );

fos.close();

assertTrue( testFile.delete() );
try {
IncrementalClassifierPersistence.save( modular, fos );
} finally {
fos.close();
assertTrue( testFile.delete() );
}

} finally {
OWL.manager.removeOntology( ontology );
}
Expand All @@ -239,18 +239,23 @@ public void testUpdatesAfterPersistence(String inputOnt) throws IOException {
IncrementalClassifier modular = PelletIncremantalReasonerFactory.getInstance().createReasoner( ontology, moduleExtractor );
modular.classify();

FileOutputStream fos = new FileOutputStream( testFile );

IncrementalClassifierPersistence.save( modular, fos );

fos.close();


FileInputStream fis = new FileInputStream( testFile );

modular = IncrementalClassifierPersistence.load( fis );

fis.close();
try {
FileOutputStream fos = new FileOutputStream( testFile );
try {
IncrementalClassifierPersistence.save( modular, fos );
} finally {
fos.close();
}

FileInputStream fis = new FileInputStream( testFile );
try {
modular = IncrementalClassifierPersistence.load( fis );
} finally {
fis.close();
}
} finally {
assertTrue( testFile.delete() );
}

// first remove a random axiom
List<OWLAxiom> axiomsToRemove = new ArrayList<OWLAxiom>( TestUtils.selectRandomAxioms( ontology, 1 ) );
Expand Down Expand Up @@ -286,17 +291,23 @@ public void testUpdatesAfterPersistence2(String inputOnt) throws IOException {
IncrementalClassifier modular = PelletIncremantalReasonerFactory.getInstance().createReasoner( ontology, createModuleExtractor() );
modular.classify();

FileOutputStream fos = new FileOutputStream( testFile );

IncrementalClassifierPersistence.save( modular, fos );

fos.close();

FileInputStream fis = new FileInputStream( testFile );

modular = IncrementalClassifierPersistence.load( fis, ontology );

fis.close();
try {
FileOutputStream fos = new FileOutputStream( testFile );
try {
IncrementalClassifierPersistence.save( modular, fos );
} finally {
fos.close();
}

FileInputStream fis = new FileInputStream( testFile );
try {
modular = IncrementalClassifierPersistence.load( fis, ontology );
} finally {
fis.close();
}
} finally {
assertTrue( testFile.delete() );
}

// first remove a random axiom
List<OWLAxiom> axiomsToRemove = new ArrayList<OWLAxiom>( TestUtils.selectRandomAxioms( ontology, 1 ) );
Expand All @@ -323,26 +334,32 @@ public void testUpdatesWhenPersisted(String inputOnt) throws IOException {
IncrementalClassifier modular = PelletIncremantalReasonerFactory.getInstance().createReasoner( ontology, createModuleExtractor() );
modular.classify();

FileOutputStream fos = new FileOutputStream( testFile );

IncrementalClassifierPersistence.save( modular, fos );

fos.close();

// perform changes while the classifier is stored on disk
// first remove a random axiom
List<OWLAxiom> axiomsToRemove = new ArrayList<OWLAxiom>( TestUtils.selectRandomAxioms( ontology, 1 ) );

for( OWLAxiom axiomToRemove : axiomsToRemove ) {
OWL.manager.applyChange( new RemoveAxiom(ontology, axiomToRemove ) );
try {
FileOutputStream fos = new FileOutputStream( testFile );
try {
IncrementalClassifierPersistence.save( modular, fos );
} finally {
fos.close();
}

// perform changes while the classifier is stored on disk
// first remove a random axiom
List<OWLAxiom> axiomsToRemove = new ArrayList<OWLAxiom>( TestUtils.selectRandomAxioms( ontology, 1 ) );

for( OWLAxiom axiomToRemove : axiomsToRemove ) {
OWL.manager.applyChange( new RemoveAxiom(ontology, axiomToRemove ) );
}

FileInputStream fis = new FileInputStream( testFile );
try {
modular = IncrementalClassifierPersistence.load( fis, ontology );
} finally {
fis.close();
}
} finally {
assertTrue( testFile.delete() );
}

FileInputStream fis = new FileInputStream( testFile );

modular = IncrementalClassifierPersistence.load( fis, ontology );

fis.close();

PelletReasoner expected = PelletReasonerFactory.getInstance().createReasoner( ontology );

assertClassificationEquals( expected, modular );
Expand Down