Skip to content

Commit

Permalink
adding test case
Browse files Browse the repository at this point in the history
  • Loading branch information
maitrimangal committed Oct 13, 2023
1 parent f5bbd21 commit 7809e1d
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
5 changes: 5 additions & 0 deletions samples/install-without-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@
<artifactId>google-cloud-bigquery</artifactId>
<version>2.33.1</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>2.28.0</version>
</dependency>
</dependencies>

<!-- compile and run all snippet tests -->
Expand Down
5 changes: 5 additions & 0 deletions samples/snapshot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@
<artifactId>google-cloud-bigquery</artifactId>
<version>2.33.1</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>2.28.0</version>
</dependency>
</dependencies>

<!-- compile and run all snippet tests -->
Expand Down
4 changes: 4 additions & 0 deletions samples/snippets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-bigquery</artifactId>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
</dependency>
<dependency>
<groupId>org.apache.avro</groupId>
<artifactId>avro</artifactId>
Expand Down
41 changes: 41 additions & 0 deletions samples/snippets/src/test/java/pubsub/AdminIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.Timeout;
import com.google.cloud.storage.Bucket;
import com.google.cloud.storage.BucketInfo;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.StorageClass;
import com.google.cloud.storage.StorageOptions;

public class AdminIT {
private ByteArrayOutputStream bout;
Expand All @@ -64,6 +69,11 @@ public class AdminIT {
private static final String bigquerySubscriptionId = "iam-bigquery-subscription-" + _suffix;
private static final String bigqueryTableId = "java_samples_table_" + _suffix;

private static final String cloudStorageSubscriptionId = "iam-cloudstorage-subscription-" + _suffix;
private static final String cloudStorageBucketName = "java_samples_gcs_bucket_" + _suffix;
private static final String cloudStorageFilenamePrefix = "log_events_";
private static final String cloudStorageFilenameSuffix = ".text";

private static final TopicName topicName = TopicName.of(projectId, topicId);
private static final SubscriptionName pullSubscriptionName =
SubscriptionName.of(projectId, pullSubscriptionId);
Expand Down Expand Up @@ -97,6 +107,9 @@ public void setUp() throws Exception {

// Create table for BigQuery subscription.
createBigQueryTable();

// Create bucket for CloudStorage subscription
createCloudStorageBucket();
}

@After
Expand Down Expand Up @@ -124,6 +137,9 @@ public void tearDown() throws Exception {
// Delete BigQuery table.
deleteBigQueryTable();

//Delete GCS Bucket
deleteCloudStorageBucket();

System.setOut(null);
}

Expand Down Expand Up @@ -153,6 +169,22 @@ private void deleteBigQueryTable() throws Exception {
bigquery.delete(datasetId, BigQuery.DatasetDeleteOption.deleteContents());
}

private void createCloudStorageBucket() throws Exception {
Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
String location = "ASIA";
Bucket bucket =
storage.create(
BucketInfo.newBuilder(cloudStorageBucketName)
.setLocation(location)
.build());
}

private void deleteCloudStorageBucket() throws Exception {
Storage storage = StorageOptions.newBuilder().setProjectId(projectId).build().getService();
Bucket bucket = storage.get(cloudStorageBucketName);
bucket.delete();
}

@Test
public void testAdmin() throws Exception {
// Test create topic.
Expand Down Expand Up @@ -264,13 +296,22 @@ public void testAdmin() throws Exception {
assertThat(bout.toString()).contains("Created a BigQuery subscription:");
assertThat(bout.toString()).contains(bigqueryTablePath);

bout.reset();
// Test create a CloudStorage susbscription
CreateCloudStorageSubscriptionExample.createCloudStorageSubscription(
projectId, topicId, cloudStorageSubscriptionId, cloudStorageBucketName,
cloudStorageFilenamePrefix, cloudStorageFilenameSuffix);
assertThat(bout.toString()).contains("Created a CloudStorage subscription:");
assertThat(bout.toString()).contains(cloudStorageBucketName);

bout.reset();
// Test delete subscription.
DeleteSubscriptionExample.deleteSubscriptionExample(projectId, pullSubscriptionId);
DeleteSubscriptionExample.deleteSubscriptionExample(projectId, pushSubscriptionId);
DeleteSubscriptionExample.deleteSubscriptionExample(projectId, orderedSubscriptionId);
DeleteSubscriptionExample.deleteSubscriptionExample(projectId, exactlyOnceSubscriptionId);
DeleteSubscriptionExample.deleteSubscriptionExample(projectId, bigquerySubscriptionId);
DeleteSubscriptionExample.deleteSubscriptionExample(projectId, cloudStorageSubscriptionId);
assertThat(bout.toString()).contains("Deleted subscription.");

bout.reset();
Expand Down

0 comments on commit 7809e1d

Please sign in to comment.