StatementFunction implements Function { @Override public Value evaluate(ValueFactory vf, Value... args) throws ValueExprEvaluationException { if (args.length != 3) { throw new ValueExprEvaluationException("expect exactly 3 arguments"); } if (!(args[0] instanceof Resource)) { throw new ValueExprEvaluationException("arg1 must be Resource"); } if (!(args[1] instanceof IRI)) { throw new ValueExprEvaluationException("arg2 must be IRI"); } if (!(args[2] instanceof Value)) { throw new ValueExprEvaluationException("arg3 must be Value"); } return vf.createTriple((Resource) args[0], (IRI) args[1], args[2]); }  @Override String getURI(); @Override Value evaluate(ValueFactory vf, Value... args);  }
@Test public void testEvaluateIRIAndIRI() { IRI subj = f.createIRI("urn:a"); IRI pred = f.createIRI("urn:b"); IRI obj = f.createIRI("urn:c"); Value value = function.evaluate(f, subj, pred, obj); assertNotNull(value); assertTrue("expect Triple", value instanceof Triple); Triple other = f.createTriple(subj, pred, obj); assertEquals("expect to be the same", value, other); }
@Test public void testEvaluateIRIAndBNode() { IRI subj = f.createIRI("urn:a"); IRI pred = f.createIRI("urn:b"); BNode obj = f.createBNode(); Value value = function.evaluate(f, subj, pred, obj); assertNotNull(value); assertTrue("expect Triple", value instanceof Triple); Triple other = f.createTriple(subj, pred, obj); assertEquals("expect to be the same", value, other); }
@Test public void testEvaluateIRIAndLiteral() { IRI subj = f.createIRI("urn:a"); IRI pred = f.createIRI("urn:b"); Literal obj = f.createLiteral(1); Value value = function.evaluate(f, subj, pred, obj); assertNotNull(value); assertTrue("expect Triple", value instanceof Triple); Triple other = f.createTriple(subj, pred, obj); assertEquals("expect to be the same", value, other); }
@Test public void testEvaluateIRIAndTriple() { IRI subj = f.createIRI("urn:a"); IRI pred = f.createIRI("urn:b"); Triple obj = f.createTriple(subj, subj, subj); Value value = function.evaluate(f, subj, pred, obj); assertNotNull(value); assertTrue("expect Triple", value instanceof Triple); Triple other = f.createTriple(subj, pred, obj); assertEquals("expect to be the same", value, other); }
@Test public void testEvaluateBNodeAndIRI() { BNode subj = f.createBNode(); IRI pred = f.createIRI("urn:b"); IRI obj = f.createIRI("urn:c"); Value value = function.evaluate(f, subj, pred, obj); assertNotNull(value); assertTrue("expect Triple", value instanceof Triple); Triple other = f.createTriple(subj, pred, obj); assertEquals("expect to be the same", value, other); }
@Test public void testEvaluateBNodeAndBNode() { BNode subj = f.createBNode(); IRI pred = f.createIRI("urn:b"); BNode obj = f.createBNode(); Value value = function.evaluate(f, subj, pred, obj); assertNotNull(value); assertTrue("expect Triple", value instanceof Triple); Triple other = f.createTriple(subj, pred, obj); assertEquals("expect to be the same", value, other); }
@Test public void testEvaluateBNodeAndLiteral() { BNode subj = f.createBNode(); IRI pred = f.createIRI("urn:b"); Literal obj = f.createLiteral(1); Value value = function.evaluate(f, subj, pred, obj); assertNotNull(value); assertTrue("expect Triple", value instanceof Triple); Triple other = f.createTriple(subj, pred, obj); assertEquals("expect to be the same", value, other); }
@Test public void testEvaluateBNodeAndTriple() { BNode subj = f.createBNode(); IRI pred = f.createIRI("urn:b"); Triple obj = f.createTriple(pred, pred, pred); Value value = function.evaluate(f, subj, pred, obj); assertNotNull(value); assertTrue("expect Triple", value instanceof Triple); Triple other = f.createTriple(subj, pred, obj); assertEquals("expect to be the same", value, other); }
@Test public void testEvaluateTripleAndIRI() { IRI pred = f.createIRI("urn:b"); IRI obj = f.createIRI("urn:c"); Triple subj = f.createTriple(pred, pred, pred); Value value = function.evaluate(f, subj, pred, obj); assertNotNull(value); assertTrue("expect Triple", value instanceof Triple); Triple other = f.createTriple(subj, pred, obj); assertEquals("expect to be the same", value, other); }
@Test public void testEvaluateTripleAndBNode() { IRI pred = f.createIRI("urn:b"); BNode obj = f.createBNode(); Triple subj = f.createTriple(pred, pred, pred); Value value = function.evaluate(f, subj, pred, obj); assertNotNull(value); assertTrue("expect Triple", value instanceof Triple); Triple other = f.createTriple(subj, pred, obj); assertEquals("expect to be the same", value, other); }
@Test public void testEvaluateTripleAndLiteral() { IRI pred = f.createIRI("urn:b"); Literal obj = f.createLiteral(1); Triple subj = f.createTriple(pred, pred, pred); Value value = function.evaluate(f, subj, pred, obj); assertNotNull(value); assertTrue("expect Triple", value instanceof Triple); Triple other = f.createTriple(subj, pred, obj); assertEquals("expect to be the same", value, other); }
@Test public void testEvaluateTripleAndTriple() { IRI pred = f.createIRI("urn:b"); Triple obj = f.createTriple(pred, pred, pred); Triple subj = f.createTriple(pred, pred, pred); Value value = function.evaluate(f, subj, pred, obj); assertNotNull(value); assertTrue("expect Triple", value instanceof Triple); Triple other = f.createTriple(subj, pred, obj); assertEquals("expect to be the same", value, other); }
@Test(expected = ValueExprEvaluationException.class) public void testNegariveWrongNumberOfArguments() { IRI subj = f.createIRI("urn:a"); IRI pred = f.createIRI("urn:b"); IRI obj = f.createIRI("urn:c"); function.evaluate(f, subj, pred, obj, null); fail("should throw ValueExprEvaluationException"); }
@Test(expected = ValueExprEvaluationException.class) public void testNegativeLiteralAsSubject() { Literal subj = f.createLiteral(1); IRI pred = f.createIRI("urn:b"); IRI obj = f.createIRI("urn:c"); function.evaluate(f, subj, pred, obj); fail("should not accept Literal as subject"); }
@Test(expected = ValueExprEvaluationException.class) public void testNegativeLiteralAsPredicate() { Literal subj = f.createLiteral(1); IRI pred = f.createIRI("urn:b"); IRI obj = f.createIRI("urn:c"); function.evaluate(f, subj, pred, obj); fail("should not accept Literal as predicate"); }