PrefixMappingUtils { public static PrefixMapping calcInUsePrefixMapping(Graph graph) { PrefixMapping prefixMapping = graph.getPrefixMapping() ; if ( prefixMapping == null ) return null ; return calcInUsePrefixMapping(graph, prefixMapping) ; }  static Graph graphInUsePrefixMapping(Graph graph); static PrefixMapping calcInUsePrefixMapping(Graph graph); static PrefixMapping calcInUsePrefixMapping(Graph graph, PrefixMapping prefixMapping); static PrefixMapping calcInUsePrefixMappingTTL(Graph graph); static PrefixMapping calcInUsePrefixMappingTTL(Graph graph, PrefixMapping prefixMapping);  }
@Test public void prefixes1() { String data1 = StrUtils.strjoinNL ("@prefix : <http: "@prefix ex: <http: "" , ":s1 :p :x1 ." , ":s1 ex:p :x1 ." ) ; Graph graph1 = create(data1) ; PrefixMapping pmap = PrefixMappingUtils.calcInUsePrefixMapping(graph1) ; PrefixMapping pmapExpected = graph1.getPrefixMapping() ; Assert.assertEquals(2, size(pmap)) ; Assert.assertEquals(pmapExpected, pmap) ; }
@Test public void prefixes2() { String data2 = StrUtils.strjoinNL ("@prefix : <http: "@prefix ex: <http: "@prefix notinuse: <http: "" , ":s1 :p :x1 ." , ":s1 ex:p :x1 ." ) ; Graph graph1 = create(data2) ; PrefixMapping pmap = PrefixMappingUtils.calcInUsePrefixMapping(graph1) ; PrefixMapping pmapExpected = new PrefixMappingImpl() ; pmapExpected.setNsPrefix("", "http: pmapExpected.setNsPrefix("ex", "http: Assert.assertEquals(2, size(pmap)) ; Assert.assertTrue(sameMapping(pmapExpected, pmap)) ; Assert.assertTrue(pmap.getNsPrefixURI("notinuse") == null) ; }
@Test public void prefixes3() { String data = StrUtils.strjoinNL ("@prefix : <http: "" , "<http: ) ; Graph graph1 = create(data) ; PrefixMapping pmap = PrefixMappingUtils.calcInUsePrefixMapping(graph1) ; PrefixMapping pmapExpected = new PrefixMappingImpl() ; pmapExpected.setNsPrefix("", "http: Assert.assertTrue(sameMapping(pmapExpected, pmap)) ; }
@Test public void prefixes4() { String data = StrUtils.strjoinNL ( "<http: ) ; Graph graph1 = create(data) ; PrefixMapping pmap = PrefixMappingUtils.calcInUsePrefixMapping(graph1) ; Assert.assertEquals(0, size(pmap)) ; PrefixMapping pmapExpected = new PrefixMappingImpl() ; Assert.assertTrue(sameMapping(pmapExpected, pmap)) ; }
@Test public void prefixesN() { String data = StrUtils.strjoinNL ("@prefix : <http: "@prefix ex: <http: "@prefix notinuse: <http: "@prefix indirect: <urn:foo:> ." , "@prefix indirectx: <urn:x:> ." , "@prefix ns: <http: "@prefix ns1: <http: "@prefix ns2: <http: "" , ":s1 :p :x1 ." , ":s1 ex:p :x1 ." , "<urn:foo:bar> :p 1 . ", "<urn:x:a:b> :p 2 . ", "<urn:verybad#.> :p 1 . ", "ns:x ns1:p 'ns1' . ", "<http: ) ; Graph graph = create(data) ; PrefixMapping pmap = PrefixMappingUtils.calcInUsePrefixMapping(graph) ; PrefixMapping pmapExpected = new PrefixMappingImpl() ; pmapExpected.setNsPrefix("", "http: pmapExpected.setNsPrefix("ex", "http: pmapExpected.setNsPrefix("indirect", "urn:foo:") ; pmapExpected.setNsPrefix("ns", "http: pmapExpected.setNsPrefix("ns1", "http: pmapExpected.setNsPrefix("indirectx", "urn:x:") ; Assert.assertTrue(sameMapping(pmapExpected, pmap)) ; Assert.assertTrue(pmap.getNsPrefixURI("notinuse") == null) ; }