Search in sources :

Example 81 with IonValue

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

the class SimpleCatalogTest method testBenchmark.

@SuppressWarnings("unchecked")
@Test
public void testBenchmark() {
    Map m = new HashMap();
    String s = "hello";
    m.put("This is a test String.", true);
    m.put(s, true);
    m.put("true", true);
    m.put("false", false);
    m.put("Something", null);
    m.put("12242.124598129", 12242.124598129);
    m.put("long", (long) 9326);
    m.put("12", 12);
    m.put("Almost Done.", true);
    m.put("Date", new Date(-10000));
    HashMap<String, String> hmap = new HashMap();
    for (int i = 0; i < 10; i++) {
        hmap.put("Key " + i, "value " + i);
    }
    TreeMap<String, String> tmap = new TreeMap();
    for (int i = 0; i < 10; i++) {
        tmap.put("Key " + i, "value " + i);
    }
    m.put("hmap", hmap);
    m.put("tmap", tmap);
    IonSystem sys = system();
    IonStruct i_tmap, i_hmap, i_map;
    Set<Entry<String, String>> set;
    i_tmap = sys.newEmptyStruct();
    set = tmap.entrySet();
    for (Entry<String, String> e : set) {
        IonString is = sys.newString(e.getValue());
        i_tmap.add(e.getKey(), is);
    }
    i_hmap = sys.newEmptyStruct();
    set = hmap.entrySet();
    for (Entry<String, String> e : set) {
        IonString is = sys.newString(e.getValue());
        i_hmap.add(e.getKey(), is);
    }
    i_map = sys.newEmptyStruct();
    set = tmap.entrySet();
    for (Entry<String, String> e : set) {
        Object val = e.getValue();
        IonValue ival;
        if (val instanceof String) {
            ival = sys.newString((String) val);
        } else if (e.getKey().equals("tmap")) {
            ival = i_tmap;
        } else if (e.getKey().equals("hmap")) {
            ival = i_hmap;
        } else {
            throw new RuntimeException("ACK! there's something in this map I don't understand!");
        }
        i_map.add(e.getKey(), ival);
    }
    IonDatagram dg = sys.newDatagram(i_map);
    byte[] bytes = dg.getBytes();
    IonValue v2 = sys.singleValue(bytes);
    assertNotNull(v2);
}
Also used : IonValue(com.amazon.ion.IonValue) IonSystem(com.amazon.ion.IonSystem) HashMap(java.util.HashMap) IonString(com.amazon.ion.IonString) TreeMap(java.util.TreeMap) Date(java.util.Date) Entry(java.util.Map.Entry) IonStruct(com.amazon.ion.IonStruct) IonString(com.amazon.ion.IonString) IonDatagram(com.amazon.ion.IonDatagram) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Test(org.junit.Test)

Example 82 with IonValue

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

the class EquivalenceTest method testFieldEquals1.

// 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 testFieldEquals1() {
    IonValue v1 = oneValue("1");
    IonValue v2 = oneValue("2");
    IonValue v3 = oneValue("3");
    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);
    assertFalse(f1.equals(f2));
    assertFalse(f1.equals(f3));
    assertFalse(f2.equals(f3));
    // Simple test that hashCode() is not badly implemented, so that fields with same
    // field names but are not equals() do not result in same hash codes.
    assertTrue(f1.hashCode() != f2.hashCode());
    assertTrue(f1.hashCode() != f3.hashCode());
}
Also used : IonValue(com.amazon.ion.IonValue) IonStruct(com.amazon.ion.IonStruct) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 83 with IonValue

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

the class ReaderDomCopyTest method iterateIon.

void iterateIon(File myTestFile) throws IOException {
    IonDatagram dg = system().getLoader().load(myTestFile);
    IonReader reader = system().newReader(dg);
    for (int i = 0; reader.next() != null; i++) {
        IonValue actual = system().newValue(reader);
        assertIonEquals(dg.get(i), actual);
    }
}
Also used : IonValue(com.amazon.ion.IonValue) IonDatagram(com.amazon.ion.IonDatagram) IonReader(com.amazon.ion.IonReader)

Example 84 with IonValue

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

the class MiscStreamingTest method testBinaryAnnotation.

@Test
public void testBinaryAnnotation() 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", t, IonType.STRUCT);
    // first make sure the ion tree got it right
    assertTrue(v.hasTypeAnnotation("item_view"));
    String[] ann = v.getTypeAnnotations();
    assertTrue(ann.length == 1 && ann[0].equals("item_view"));
    // now take the string and get a text iterator and
    // make sure it got the annotation right
    IonReader it = system().newReader(s);
    t = it.next();
    assertSame("should be a struct", t, IonType.STRUCT);
    ann = it.getTypeAnnotations();
    assertTrue(ann.length == 1 && ann[0].equals("item_view"));
    // finally get the byte array from the tree, make a
    // binary iterator and check its annotation handling
    byte[] buf = dg.getBytes();
    it = system().newReader(buf);
    t = it.next();
    assertSame("should be a struct", t, IonType.STRUCT);
    ann = it.getTypeAnnotations();
    assertTrue(ann.length == 1 && ann[0].equals("item_view"));
}
Also used : IonValue(com.amazon.ion.IonValue) IonSystem(com.amazon.ion.IonSystem) 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 85 with IonValue

use of com.amazon.ion.IonValue in project jackson-dataformats-binary by FasterXML.

the class EnumAsIonSymbolSerializationTest method testUsingName.

@Test
public void testUsingName() throws Exception {
    final IonValue EXP = ION_SYSTEM.singleValue("SOME_VALUE");
    Assert.assertEquals(EXP, newMapper(false, false).writeValueAsIonValue(SomeEnum.SOME_VALUE));
    Assert.assertEquals(EXP, newMapper(true, false).writeValueAsIonValue(SomeEnum.SOME_VALUE));
}
Also used : IonValue(com.amazon.ion.IonValue) Test(org.junit.Test)

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