diff --git a/src/main/java/uk/ac/cam/cares/jps/base/listener/BaseBatteryOntologyModelManager.java b/src/main/java/uk/ac/cam/cares/jps/base/listener/BaseBatteryOntologyModelManager.java deleted file mode 100644 index aa417d26c..000000000 --- a/src/main/java/uk/ac/cam/cares/jps/base/listener/BaseBatteryOntologyModelManager.java +++ /dev/null @@ -1,11 +0,0 @@ -package uk.ac.cam.cares.jps.base.listener; - -import javax.servlet.ServletContextEvent; - -public class BaseBatteryOntologyModelManager extends BaseOntologyModelManager { - - public void contextInitialized(ServletContextEvent sce) { - //@todo LKA - implementation - } - -} diff --git a/src/main/java/uk/ac/cam/cares/jps/base/listener/BaseChimneyOntologyModelManager.java b/src/main/java/uk/ac/cam/cares/jps/base/listener/BaseChimneyOntologyModelManager.java deleted file mode 100644 index d9622f644..000000000 --- a/src/main/java/uk/ac/cam/cares/jps/base/listener/BaseChimneyOntologyModelManager.java +++ /dev/null @@ -1,145 +0,0 @@ -package uk.ac.cam.cares.jps.base.listener; - -import java.io.File; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import javax.servlet.ServletContextEvent; - -import org.apache.jena.ontology.OntModel; -import org.apache.jena.query.ResultSet; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import uk.ac.cam.cares.jps.base.config.AgentLocator; -import uk.ac.cam.cares.jps.base.exception.JPSRuntimeException; - - -public class BaseChimneyOntologyModelManager extends BaseOntologyModelManager { - - private static final String CHIMNEY = "Chimney-1"; - public static final String OWL_CHIMNEY = CHIMNEY + ".owl"; - protected static final String OWL_CHIMNEY_TEMP = CHIMNEY + "-temp.owl"; - public static final String CPT_NUMVAL = "#numericalValue"; - public static final String CPT_HASPROP = "#hasProperty"; - public static final String CPT_HASVAL = "#hasValue"; - public static final String CPT_HASUOM = "#hasUnitOfMeasure"; - public static final String CPT_SCLVAL = "#ScalarValue"; - public static final String CPT_CONTAINS = "#contains"; - public static final String CPT_PMAMT = "#ParticulateMaterialAmount"; - public static final String CPT_CONVMFLR = "#ConvectiveMassFlowrate"; - public static final String CPT_SINGPART = "#SingleParticle"; - public static final String CPT_HASREPRPART = "#hasRepresentativeParticle"; - public static final String CPT_SI_M = "SI_unit.owl#m"; - public static final String CPT_SI_GPS = "derived_SI_units.owl#g_per_s"; - public static final String CPT_SI_KGPCM = "derived_SI_units.owl#kg_per_cubic_m"; - public static final String CPT_DIAM = "#Diameter"; - public static final String CPT_HASLEN = "#has_length"; - public static final String CPT_DENS = "#Density"; - public static final String CPT_MASSFR = "#MassFraction"; - public static final String CPT_HASDENS = "#has_density"; - private static final String IRI_ONTOLOGY = "http://www.theworldavatar.com/ontology/"; - private static final String IRI_ONTOCAPE = IRI_ONTOLOGY + "ontocape/"; - private static final String OWL_ONTOCAPE_UPPER = IRI_ONTOCAPE + "upper_level/"; - private static final String OWL_ONTOCAPE_UPPER_SYSTEM = OWL_ONTOCAPE_UPPER + "system.owl"; - private static final String OWL_ONTOCAPE_CPS_BEHAVIOR = IRI_ONTOCAPE + "chemical_process_system/CPS_behavior/behavior.owl"; - private static final String OWL_ONTOCAPE_SUP_CONCEPTS_SI = IRI_ONTOCAPE + "supporting_concepts/SI_unit/"; - private static final String OWL_ONTOCAPE_SUP_CONCEPTS_GEOM = IRI_ONTOCAPE + "supporting_concepts/geometry/geometry.owl"; - private static final String OWL_ONTOCAPE_MAT_PS = IRI_ONTOCAPE + "material/phase_system/phase_system.owl"; - public static final String SPQ_WASTE = "PREFIX j4:<" + IRI_ONTOCAPE + "chemical_process_system/CPS_function/process.owl#> " + - "PREFIX j7:<" + IRI_ONTOLOGY + "meta_model/topology/topology.owl#> " + - "SELECT ?wasteStream \r\n" + - "WHERE " + - "{ ?chimney j7:hasOutput ?wasteStream ." + - " ?wasteStream a j4:NonReusableWasteProduct ." + - "}"; - - private static final String PATH_KB_BASE = ABSDIR_ROOT + "/kb/base/"; - public static final String PATH_KB_BASE_TEST = ABSDIR_ROOT_TEST + "/kb/base/"; - public static final String PATH_BASE_CHIMNEY = PATH_KB_BASE + OWL_CHIMNEY_TEMP; - public static final String PATH_BASE_CHIMNEY_TEST = PATH_KB_BASE_TEST + OWL_CHIMNEY_TEMP; - public static final String IRI_KB_BASE = IRI_KB + "base/"; - - private static ConcurrentHashMap speciesMap = new ConcurrentHashMap<>(); - - /** - * Logger for error output. - */ - private static final Logger LOGGER = LogManager.getLogger(BaseChimneyOntologyModelManager.class); - - public void contextInitialized(ServletContextEvent sce) { - LOGGER.info("initializing the local ontology manager"); - try { - baseEntityModel = createBaseChimneyModel(); - LOGGER.info("createbase chimney is successful"); - } catch (IOException e) { - LOGGER.error("initializing the local ontology manager failed"); - throw new JPSRuntimeException("Could not create base model for chimney: " + PATH_BASE_CHIMNEY); - } finally { - setConcepts(); - setSpecies(); - LOGGER.info("setspecies is finished" + "species map size= "+ String.valueOf(speciesMap.size())); - } - } - - private OntModel createBaseChimneyModel() throws IOException { - String content = getBaseChimneyContent(); - return createModelFromString(content); - } - - private void setConcepts() { - try { - conceptMap.put(CPT_NUMVAL, baseEntityModel.getDatatypeProperty(OWL_ONTOCAPE_UPPER_SYSTEM + CPT_NUMVAL)); - conceptMap.put(CPT_HASPROP, baseEntityModel.getObjectProperty(OWL_ONTOCAPE_UPPER_SYSTEM + CPT_HASPROP)); - conceptMap.put(CPT_HASVAL, baseEntityModel.getObjectProperty(OWL_ONTOCAPE_UPPER_SYSTEM + CPT_HASVAL)); - conceptMap.put(CPT_HASUOM, baseEntityModel.getObjectProperty(OWL_ONTOCAPE_UPPER_SYSTEM + CPT_HASUOM)); - conceptMap.put(CPT_SCLVAL, baseEntityModel.getOntClass(OWL_ONTOCAPE_UPPER_SYSTEM + CPT_SCLVAL)); - conceptMap.put(CPT_CONTAINS, baseEntityModel.getObjectProperty(OWL_ONTOCAPE_UPPER_SYSTEM + CPT_CONTAINS)); - conceptMap.put(CPT_PMAMT, baseEntityModel.getOntClass(OWL_ONTOCAPE_CPS_BEHAVIOR + CPT_PMAMT)); - conceptMap.put(CPT_CONVMFLR, baseEntityModel.getOntClass(OWL_ONTOCAPE_CPS_BEHAVIOR + CPT_CONVMFLR)); - conceptMap.put(CPT_SINGPART, baseEntityModel.getOntClass(OWL_ONTOCAPE_CPS_BEHAVIOR + CPT_SINGPART)); - conceptMap.put(CPT_HASREPRPART, baseEntityModel.getObjectProperty(OWL_ONTOCAPE_CPS_BEHAVIOR + CPT_HASREPRPART)); - conceptMap.put(CPT_SI_M, baseEntityModel.getIndividual(OWL_ONTOCAPE_SUP_CONCEPTS_SI + CPT_SI_M)); - conceptMap.put(CPT_SI_GPS, baseEntityModel.getIndividual(OWL_ONTOCAPE_SUP_CONCEPTS_SI + CPT_SI_GPS)); - conceptMap.put(CPT_SI_KGPCM, baseEntityModel.getIndividual(OWL_ONTOCAPE_SUP_CONCEPTS_SI + CPT_SI_KGPCM)); - conceptMap.put(CPT_DIAM, baseEntityModel.getOntClass(OWL_ONTOCAPE_SUP_CONCEPTS_GEOM + CPT_DIAM)); - conceptMap.put(CPT_HASLEN, baseEntityModel.getObjectProperty(OWL_ONTOCAPE_SUP_CONCEPTS_GEOM + CPT_HASLEN)); - conceptMap.put(CPT_DENS, baseEntityModel.getOntClass(OWL_ONTOCAPE_MAT_PS + CPT_DENS)); - conceptMap.put(CPT_MASSFR, baseEntityModel.getOntClass(OWL_ONTOCAPE_MAT_PS + CPT_MASSFR)); - conceptMap.put(CPT_HASDENS, baseEntityModel.getObjectProperty(OWL_ONTOCAPE_MAT_PS + CPT_HASDENS)); - } catch (Exception e) { - throw new JPSRuntimeException("Could not load required " + IRI_ONTOCAPE + " concepts using " + PATH_BASE_CHIMNEY + " model."); - } - } - - private void setSpecies() { - speciesMap.put("CO", "ChemSpecies_Carbon__monoxide"); - speciesMap.put("CO2", "ChemSpecies_Carbon__dioxide"); - speciesMap.put("NO2", "ChemSpecies_Nitrogen__dioxide"); - speciesMap.put("HC", "PseudoComponent_Unburned_Hydrocarbon"); - speciesMap.put("NOx", "PseudoComponent_Nitrogen__oxides"); - speciesMap.put("SO2", "ChemSpecies_Sulfur__dioxide"); - speciesMap.put("O3", "ChemSpecies_Ozone"); - } - - public static String getBaseChimneyContent() throws IOException { - File source; - if (!AgentLocator.isJPSRunningForTest()) { - source = new File(PATH_BASE_CHIMNEY); - } else { - source = new File(PATH_BASE_CHIMNEY_TEST); - } - return new String(Files.readAllBytes(source.toPath()), StandardCharsets.UTF_8); - } - - public static Map getSpeciesMap() { - return speciesMap; - } - - public static ResultSet getWasteStreamInfo(OntModel jenaOwlModel) { - return query(SPQ_WASTE, jenaOwlModel); - } -} diff --git a/src/main/java/uk/ac/cam/cares/jps/base/listener/BaseOntologyModelManager.java b/src/main/java/uk/ac/cam/cares/jps/base/listener/BaseOntologyModelManager.java deleted file mode 100644 index e7c6661b1..000000000 --- a/src/main/java/uk/ac/cam/cares/jps/base/listener/BaseOntologyModelManager.java +++ /dev/null @@ -1,141 +0,0 @@ -package uk.ac.cam.cares.jps.base.listener; - -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.charset.StandardCharsets; -import java.nio.file.Paths; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.locks.ReadWriteLock; -import java.util.concurrent.locks.ReentrantReadWriteLock; - -import javax.servlet.ServletContextEvent; - -import org.apache.jena.ontology.OntModel; -import org.apache.jena.ontology.OntModelSpec; -import org.apache.jena.query.Query; -import org.apache.jena.query.QueryExecution; -import org.apache.jena.query.QueryExecutionFactory; -import org.apache.jena.query.QueryFactory; -import org.apache.jena.query.ResultSet; -import org.apache.jena.query.ResultSetFactory; -import org.apache.jena.rdf.model.ModelFactory; -import org.apache.jena.rdf.model.Resource; -import org.apache.jena.shared.Lock; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import uk.ac.cam.cares.jps.base.config.AgentLocator; -import uk.ac.cam.cares.jps.base.config.IKeys; -import uk.ac.cam.cares.jps.base.config.KeyValueMap; -import uk.ac.cam.cares.jps.base.exception.JPSRuntimeException; - -public class BaseOntologyModelManager { - - private static final String IRI_BASE = "http://www.theworldavatar.com"; - protected static final String IRI_KB = IRI_BASE + "/kb/"; - private static final String EX_SAVE_OWL = "Saving OWL failed: "; - static final String ABSDIR_ROOT = "C://TOMCAT/webapps/ROOT"; - private static final String ABSDIR_KB = ABSDIR_ROOT + "/kb/"; - // now reading from JPS_BASE_LIB/src/main/resources in jpstest.properties - protected static final String ABSDIR_ROOT_TEST = KeyValueMap.getProperty("/jpstest.properties",IKeys.ABSDIR_ROOT); - private static final String ABSDIR_KB_TEST = ABSDIR_ROOT_TEST + "/kb/"; - private static final String IRI_BASE_TEST = "http://localhost:8080"; - protected static final String IRI_KB_TEST = IRI_BASE_TEST + "/kb/"; - - static ConcurrentHashMap conceptMap = new ConcurrentHashMap<>(); - static OntModel baseEntityModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); - private static Logger LOGGER = LogManager.getLogger(BaseOntologyModelManager.class); - - public void contextDestroyed(ServletContextEvent sce) { - baseEntityModel.close(); - } - - protected static OntModel createModelFromString(String content) { - byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8); - OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); - model.read(new ByteArrayInputStream(contentBytes), null); - return model; - } - - public static Resource getConcept(String name) { - return conceptMap.get(name); - } - - public static void save(OntModel jenaOwlModel, String iriOfChimney, String mmsi) { - ReadWriteLock readWriteLock = new ReentrantReadWriteLock(); - readWriteLock.writeLock().lock(); - try { - saveToOwl(jenaOwlModel, iriOfChimney, mmsi); - } catch (IOException e) { - throw new JPSRuntimeException(EX_SAVE_OWL + iriOfChimney); - } finally { - readWriteLock.writeLock().unlock(); - } - } - - public static void saveToOwl(OntModel jenaOwlModel, String iriOfChimney, String mmsi) throws IOException { - String filePath2; - if (!AgentLocator.isJPSRunningForTest()) { - filePath2= iriOfChimney.replaceAll(IRI_KB, ABSDIR_KB).split("#")[0]; - } else { - filePath2= Paths.get(ABSDIR_KB_TEST,"ships",mmsi,"Chimney-1.owl").toString(); - } - - LOGGER.info("Created file is at: {}", filePath2); - - try { - prepareDirectory(filePath2); - } catch (IOException e) { - throw new JPSRuntimeException(EX_SAVE_OWL + filePath2); - } finally { - FileOutputStream out = new FileOutputStream(filePath2); - - jenaOwlModel.write(out, "RDF/XML-ABBREV"); - out.close(); - } -// String finalcontent=JenaHelper.writeToString(jenaOwlModel); -// new QueryBroker().putOld(iriOfChimney,finalcontent); - } - - public static void prepareDirectory(String filePath2) throws IOException { - File stockDir = new File(filePath2).getParentFile(); - - boolean stockdir = true; - - if (!stockDir.exists()) { - stockdir = stockDir.mkdirs(); - } - if (stockdir) { - File[] listOfFiles = stockDir.listFiles(); - if (listOfFiles != null) { - for (File listOfFile : listOfFiles) { - listOfFile.delete(); - //@todo AC: work on general concurrent filesystem access solution for JPS - /* - if (!listOfFile.delete()) { - throw new IOException("Could not clean up: " + filePath2); - }*/ - } - } - } else { - throw new IOException("No such directory: " + filePath2); - } - } - - public static ResultSet query(String sparql, OntModel model) { - Query query = QueryFactory.create(sparql); - ResultSet rs; - model.enterCriticalSection(Lock.READ); - try { - QueryExecution queryExec = QueryExecutionFactory.create(query, model); - rs = queryExec.execSelect(); - } finally { - model.leaveCriticalSection() ; - } - - return ResultSetFactory.copyResults(rs); - } - -} diff --git a/src/test/java/uk/ac/cam/cares/jps/base/listener/BaseChimneyOntologyModelManagerTest.java b/src/test/java/uk/ac/cam/cares/jps/base/listener/BaseChimneyOntologyModelManagerTest.java deleted file mode 100644 index e2823ac69..000000000 --- a/src/test/java/uk/ac/cam/cares/jps/base/listener/BaseChimneyOntologyModelManagerTest.java +++ /dev/null @@ -1,63 +0,0 @@ -package uk.ac.cam.cares.jps.base.listener; - -import java.lang.reflect.Field; -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.jena.ontology.OntModel; -import org.apache.jena.ontology.OntModelSpec; -import org.apache.jena.query.QueryExecution; -import org.apache.jena.query.QueryExecutionFactory; -import org.apache.jena.query.ResultSet; -import org.apache.jena.rdf.model.Model; -import org.apache.jena.rdf.model.ModelFactory; -import org.apache.jena.rdf.model.Resource; -import org.junit.Assert; -import org.junit.Test; -import org.mockito.MockedStatic; -import org.mockito.Mockito; - -public class BaseChimneyOntologyModelManagerTest { - - public static final String SPQ_WASTE = "PREFIX j4:<" + "http://www.theworldavatar.com/ontology/ontocape/" + "chemical_process_system/CPS_function/process.owl#> " + - "PREFIX j7:<" + "http://www.theworldavatar.com/ontology/" + "meta_model/topology/topology.owl#> " + - "SELECT ?wasteStream \r\n" + - "WHERE " + - "{ ?chimney j7:hasOutput ?wasteStream ." + - " ?wasteStream a j4:NonReusableWasteProduct ." + - "}"; - - @Test - public void testGetSpeciesMap() throws Exception{ - Model testModel = ModelFactory.createDefaultModel(); - ConcurrentHashMap testMap = new ConcurrentHashMap<>(); - Resource r1 = testModel.createResource("http://somewhere/test1"); - Resource r2 = testModel.createResource("http://somewhere/test2"); - testMap.put("test1", r1); - testMap.put("test2", r2); - - Field testConcept = BaseChimneyOntologyModelManager.class.getDeclaredField("speciesMap"); - testConcept.setAccessible(true); - testConcept.set(null, testMap); - - Assert.assertEquals(testMap, BaseChimneyOntologyModelManager.getSpeciesMap()); - } - - @Test - public void testGetWasteStreamInfo() { - - OntModel testModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); - QueryExecution queryExec = QueryExecutionFactory.create(SPQ_WASTE, testModel); - ResultSet expectedResult = queryExec.execSelect(); - - try (MockedStatic mockedStatic = Mockito.mockStatic(BaseOntologyModelManager.class)) { - mockedStatic - .when(() -> BaseOntologyModelManager.query(SPQ_WASTE,testModel)) - .thenReturn(expectedResult); - - ResultSet actualResult = BaseChimneyOntologyModelManager.getWasteStreamInfo(testModel); - - Assert.assertEquals(expectedResult, actualResult); - } - } - -} diff --git a/src/test/java/uk/ac/cam/cares/jps/base/listener/BaseOntologyModelManagerTest.java b/src/test/java/uk/ac/cam/cares/jps/base/listener/BaseOntologyModelManagerTest.java deleted file mode 100644 index 3205efcce..000000000 --- a/src/test/java/uk/ac/cam/cares/jps/base/listener/BaseOntologyModelManagerTest.java +++ /dev/null @@ -1,175 +0,0 @@ -package uk.ac.cam.cares.jps.base.listener; - -import static org.mockito.Mockito.RETURNS_DEEP_STUBS; - -import java.io.File; -import java.io.IOException; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.nio.file.Paths; -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.jena.ontology.OntDocumentManager; -import org.apache.jena.ontology.OntModel; -import org.apache.jena.ontology.OntModelSpec; -import org.apache.jena.query.QuerySolution; -import org.apache.jena.query.ResultSet; -import org.apache.jena.rdf.model.Model; -import org.apache.jena.rdf.model.ModelFactory; -import org.apache.jena.rdf.model.Resource; -import org.apache.jena.vocabulary.VCARD; -import org.junit.Assert; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.TemporaryFolder; -import org.mockito.MockedStatic; -import org.mockito.Mockito; - -import uk.ac.cam.cares.jps.base.config.AgentLocator; - -public class BaseOntologyModelManagerTest { - - @Rule - public TemporaryFolder folder= new TemporaryFolder(); - - @Test - public void testGetConcept() throws Exception{ - Model testModel = ModelFactory.createDefaultModel(); - ConcurrentHashMap testMap = new ConcurrentHashMap<>(); - Resource r1 = testModel.createResource("http://somewhere/test1"); - Resource r2 = testModel.createResource("http://somewhere/test2"); - testMap.put("test1", r1); - testMap.put("test2", r2); - - Field testConcept = BaseOntologyModelManager.class.getDeclaredField("conceptMap"); - testConcept.setAccessible(true); - testConcept.set(null, testMap); - - Assert.assertEquals("http://somewhere/test2", BaseOntologyModelManager.getConcept("test2").toString()); - - } - - @Test - public void testSaveToOwl() throws Exception { - - // (Re)set default readhook. OntDocumentManager is a singleton and is modified by - // uk.ac.cam.cares.jps.base.query.fed.test causing this test to fail. - OntDocumentManager.getInstance().setReadHook(new OntDocumentManager.DefaultReadHook()); - - // Create a test model that should be written to a file - OntModel testModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); - // The model contains a single triple - String testURI ="http://somewhere/test1"; - String testData = "test1"; - Resource testR = testModel.createResource(testURI); - testR.addProperty(VCARD.FN, testData); - - // Create temporary folder for writing the owl file - File testFolder = folder.newFolder("test"); - // Defining the paths for where to write the owl files - String filePath1 = Paths.get(testFolder.getAbsolutePath() , "test.owl").toString(); - String filePath2 = Paths.get(testFolder.getAbsolutePath(), "Chimney-1.owl").toString(); - - - // Set the fields of the BaseOntologyModelManager to use the paths to the test files - // Related to file1 - String ABSDIR_KB = testFolder.getAbsolutePath(); - String IRI_KB = "http://localhost/kb/"; - // Related to file2 - String ABSDIR_KB_TEST = testFolder.getAbsolutePath(); - - - Field modifiersField = Field.class.getDeclaredField("modifiers"); - modifiersField.setAccessible(true); - - Field test_ABSDIR_KB = BaseOntologyModelManager.class.getDeclaredField("ABSDIR_KB"); - test_ABSDIR_KB.setAccessible(true); - modifiersField.setInt( test_ABSDIR_KB, test_ABSDIR_KB.getModifiers() & ~Modifier.FINAL ); - test_ABSDIR_KB.set(null, ABSDIR_KB); - - Field test_ABSDIR_KB_TEST = BaseOntologyModelManager.class.getDeclaredField("ABSDIR_KB_TEST"); - test_ABSDIR_KB_TEST.setAccessible(true); - modifiersField.setInt( test_ABSDIR_KB_TEST, test_ABSDIR_KB_TEST.getModifiers() & ~Modifier.FINAL ); - test_ABSDIR_KB_TEST.set(null, ABSDIR_KB_TEST); - - Field test_IRI_KB = BaseOntologyModelManager.class.getDeclaredField("IRI_KB"); - test_IRI_KB.setAccessible(true); - modifiersField.setInt( test_IRI_KB, test_IRI_KB.getModifiers() & ~Modifier.FINAL ); - test_IRI_KB.set(null, IRI_KB); - - String mmsi = "mmsi"; - - try (MockedStatic mockAgentLocator = Mockito.mockStatic(AgentLocator.class)) { - mockAgentLocator.when(AgentLocator::isJPSRunningForTest).thenReturn(false); - String testIRI = filePath1 + "#test"; - BaseOntologyModelManager.saveToOwl(testModel, testIRI, mmsi); - File file1 = new File(filePath1); - Assert.assertTrue(file1.exists()); - // Read the saved ontology back in and assert that the property is in there - OntModel readModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); - readModel.read(filePath1); - Assert.assertTrue(readModel.isInBaseModel(testR)); - Assert.assertEquals(testData, readModel.getProperty(testR, VCARD.FN).getString()); - } - - try (MockedStatic mockAgentLocator = Mockito.mockStatic(AgentLocator.class); - MockedStatic mockPath = Mockito.mockStatic(Paths.class, RETURNS_DEEP_STUBS)) { - mockAgentLocator.when(AgentLocator::isJPSRunningForTest).thenReturn(true); - mockPath.when(() -> Paths.get(ABSDIR_KB_TEST, "ships", mmsi,"Chimney-1.owl").toString()) - .thenReturn(filePath2); - - String testIRI = filePath2 + "#test"; - BaseOntologyModelManager.saveToOwl(testModel, testIRI, mmsi); - File file2 = new File(filePath2); - Assert.assertTrue(file2.exists()); - // Read the saved ontology back in and assert that the property is in there - OntModel readModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); - readModel.read(file2.getAbsolutePath()); - Assert.assertTrue(readModel.isInBaseModel(testR)); - Assert.assertEquals(testData, readModel.getProperty(testR, VCARD.FN).getString()); - } - } - - @Test - public void testPrepareDirectory() throws IOException { - File createdFolder= folder.newFolder("testFolder"); - File testFolder= folder.newFolder("testFolder/test"); - File testFile= folder.newFile("testFolder/test.owl"); - String testFilePath2 = createdFolder.getPath() + "/test"; - String testFilePath1 = createdFolder.getPath() + "/testFolder1/test"; - - BaseOntologyModelManager.prepareDirectory(testFilePath2); - Assert.assertTrue(createdFolder.isDirectory()); - Assert.assertFalse(testFile.exists()); - Assert.assertFalse(testFolder.exists()); - - File testFile1 = folder.newFolder("testFolder1/test"); - BaseOntologyModelManager.prepareDirectory(testFilePath1); - Assert.assertTrue(testFile1.exists()); - - } - - @Test - public void testQuery() { - OntModel testM = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); - String[] personURI ={ "http://somewhere/test", "http://somewhere/test", - "http://somewhere/test3","http://somewhere/test4"}; - String[] testData = {"test1","test2","test3","test4"}; - - for (int i=0;i