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());
}
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();
}
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);
}
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());
}
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);
}
Aggregations