9999import io .grpc .Status ;
100100import io .grpc .Status .Code ;
101101import java .io .IOException ;
102+ import java .net .URISyntaxException ;
103+ import java .net .URL ;
104+ import java .nio .file .Files ;
105+ import java .nio .file .Paths ;
102106import java .util .List ;
103107import java .util .Map ;
104108import java .util .concurrent .ExecutionException ;
@@ -1339,6 +1343,7 @@ public void testCreateSchemaBundle() throws IOException {
13391343 // Setup
13401344 Mockito .when (mockStub .createSchemaBundleOperationCallable ())
13411345 .thenReturn (mockCreateSchemaBundleOperationCallable );
1346+ byte [] content = Files .readAllBytes (Paths .get (getResourceFilePath (TEST_PROTO_SCHEMA_BUNDLE )));
13421347
13431348 com .google .bigtable .admin .v2 .CreateSchemaBundleRequest expectedRequest =
13441349 com .google .bigtable .admin .v2 .CreateSchemaBundleRequest .newBuilder ()
@@ -1348,7 +1353,7 @@ public void testCreateSchemaBundle() throws IOException {
13481353 com .google .bigtable .admin .v2 .SchemaBundle .newBuilder ()
13491354 .setProtoSchema (
13501355 com .google .bigtable .admin .v2 .ProtoSchema .newBuilder ()
1351- .setProtoDescriptors (ByteString .copyFromUtf8 ( "schema" ))))
1356+ .setProtoDescriptors (ByteString .copyFrom ( content ))))
13521357 .build ();
13531358
13541359 com .google .bigtable .admin .v2 .SchemaBundle expectedResponse =
@@ -1358,7 +1363,7 @@ public void testCreateSchemaBundle() throws IOException {
13581363 PROJECT_ID , INSTANCE_ID , TABLE_ID , SCHEMA_BUNDLE_ID ))
13591364 .setProtoSchema (
13601365 com .google .bigtable .admin .v2 .ProtoSchema .newBuilder ()
1361- .setProtoDescriptors (ByteString .copyFromUtf8 ( "schema" )))
1366+ .setProtoDescriptors (ByteString .copyFrom ( content )))
13621367 .build ();
13631368
13641369 mockOperationResult (
@@ -1371,7 +1376,7 @@ public void testCreateSchemaBundle() throws IOException {
13711376
13721377 CreateSchemaBundleRequest req =
13731378 CreateSchemaBundleRequest .of (TABLE_ID , SCHEMA_BUNDLE_ID )
1374- .setProtoSchema (TEST_PROTO_SCHEMA_BUNDLE );
1379+ .setProtoSchema (getResourceFilePath ( TEST_PROTO_SCHEMA_BUNDLE ) );
13751380
13761381 // Execute
13771382 SchemaBundle actualResult = adminClient .createSchemaBundle (req );
@@ -1385,6 +1390,8 @@ public void testUpdateSchemaBundle() throws IOException {
13851390 // Setup
13861391 Mockito .when (mockStub .updateSchemaBundleOperationCallable ())
13871392 .thenReturn (mockUpdateSchemaBundleOperationCallable );
1393+ byte [] content =
1394+ Files .readAllBytes (Paths .get (getResourceFilePath (TEST_UPDATED_PROTO_SCHEMA_BUNDLE )));
13881395
13891396 com .google .bigtable .admin .v2 .UpdateSchemaBundleRequest expectedRequest =
13901397 com .google .bigtable .admin .v2 .UpdateSchemaBundleRequest .newBuilder ()
@@ -1395,7 +1402,7 @@ public void testUpdateSchemaBundle() throws IOException {
13951402 PROJECT_ID , INSTANCE_ID , TABLE_ID , SCHEMA_BUNDLE_ID ))
13961403 .setProtoSchema (
13971404 com .google .bigtable .admin .v2 .ProtoSchema .newBuilder ()
1398- .setProtoDescriptors (ByteString .copyFromUtf8 ( "schema" )))
1405+ .setProtoDescriptors (ByteString .copyFrom ( content )))
13991406 .build ())
14001407 .setUpdateMask (FieldMask .newBuilder ().addPaths ("proto_schema" ))
14011408 .build ();
@@ -1407,7 +1414,7 @@ public void testUpdateSchemaBundle() throws IOException {
14071414 PROJECT_ID , INSTANCE_ID , TABLE_ID , SCHEMA_BUNDLE_ID ))
14081415 .setProtoSchema (
14091416 com .google .bigtable .admin .v2 .ProtoSchema .newBuilder ()
1410- .setProtoDescriptors (ByteString .copyFromUtf8 ( "schema" )))
1417+ .setProtoDescriptors (ByteString .copyFrom ( content )))
14111418 .build ();
14121419
14131420 mockOperationResult (
@@ -1420,7 +1427,7 @@ public void testUpdateSchemaBundle() throws IOException {
14201427
14211428 UpdateSchemaBundleRequest req =
14221429 UpdateSchemaBundleRequest .of (TABLE_ID , SCHEMA_BUNDLE_ID )
1423- .setProtoSchema (TEST_UPDATED_PROTO_SCHEMA_BUNDLE );
1430+ .setProtoSchema (getResourceFilePath ( TEST_UPDATED_PROTO_SCHEMA_BUNDLE ) );
14241431
14251432 // Execute
14261433 SchemaBundle actualResult = adminClient .updateSchemaBundle (req );
@@ -1667,4 +1674,10 @@ private <ReqT, RespT, MetaT> void mockOperationResult(
16671674 OperationFutures .immediateOperationFuture (operationSnapshot );
16681675 Mockito .when (callable .futureCall (request )).thenReturn (operationFuture );
16691676 }
1677+
1678+ private String getResourceFilePath (String filePath ) throws URISyntaxException {
1679+ ClassLoader cl = Thread .currentThread ().getContextClassLoader ();
1680+ URL protoSchema = cl .getResource (filePath );
1681+ return Paths .get (protoSchema .toURI ()).toAbsolutePath ().toString ();
1682+ }
16701683}
0 commit comments