2222import com .google .protobuf .ByteString ;
2323import com .google .protobuf .FieldMask ;
2424import java .io .IOException ;
25+ import java .net .URISyntaxException ;
26+ import java .net .URL ;
27+ import java .nio .file .Files ;
28+ import java .nio .file .Paths ;
2529import org .junit .Test ;
2630import org .junit .runner .RunWith ;
2731import org .junit .runners .JUnit4 ;
@@ -38,11 +42,12 @@ public class UpdateSchemaBundleRequestTest {
3842 private static final String TEST_UPDATED_PROTO_SCHEMA_BUNDLE = "updated_proto_schema_bundle.pb" ;
3943
4044 @ Test
41- public void testToProto () throws IOException {
45+ public void testToProto () throws IOException , URISyntaxException {
4246 UpdateSchemaBundleRequest request =
4347 UpdateSchemaBundleRequest .of (TABLE_ID , SCHEMA_BUNDLE_ID )
44- .setProtoSchema (TEST_PROTO_SCHEMA_BUNDLE )
48+ .setProtoSchema (getResourceFilePath ( TEST_PROTO_SCHEMA_BUNDLE ) )
4549 .setIgnoreWarnings (true );
50+ byte [] content = Files .readAllBytes (Paths .get (getResourceFilePath (TEST_PROTO_SCHEMA_BUNDLE )));
4651
4752 com .google .bigtable .admin .v2 .UpdateSchemaBundleRequest requestProto =
4853 com .google .bigtable .admin .v2 .UpdateSchemaBundleRequest .newBuilder ()
@@ -53,7 +58,7 @@ public void testToProto() throws IOException {
5358 PROJECT_ID , INSTANCE_ID , TABLE_ID , SCHEMA_BUNDLE_ID ))
5459 .setProtoSchema (
5560 com .google .bigtable .admin .v2 .ProtoSchema .newBuilder ()
56- .setProtoDescriptors (ByteString .copyFromUtf8 ( "schema" ))
61+ .setProtoDescriptors (ByteString .copyFrom ( content ))
5762 .build ())
5863 .build ())
5964 .setUpdateMask (FieldMask .newBuilder ().addPaths ("proto_schema" ))
@@ -63,21 +68,23 @@ public void testToProto() throws IOException {
6368 }
6469
6570 @ Test
66- public void testUpdateProtoSchema () throws IOException {
71+ public void testUpdateProtoSchema () throws IOException , URISyntaxException {
72+ byte [] content = Files .readAllBytes (Paths .get (getResourceFilePath (TEST_PROTO_SCHEMA_BUNDLE )));
73+
6774 com .google .bigtable .admin .v2 .SchemaBundle existingSchemaBundle =
6875 com .google .bigtable .admin .v2 .SchemaBundle .newBuilder ()
6976 .setName (
7077 NameUtil .formatSchemaBundleName (
7178 PROJECT_ID , INSTANCE_ID , TABLE_ID , SCHEMA_BUNDLE_ID ))
7279 .setProtoSchema (
7380 com .google .bigtable .admin .v2 .ProtoSchema .newBuilder ()
74- .setProtoDescriptors (ByteString .copyFromUtf8 ( "schema" ))
81+ .setProtoDescriptors (ByteString .copyFrom ( content ))
7582 .build ())
7683 .build ();
7784
7885 UpdateSchemaBundleRequest request =
7986 UpdateSchemaBundleRequest .of (SchemaBundle .fromProto (existingSchemaBundle ))
80- .setProtoSchema (TEST_UPDATED_PROTO_SCHEMA_BUNDLE );
87+ .setProtoSchema (getResourceFilePath ( TEST_UPDATED_PROTO_SCHEMA_BUNDLE ) );
8188
8289 com .google .bigtable .admin .v2 .UpdateSchemaBundleRequest requestProto =
8390 com .google .bigtable .admin .v2 .UpdateSchemaBundleRequest .newBuilder ()
@@ -88,38 +95,44 @@ public void testUpdateProtoSchema() throws IOException {
8895 }
8996
9097 @ Test
91- public void testEquality () throws IOException {
98+ public void testEquality () throws IOException , URISyntaxException {
9299 UpdateSchemaBundleRequest request =
93100 UpdateSchemaBundleRequest .of (TABLE_ID , SCHEMA_BUNDLE_ID )
94- .setProtoSchema (TEST_PROTO_SCHEMA_BUNDLE );
101+ .setProtoSchema (getResourceFilePath ( TEST_PROTO_SCHEMA_BUNDLE ) );
95102
96103 assertThat (request )
97104 .isEqualTo (
98105 UpdateSchemaBundleRequest .of (TABLE_ID , SCHEMA_BUNDLE_ID )
99- .setProtoSchema (TEST_PROTO_SCHEMA_BUNDLE ));
106+ .setProtoSchema (getResourceFilePath ( TEST_PROTO_SCHEMA_BUNDLE ) ));
100107
101108 assertThat (request )
102109 .isNotEqualTo (
103110 UpdateSchemaBundleRequest .of (TABLE_ID , SCHEMA_BUNDLE_ID )
104- .setProtoSchema (TEST_UPDATED_PROTO_SCHEMA_BUNDLE ));
111+ .setProtoSchema (getResourceFilePath ( TEST_UPDATED_PROTO_SCHEMA_BUNDLE ) ));
105112 }
106113
107114 @ Test
108- public void testHashCode () throws IOException {
115+ public void testHashCode () throws IOException , URISyntaxException {
109116 UpdateSchemaBundleRequest request =
110117 UpdateSchemaBundleRequest .of (TABLE_ID , SCHEMA_BUNDLE_ID )
111- .setProtoSchema (TEST_PROTO_SCHEMA_BUNDLE );
118+ .setProtoSchema (getResourceFilePath ( TEST_PROTO_SCHEMA_BUNDLE ) );
112119
113120 assertThat (request .hashCode ())
114121 .isEqualTo (
115122 UpdateSchemaBundleRequest .of (TABLE_ID , SCHEMA_BUNDLE_ID )
116- .setProtoSchema (TEST_PROTO_SCHEMA_BUNDLE )
123+ .setProtoSchema (getResourceFilePath ( TEST_PROTO_SCHEMA_BUNDLE ) )
117124 .hashCode ());
118125
119126 assertThat (request .hashCode ())
120127 .isNotEqualTo (
121128 UpdateSchemaBundleRequest .of (TABLE_ID , SCHEMA_BUNDLE_ID )
122- .setProtoSchema (TEST_UPDATED_PROTO_SCHEMA_BUNDLE )
129+ .setProtoSchema (getResourceFilePath ( TEST_UPDATED_PROTO_SCHEMA_BUNDLE ) )
123130 .hashCode ());
124131 }
132+
133+ private String getResourceFilePath (String filePath ) throws URISyntaxException {
134+ ClassLoader cl = Thread .currentThread ().getContextClassLoader ();
135+ URL protoSchema = cl .getResource (filePath );
136+ return Paths .get (protoSchema .toURI ()).toAbsolutePath ().toString ();
137+ }
125138}
0 commit comments