Search in sources :

Example 61 with IonValue

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

the class IonWriterTestCase method testWritingClearedAnnotations.

/**
 * Test case to ensure that {@link IonWriter#setTypeAnnotations(String...)}
 * and {@link IonWriter#setTypeAnnotationSymbols(SymbolToken...)} clearing
 * of type annotations behavior is correct.
 */
@Test
public void testWritingClearedAnnotations() throws Exception {
    iw = makeWriter();
    IonDatagram expected = system().newDatagram();
    // ===== Test on IonWriter.setTypeAnnotationSymbols(...) =====
    // empty SymbolToken[]
    iw.setTypeAnnotationSymbols(new SymbolToken[0]);
    iw.writeNull();
    IonValue v = expected.add().newNull();
    v.clearTypeAnnotations();
    // null SymbolToken[]
    iw.setTypeAnnotationSymbols((SymbolToken[]) null);
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    iw.addTypeAnnotation("b");
    // empty SymbolToken[]
    iw.setTypeAnnotationSymbols(new SymbolToken[0]);
    // expected: the pending "b" annotation is cleared
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    iw.addTypeAnnotation("b");
    // null SymbolToken[]
    iw.setTypeAnnotationSymbols((SymbolToken[]) null);
    // expected: the pending "b" annotation is cleared
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    // ===== Test on IonWriter.setTypeAnnotations(...) =====
    // empty String[]
    iw.setTypeAnnotations(new String[0]);
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    // null String[]
    iw.setTypeAnnotations((String[]) null);
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    iw.addTypeAnnotation("b");
    // empty String[]
    iw.setTypeAnnotations(new String[0]);
    // expected: the pending "b" annotation is cleared
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    iw.addTypeAnnotation("b");
    // null String[]
    iw.setTypeAnnotations((String[]) null);
    // expected: the pending "b" annotation is cleared
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    assertEquals(expected, reload());
}
Also used : IonValue(com.amazon.ion.IonValue) SymbolToken(com.amazon.ion.SymbolToken) com.amazon.ion.impl._Private_Utils.newSymbolToken(com.amazon.ion.impl._Private_Utils.newSymbolToken) FakeSymbolToken(com.amazon.ion.FakeSymbolToken) IonDatagram(com.amazon.ion.IonDatagram) IonString(com.amazon.ion.IonString) Test(org.junit.Test)

Example 62 with IonValue

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

the class IonWriterTestCase method testWritingAnnotations.

@Test
public void testWritingAnnotations() throws Exception {
    iw = makeWriter();
    IonDatagram expected = system().newDatagram();
    iw.addTypeAnnotation("a");
    iw.writeNull();
    IonValue v = expected.add().newNull();
    v.addTypeAnnotation("a");
    iw.addTypeAnnotation("b");
    iw.addTypeAnnotation("c");
    iw.writeNull();
    v = expected.add().newNull();
    v.addTypeAnnotation("b");
    v.addTypeAnnotation("c");
    iw.addTypeAnnotation("b");
    iw.addTypeAnnotation("b");
    iw.writeNull();
    v = expected.add().newNull();
    v.setTypeAnnotations("b", "b");
    iw.setTypeAnnotations("b", "b");
    iw.writeNull();
    v = expected.add().newNull();
    v.setTypeAnnotations("b", "b");
    iw.addTypeAnnotation("b");
    iw.setTypeAnnotations("c", "d");
    iw.writeNull();
    v = expected.add().newNull();
    v.setTypeAnnotations("c", "d");
    iw.addTypeAnnotation("b");
    iw.setTypeAnnotations(new String[0]);
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    iw.addTypeAnnotation("b");
    iw.setTypeAnnotations((String[]) null);
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    iw.addTypeAnnotation("b");
    iw.setTypeAnnotations();
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    iw.addTypeAnnotation("b");
    iw.setTypeAnnotationSymbols(new SymbolToken[0]);
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    iw.addTypeAnnotation("b");
    iw.setTypeAnnotationSymbols((SymbolToken[]) null);
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    iw.addTypeAnnotation("b");
    iw.setTypeAnnotationSymbols();
    iw.writeNull();
    v = expected.add().newNull();
    v.clearTypeAnnotations();
    assertEquals(expected, reload());
}
Also used : IonValue(com.amazon.ion.IonValue) SymbolToken(com.amazon.ion.SymbolToken) com.amazon.ion.impl._Private_Utils.newSymbolToken(com.amazon.ion.impl._Private_Utils.newSymbolToken) FakeSymbolToken(com.amazon.ion.FakeSymbolToken) IonDatagram(com.amazon.ion.IonDatagram) IonString(com.amazon.ion.IonString) Test(org.junit.Test)

Example 63 with IonValue

use of com.amazon.ion.IonValue 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 64 with IonValue

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

the class IterationTest method testSimpleIteration.

// =========================================================================
// Test cases
@Test
public void testSimpleIteration() {
    Iterator<IonValue> i = system().iterate("abc");
    assertTrue(i.hasNext());
    IonSymbol value = (IonSymbol) i.next();
    checkSymbol("abc", value);
    assertFalse(i.hasNext());
    checkEmptyIterator(i);
}
Also used : IonValue(com.amazon.ion.IonValue) IonSymbol(com.amazon.ion.IonSymbol) Test(org.junit.Test)

Example 65 with IonValue

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

the class ReverseBinaryEncoder method writeIonDatagramContent.

private void writeIonDatagramContent(IonDatagram dg) {
    ListIterator<IonValue> reverseIter = dg.listIterator(dg.size());
    while (reverseIter.hasPrevious()) {
        IonValue currentTopLevelValue = reverseIter.previous();
        checkLocalSymbolTablePlacement(currentTopLevelValue);
        writeIonValue(currentTopLevelValue);
    }
}
Also used : IonValue(com.amazon.ion.IonValue)

Aggregations

IonValue (com.amazon.ion.IonValue)185 Test (org.junit.Test)115 IonSequence (com.amazon.ion.IonSequence)61 SymbolTable (com.amazon.ion.SymbolTable)21 IonDatagram (com.amazon.ion.IonDatagram)20 IonStruct (com.amazon.ion.IonStruct)18 IonInt (com.amazon.ion.IonInt)16 IOException (java.io.IOException)14 IonReader (com.amazon.ion.IonReader)13 IonSystem (com.amazon.ion.IonSystem)12 Result (software.amazon.qldb.Result)11 SymbolToken (com.amazon.ion.SymbolToken)10 ArrayList (java.util.ArrayList)10 IonString (com.amazon.ion.IonString)9 IonException (com.amazon.ion.IonException)7 IonType (com.amazon.ion.IonType)6 IonObjectMapper (com.fasterxml.jackson.dataformat.ion.IonObjectMapper)6 Event (com.amazon.tools.events.Event)5 com.amazon.ion.impl._Private_IonValue (com.amazon.ion.impl._Private_IonValue)4 EventType (com.amazon.tools.events.EventType)4