Search in sources :

Example 61 with IonStruct

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

the class IonReaderBinaryIncrementalTest method incrementalMultipleValuesIterate.

private static void incrementalMultipleValuesIterate(Iterator<IonValue> iterator, ResizingPipedInputStream pipe) throws Exception {
    byte[] bytes = toBinary("value_type::\"StringValueLong\"");
    for (byte b : bytes) {
        assertFalse(iterator.hasNext());
        pipe.receive(b);
    }
    assertTrue(iterator.hasNext());
    IonString string = (IonString) iterator.next();
    assertEquals("StringValueLong", string.stringValue());
    assertEquals(Collections.singletonList("value_type"), Arrays.asList(string.getTypeAnnotations()));
    bytes = toBinary("{foobar: \"StringValueLong\"}");
    for (byte b : bytes) {
        assertFalse(iterator.hasNext());
        pipe.receive(b);
    }
    assertTrue(iterator.hasNext());
    IonStruct struct = (IonStruct) iterator.next();
    string = (IonString) struct.get("foobar");
    assertEquals("StringValueLong", string.stringValue());
    assertFalse(iterator.hasNext());
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonString(com.amazon.ion.IonString)

Example 62 with IonStruct

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

the class IonReaderBinaryIncrementalTest method incrementalMultipleValuesLoadFromReader.

@Test
public void incrementalMultipleValuesLoadFromReader() throws Exception {
    ResizingPipedInputStream pipe = new ResizingPipedInputStream(128);
    final IonReaderBinaryIncremental reader = new IonReaderBinaryIncremental(STANDARD_READER_BUILDER, pipe);
    final IonLoader loader = SYSTEM.getLoader();
    byte[] bytes = toBinary("value_type::\"StringValueLong\"");
    for (byte b : bytes) {
        IonDatagram empty = loader.load(reader);
        assertTrue(empty.isEmpty());
        pipe.receive(b);
    }
    IonDatagram firstValue = loader.load(reader);
    assertEquals(1, firstValue.size());
    IonString string = (IonString) firstValue.get(0);
    assertEquals("StringValueLong", string.stringValue());
    assertEquals(Collections.singletonList("value_type"), Arrays.asList(string.getTypeAnnotations()));
    bytes = toBinary("{foobar: \"StringValueLong\"}");
    for (byte b : bytes) {
        IonDatagram empty = loader.load(reader);
        assertTrue(empty.isEmpty());
        pipe.receive(b);
    }
    IonDatagram secondValue = loader.load(reader);
    assertEquals(1, secondValue.size());
    IonStruct struct = (IonStruct) secondValue.get(0);
    string = (IonString) struct.get("foobar");
    assertEquals("StringValueLong", string.stringValue());
    IonDatagram empty = loader.load(reader);
    assertTrue(empty.isEmpty());
    reader.close();
}
Also used : IonStruct(com.amazon.ion.IonStruct) IonString(com.amazon.ion.IonString) IonDatagram(com.amazon.ion.IonDatagram) IonLoader(com.amazon.ion.IonLoader) Test(org.junit.Test)

Example 63 with IonStruct

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

the class MiscStreamingTest 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);
    IonType t = v.getType();
    assertSame("should be a struct", IonType.STRUCT, t);
    int tree_count = ((IonStruct) v).size();
    IonReader it = system().newReader(s);
    t = it.next();
    assertSame("should be a struct", IonType.STRUCT, t);
    int string_count = 0;
    it.stepIn();
    while (it.next() != null) {
        string_count++;
    }
    it.stepOut();
    assertSame("tree and string iterator should have the same size", tree_count, string_count);
    byte[] buf = dg.getBytes();
    it = system().newReader(buf);
    t = it.next();
    assertSame("should be a struct", IonType.STRUCT, t);
    int bin_count = 0;
    it.stepIn();
    while (it.next() != null) {
        bin_count++;
    }
    it.stepOut();
    assertSame("tree and binary iterator should have the same size", tree_count, bin_count);
}
Also used : IonValue(com.amazon.ion.IonValue) IonSystem(com.amazon.ion.IonSystem) IonStruct(com.amazon.ion.IonStruct) IonType(com.amazon.ion.IonType) IonDatagram(com.amazon.ion.IonDatagram) IonReader(com.amazon.ion.IonReader) IonString(com.amazon.ion.IonString) Test(org.junit.Test) BinaryTest(com.amazon.ion.BinaryTest)

Example 64 with IonStruct

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

the class IonContextTest method testInsertion.

private void testInsertion(boolean usePadding) throws Exception {
    // String representation of the IonValue (input IonContext) to be added
    // into an IonContainer (output IonContext).
    // We cover local, system, and shared symbols here.
    String ionText = "ann1::{a:sym, b:name, c:ann2::fred_1}";
    IonStruct struct = (IonStruct) getInputContextMaker().newIonValue(system(), ionText);
    getOutputContext().addToContainer(system(), struct, usePadding);
    SymbolTable symtab = struct.getSymbolTable();
    checkSymbolToken("ann1", symtab, struct.getTypeAnnotationSymbols()[0]);
    IonValue elt = struct.get("a");
    checkSymbolToken("a", symtab, elt.getFieldNameSymbol());
    checkSymbolToken("sym", symtab, ((IonSymbol) elt).symbolValue());
    elt = struct.get("b");
    checkSymbolToken("b", symtab, elt.getFieldNameSymbol());
    checkSymbolToken("name", symtab, ((IonSymbol) elt).symbolValue());
    elt = struct.get("c");
    checkSymbolToken("c", symtab, elt.getFieldNameSymbol());
    checkSymbolToken("ann2", symtab, elt.getTypeAnnotationSymbols()[0]);
    checkSymbolToken("fred_1", symtab, ((IonSymbol) elt).symbolValue());
}
Also used : IonValue(com.amazon.ion.IonValue) IonStruct(com.amazon.ion.IonStruct) SymbolTable(com.amazon.ion.SymbolTable)

Example 65 with IonStruct

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

the class EquivalenceTest method testFieldEquals2.

// TODO amzn/ion-java/issues/58 : Remove the ignore annotation from this test after
// making the required changes to Equivalence.Field.hashCode.
@Ignore
@Test
public void testFieldEquals2() {
    String intOne = "1";
    IonValue v1 = oneValue(intOne);
    IonValue v2 = oneValue(intOne);
    IonValue v3 = oneValue(intOne);
    IonStruct struct = system().newEmptyStruct();
    String fieldName = "a";
    struct.add(fieldName, v1);
    struct.add(fieldName, v2);
    struct.add(fieldName, v3);
    assertEquals(3, struct.size());
    Equivalence.Configuration configuration = new Equivalence.Configuration(new Equivalence.Builder().withStrict(true));
    Equivalence.Field f1 = new Equivalence.Field(v1, configuration);
    Equivalence.Field f2 = new Equivalence.Field(v2, configuration);
    Equivalence.Field f3 = new Equivalence.Field(v3, configuration);
    assertEquals(f1, f2);
    // symmetric
    assertEquals(f2, f1);
    assertEquals(f1, f3);
    // symmetric
    assertEquals(f3, f1);
    // transitive
    assertEquals(f2, f3);
    // symmetric
    assertEquals(f3, f2);
}
Also used : IonValue(com.amazon.ion.IonValue) IonStruct(com.amazon.ion.IonStruct) Ignore(org.junit.Ignore) 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