Search in sources :

Example 61 with IonDatagram

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

the class SymbolTableTest method testInjectingMaxIdIntoImport.

@Test
public // TODO implement
void testInjectingMaxIdIntoImport() {
    SymbolTable importedTable = registerImportedV1();
    String text = LocalSymbolTablePrefix + "{" + "  imports:[{name:'''imported''',version:1}],\n" + "}\n" + "null";
    IonDatagram dg = loader().load(text);
    SymbolTable symbolTable = dg.get(0).getSymbolTable();
    checkLocalTable(symbolTable);
    SymbolTable[] imported = symbolTable.getImportedTables();
    assertEquals(1, imported.length);
    assertSame(importedTable, imported[0]);
    // Check that the encoded table has max_id on import
    byte[] binary = dg.getBytes();
    dg = loader().load(binary);
    IonStruct symtabStruct = (IonStruct) dg.systemGet(1);
    IonList imports = (IonList) symtabStruct.get("imports");
    IonStruct importStruct = (IonStruct) imports.get(0);
    checkString("imported", importStruct.get("name"));
    IonValue maxIdValue = importStruct.get("max_id");
    assertNotNull("max_id wasn't injected into import", maxIdValue);
    checkInt(IMPORTED_1_MAX_ID, maxIdValue);
}
Also used : IonValue(com.amazon.ion.IonValue) IonStruct(com.amazon.ion.IonStruct) IonDatagram(com.amazon.ion.IonDatagram) IonList(com.amazon.ion.IonList) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 62 with IonDatagram

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

the class IonWriterTestCase method testWritingNonAscii.

@Test
public void testWritingNonAscii() throws Exception {
    String text = TestUtils.YEN_SIGN + FERMATA;
    iw = makeWriter();
    iw.writeString(text);
    iw.writeSymbol(text);
    IonDatagram dg = reload();
    IonText t = (IonString) dg.get(0);
    assertEquals(text, t.stringValue());
    t = (IonSymbol) dg.get(1);
    checkSymbol(text, t);
}
Also used : IonText(com.amazon.ion.IonText) IonString(com.amazon.ion.IonString) IonDatagram(com.amazon.ion.IonDatagram) IonString(com.amazon.ion.IonString) Test(org.junit.Test)

Example 63 with IonDatagram

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

the class IonWriterTestCase method testWritingAnnotationWithUnknownText.

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

Example 64 with IonDatagram

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

the class IonWriterTestCase method testWritingNulls.

@Test
public void testWritingNulls() throws Exception {
    iw = makeWriter();
    IonDatagram expected = system().newDatagram();
    iw.writeBlob(null);
    expected.add().newNullBlob();
    iw.writeClob(null);
    expected.add().newNullClob();
    iw.writeDecimal((BigDecimal) null);
    expected.add().newNullDecimal();
    iw.writeString(null);
    expected.add().newNullString();
    iw.writeSymbol(null);
    expected.add().newNullSymbol();
    iw.writeTimestamp(null);
    expected.add().newNullTimestamp();
    assertEquals(expected, reload());
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) Test(org.junit.Test)

Example 65 with IonDatagram

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

the class IonWriterTestCase method testWritingClob.

@Test
public void testWritingClob() throws Exception {
    byte[] data = new byte[256];
    for (int i = 0; i < data.length; i++) {
        data[i] = (byte) i;
    }
    iw = makeWriter();
    iw.writeBlob(data);
    iw.writeBlob(data, 10, 90);
    iw.writeClob(data);
    iw.writeClob(data, 20, 30);
    byte[] bytes = outputByteArray();
    IonDatagram dg = loader().load(bytes);
    assertEquals(4, dg.size());
    IonLob lob = (IonBlob) dg.get(0);
    assertTrue(Arrays.equals(data, lob.getBytes()));
    lob = (IonBlob) dg.get(1);
    assertEqualBytes(data, 10, 90, lob.getBytes());
    lob = (IonClob) dg.get(2);
    assertTrue(Arrays.equals(data, lob.getBytes()));
    lob = (IonClob) dg.get(3);
    assertEqualBytes(data, 20, 30, lob.getBytes());
}
Also used : IonDatagram(com.amazon.ion.IonDatagram) IonLob(com.amazon.ion.IonLob) IonBlob(com.amazon.ion.IonBlob) 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