WriteChannelConfiguration setProjectId(String projectId) { if (Strings.isNullOrEmpty(getDestinationTable().getProject())) { return toBuilder().setDestinationTable(getDestinationTable().setProjectId(projectId)).build(); } return this; }
@Test public void testOf() { WriteChannelConfiguration configuration = WriteChannelConfiguration.of(TABLE_ID); assertEquals(TABLE_ID, configuration.getDestinationTable()); configuration = WriteChannelConfiguration.of(TABLE_ID, CSV_OPTIONS); assertEquals(TABLE_ID, configuration.getDestinationTable()); assertEquals(FORMAT, configuration.getFormat()); assertEquals(CSV_OPTIONS, configuration.getCsvOptions()); }
@Test public void testSetProjectIdDoNotOverride() { WriteChannelConfiguration configuration = WriteChannelConfiguration.of(TABLE_ID).setProjectId("project"); configuration.setProjectId("different-project").toBuilder(); assertEquals("project", configuration.getDestinationTable().getProject()); }
@Test public void testToBuilder() { compareLoadConfiguration(LOAD_CONFIGURATION_CSV, LOAD_CONFIGURATION_CSV.toBuilder().build()); WriteChannelConfiguration configuration = LOAD_CONFIGURATION_CSV .toBuilder() .setDestinationTable(TableId.of("dataset", "newTable")) .build(); assertEquals("newTable", configuration.getDestinationTable().getTable()); configuration = configuration.toBuilder().setDestinationTable(TABLE_ID).build(); compareLoadConfiguration(LOAD_CONFIGURATION_CSV, configuration); }
private void compareLoadConfiguration( WriteChannelConfiguration expected, WriteChannelConfiguration value) { assertEquals(expected, value); assertEquals(expected.hashCode(), value.hashCode()); assertEquals(expected.toString(), value.toString()); assertEquals(expected.getDestinationTable(), value.getDestinationTable()); assertEquals(expected.getCreateDisposition(), value.getCreateDisposition()); assertEquals(expected.getWriteDisposition(), value.getWriteDisposition()); assertEquals(expected.getNullMarker(), value.getNullMarker()); assertEquals(expected.getCsvOptions(), value.getCsvOptions()); assertEquals(expected.getFormat(), value.getFormat()); assertEquals(expected.ignoreUnknownValues(), value.ignoreUnknownValues()); assertEquals(expected.getMaxBadRecords(), value.getMaxBadRecords()); assertEquals(expected.getDatastoreBackupOptions(), value.getDatastoreBackupOptions()); assertEquals(expected.getSchema(), value.getSchema()); assertEquals(expected.getSchemaUpdateOptions(), value.getSchemaUpdateOptions()); assertEquals(expected.getAutodetect(), value.getAutodetect()); assertEquals(expected.getTimePartitioning(), value.getTimePartitioning()); assertEquals(expected.getClustering(), value.getClustering()); } }
@Test public void testBuilder() { assertEquals(TABLE_ID, LOAD_CONFIGURATION_CSV.getDestinationTable()); assertEquals(CREATE_DISPOSITION, LOAD_CONFIGURATION_CSV.getCreateDisposition()); assertEquals(WRITE_DISPOSITION, LOAD_CONFIGURATION_CSV.getWriteDisposition()); .setAutodetect(AUTODETECT); WriteChannelConfiguration loadConfigurationCSV = builder.build(); assertEquals(TABLE_ID, loadConfigurationCSV.getDestinationTable()); assertEquals(CREATE_DISPOSITION, loadConfigurationCSV.getCreateDisposition()); assertEquals(WRITE_DISPOSITION, loadConfigurationCSV.getWriteDisposition());
WriteChannelConfiguration setProjectId(String projectId) { if (Strings.isNullOrEmpty(getDestinationTable().getProject())) { return toBuilder().setDestinationTable(getDestinationTable().setProjectId(projectId)).build(); } return this; }