XmlBackupOps extends BackupOpsBase implements XmlConstants { @Override public Backup read(InputStream input, Map context) { return getXmlPersister().read(Backup.class, input, context); } XmlBackupOps(); @Override Backup read(InputStream input, Map context); @Override void write(Backup backup, OutputStream output, Map context); XmlPersister getXmlPersister();  }
@Test public void testReadRowSet() { Backup expected = new Backup(); expected.setDatabase(new Database()); expected.setFormat("csv"); TableRowSet rowSet = new TableRowSet(); rowSet.setType("table"); rowSet.setName("test.t1"); rowSet.setRowCount(1L); rowSet.setCatalog("test"); rowSet.setTable("t1"); rowSet.addColumn("f1", STRING); Chunk chunk = new Chunk(); chunk.setName("test.t1.csv"); chunk.setRowCount(1L); rowSet.addChunk(chunk); expected.addRowSet(rowSet); String input = "<?xml version=\"1.0\"?>\n" + "<backup version=\"" + Migrator.getVersion() + "\" format=\"csv\">\n" + " <database/>\n" + " <row-set type=\"table\" name=\"test.t1\" row-count=\"1\" catalog=\"test\" table=\"t1\">\n" + " <column name=\"f1\" value-type=\"string\"/>\n" + " <chunk name=\"test.t1.csv\" row-count=\"1\"/>\n" + " </row-set>\n" + "</backup>"; Backup actual = xmlBackupOps.read(toInputStream(input)); assertEquals(actual, expected); }
@Test public void testReadExplicitlyDeclaredTables() { Backup expected = new Backup(); Database database = new Database(); Schema schema = database.addCatalog("test").addSchema(EMPTY); Table foreignTable = schema.addTable("t1"); Column foreignColumn = foreignTable.addColumn("t1_f1"); foreignColumn.setJdbcType(new JdbcType(new JdbcTypeDesc(4, "INT"), newOptions(10, 10, 0))); ForeignKey foreignKey = new ForeignKey("fk_1"); Table primaryTable = schema.addTable("t2"); Column primaryColumn = primaryTable.addColumn("t2_f1"); foreignKey.addReference(primaryColumn, foreignColumn); foreignTable.addForeignKey(foreignKey); expected.setFormat("csv"); expected.setDatabase(database); String input = "<?xml version=\"1.0\"?>\n" + "<backup version=\"" + Migrator.getVersion() + "\" format=\"csv\">\n" + " <database>\n" + " <catalog name=\"test\">\n" + " <schema>\n" + " <table name=\"t1\" type=\"TABLE\">\n" + " <column name=\"t1_f1\">\n" + " <type code=\"4\" name=\"INT\" size=\"10\" precision=\"10\" scale=\"0\"/>\n" + " </column>\n" + " <foreign-key name=\"fk_1\" primary-catalog=\"test\" primary-table=\"t2\" " + "foreign-catalog=\"test\" foreign-table=\"t1\" update-action=\"no_action\" " + "delete-action=\"no_action\" deferrability=\"not_deferrable\">\n" + " <reference primary-column=\"t2_f1\" foreign-column=\"t1_f1\"/>\n" + " </foreign-key>\n" + " </table>\n" + " </schema>\n" + " </catalog>\n" + " </database>\n" + "</backup>"; Backup actual = xmlBackupOps.read(toInputStream(input)); assertEquals(actual, expected); assertEquals(actual.getDatabase().getSchemas(), expected.getDatabase().getSchemas()); }