Search in sources :

Example 11 with IonStruct

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

the class SharedSymbolTableTest method testDomSharedSymbolTable.

@Test
public void testDomSharedSymbolTable() {
    String[] symbols = { "hello" };
    IonStruct struct = sharedSymtabStruct(system(), "foobar", 1, symbols);
    final SymbolTable table = myMaker.newSharedSymtab(system(), struct);
    checkSharedTable("foobar", 1, new String[] { "hello" }, table);
}
Also used : IonStruct(com.amazon.ion.IonStruct) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Example 12 with IonStruct

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

the class SharedSymbolTableTest method testMalformedVersion.

public void testMalformedVersion(String versionValue) {
    IonStruct s = sharedSymtabStruct(system(), "ST", 1, "x", "y");
    putParsedValue(s, SystemSymbols.VERSION, versionValue);
    SymbolTable st = myMaker.newSharedSymtab(system(), s);
    checkSharedTable("ST", 1, new String[] { "x", "y" }, st);
}
Also used : IonStruct(com.amazon.ion.IonStruct) SymbolTable(com.amazon.ion.SymbolTable)

Example 13 with IonStruct

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

the class SymbolTableTest method append_some_data.

private void append_some_data(IonDatagram data) {
    IonStruct contents = system().newEmptyStruct();
    contents.add("one", system().newInt(1));
    contents.add("two", system().newInt(2));
    data.add(contents);
}
Also used : IonStruct(com.amazon.ion.IonStruct)

Example 14 with IonStruct

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

the class IonAssert method doAssertIonEquals.

// ========================================================================
private static void doAssertIonEquals(String path, IonValue expected, IonValue actual) {
    if (expected == actual)
        return;
    IonType expectedType = expected.getType();
    assertSame(path + " type", expectedType, actual.getType());
    assertEqualAnnotations(path, expected, actual);
    if (expected.isNullValue() || actual.isNullValue()) {
        assertEquals(path, expected, actual);
        return;
    }
    switch(expectedType) {
        case BOOL:
        case DECIMAL:
        case FLOAT:
        case INT:
        case NULL:
        case STRING:
        case SYMBOL:
        case TIMESTAMP:
            {
                // "Normal" IonValue.equals()
                assertEquals(path + " IonValue", expected, actual);
                break;
            }
        case BLOB:
        case CLOB:
            {
                assertArrayEquals(path, ((IonLob) expected).getBytes(), ((IonLob) actual).getBytes());
                break;
            }
        // user data, not system data.
        case DATAGRAM:
        case LIST:
        case SEXP:
            {
                assertSequenceEquals(path, (IonSequence) expected, (IonSequence) actual);
                break;
            }
        case STRUCT:
            {
                assertStructEquals(path, (IonStruct) expected, (IonStruct) actual);
                break;
            }
    }
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonType(com.amazon.ion.IonType) IonLob(com.amazon.ion.IonLob) IonSequence(com.amazon.ion.IonSequence)

Example 15 with IonStruct

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

the class BinaryStreamingTest method testValue2.

@Test
public void testValue2() throws Exception {
    String s = "item_view::{item_id:\"B00096H8Q4\",marketplace_id:2," + "product:{item_name:[" + "{value:'''Method 24CT Leather Wipes''',lang:EN_CA}," + "{value:'''Method 24CT Chiffons de Cuir''',lang:FR_CA}]," + "list_price:{value:18.23,unit:EUR},}" + ",index_suppressed:true," + "offline_store_only:true,version:2,}";
    IonSystem sys = system();
    IonDatagram dg = sys.getLoader().load(s);
    IonValue v = dg.get(0);
    IonValue v2 = ((IonStruct) v).get("offline_store_only");
    SymbolTable sym = v.getSymbolTable();
    assert v2.getSymbolTable() == sym;
    IonReader ir = system().newReader(s);
    Iterator<String> symbols = sym.iterateDeclaredSymbolNames();
    SymbolTable u = system().newSharedSymbolTable("items", 1, symbols);
    IonBinaryWriter wr = system().newBinaryWriter(u);
    wr.writeValues(ir);
    byte[] buffer = wr.getBytes();
    dumpBuffer(buffer, buffer.length);
    ir = getStreamingMode().newIonReader(system().getCatalog(), buffer);
    wr = system().newBinaryWriter(u);
    wr.writeValues(ir);
    buffer = wr.getBytes();
    dumpBuffer(buffer, buffer.length);
}
Also used : IonValue(com.amazon.ion.IonValue) IonSystem(com.amazon.ion.IonSystem) IonStruct(com.amazon.ion.IonStruct) IonDatagram(com.amazon.ion.IonDatagram) IonReader(com.amazon.ion.IonReader) IonBinaryWriter(com.amazon.ion.IonBinaryWriter) SymbolTable(com.amazon.ion.SymbolTable) Test(org.junit.Test)

Aggregations

IonStruct (com.amazon.ion.IonStruct)68 Test (org.junit.Test)28 IonValue (com.amazon.ion.IonValue)18 IonDatagram (com.amazon.ion.IonDatagram)13 IonList (com.amazon.ion.IonList)13 IonReader (com.amazon.ion.IonReader)13 SymbolTable (com.amazon.ion.SymbolTable)13 IOException (java.io.IOException)8 IonString (com.amazon.ion.IonString)7 IonSystem (com.amazon.ion.IonSystem)6 IonException (com.amazon.ion.IonException)5 IonSequence (com.amazon.ion.IonSequence)5 IonType (com.amazon.ion.IonType)5 IonFloat (com.amazon.ion.IonFloat)4 IonSymbol (com.amazon.ion.IonSymbol)4 IonTimestamp (com.amazon.ion.IonTimestamp)4 IonWriter (com.amazon.ion.IonWriter)4 SymbolToken (com.amazon.ion.SymbolToken)4 ArrayList (java.util.ArrayList)4 IonBlob (com.amazon.ion.IonBlob)3