Search in sources :

Example 21 with IonDatagram

use of com.amazon.ion.IonDatagram in project ion-java by amzn.

the class IonWriterTestCase method testWriteValuesCopiesCurrentValue.

@Test
public void testWriteValuesCopiesCurrentValue() throws Exception {
    String data = "1 2 3";
    IonReader ir = system().newReader(data);
    ir.next();
    iw = makeWriter();
    iw.writeValues(ir);
    IonDatagram dg = reload();
    assertEquals(loader().load(data), dg);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) IonReader(com.amazon.ion.IonReader) IonString(com.amazon.ion.IonString) Test(org.junit.Test)

Example 22 with IonDatagram

use of com.amazon.ion.IonDatagram in project ion-java by amzn.

the class IonWriterTestCase method reload.

/**
 * Extracts bytes from the current writer and loads it into a datagram.
 */
@SuppressWarnings("unused")
protected IonDatagram reload() throws Exception {
    byte[] bytes = outputByteArray();
    IonDatagram dg;
    if (// Edit for debugging
    false) {
        try {
            // force all the classes to load to we can step
            // into the next time we try this and actually
            // see what's going on
            dg = loader().load(bytes);
        } catch (IonException e) {
        // do nothing
        }
    }
    dg = loader().load(bytes);
    return dg;
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) IonException(com.amazon.ion.IonException)

Example 23 with IonDatagram

use of com.amazon.ion.IonDatagram in project ion-java by amzn.

the class IonWriterTestCase method testWritingEmptySymtab.

@Test
public void testWritingEmptySymtab() throws Exception {
    iw = makeWriter();
    iw.addTypeAnnotation(ION_SYMBOL_TABLE);
    iw.stepIn(IonType.STRUCT);
    iw.stepOut();
    iw.writeSymbol("foo");
    iw.close();
    IonDatagram dg = reload();
    IonSymbol foo = (IonSymbol) dg.get(0);
    assertEquals(0, foo.getTypeAnnotations().length);
}
Also used : IonSymbol(com.amazon.ion.IonSymbol) IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 24 with IonDatagram

use of com.amazon.ion.IonDatagram in project ion-java by amzn.

the class IonWriterTestCase method testWritingAnnotationWithBadSid.

@Test
public void testWritingAnnotationWithBadSid() throws Exception {
    iw = makeWriter();
    IonDatagram expected = system().newDatagram();
    iw.setTypeAnnotationSymbols(newSymbolToken("a", 99));
    // expected: the type annotation is written
    iw.writeNull();
    IonValue v = expected.add().newNull();
    v.setTypeAnnotations("a");
    assertEquals(expected, reload());
}
Also used : IonValue(com.amazon.ion.IonValue) IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 25 with IonDatagram

use of com.amazon.ion.IonDatagram in project ion-java by amzn.

the class OptimizedBinaryWriterSymbolTableTest method testOptimizedWriteValueSameLST1.

/**
 * Writer's LST identical to Reader's - optimize.
 */
@Test
public void testOptimizedWriteValueSameLST1() throws Exception {
    String readerLST = printLocalSymtab("amazon", "website");
    byte[] source = encode(readerLST + "amazon website");
    ir = makeReaderProxy(source);
    iw = makeWriterWithLocalSymtab("amazon", "website");
    // writer's symtab same as reader's
    // amazon
    checkWriteValueWithCompatibleSymtab();
    // website
    checkWriteValueWithCompatibleSymtab();
    iw.close();
    IonDatagram expected = loader().load("amazon website");
    IonDatagram actual = loader().load(outputByteArray());
    assertIonEquals(expected, actual);
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Aggregations

IonDatagram (com.amazon.ion.IonDatagram)92 Test (org.junit.Test)77 IonValue (com.amazon.ion.IonValue)20 SymbolTable (com.amazon.ion.SymbolTable)18 IonReader (com.amazon.ion.IonReader)17 IonString (com.amazon.ion.IonString)15 IonStruct (com.amazon.ion.IonStruct)13 IonWriter (com.amazon.ion.IonWriter)11 IonSymbol (com.amazon.ion.IonSymbol)6 IonSystem (com.amazon.ion.IonSystem)6 IonLoader (com.amazon.ion.IonLoader)5 IonType (com.amazon.ion.IonType)5 SimpleCatalog (com.amazon.ion.system.SimpleCatalog)5 BlobTest (com.amazon.ion.BlobTest)4 ClobTest (com.amazon.ion.ClobTest)4 IntTest (com.amazon.ion.IntTest)4 IonList (com.amazon.ion.IonList)4 IonTextWriterBuilder (com.amazon.ion.system.IonTextWriterBuilder)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 BinaryTest (com.amazon.ion.BinaryTest)2