Skip to content

Commit

Permalink
Fix inspect tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sushicw committed Jun 3, 2020
1 parent 0ae4d1c commit 0f58e94
Showing 1 changed file with 8 additions and 40 deletions.
48 changes: 8 additions & 40 deletions dlp/src/test/java/dlp/snippets/InspectTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@
import com.google.cloud.dlp.v2.DlpServiceClient;
import com.google.privacy.dlp.v2.CancelDlpJobRequest;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -124,60 +122,30 @@ public void testInspectImageFile() {
}

@Test
public void testInspectGcsFile() throws InterruptedException, ExecutionException, IOException {

public void testInspectGcsFile() throws Exception {
InspectGcsFile.inspectGcsFile(PROJECT_ID, GCS_PATH, TOPIC_ID, SUBSCRIPTION_ID);
// Await job creation
TimeUnit.SECONDS.sleep(3);

String output = bout.toString();
assertThat(output, containsString("Job created: "));

// Cancelling the job early to conserve quota
String jobId = output.split("Job created: ")[1].split("\n")[0];
CancelDlpJobRequest request = CancelDlpJobRequest.newBuilder().setName(jobId).build();
try (DlpServiceClient client = DlpServiceClient.create()) {
client.cancelDlpJob(request);
}
assertThat(output, containsString("Job status: DONE"));
}

@Test
public void testInspectDatastoreEntity()
throws InterruptedException, ExecutionException, IOException {
public void testInspectDatastoreEntity() throws Exception {

InspectDatastoreEntity.insepctDatastoreEntity(
PROJECT_ID, datastoreNamespace, datastoreKind, TOPIC_ID, SUBSCRIPTION_ID);
// Await job creation
TimeUnit.SECONDS.sleep(3);

String output = bout.toString();
assertThat(output, containsString("Job created: "));

// Cancelling the job early to conserve quota
String jobId = output.split("Job created: ")[1].split("\n")[0];
CancelDlpJobRequest request = CancelDlpJobRequest.newBuilder().setName(jobId).build();
try (DlpServiceClient client = DlpServiceClient.create()) {
client.cancelDlpJob(request);
}
assertThat(output, containsString("Job status: DONE"));
}

@Test
public void testInspectBigQueryTable()
throws InterruptedException, ExecutionException, IOException {
public void testInspectBigQueryTable() throws Exception {

InspectBigQueryTable.inspectBigQueryTable(
PROJECT_ID, DATASET_ID, TABLE_ID, TOPIC_ID, SUBSCRIPTION_ID);
// Await job creation
TimeUnit.SECONDS.sleep(3);
InspectBigQueryTable
.inspectBigQueryTable(PROJECT_ID, DATASET_ID, TABLE_ID, TOPIC_ID, SUBSCRIPTION_ID);

String output = bout.toString();
assertThat(output, containsString("Job created: "));

// Cancelling the job early to conserve quota
String jobId = output.split("Job created: ")[1].split("\n")[0];
CancelDlpJobRequest request = CancelDlpJobRequest.newBuilder().setName(jobId).build();
try (DlpServiceClient client = DlpServiceClient.create()) {
client.cancelDlpJob(request);
}
assertThat(output, containsString("Job status: DONE"));
}
}

0 comments on commit 0f58e94

Please sign in to comment.