|
20 | 20 | import static org.hamcrest.core.StringContains.containsString;
|
21 | 21 | import static org.junit.Assert.assertNotNull;
|
22 | 22 |
|
| 23 | +import com.google.cloud.dlp.v2.DlpServiceClient; |
| 24 | +import com.google.privacy.dlp.v2.CancelDlpJobRequest; |
23 | 25 | import java.io.ByteArrayOutputStream;
|
24 | 26 | import java.io.IOException;
|
25 | 27 | import java.io.PrintStream;
|
26 | 28 | import java.util.concurrent.ExecutionException;
|
| 29 | +import java.util.concurrent.TimeUnit; |
27 | 30 | import org.junit.After;
|
28 | 31 | import org.junit.Before;
|
29 | 32 | import org.junit.Test;
|
@@ -100,31 +103,59 @@ public void testInspectImageFile() {
|
100 | 103 |
|
101 | 104 | @Test
|
102 | 105 | public void testInspectGcsFile() throws InterruptedException, ExecutionException, IOException {
|
| 106 | + |
103 | 107 | InspectGcsFile.inspectGcsFile(PROJECT_ID, GCS_PATH, TOPIC_ID, SUBSCRIPTION_ID);
|
| 108 | + // Await job creation |
| 109 | + TimeUnit.SECONDS.sleep(3); |
104 | 110 |
|
105 | 111 | String output = bout.toString();
|
106 |
| - assertThat(output, containsString("Info type: PHONE_NUMBER")); |
107 |
| - assertThat(output, containsString("Info type: EMAIL_ADDRESS")); |
| 112 | + assertThat(output, containsString("Job created: ")); |
| 113 | + |
| 114 | + // Cancelling the job early to conserve quota |
| 115 | + String jobId = output.split("Job created: ")[1].split("\n")[0]; |
| 116 | + CancelDlpJobRequest request = CancelDlpJobRequest.newBuilder().setName(jobId).build(); |
| 117 | + try (DlpServiceClient client = DlpServiceClient.create()) { |
| 118 | + client.cancelDlpJob(request); |
| 119 | + } |
108 | 120 | }
|
109 | 121 |
|
110 | 122 | @Test
|
111 | 123 | public void testInspectDatastoreEntity()
|
112 | 124 | throws InterruptedException, ExecutionException, IOException {
|
| 125 | + |
113 | 126 | InspectDatastoreEntity.insepctDatastoreEntity(
|
114 | 127 | PROJECT_ID, datastoreNamespace, datastoreKind, TOPIC_ID, SUBSCRIPTION_ID);
|
| 128 | + // Await job creation |
| 129 | + TimeUnit.SECONDS.sleep(3); |
115 | 130 |
|
116 | 131 | String output = bout.toString();
|
117 |
| - assertThat(output, containsString("Info type: PHONE_NUMBER")); |
118 |
| - assertThat(output, containsString("Info type: EMAIL_ADDRESS")); |
| 132 | + assertThat(output, containsString("Job created: ")); |
| 133 | + |
| 134 | + // Cancelling the job early to conserve quota |
| 135 | + String jobId = output.split("Job created: ")[1].split("\n")[0]; |
| 136 | + CancelDlpJobRequest request = CancelDlpJobRequest.newBuilder().setName(jobId).build(); |
| 137 | + try (DlpServiceClient client = DlpServiceClient.create()) { |
| 138 | + client.cancelDlpJob(request); |
| 139 | + } |
119 | 140 | }
|
120 | 141 |
|
121 | 142 | @Test
|
122 | 143 | public void testInspectBigQueryTable()
|
123 | 144 | throws InterruptedException, ExecutionException, IOException {
|
| 145 | + |
124 | 146 | InspectBigQueryTable.inspectBigQueryTable(
|
125 | 147 | PROJECT_ID, DATASET_ID, TABLE_ID, TOPIC_ID, SUBSCRIPTION_ID);
|
| 148 | + // Await job creation |
| 149 | + TimeUnit.SECONDS.sleep(3); |
126 | 150 |
|
127 | 151 | String output = bout.toString();
|
128 |
| - assertThat(output, containsString("Info type: PHONE_NUMBER")); |
| 152 | + assertThat(output, containsString("Job created: ")); |
| 153 | + |
| 154 | + // Cancelling the job early to conserve quota |
| 155 | + String jobId = output.split("Job created: ")[1].split("\n")[0]; |
| 156 | + CancelDlpJobRequest request = CancelDlpJobRequest.newBuilder().setName(jobId).build(); |
| 157 | + try (DlpServiceClient client = DlpServiceClient.create()) { |
| 158 | + client.cancelDlpJob(request); |
| 159 | + } |
129 | 160 | }
|
130 | 161 | }
|
0 commit comments