package test.io.mindmaps.migration.owl;

import java.util.Map;
import java.util.Set;

import org.junit.Before;
import org.junit.Test;
import org.junit.Assert;
import org.semanticweb.HermiT.Reasoner;
import org.semanticweb.HermiT.Configuration;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLOntology;

import io.mindmaps.graql.Graql;

public class TestSubProperties extends TestOwlMindMapsBase {
	private IRI baseIri = IRI.create("http://www.workingontologist.org/Examples/Chapter3/shakespeare.owl");
	private OWLOntology shakespeare = null;
	
	@Before
	public void loadShakespeare() {
        try {
            shakespeare = loadOntologyFromResource("/io/mindmaps/migration/owl/samples/shakespeare.owl");               
            migrator.ontology(shakespeare).graph(graph).migrate();
            migrator.graph().commit();
        }
        catch (Throwable t) {
            t.printStackTrace(System.err);
            System.exit(-1);
        }		
	}
	
    @Test
    public void testSubpropertyInference() {
    	Reasoner reasoner = new Reasoner(new Configuration(), shakespeare);
    	IRI createdProp = baseIri.resolve("#created");
    	Map<OWLNamedIndividual, Set<OWLNamedIndividual>> createdInstances = 
    			reasoner.getObjectPropertyInstances(manager.getOWLDataFactory().getOWLObjectProperty(createdProp));
    	int owlCount = createdInstances.values().stream().mapToInt(S -> S.size()).sum();
    	int mmCount = Graql.withGraph(migrator.graph()).match(Graql.var("r").isa(migrator.namer().objectPropertyName(createdProp)))
    		.stream().mapToInt(M -> 1).sum();
    	Assert.assertEquals(owlCount, mmCount);
    }
}

@@ -45,46 +45,116 @@
 ort 
-java.util.Map;%0Aimport java.util.Se
+io.mindmaps.exception.MindmapsValidationException;%0Aimport io.mindmaps.graql.Graql;%0Aimport org.junit.Asser
 t;%0A
-%0A
 impo
@@ -201,73 +201,8 @@
 st;%0A
-import org.junit.Assert;%0Aimport org.semanticweb.HermiT.Reasoner;%0A
 impo
@@ -238,24 +238,64 @@
 figuration;%0A
+import org.semanticweb.HermiT.Reasoner;%0A
 import org.s
@@ -436,39 +436,51 @@
 %0Aimport 
-io.mindmaps.graql.Graql
+java.util.Map;%0Aimport java.util.Set
 ;%0A%0Apubli
@@ -727,28 +727,45 @@
 e() 
-%7B%0A        try %7B%0A    
+throws MindmapsValidationException %7B%0A
     
@@ -865,28 +865,9 @@
 l%22);
-               %0A    
+%0A
     
@@ -929,28 +929,24 @@
 ();%0A        
-    
 migrator.gra
@@ -964,132 +964,8 @@
 ();%0A
-        %7D%0A        catch (Throwable t) %7B%0A            t.printStackTrace(System.err);%0A            System.exit(-1);%0A        %7D%09%09%0A
 %09%7D%0A%09

Remove System.exit from last OWL migration test (#421)