Skip to content
This repository was archived by the owner on May 8, 2026. It is now read-only.

Commit 4783b5e

Browse files
committed
add tests
1 parent e032e57 commit 4783b5e

3 files changed

Lines changed: 351 additions & 0 deletions

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.bigtable.admin.v2.models;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
22+
import com.google.protobuf.ByteString;
23+
import org.junit.Test;
24+
import org.junit.runner.RunWith;
25+
import org.junit.runners.JUnit4;
26+
27+
@RunWith(JUnit4.class)
28+
public class CreateSchemaBundleRequestTest {
29+
private static final String PROJECT_ID = "my-project";
30+
private static final String INSTANCE_ID = "my-instance";
31+
private static final String TABLE_ID = "my-table";
32+
private static final String SCHEMA_BUNDLE_ID = "my-schema-bundle";
33+
34+
@Test
35+
public void testToProto() {
36+
CreateSchemaBundleRequest request =
37+
CreateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID).setProtoSchema("file.pb");
38+
39+
com.google.bigtable.admin.v2.CreateSchemaBundleRequest requestProto =
40+
com.google.bigtable.admin.v2.CreateSchemaBundleRequest.newBuilder()
41+
.setParent(NameUtil.formatTableName(PROJECT_ID, INSTANCE_ID, TABLE_ID))
42+
.setSchemaBundleId(SCHEMA_BUNDLE_ID)
43+
.setSchemaBundle(
44+
com.google.bigtable.admin.v2.SchemaBundle.newBuilder()
45+
.setProtoSchema(
46+
com.google.bigtable.admin.v2.ProtoSchema.newBuilder()
47+
.setProtoDescriptors(ByteString.copyFromUtf8("schema"))
48+
.build())
49+
.build())
50+
.build();
51+
assertThat(request.toProto(PROJECT_ID, INSTANCE_ID)).isEqualTo(requestProto);
52+
}
53+
54+
@Test
55+
public void testEquality() {
56+
CreateSchemaBundleRequest request =
57+
CreateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID).setProtoSchema("file.pb");
58+
59+
assertThat(request)
60+
.isEqualTo(
61+
CreateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID).setProtoSchema("file.pb"));
62+
63+
assertThat(request)
64+
.isNotEqualTo(
65+
CreateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
66+
.setProtoSchema("updated_file.pb"));
67+
}
68+
69+
@Test
70+
public void testHashCode() {
71+
CreateSchemaBundleRequest request =
72+
CreateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID).setProtoSchema("file.pb");
73+
74+
assertThat(request.hashCode())
75+
.isEqualTo(
76+
CreateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
77+
.setProtoSchema("file.pb")
78+
.hashCode());
79+
80+
assertThat(request.hashCode())
81+
.isNotEqualTo(
82+
CreateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
83+
.setProtoSchema("updated_file.pb")
84+
.hashCode());
85+
}
86+
}
Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.bigtable.admin.v2.models;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import com.google.bigtable.admin.v2.SchemaBundleName;
22+
import com.google.protobuf.ByteString;
23+
import org.junit.Test;
24+
import org.junit.runner.RunWith;
25+
import org.junit.runners.JUnit4;
26+
27+
@RunWith(JUnit4.class)
28+
public class SchemaBundleTest {
29+
private static final String PROJECT_ID = "my-project";
30+
private static final String INSTANCE_ID = "my-instance";
31+
private static final String TABLE_ID = "my-table";
32+
private static final String SCHEMA_BUNDLE_ID = "my-schema-bundle";
33+
34+
@Test
35+
public void testFromProto() {
36+
SchemaBundleName schemaBundleName =
37+
SchemaBundleName.of(PROJECT_ID, INSTANCE_ID, TABLE_ID, SCHEMA_BUNDLE_ID);
38+
39+
com.google.bigtable.admin.v2.SchemaBundle schemaBundleProto =
40+
com.google.bigtable.admin.v2.SchemaBundle.newBuilder()
41+
.setName(schemaBundleName.toString())
42+
.setProtoSchema(
43+
com.google.bigtable.admin.v2.ProtoSchema.newBuilder()
44+
.setProtoDescriptors(ByteString.copyFromUtf8("schema"))
45+
.build())
46+
.build();
47+
48+
SchemaBundle result = SchemaBundle.fromProto(schemaBundleProto);
49+
50+
assertThat(result.getId()).isEqualTo(SCHEMA_BUNDLE_ID);
51+
assertThat(result.getTableId()).isEqualTo(TABLE_ID);
52+
assertThat(result.getProtoSchema()).isEqualTo(ByteString.copyFromUtf8("schema"));
53+
}
54+
55+
@Test
56+
public void testRequiresName() {
57+
com.google.bigtable.admin.v2.SchemaBundle proto =
58+
com.google.bigtable.admin.v2.SchemaBundle.newBuilder()
59+
.setProtoSchema(
60+
com.google.bigtable.admin.v2.ProtoSchema.newBuilder()
61+
.setProtoDescriptors(ByteString.copyFromUtf8("schema"))
62+
.build())
63+
.build();
64+
Exception actualException = null;
65+
66+
try {
67+
SchemaBundle.fromProto(proto);
68+
} catch (Exception e) {
69+
actualException = e;
70+
}
71+
72+
assertThat(actualException).isInstanceOf(IllegalArgumentException.class);
73+
}
74+
75+
@Test
76+
public void testRequiresSchemaBundleType() {
77+
SchemaBundleName schemaBundleName =
78+
SchemaBundleName.of(PROJECT_ID, INSTANCE_ID, TABLE_ID, SCHEMA_BUNDLE_ID);
79+
com.google.bigtable.admin.v2.SchemaBundle proto =
80+
com.google.bigtable.admin.v2.SchemaBundle.newBuilder()
81+
.setName(schemaBundleName.toString())
82+
.build();
83+
Exception actualException = null;
84+
85+
try {
86+
SchemaBundle.fromProto(proto);
87+
} catch (Exception e) {
88+
actualException = e;
89+
}
90+
91+
assertThat(actualException).isInstanceOf(IllegalArgumentException.class);
92+
}
93+
94+
@Test
95+
public void testEquality() {
96+
SchemaBundleName schemaBundleName =
97+
SchemaBundleName.of(PROJECT_ID, INSTANCE_ID, TABLE_ID, SCHEMA_BUNDLE_ID);
98+
com.google.bigtable.admin.v2.SchemaBundle proto =
99+
com.google.bigtable.admin.v2.SchemaBundle.newBuilder()
100+
.setName(schemaBundleName.toString())
101+
.setProtoSchema(
102+
com.google.bigtable.admin.v2.ProtoSchema.newBuilder()
103+
.setProtoDescriptors(ByteString.copyFromUtf8("schema"))
104+
.build())
105+
.build();
106+
SchemaBundle schemaBundle = SchemaBundle.fromProto(proto);
107+
108+
assertThat(schemaBundle).isEqualTo(SchemaBundle.fromProto(proto));
109+
110+
assertThat(schemaBundle)
111+
.isNotEqualTo(
112+
com.google.bigtable.admin.v2.SchemaBundle.newBuilder()
113+
.setName(schemaBundleName.toString())
114+
.setProtoSchema(
115+
com.google.bigtable.admin.v2.ProtoSchema.newBuilder()
116+
.setProtoDescriptors(ByteString.copyFromUtf8("schema"))
117+
.build())
118+
.build());
119+
}
120+
121+
@Test
122+
public void testHashCode() {
123+
SchemaBundleName schemaBundleName =
124+
SchemaBundleName.of(PROJECT_ID, INSTANCE_ID, TABLE_ID, SCHEMA_BUNDLE_ID);
125+
com.google.bigtable.admin.v2.SchemaBundle proto =
126+
com.google.bigtable.admin.v2.SchemaBundle.newBuilder()
127+
.setName(schemaBundleName.toString())
128+
.setProtoSchema(
129+
com.google.bigtable.admin.v2.ProtoSchema.newBuilder()
130+
.setProtoDescriptors(ByteString.copyFromUtf8("schema"))
131+
.build())
132+
.build();
133+
SchemaBundle schemaBundle = SchemaBundle.fromProto(proto);
134+
135+
assertThat(schemaBundle.hashCode()).isEqualTo(SchemaBundle.fromProto(proto).hashCode());
136+
137+
assertThat(schemaBundle.hashCode())
138+
.isNotEqualTo(
139+
com.google.bigtable.admin.v2.SchemaBundle.newBuilder()
140+
.setName(schemaBundleName.toString())
141+
.setProtoSchema(
142+
com.google.bigtable.admin.v2.ProtoSchema.newBuilder()
143+
.setProtoDescriptors(ByteString.copyFromUtf8("schema"))
144+
.build())
145+
.build()
146+
.hashCode());
147+
}
148+
}
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.bigtable.admin.v2.models;
18+
19+
import static com.google.common.truth.Truth.assertThat;
20+
21+
import com.google.cloud.bigtable.admin.v2.internal.NameUtil;
22+
import com.google.protobuf.ByteString;
23+
import com.google.protobuf.FieldMask;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
import org.junit.runners.JUnit4;
27+
28+
@RunWith(JUnit4.class)
29+
public class UpdateSchemaBundleRequestTest {
30+
private static final String PROJECT_ID = "my-project";
31+
private static final String INSTANCE_ID = "my-instance";
32+
private static final String TABLE_ID = "my-table";
33+
private static final String SCHEMA_BUNDLE_ID = "my-schema-bundle";
34+
35+
@Test
36+
public void testToProto() {
37+
UpdateSchemaBundleRequest request =
38+
UpdateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
39+
.setProtoSchema("file.pb")
40+
.setIgnoreWarnings(true);
41+
42+
com.google.bigtable.admin.v2.UpdateSchemaBundleRequest requestProto =
43+
com.google.bigtable.admin.v2.UpdateSchemaBundleRequest.newBuilder()
44+
.setSchemaBundle(
45+
com.google.bigtable.admin.v2.SchemaBundle.newBuilder()
46+
.setName(
47+
NameUtil.formatSchemaBundleName(
48+
PROJECT_ID, INSTANCE_ID, TABLE_ID, SCHEMA_BUNDLE_ID))
49+
.setProtoSchema(
50+
com.google.bigtable.admin.v2.ProtoSchema.newBuilder()
51+
.setProtoDescriptors(ByteString.copyFromUtf8("schema"))
52+
.build())
53+
.build())
54+
.setUpdateMask(FieldMask.newBuilder().addPaths("proto_schema"))
55+
.setIgnoreWarnings(true)
56+
.build();
57+
assertThat(request.toProto(PROJECT_ID, INSTANCE_ID)).isEqualTo(requestProto);
58+
}
59+
60+
@Test
61+
public void testUpdateProtoSchema() {
62+
com.google.bigtable.admin.v2.SchemaBundle existingSchemaBundle =
63+
com.google.bigtable.admin.v2.SchemaBundle.newBuilder()
64+
.setName(
65+
NameUtil.formatSchemaBundleName(
66+
PROJECT_ID, INSTANCE_ID, TABLE_ID, SCHEMA_BUNDLE_ID))
67+
.setProtoSchema(
68+
com.google.bigtable.admin.v2.ProtoSchema.newBuilder()
69+
.setProtoDescriptors(ByteString.copyFromUtf8("schema"))
70+
.build())
71+
.build();
72+
73+
UpdateSchemaBundleRequest request =
74+
UpdateSchemaBundleRequest.of(SchemaBundle.fromProto(existingSchemaBundle))
75+
.setProtoSchema("updated_file.pb");
76+
77+
com.google.bigtable.admin.v2.UpdateSchemaBundleRequest requestProto =
78+
com.google.bigtable.admin.v2.UpdateSchemaBundleRequest.newBuilder()
79+
.setSchemaBundle(existingSchemaBundle.toBuilder())
80+
.setUpdateMask(FieldMask.newBuilder().addPaths("proto_schema"))
81+
.build();
82+
assertThat(request.toProto(PROJECT_ID, INSTANCE_ID)).isEqualTo(requestProto);
83+
}
84+
85+
@Test
86+
public void testEquality() {
87+
UpdateSchemaBundleRequest request =
88+
UpdateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID).setProtoSchema("file.pb");
89+
90+
assertThat(request)
91+
.isEqualTo(
92+
UpdateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID).setProtoSchema("file.pb"));
93+
94+
assertThat(request)
95+
.isNotEqualTo(
96+
UpdateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
97+
.setProtoSchema("updated_file.pb"));
98+
}
99+
100+
@Test
101+
public void testHashCode() {
102+
UpdateSchemaBundleRequest request =
103+
UpdateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID).setProtoSchema("file.pb");
104+
105+
assertThat(request.hashCode())
106+
.isEqualTo(
107+
UpdateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
108+
.setProtoSchema("file.pb")
109+
.hashCode());
110+
111+
assertThat(request.hashCode())
112+
.isNotEqualTo(
113+
UpdateSchemaBundleRequest.of(TABLE_ID, SCHEMA_BUNDLE_ID)
114+
.setProtoSchema("updated_file.pb")
115+
.hashCode());
116+
}
117+
}

0 commit comments

Comments
 (0)