2222import com .google .api .gax .grpc .testing .MockServiceHelper ;
2323import com .google .api .gax .rpc .InvalidArgumentException ;
2424import com .google .longrunning .Operation ;
25+ import com .google .privacy .dlp .v2beta1 .CloudStorageOptions ;
26+ import com .google .privacy .dlp .v2beta1 .CloudStorageOptions .FileSet ;
2527import com .google .privacy .dlp .v2beta1 .ContentItem ;
2628import com .google .privacy .dlp .v2beta1 .CreateInspectOperationRequest ;
29+ import com .google .privacy .dlp .v2beta1 .InfoType ;
2730import com .google .privacy .dlp .v2beta1 .InspectConfig ;
2831import com .google .privacy .dlp .v2beta1 .InspectContentRequest ;
2932import com .google .privacy .dlp .v2beta1 .InspectContentResponse ;
4548import io .grpc .Status ;
4649import io .grpc .StatusRuntimeException ;
4750import java .io .IOException ;
48- import java .util .ArrayList ;
4951import java .util .Arrays ;
5052import java .util .List ;
5153import java .util .concurrent .ExecutionException ;
@@ -79,7 +81,7 @@ public static void stopServer() {
7981 public void setUp () throws IOException {
8082 serviceHelper .reset ();
8183 DlpServiceSettings settings =
82- DlpServiceSettings .defaultBuilder ()
84+ DlpServiceSettings .newBuilder ()
8385 .setTransportProvider (
8486 GrpcTransportProvider .newBuilder ()
8587 .setChannelProvider (serviceHelper .createChannelProvider ())
@@ -100,8 +102,14 @@ public void inspectContentTest() {
100102 InspectContentResponse expectedResponse = InspectContentResponse .newBuilder ().build ();
101103 mockDlpService .addResponse (expectedResponse );
102104
103- InspectConfig inspectConfig = InspectConfig .newBuilder ().build ();
104- List <ContentItem > items = new ArrayList <>();
105+ String name = "EMAIL_ADDRESS" ;
106+ InfoType infoTypesElement = InfoType .newBuilder ().setName (name ).build ();
107+ List <InfoType > infoTypes = Arrays .asList (infoTypesElement );
108+ InspectConfig inspectConfig = InspectConfig .newBuilder ().addAllInfoTypes (infoTypes ).build ();
109+ String type = "text/plain" ;
110+ String value =
"My email is [email protected] ." ;
111+ ContentItem itemsElement = ContentItem .newBuilder ().setType (type ).setValue (value ).build ();
112+ List <ContentItem > items = Arrays .asList (itemsElement );
105113
106114 InspectContentResponse actualResponse = client .inspectContent (inspectConfig , items );
107115 Assert .assertEquals (expectedResponse , actualResponse );
@@ -121,8 +129,14 @@ public void inspectContentExceptionTest() throws Exception {
121129 mockDlpService .addException (exception );
122130
123131 try {
124- InspectConfig inspectConfig = InspectConfig .newBuilder ().build ();
125- List <ContentItem > items = new ArrayList <>();
132+ String name = "EMAIL_ADDRESS" ;
133+ InfoType infoTypesElement = InfoType .newBuilder ().setName (name ).build ();
134+ List <InfoType > infoTypes = Arrays .asList (infoTypesElement );
135+ InspectConfig inspectConfig = InspectConfig .newBuilder ().addAllInfoTypes (infoTypes ).build ();
136+ String type = "text/plain" ;
137+ String value =
"My email is [email protected] ." ;
138+ ContentItem itemsElement = ContentItem .newBuilder ().setType (type ).setValue (value ).build ();
139+ List <ContentItem > items = Arrays .asList (itemsElement );
126140
127141 client .inspectContent (inspectConfig , items );
128142 Assert .fail ("No exception raised" );
@@ -137,9 +151,23 @@ public void redactContentTest() {
137151 RedactContentResponse expectedResponse = RedactContentResponse .newBuilder ().build ();
138152 mockDlpService .addResponse (expectedResponse );
139153
140- InspectConfig inspectConfig = InspectConfig .newBuilder ().build ();
141- List <ContentItem > items = new ArrayList <>();
142- List <RedactContentRequest .ReplaceConfig > replaceConfigs = new ArrayList <>();
154+ String name = "EMAIL_ADDRESS" ;
155+ InfoType infoTypesElement = InfoType .newBuilder ().setName (name ).build ();
156+ List <InfoType > infoTypes = Arrays .asList (infoTypesElement );
157+ InspectConfig inspectConfig = InspectConfig .newBuilder ().addAllInfoTypes (infoTypes ).build ();
158+ String type = "text/plain" ;
159+ String value =
"My email is [email protected] ." ;
160+ ContentItem itemsElement = ContentItem .newBuilder ().setType (type ).setValue (value ).build ();
161+ List <ContentItem > items = Arrays .asList (itemsElement );
162+ String name2 = "EMAIL_ADDRESS" ;
163+ InfoType infoType = InfoType .newBuilder ().setName (name2 ).build ();
164+ String replaceWith = "REDACTED" ;
165+ RedactContentRequest .ReplaceConfig replaceConfigsElement =
166+ RedactContentRequest .ReplaceConfig .newBuilder ()
167+ .setInfoType (infoType )
168+ .setReplaceWith (replaceWith )
169+ .build ();
170+ List <RedactContentRequest .ReplaceConfig > replaceConfigs = Arrays .asList (replaceConfigsElement );
143171
144172 RedactContentResponse actualResponse =
145173 client .redactContent (inspectConfig , items , replaceConfigs );
@@ -161,9 +189,24 @@ public void redactContentExceptionTest() throws Exception {
161189 mockDlpService .addException (exception );
162190
163191 try {
164- InspectConfig inspectConfig = InspectConfig .newBuilder ().build ();
165- List <ContentItem > items = new ArrayList <>();
166- List <RedactContentRequest .ReplaceConfig > replaceConfigs = new ArrayList <>();
192+ String name = "EMAIL_ADDRESS" ;
193+ InfoType infoTypesElement = InfoType .newBuilder ().setName (name ).build ();
194+ List <InfoType > infoTypes = Arrays .asList (infoTypesElement );
195+ InspectConfig inspectConfig = InspectConfig .newBuilder ().addAllInfoTypes (infoTypes ).build ();
196+ String type = "text/plain" ;
197+ String value =
"My email is [email protected] ." ;
198+ ContentItem itemsElement = ContentItem .newBuilder ().setType (type ).setValue (value ).build ();
199+ List <ContentItem > items = Arrays .asList (itemsElement );
200+ String name2 = "EMAIL_ADDRESS" ;
201+ InfoType infoType = InfoType .newBuilder ().setName (name2 ).build ();
202+ String replaceWith = "REDACTED" ;
203+ RedactContentRequest .ReplaceConfig replaceConfigsElement =
204+ RedactContentRequest .ReplaceConfig .newBuilder ()
205+ .setInfoType (infoType )
206+ .setReplaceWith (replaceWith )
207+ .build ();
208+ List <RedactContentRequest .ReplaceConfig > replaceConfigs =
209+ Arrays .asList (replaceConfigsElement );
167210
168211 client .redactContent (inspectConfig , items , replaceConfigs );
169212 Assert .fail ("No exception raised" );
@@ -175,9 +218,9 @@ public void redactContentExceptionTest() throws Exception {
175218 @ Test
176219 @ SuppressWarnings ("all" )
177220 public void createInspectOperationTest () throws Exception {
178- ResultName name = ResultName .create ("[RESULT]" );
221+ ResultName name2 = ResultName .create ("[RESULT]" );
179222 InspectOperationResult expectedResponse =
180- InspectOperationResult .newBuilder ().setNameWithResultName (name ).build ();
223+ InspectOperationResult .newBuilder ().setNameWithResultName (name2 ).build ();
181224 Operation resultOperation =
182225 Operation .newBuilder ()
183226 .setName ("createInspectOperationTest" )
@@ -186,8 +229,17 @@ public void createInspectOperationTest() throws Exception {
186229 .build ();
187230 mockDlpService .addResponse (resultOperation );
188231
189- InspectConfig inspectConfig = InspectConfig .newBuilder ().build ();
190- StorageConfig storageConfig = StorageConfig .newBuilder ().build ();
232+ String name = "EMAIL_ADDRESS" ;
233+ InfoType infoTypesElement = InfoType .newBuilder ().setName (name ).build ();
234+ List <InfoType > infoTypes = Arrays .asList (infoTypesElement );
235+ InspectConfig inspectConfig = InspectConfig .newBuilder ().addAllInfoTypes (infoTypes ).build ();
236+ String url = "gs://example_bucket/example_file.png" ;
237+ CloudStorageOptions .FileSet fileSet =
238+ CloudStorageOptions .FileSet .newBuilder ().setUrl (url ).build ();
239+ CloudStorageOptions cloudStorageOptions =
240+ CloudStorageOptions .newBuilder ().setFileSet (fileSet ).build ();
241+ StorageConfig storageConfig =
242+ StorageConfig .newBuilder ().setCloudStorageOptions (cloudStorageOptions ).build ();
191243 OutputStorageConfig outputConfig = OutputStorageConfig .newBuilder ().build ();
192244
193245 InspectOperationResult actualResponse =
@@ -211,8 +263,17 @@ public void createInspectOperationExceptionTest() throws Exception {
211263 mockDlpService .addException (exception );
212264
213265 try {
214- InspectConfig inspectConfig = InspectConfig .newBuilder ().build ();
215- StorageConfig storageConfig = StorageConfig .newBuilder ().build ();
266+ String name = "EMAIL_ADDRESS" ;
267+ InfoType infoTypesElement = InfoType .newBuilder ().setName (name ).build ();
268+ List <InfoType > infoTypes = Arrays .asList (infoTypesElement );
269+ InspectConfig inspectConfig = InspectConfig .newBuilder ().addAllInfoTypes (infoTypes ).build ();
270+ String url = "gs://example_bucket/example_file.png" ;
271+ CloudStorageOptions .FileSet fileSet =
272+ CloudStorageOptions .FileSet .newBuilder ().setUrl (url ).build ();
273+ CloudStorageOptions cloudStorageOptions =
274+ CloudStorageOptions .newBuilder ().setFileSet (fileSet ).build ();
275+ StorageConfig storageConfig =
276+ StorageConfig .newBuilder ().setCloudStorageOptions (cloudStorageOptions ).build ();
216277 OutputStorageConfig outputConfig = OutputStorageConfig .newBuilder ().build ();
217278
218279 client .createInspectOperationAsync (inspectConfig , storageConfig , outputConfig ).get ();
@@ -268,8 +329,8 @@ public void listInfoTypesTest() {
268329 ListInfoTypesResponse expectedResponse = ListInfoTypesResponse .newBuilder ().build ();
269330 mockDlpService .addResponse (expectedResponse );
270331
271- String category = "category50511102 " ;
272- String languageCode = "languageCode-412800396 " ;
332+ String category = "PII " ;
333+ String languageCode = "en " ;
273334
274335 ListInfoTypesResponse actualResponse = client .listInfoTypes (category , languageCode );
275336 Assert .assertEquals (expectedResponse , actualResponse );
@@ -289,8 +350,8 @@ public void listInfoTypesExceptionTest() throws Exception {
289350 mockDlpService .addException (exception );
290351
291352 try {
292- String category = "category50511102 " ;
293- String languageCode = "languageCode-412800396 " ;
353+ String category = "PII " ;
354+ String languageCode = "en " ;
294355
295356 client .listInfoTypes (category , languageCode );
296357 Assert .fail ("No exception raised" );
@@ -305,7 +366,7 @@ public void listRootCategoriesTest() {
305366 ListRootCategoriesResponse expectedResponse = ListRootCategoriesResponse .newBuilder ().build ();
306367 mockDlpService .addResponse (expectedResponse );
307368
308- String languageCode = "languageCode-412800396 " ;
369+ String languageCode = "en " ;
309370
310371 ListRootCategoriesResponse actualResponse = client .listRootCategories (languageCode );
311372 Assert .assertEquals (expectedResponse , actualResponse );
@@ -324,7 +385,7 @@ public void listRootCategoriesExceptionTest() throws Exception {
324385 mockDlpService .addException (exception );
325386
326387 try {
327- String languageCode = "languageCode-412800396 " ;
388+ String languageCode = "en " ;
328389
329390 client .listRootCategories (languageCode );
330391 Assert .fail ("No exception raised" );
0 commit comments