@Test public void testBuilder() { initializeExpectedTable(2); replay(bigquery); Table builtTable = new Table.Builder(serviceMockReturnsOptions, TABLE_ID1, TABLE_DEFINITION) .setCreationTime(CREATION_TIME) .setDescription(DESCRIPTION) .setEtag(ETAG) .setExpirationTime(EXPIRATION_TIME) .setFriendlyName(FRIENDLY_NAME) .setGeneratedId(GENERATED_ID) .setLastModifiedTime(LAST_MODIFIED_TIME) .setSelfLink(SELF_LINK) .build(); assertEquals(TABLE_ID1, builtTable.getTableId()); assertEquals(CREATION_TIME, builtTable.getCreationTime()); assertEquals(DESCRIPTION, builtTable.getDescription()); assertEquals(ETAG, builtTable.getEtag()); assertEquals(EXPIRATION_TIME, builtTable.getExpirationTime()); assertEquals(FRIENDLY_NAME, builtTable.getFriendlyName()); assertEquals(GENERATED_ID, builtTable.getGeneratedId()); assertEquals(LAST_MODIFIED_TIME, builtTable.getLastModifiedTime()); assertEquals(TABLE_DEFINITION, builtTable.getDefinition()); assertEquals(SELF_LINK, builtTable.getSelfLink()); assertSame(serviceMockReturnsOptions, builtTable.getBigQuery()); }
@Test public void testCreateAndGetTableWithSelectedField() { String tableName = "test_create_and_get_selected_fields_table"; TableId tableId = TableId.of(DATASET, tableName); StandardTableDefinition tableDefinition = StandardTableDefinition.of(TABLE_SCHEMA); Table createdTable = bigquery.create( TableInfo.newBuilder(tableId, tableDefinition) .setLabels(Collections.singletonMap("a", "b")) .build()); assertNotNull(createdTable); assertEquals(DATASET, createdTable.getTableId().getDataset()); assertEquals(tableName, createdTable.getTableId().getTable()); Table remoteTable = bigquery.getTable( DATASET, tableName, TableOption.fields(TableField.CREATION_TIME, TableField.LABELS)); assertNotNull(remoteTable); assertTrue(remoteTable.getDefinition() instanceof StandardTableDefinition); assertEquals(createdTable.getTableId(), remoteTable.getTableId()); assertEquals(TableDefinition.Type.TABLE, remoteTable.getDefinition().getType()); assertThat(remoteTable.getLabels()).containsExactly("a", "b"); assertNotNull(remoteTable.getCreationTime()); assertNull(remoteTable.getDefinition().getSchema()); assertNull(remoteTable.getLastModifiedTime()); assertNull(remoteTable.<StandardTableDefinition>getDefinition().getNumBytes()); assertNull(remoteTable.<StandardTableDefinition>getDefinition().getNumRows()); assertNull(remoteTable.<StandardTableDefinition>getDefinition().getTimePartitioning()); assertNull(remoteTable.<StandardTableDefinition>getDefinition().getClustering()); assertTrue(remoteTable.delete()); }
@Test public void testUpdateTableWithSelectedFields() { String tableName = "test_update_with_selected_fields_table"; StandardTableDefinition tableDefinition = StandardTableDefinition.of(TABLE_SCHEMA); TableInfo tableInfo = TableInfo.of(TableId.of(DATASET, tableName), tableDefinition); Table createdTable = bigquery.create(tableInfo); assertNotNull(createdTable); Table updatedTable = bigquery.update( tableInfo.toBuilder().setDescription("newDescr").build(), TableOption.fields(TableField.DESCRIPTION)); assertTrue(updatedTable.getDefinition() instanceof StandardTableDefinition); assertEquals(DATASET, updatedTable.getTableId().getDataset()); assertEquals(tableName, updatedTable.getTableId().getTable()); assertEquals("newDescr", updatedTable.getDescription()); assertNull(updatedTable.getDefinition().getSchema()); assertNull(updatedTable.getLastModifiedTime()); assertNull(updatedTable.<StandardTableDefinition>getDefinition().getNumBytes()); assertNull(updatedTable.<StandardTableDefinition>getDefinition().getNumRows()); assertTrue(createdTable.delete()); }
assertEquals(TABLE_SCHEMA, remoteTable.getDefinition().getSchema()); assertNotNull(remoteTable.getCreationTime()); assertNotNull(remoteTable.getLastModifiedTime()); assertNotNull(remoteTable.<StandardTableDefinition>getDefinition().getNumBytes()); assertNotNull(remoteTable.<StandardTableDefinition>getDefinition().getNumRows());