1 package eu.fbk.rdfpro.util; 2 3 import com.google.common.collect.ImmutableList; 4 import com.google.common.collect.ImmutableSet; 5 6 import org.junit.Assert; 7 import org.junit.Test; 8 import org.openrdf.model.Literal; 9 import org.openrdf.model.URI; 10 import org.openrdf.model.impl.LiteralImpl; 11 import org.openrdf.model.impl.URIImpl; 12 import org.openrdf.model.vocabulary.OWL; 13 import org.openrdf.model.vocabulary.RDF; 14 import org.openrdf.model.vocabulary.RDFS; 15 16 import eu.fbk.rdfpro.util.StatementMatcher; 17 18 public class StatementMatcherTest { 19 20 @Test 21 public void test() { 22 23 final URI uri1 = new URIImpl("ex:uri1"); 24 final URI uri2 = new URIImpl("ex:uri2"); 25 final Literal lit1 = new LiteralImpl("label"); 26 27 final StatementMatcher matcher = StatementMatcher.builder() 28 .addValues(null, RDF.TYPE, OWL.THING, null, null, "x") 29 .addValues(null, RDFS.LABEL, null, null, null, "y", "w").build(null); 30 31 Assert.assertFalse(matcher.match(uri1, OWL.SAMEAS, uri1, null)); 32 33 Assert.assertFalse(matcher.match(uri1, RDF.TYPE, RDFS.CLASS, uri2)); 34 Assert.assertEquals(ImmutableList.of(), 35 matcher.map(uri1, RDF.TYPE, RDFS.CLASS, uri2, String.class)); 36 37 Assert.assertTrue(matcher.match(uri1, RDF.TYPE, OWL.THING, uri2)); 38 Assert.assertEquals(ImmutableList.of("x"), 39 matcher.map(uri1, RDF.TYPE, OWL.THING, uri2, String.class)); 40 Assert.assertEquals(ImmutableList.of("x"), 41 matcher.map(uri1, RDF.TYPE, OWL.THING, uri2, Object.class)); 42 Assert.assertEquals(ImmutableList.of(), 43 matcher.map(uri1, RDF.TYPE, OWL.THING, uri2, Integer.class)); 44 45 Assert.assertTrue(matcher.match(uri1, RDFS.LABEL, lit1, uri2)); 46 Assert.assertEquals(ImmutableSet.of("y", "w"), 47 ImmutableSet.copyOf(matcher.map(uri1, RDFS.LABEL, lit1, uri2, String.class))); 48 } 49 50 @Test 51 public void test2() { 52 53 final URI uri1 = new URIImpl("ex:uri1"); 54 final URI uri2 = new URIImpl("ex:uri2"); 55 final Literal lit1 = new LiteralImpl("label"); 56 57 final StatementMatcher matcher = StatementMatcher.builder() 58 .addValues(null, null, null, null, null, "x") 59 .addValues(null, RDFS.LABEL, null, null, null, "y", "w").build(null); 60 61 Assert.assertTrue(matcher.match(uri1, RDF.TYPE, RDFS.CLASS, uri2)); 62 Assert.assertEquals(ImmutableList.of("x"), 63 matcher.map(uri1, RDF.TYPE, RDFS.CLASS, uri2, String.class)); 64 65 Assert.assertTrue(matcher.match(uri1, RDFS.LABEL, lit1, uri2)); 66 Assert.assertEquals(ImmutableSet.of("x", "y", "w"), 67 ImmutableSet.copyOf(matcher.map(uri1, RDFS.LABEL, lit1, uri2, String.class))); 68 } 69 70 }