use of org.eclipse.rdf4j.http.protocol.transaction.operations.TransactionOperation in project rdf4j by eclipse.
the class TransactionReaderTest method testRoundtrip.
@Test
public void testRoundtrip() throws Exception {
AddStatementOperation operation = new AddStatementOperation(bob, knows, alice, context1, context2);
List<TransactionOperation> txn = new ArrayList<TransactionOperation>();
txn.add(operation);
ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
TransactionWriter w = new TransactionWriter();
w.serialize(txn, out);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
TransactionReader r = new TransactionReader();
Collection<TransactionOperation> parsedTxn = r.parse(in);
assertNotNull(parsedTxn);
for (TransactionOperation op : parsedTxn) {
assertTrue(op instanceof AddStatementOperation);
AddStatementOperation addOp = (AddStatementOperation) op;
Resource[] contexts = addOp.getContexts();
assertEquals(2, contexts.length);
assertTrue(contexts[0].equals(context1) || contexts[1].equals(context1));
assertTrue(contexts[0].equals(context2) || contexts[1].equals(context2));
}
}
use of org.eclipse.rdf4j.http.protocol.transaction.operations.TransactionOperation in project rdf4j by eclipse.
the class TransactionWriter method serialize.
/**
* serialize the passed list of operations to the passed writer.
*
* @param txn
* the operations
* @param out
* the output stream to write to
* @throws IllegalArgumentException
* when one of the parameters is null
*/
public void serialize(Iterable<? extends TransactionOperation> txn, OutputStream out) throws IOException {
assert txn != null : "operation list must not be null";
assert out != null : "output stream must not be null";
XMLWriter xmlWriter = new XMLWriter(out);
xmlWriter.setPrettyPrint(true);
xmlWriter.startDocument();
xmlWriter.startTag(TransactionXMLConstants.TRANSACTION_TAG);
for (TransactionOperation op : txn) {
serialize(op, xmlWriter);
}
xmlWriter.endTag(TransactionXMLConstants.TRANSACTION_TAG);
xmlWriter.endDocument();
}
use of org.eclipse.rdf4j.http.protocol.transaction.operations.TransactionOperation in project rdf4j by eclipse.
the class TransactionReaderTest method testControlCharHandling.
@Test
public void testControlCharHandling() throws Exception {
AddStatementOperation operation = new AddStatementOperation(bob, knows, controlCharText);
List<TransactionOperation> txn = new ArrayList<TransactionOperation>();
txn.add(operation);
ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
TransactionWriter w = new TransactionWriter();
w.serialize(txn, out);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
TransactionReader r = new TransactionReader();
Collection<TransactionOperation> parsedTxn = r.parse(in);
assertNotNull(parsedTxn);
for (TransactionOperation op : parsedTxn) {
assertTrue(op instanceof AddStatementOperation);
AddStatementOperation addOp = (AddStatementOperation) op;
assertTrue(addOp.getObject().equals(controlCharText));
}
}
Aggregations