Search in sources :

Example 1 with TransactionOperation

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));
    }
}
Also used : AddStatementOperation(org.eclipse.rdf4j.http.protocol.transaction.operations.AddStatementOperation) TransactionOperation(org.eclipse.rdf4j.http.protocol.transaction.operations.TransactionOperation) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) Resource(org.eclipse.rdf4j.model.Resource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 2 with TransactionOperation

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();
}
Also used : TransactionOperation(org.eclipse.rdf4j.http.protocol.transaction.operations.TransactionOperation) XMLWriter(org.eclipse.rdf4j.common.xml.XMLWriter)

Example 3 with TransactionOperation

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));
    }
}
Also used : AddStatementOperation(org.eclipse.rdf4j.http.protocol.transaction.operations.AddStatementOperation) TransactionOperation(org.eclipse.rdf4j.http.protocol.transaction.operations.TransactionOperation) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

TransactionOperation (org.eclipse.rdf4j.http.protocol.transaction.operations.TransactionOperation)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ArrayList (java.util.ArrayList)2 AddStatementOperation (org.eclipse.rdf4j.http.protocol.transaction.operations.AddStatementOperation)2 Test (org.junit.Test)2 XMLWriter (org.eclipse.rdf4j.common.xml.XMLWriter)1 Resource (org.eclipse.rdf4j.model.Resource)1