Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions asset/src/test/java/com/example/asset/QuickStartIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,35 @@
import com.google.cloud.asset.v1.ContentType;
import com.google.cloud.bigquery.BigQuery;
import com.google.cloud.bigquery.BigQuery.DatasetDeleteOption;
import com.google.cloud.bigquery.BigQueryException;
import com.google.cloud.bigquery.BigQueryOptions;
import com.google.cloud.bigquery.Dataset;
import com.google.cloud.bigquery.DatasetId;
import com.google.cloud.bigquery.DatasetInfo;
import com.google.cloud.bigquery.testing.RemoteBigQueryHelper;
import com.google.cloud.storage.BlobInfo;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.Storage.BlobListOption;
import com.google.cloud.storage.StorageOptions;
import com.google.cloud.testing.junit4.MultipleAttemptsRule;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/** Tests for quickstart sample. */
@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class QuickStartIT {
@Rule public final Timeout testTimeout = new Timeout(10, TimeUnit.MINUTES);
@Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3);

private static final String bucketName = "java-docs-samples-testing";
private static final String path = UUID.randomUUID().toString();
private static final String datasetName = RemoteBigQueryHelper.generateDatasetName();
Expand All @@ -69,9 +76,6 @@ private static final void deleteObjects() {
@Before
public void setUp() {
bigquery = BigQueryOptions.getDefaultInstance().getService();
if (bigquery.getDataset(datasetName) == null) {
Dataset dataset = bigquery.create(DatasetInfo.newBuilder(datasetName).build());
}
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
Expand All @@ -98,8 +102,7 @@ public void testExportAssetExample() throws Exception {

@Test
public void testExportAssetBigqueryPerTypeExample() throws Exception {
String dataset =
String.format("projects/%s/datasets/%s", ServiceOptions.getDefaultProjectId(), datasetName);
String dataset = getDataset();
String table = "java_test_per_type";
ExportAssetsBigqueryExample.exportBigQuery(
dataset, table, ContentType.RESOURCE, /*perType*/ true);
Expand All @@ -109,8 +112,7 @@ public void testExportAssetBigqueryPerTypeExample() throws Exception {

@Test
public void testExportAssetBigqueryExample() throws Exception {
String dataset =
String.format("projects/%s/datasets/%s", ServiceOptions.getDefaultProjectId(), datasetName);
String dataset = getDataset();
String table = "java_test";
ExportAssetsBigqueryExample.exportBigQuery(
dataset, table, ContentType.RESOURCE, /*perType*/ false);
Expand All @@ -127,4 +129,13 @@ public void testBatchGetAssetsHistory() throws Exception {
assertThat(got).contains(bucketAssetName);
}
}

protected String getDataset() throws BigQueryException {
if (bigquery.getDataset(datasetName) == null) {
bigquery.create(DatasetInfo.newBuilder(datasetName).build());
}
return String.format(
"projects/%s/datasets/%s", ServiceOptions.getDefaultProjectId(), datasetName);

}
}
3 changes: 3 additions & 0 deletions automl/src/test/java/beta/automl/TablesCreateModelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.TestCase.assertNotNull;

import com.google.cloud.testing.junit4.MultipleAttemptsRule;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
Expand All @@ -27,13 +28,15 @@
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class TablesCreateModelTest {
@Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3);

private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String DATASET_ID = "TBL00000000000000000000";
Expand Down
3 changes: 3 additions & 0 deletions automl/src/test/java/beta/automl/TablesPredictTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.cloud.automl.v1.DeployModelRequest;
import com.google.cloud.automl.v1.Model;
import com.google.cloud.automl.v1.ModelName;
import com.google.cloud.testing.junit4.MultipleAttemptsRule;
import com.google.protobuf.Value;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand All @@ -33,13 +34,15 @@
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class TablesPredictTest {
@Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3);

private static final String PROJECT_ID = System.getenv("GOOGLE_CLOUD_PROJECT");
private static final String MODEL_ID = "TBL7972827093840953344";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.google.common.truth.Truth.assertThat;
import static junit.framework.TestCase.assertNotNull;

import com.google.cloud.testing.junit4.MultipleAttemptsRule;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
Expand All @@ -27,13 +28,15 @@
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
@SuppressWarnings("checkstyle:abbreviationaswordinname")
public class LanguageTextClassificationCreateModelTest {
@Rule public final MultipleAttemptsRule multipleAttemptsRule = new MultipleAttemptsRule(3);

private static final String PROJECT_ID = System.getenv("AUTOML_PROJECT_ID");
private static final String DATASET_ID = "TCN00000000000000000000";
Expand Down