use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.
the class SymbolTableTest method testLocalTableWithGreaterImport.
/**
* Import v2 but catalog has v3.
*/
@Test
public void testLocalTableWithGreaterImport() throws IOException {
final int import1id = systemMaxId() + 1;
final int import2id = systemMaxId() + 2;
final int fred3id = systemMaxId() + 3;
final int maxLocalId = systemMaxId() + IMPORTED_2_MAX_ID + 3;
registerImportedV1();
registerImportedV2();
registerImportedV3();
// fred5 is not in table version 2, so it gets local symbol
String text = LocalSymbolTablePrefix + "{" + " imports:[{name:\"imported\", version:2, " + " max_id:" + IMPORTED_2_MAX_ID + "}]," + "}\n" + "local1 local2 'imported 1' 'imported 2' fred3 fred5";
byte[] binary = encode(text);
// Remove the imported table before decoding the binary.
SimpleCatalog catalog = (SimpleCatalog) system().getCatalog();
assertNotNull(catalog.removeTable("imported", 2));
IonDatagram dg = loader().load(binary);
checkSymbol("local1", dg.get(0));
checkSymbol("local2", dg.get(1));
checkSymbol("imported 1", import1id, dg.get(2));
checkUnknownSymbol(import2id, dg.get(3));
checkSymbol("fred3", fred3id, dg.get(4));
checkSymbol("fred5", dg.get(5));
SymbolTable st = dg.get(0).getSymbolTable();
checkFirstImport("imported", 2, new String[] { "imported 1", null, "fred3", "fred4" }, st);
SymbolTable imported = st.getImportedTables()[0];
checkUnknownSymbol("fred5", 5, imported);
assertTrue(st.isLocalTable());
assertEquals(maxLocalId, st.getMaxId());
}
use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.
the class SymbolTableTest method testLocalTableWithLesserImport.
/**
* Import v2 but catalog has v1.
*/
@Test
public void testLocalTableWithLesserImport() throws IOException {
final int import1id = systemMaxId() + 1;
final int import2id = systemMaxId() + 2;
final int fred3id = systemMaxId() + 3;
final int maxLocalId = systemMaxId() + IMPORTED_2_MAX_ID + 2;
registerImportedV1();
registerImportedV2();
String text = LocalSymbolTablePrefix + "{" + " imports:[{name:\"imported\", version:2, " + " max_id:" + IMPORTED_2_MAX_ID + "}]," + "}\n" + "local1 local2 'imported 1' 'imported 2' fred3";
byte[] binary = encode(text);
// Remove the imported table before decoding the binary.
SimpleCatalog catalog = (SimpleCatalog) system().getCatalog();
assertNotNull(catalog.removeTable("imported", 2));
IonDatagram dg = loader().load(binary);
checkSymbol("local1", dg.get(0));
checkSymbol("local2", dg.get(1));
checkSymbol("imported 1", import1id, dg.get(2));
checkSymbol("imported 2", import2id, dg.get(3));
checkUnknownSymbol(fred3id, dg.get(4));
SymbolTable st = dg.get(0).getSymbolTable();
checkFirstImport("imported", 2, new String[] { "imported 1", "imported 2", null, null }, st);
assertTrue(st.isLocalTable());
assertEquals(maxLocalId, st.getMaxId());
}
use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.
the class IonReaderBinaryIncrementalTest method symbolTableWithSymbolsThenImports.
@Test
public void symbolTableWithSymbolsThenImports() throws Exception {
SimpleCatalog catalog = new SimpleCatalog();
catalog.putTable(SYSTEM.newSharedSymbolTable("foo", 1, Arrays.asList("abc", "def").iterator()));
readerBuilder = IonReaderBuilder.standard().withCatalog(catalog);
IonReaderBinaryIncremental reader = readerFor(new RawWriterFunction() {
@Override
public void write(_Private_IonRawWriter writer, ByteArrayOutputStream out) throws IOException {
SymbolTable systemTable = SharedSymbolTable.getSystemSymbolTable(1);
writer.addTypeAnnotationSymbol(systemTable.findSymbol("$ion_symbol_table"));
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("symbols"));
writer.stepIn(IonType.LIST);
writer.writeString("ghi");
writer.stepOut();
writer.setFieldNameSymbol(systemTable.findSymbol("imports"));
writer.stepIn(IonType.LIST);
writer.stepIn(IonType.STRUCT);
writer.setFieldNameSymbol(systemTable.findSymbol("name"));
writer.writeString("foo");
writer.setFieldNameSymbol(systemTable.findSymbol("version"));
writer.writeInt(1);
writer.setFieldNameSymbol(systemTable.findSymbol("max_id"));
writer.writeInt(2);
writer.stepOut();
writer.stepOut();
writer.stepOut();
writer.writeSymbolToken(10);
writer.writeSymbolToken(11);
writer.writeSymbolToken(12);
}
});
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("abc", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("def", reader.stringValue());
assertEquals(IonType.SYMBOL, reader.next());
assertEquals("ghi", reader.stringValue());
assertNull(reader.next());
reader.close();
}
use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.
the class ContainerTestCase method checkClones.
private void checkClones(IonContainer c, IonSymbol child) {
IonContainer clone = c.clone();
checkClone(c, child, clone);
// clone w/ same system
clone = system().clone(c);
checkClone(c, child, clone);
// clone w/ other system
clone = newSystem(new SimpleCatalog()).clone(c);
checkClone(c, child, clone);
}
use of com.amazon.ion.system.SimpleCatalog in project ion-java by amzn.
the class CloneTest method testDifferentValueFactoryCloneWithUnknownSymbolText.
@Test
public void testDifferentValueFactoryCloneWithUnknownSymbolText() {
IonSystem otherSystem = newSystem(new SimpleCatalog());
SymbolToken tok = newSymbolToken(99);
IonSymbol original = system().newSymbol(tok);
// TODO amzn/ion-java/issues/30 An UnknownSymbolException is expected here, but
// it isn't thrown.
IonSymbol copy = otherSystem.clone(original);
// If we don't fail we should at least retain the SID.
assertEquals(99, copy.symbolValue().getSid());
}
Aggregations