use of com.amazon.ion.IonValue in project ion-java by amzn.
the class IonSequenceLiteSubListViewEqualityTests method testSublistNonEquivalence.
// makes a sublist of seq and asserts its non-equivalence to the same subList range of the "other" sequence
// and to a sublist derived from OTHER_ARRAY_LIST
private static void testSublistNonEquivalence(List<IonValue> seq, SublistMaker maker) {
// A hash collision is unlikely but possible so we do not assert that the hashCodes are different here.
List<IonValue> subList = maker.makeSublist(seq);
for (IonSequence otherSeq : getOtherTestSequences()) {
List<IonValue> otherSubList = maker.makeSublist(otherSeq);
assertNotEquals("subLists should *not* be equivalent", subList, otherSubList);
}
assertNotEquals("subList should *not* be equivalent to a sublist of OTHER_ARRAY_LIST", maker.makeSublist(OTHER_ARRAY_LIST), subList);
}
use of com.amazon.ion.IonValue in project ion-java by amzn.
the class SIDPresentLifecycleTest method testPropagationAcrossGraph.
@Test
public void testPropagationAcrossGraph() {
IonStructLite struct = (IonStructLite) system().newEmptyStruct();
assertFalse(struct._isSymbolIdPresent());
// 1. test addition of child by field WITHOUT SID causes no propagation
IonStringLite keyValue1 = (IonStringLite) system().newString("Foo");
struct.add(_Private_Utils.newSymbolToken("field_1", -1), keyValue1);
assertFalse(struct._isSymbolIdPresent());
assertFalse(keyValue1._isSymbolIdPresent());
// 2. test addition of child by field WITH SID but also with field text causes no propagation
// (struct only takes field name if present and strips SID)
IonStringLite keyValue2 = (IonStringLite) system().newString("Bar");
struct.add(_Private_Utils.newSymbolToken("field_2", 87), keyValue2);
assertFalse(struct._isSymbolIdPresent());
assertFalse(keyValue1._isSymbolIdPresent());
assertFalse(keyValue2._isSymbolIdPresent());
// 3. test addition of child by field with SID ONLY causes propagation due to retention of field SID
IonStringLite keyValue3 = (IonStringLite) system().newString("Car");
struct.add(_Private_Utils.newSymbolToken(76), keyValue3);
assertTrue(struct._isSymbolIdPresent());
assertFalse(keyValue1._isSymbolIdPresent());
assertFalse(keyValue2._isSymbolIdPresent());
assertTrue(keyValue3._isSymbolIdPresent());
// 4. test explicitly annotating a field propagates
IonStructLite struct2 = (IonStructLite) system().newEmptyStruct();
IonStringLite keyValue4 = (IonStringLite) system().newString("But");
struct2.add("field_1", keyValue4);
keyValue4.setTypeAnnotationSymbols(_Private_Utils.newSymbolToken("Lah", 13));
assertTrue(struct2._isSymbolIdPresent());
// 5. test clone propagates clearing of status. NOTE - clone with an unresolvable SID for a field ID fails
try {
struct.clone();
fail("clone was expected NOT to succeed due to behavior at time of writing where unresolvable SID's fail");
} catch (UnknownSymbolException use) {
// this is expected??! until someone fixed the TO DO in IonValueLite#getFieldName
}
// remove the field without SID such that the clone can be enacted.
struct.remove_child(2);
IonStructLite clonedStruct = struct.clone();
assertFalse(clonedStruct._isSymbolIdPresent());
for (IonValue value : clonedStruct) {
assertFalse(((IonValueLite) value)._isSymbolIdPresent());
}
// 6. ensure clearing symbols propogates from root to impacted leaves
// add back in field ID (SID) only child before clearing to test SID retained
struct.add(_Private_Utils.newSymbolToken(76), keyValue3);
struct.clearSymbolIDValues();
assertTrue(struct._isSymbolIdPresent());
assertFalse(keyValue1._isSymbolIdPresent());
assertFalse(keyValue2._isSymbolIdPresent());
assertTrue(keyValue3._isSymbolIdPresent());
// 7. ensure that nested SID-only annotation clone behavior propogates to cloned root.
IonStructLite outer = (IonStructLite) system().newEmptyStruct();
IonListLite middle = (IonListLite) system().newEmptyList();
IonIntLite inner = (IonIntLite) system().newInt(10);
middle.add(inner);
outer.put("foo", middle);
// now add a SID only annotation to inner
inner.setTypeAnnotationSymbols(_Private_Utils.newSymbolToken(99));
// verify that all components are signaling SID present
assertTrue(outer._isSymbolIdPresent());
assertTrue(middle._isSymbolIdPresent());
assertTrue(inner._isSymbolIdPresent());
// conduct a clone and verify all cloned components have retained SID
IonStructLite clonedOuter = outer.clone();
assertTrue(clonedOuter._isSymbolIdPresent());
IonListLite clonedMiddle = (IonListLite) outer.get("foo");
assertTrue(clonedMiddle._isSymbolIdPresent());
assertTrue(clonedMiddle.get_child(0)._isSymbolIdPresent());
}
use of com.amazon.ion.IonValue in project ion-java by amzn.
the class BaseIonSequenceLiteSublistTestCase method sublistAddWithIndexConcurrentModification.
@Test(expected = ConcurrentModificationException.class)
public void sublistAddWithIndexConcurrentModification() {
final IonSequence sequence = newSequence();
final List<IonValue> sublist = sequence.subList(2, 5);
sequence.remove(0);
sublist.add(0, SYSTEM.newInt(0));
}
use of com.amazon.ion.IonValue in project ion-java by amzn.
the class BaseIonSequenceLiteSublistTestCase method sublistContainsConcurrentModification.
@Test(expected = ConcurrentModificationException.class)
public void sublistContainsConcurrentModification() {
final IonSequence sequence = newSequence();
final List<IonValue> sublist = sequence.subList(2, 5);
final IonInt value = SYSTEM.newInt(99);
sequence.add(value);
sublist.contains(value);
}
use of com.amazon.ion.IonValue in project ion-java by amzn.
the class BaseIonSequenceLiteSublistTestCase method sublistToArrayConcurrentModification.
@Test(expected = ConcurrentModificationException.class)
public void sublistToArrayConcurrentModification() {
final IonSequence sequence = newSequence();
final List<IonValue> sublist = sequence.subList(2, 5);
sequence.remove(0);
sublist.toArray();
}
Aggregations