@Test public void test_RS_1() { ResultSetRewindable rs1 = new ResultSetMem() ; ByteArrayOutputStream arr = new ByteArrayOutputStream() ; ResultSetFormatter.outputAsXML(arr, rs1) ; rs1.reset() ; ByteArrayInputStream ins = new ByteArrayInputStream(arr.toByteArray()) ; ResultSet rs2 = ResultSetFactory.fromXML(ins) ; assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2)) ; }
@Test public void test_RS_5() { ResultSetRewindable rs1 = new ResultSetMem() ; ByteArrayOutputStream arr = new ByteArrayOutputStream() ; ResultSetFormatter.outputAsJSON(arr, rs1) ; rs1.reset() ; ByteArrayInputStream ins = new ByteArrayInputStream(arr.toByteArray()) ; ResultSet rs2 = ResultSetFactory.fromJSON(ins) ; assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2)) ; }
@Test public void test_RS_cmp_1() { ResultSetRewindable rs1 = new ResultSetMem() ; ResultSetRewindable rs2 = new ResultSetMem() ; assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2)) ; rs1.reset() ; rs2.reset() ; assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2)) ; }
@Test public void test_RS_2() { ResultSetRewindable rs1 = makeRewindable("x", org.apache.jena.graph.NodeFactory.createURI("tag:local")) ; ByteArrayOutputStream arr = new ByteArrayOutputStream() ; ResultSetFormatter.outputAsXML(arr, rs1) ; rs1.reset() ; ByteArrayInputStream ins = new ByteArrayInputStream(arr.toByteArray()) ; ResultSet rs2 = ResultSetFactory.fromXML(ins) ; assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2)) ; }
@Test public void test_RS_6() { ResultSetRewindable rs1 = make2Rewindable("x", org.apache.jena.graph.NodeFactory.createURI("tag:local")) ; ByteArrayOutputStream arr = new ByteArrayOutputStream() ; ResultSetFormatter.outputAsJSON(arr, rs1) ; rs1.reset() ; ByteArrayInputStream ins = new ByteArrayInputStream(arr.toByteArray()) ; ResultSet rs2 = ResultSetFactory.fromJSON(ins) ; // Test using the DAWG examples assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2)) ; }
@Test public void test_RS_cmp_4() { ResultSet rs1 = make("x", org.apache.jena.graph.NodeFactory.createURI("tag:local")) ; ResultSet rs2 = make("x", org.apache.jena.graph.NodeFactory.createURI("tag:local")) ; assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2)) ; assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2)) ; }
private void isotest(String[] rs1$2, String[] rs2$2) { ResultSetRewindable rs1 = ResultSetFactory.makeRewindable(BuilderResultSet.build(SSE.parseItem(StrUtils.strjoinNL(rs1$)))) ; ResultSetRewindable rs2 = ResultSetFactory.makeRewindable(BuilderResultSet.build(SSE.parseItem(StrUtils.strjoinNL(rs2$)))) ; assertTrue(ResultSetCompare.isomorphic(rs1, rs2)) ; rs1.reset() ; rs2.reset() ; assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2)) ; assertTrue(ResultSetCompare.equalsByValue(rs1, rs2)) ; }
@Test public void test_RS_peeking_7() { // Peeking may fail if someone moves backwards in the result set // If we hadn't moved pass the first item this should be safe ResultSetRewindable inner = makeRewindable("x", NodeFactory.createURI("tag:local")); ResultSetPeekable rs = ResultSetFactory.makePeekable(inner); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); // Reset the inner result set independently inner.reset(); // Since we moved the underlying result set backwards but we hadn't gone anywhere // we should still be able to safely access the underlying results assertTrue(rs.hasNext()); }
@Test public void test_RS_1_str() { ResultSetRewindable rs1 = new ResultSetMem() ; String x = ResultSetFormatter.asXMLString(rs1) ; rs1.reset() ; InputStream in = new ByteArrayInputStream(StrUtils.asUTF8bytes(x)); ResultSet rs2 = ResultSetFactory.fromXML(in) ; assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2)) ; }
@Test public void test_RS_peeking_3() { // Expect that a rewindable result set will be peekable ResultSetPeekable rs = (ResultSetPeekable)makeRewindable("x", NodeFactory.createURI("tag:local")); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); // Peeking should not move the result set onwards so hasNext() should still report true assertTrue(rs.hasNext()); assertNotNull(rs.next()); assertFalse(rs.hasNext()); }
@Test public void test_RS_peeking_1() { ResultSetPeekable rs = makePeekable("x", NodeFactory.createURI("tag:local")); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); // Peeking should not move the result set onwards so hasNext() should still report true assertTrue(rs.hasNext()); assertNotNull(rs.next()); assertFalse(rs.hasNext()); }
@Test(expected=NoSuchElementException.class) public void test_RS_peeking_2() { ResultSetPeekable rs = makePeekable("x", NodeFactory.createURI("tag:local")); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); // Peeking should not move the result set onwards so hasNext() should still report true assertTrue(rs.hasNext()); assertNotNull(rs.next()); assertFalse(rs.hasNext()); // Peeking beyond end of results throws an error rs.peek(); }
@Test public void test_RS_2_str() { ResultSetRewindable rs1 = makeRewindable("x", org.apache.jena.graph.NodeFactory.createURI("tag:local")) ; String x = ResultSetFormatter.asXMLString(rs1) ; rs1.reset() ; InputStream in = new ByteArrayInputStream(StrUtils.asUTF8bytes(x)); ResultSet rs2 = ResultSetFactory.fromXML(in) ; assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2)) ; }
@Test(expected=NoSuchElementException.class) public void test_RS_peeking_4() { // Expect that a rewindable result set will be peekable ResultSetPeekable rs = (ResultSetPeekable) makeRewindable("x", NodeFactory.createURI("tag:local")); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); // Peeking should not move the result set onwards so hasNext() should still report true assertTrue(rs.hasNext()); assertNotNull(rs.next()); assertFalse(rs.hasNext()); // Peeking beyond end of results throws an error rs.peek(); }
@Test public void test_RS_3() { ResultSetRewindable rs1 = new ResultSetMem() ; Model model = RDFOutput.encodeAsModel(rs1) ; rs1.reset() ; ResultSet rs2 = RDFInput.fromRDF(model) ; assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2)) ; }
@Test public void test_RS_peeking_6() { // Peeking should be able to cope with people moving on the underlying result set independently ResultSet inner = new ResultSetMem(make("x", NodeFactory.createURI("tag:local")), make("x", NodeFactory.createURI("tag:local")), make("x", NodeFactory.createURI("tag:local"))); ResultSetPeekable rs = ResultSetFactory.makePeekable(inner); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); // Move on the inner result set independently inner.next(); // Since we fiddled with the underlying result set we'll be out of sync // but there should still be further data available assertTrue(rs.hasNext()); }
@Test public void test_RS_cmp_value_1() { ResultSetRewindable rs1 = makeRewindable("x", NodeFactoryExtra.parseNode("123")) ; ResultSetRewindable rs2 = makeRewindable("x", NodeFactoryExtra.parseNode("0123")) ; assertFalse(ResultSetCompare.equalsByTerm(rs1, rs2)) ; assertTrue(ResultSetCompare.equalsByValue(rs1, rs2)) ; }
private static void preserve_bnodes(Lang sparqlresultlang, Context cxt, boolean same) { ResultSetRewindable rs1 = ResultSetFactory.makeRewindable(BuilderResultSet.build(SSE.parseItem(StrUtils.strjoinNL(rs1$)))) ; ByteArrayOutputStream x = new ByteArrayOutputStream(); ResultsWriter.create().context(cxt).lang(sparqlresultlang).write(x, rs1); ByteArrayInputStream y = new ByteArrayInputStream(x.toByteArray()); ResultSetRewindable rs2 = ResultSetFactory.copyResults( ResultsReader.create().context(cxt).lang(sparqlresultlang).read(y) ); rs1.reset(); rs2.reset(); if ( same ) assertTrue(ResultSetCompare.equalsExact(rs1, rs2)); else assertFalse(ResultSetCompare.equalsExact(rs1, rs2)); }
@Test public void test_RS_union_1() { ResultSet rs1 = make("x", org.apache.jena.graph.NodeFactory.createURI("tag:local")) ; ResultSet rs2 = make("x", org.apache.jena.graph.NodeFactory.createURI("tag:local")) ; ResultSet rs3 = make2("x", org.apache.jena.graph.NodeFactory.createURI("tag:local")) ; assertTrue(ResultSetCompare.equalsByTerm(rs3, ResultSetUtils.union(rs1, rs2))) ; }
@Test public void test_RS_peeking_5() { // Peeking should be able to cope with people moving on the underlying result set independently ResultSet inner = new ResultSetMem(make("x", NodeFactory.createURI("tag:local")), make("x", NodeFactory.createURI("tag:local"))); ResultSetPeekable rs = ResultSetFactory.makePeekable(inner); assertTrue(rs.hasNext()); assertNotNull(rs.peek()); // Move on the inner result set independently inner.next(); // Since we fiddled with the underlying result set there won't be further elements available anymore assertFalse(rs.hasNext()); }