-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: Add Showcase Http Annotations Test #1568
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ef36868
chore: Add Showcase Compliance Suite
lqiu96 fdbb116
chore: Download compliance_suite.json when running showcase ITs
lqiu96 db555b3
chore: Rename ITCompliance file to ITHttpAnnotation
lqiu96 c08ee83
chore: Update HttpAnnotation class
lqiu96 13e0cdf
chore: Update the compliance suite
lqiu96 118aa11
chore: Update PR comments
lqiu96 0a7a1fb
chore: Update PR comments
lqiu96 c58bb65
chore: Split each group into a separate test
lqiu96 a5bc209
chore: Add in gitignore
lqiu96 b0845c1
chore: Restructure to use parameters
lqiu96 e5446ca
chore: Cleanup the files
lqiu96 fecfeb5
chore: Fix pr comments
lqiu96 23d4d00
chore: Add json file
lqiu96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name: SonarCloud Build | ||
env: | ||
SHOWCASE_VERSION: 0.25.0 | ||
SHOWCASE_VERSION: 0.26.0 | ||
on: | ||
push: | ||
branches: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,4 +15,4 @@ target/ | |
# Vscode Settings | ||
.vscode/settings.json | ||
|
||
*.iml | ||
*.iml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
showcase/gapic-showcase/src/test/java/com/google/showcase/v1beta1/it/ITHttpAnnotation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Copyright 2023 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.showcase.v1beta1.it; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import com.google.api.client.http.javanet.NetHttpTransport; | ||
import com.google.api.gax.core.NoCredentialsProvider; | ||
import com.google.common.collect.ImmutableMap; | ||
import com.google.protobuf.util.JsonFormat; | ||
import com.google.showcase.v1beta1.ComplianceClient; | ||
import com.google.showcase.v1beta1.ComplianceData; | ||
import com.google.showcase.v1beta1.ComplianceGroup; | ||
import com.google.showcase.v1beta1.ComplianceSettings; | ||
import com.google.showcase.v1beta1.ComplianceSuite; | ||
import com.google.showcase.v1beta1.RepeatRequest; | ||
import com.google.showcase.v1beta1.RepeatResponse; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.security.GeneralSecurityException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.function.Function; | ||
import java.util.stream.Collectors; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
// This test runs from the parameters in the compliance_suite.json file | ||
// The file is downloaded from the gapic-showcase repo. Each compliance | ||
// group is a set of HttpJson behaviors we want to test for. Each group | ||
// tests the product of the rpc list and requests list. | ||
@RunWith(Parameterized.class) | ||
public class ITHttpAnnotation { | ||
|
||
@Parameterized.Parameters(name = "Compliance Group Name: {0}") | ||
public static String[] data() { | ||
return new String[] { | ||
"Fully working conversions, resources", | ||
"Binding selection testing", | ||
"Cases that apply to non-path requests", | ||
"Fully working conversions, no resources" | ||
}; | ||
} | ||
|
||
@Parameterized.Parameter(0) | ||
public String groupName; | ||
|
||
private ComplianceSuite complianceSuite; | ||
private ComplianceClient complianceClient; | ||
private Map<String, Function<RepeatRequest, RepeatResponse>> validComplianceRpcMap; | ||
|
||
@Before | ||
public void createClient() throws IOException, GeneralSecurityException { | ||
ComplianceSuite.Builder builder = ComplianceSuite.newBuilder(); | ||
JsonFormat.parser() | ||
.merge( | ||
new InputStreamReader( | ||
ITHttpAnnotation.class | ||
.getClassLoader() | ||
.getResourceAsStream("compliance_suite.json")), | ||
builder); | ||
complianceSuite = builder.build(); | ||
|
||
ComplianceSettings httpjsonComplianceSettings = | ||
ComplianceSettings.newHttpJsonBuilder() | ||
.setCredentialsProvider(NoCredentialsProvider.create()) | ||
.setTransportChannelProvider( | ||
ComplianceSettings.defaultHttpJsonTransportProviderBuilder() | ||
.setHttpTransport( | ||
new NetHttpTransport.Builder().doNotValidateCertificate().build()) | ||
.setEndpoint("http://localhost:7469") | ||
.build()) | ||
.build(); | ||
complianceClient = ComplianceClient.create(httpjsonComplianceSettings); | ||
|
||
// Mapping of Compliance Suite file RPC Names to ComplianceClient methods | ||
validComplianceRpcMap = | ||
ImmutableMap.of( | ||
"Compliance.RepeatDataBody", | ||
complianceClient::repeatDataBody, | ||
"Compliance.RepeatDataBodyInfo", | ||
complianceClient::repeatDataBodyInfo, | ||
"Compliance.RepeatDataQuery", | ||
complianceClient::repeatDataQuery, | ||
"Compliance.RepeatDataSimplePath", | ||
complianceClient::repeatDataSimplePath, | ||
"Compliance.RepeatDataBodyPut", | ||
complianceClient::repeatDataBodyPut, | ||
"Compliance.RepeatDataBodyPatch", | ||
complianceClient::repeatDataBodyPatch, | ||
"Compliance.RepeatDataPathResource", | ||
complianceClient::repeatDataPathResource); | ||
} | ||
|
||
@After | ||
public void destroyClient() { | ||
complianceClient.close(); | ||
} | ||
|
||
// Verify that the input's info is the same as the response's info | ||
// This ensures that the entire group's behavior over HttpJson | ||
// works as intended | ||
@Test | ||
public void testComplianceGroup() { | ||
Optional<ComplianceGroup> complianceGroupOptional = | ||
complianceSuite.getGroupList().stream() | ||
.filter(x -> x.getName().equals(groupName)) | ||
.findFirst(); | ||
assertThat(complianceGroupOptional.isPresent()).isTrue(); | ||
ComplianceGroup complianceGroup = complianceGroupOptional.get(); | ||
List<String> validRpcList = | ||
complianceGroup.getRpcsList().stream() | ||
.filter(validComplianceRpcMap::containsKey) | ||
.collect(Collectors.toList()); | ||
for (String rpcName : validRpcList) { | ||
Function<RepeatRequest, RepeatResponse> rpc = validComplianceRpcMap.get(rpcName); | ||
for (RepeatRequest repeatRequest : complianceGroup.getRequestsList()) { | ||
ComplianceData expectedData = repeatRequest.getInfo(); | ||
RepeatResponse response = rpc.apply(repeatRequest); | ||
assertThat(response.getRequest().getInfo()).isEqualTo(expectedData); | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
showcase/gapic-showcase/src/test/resources/META-INF/native-image/resource-config.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"resources":[{"pattern": ".*.json"}] | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may be missing a copyright header for this file?
Hm I wonder why our checkstyle didn't fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the copyright header. I'll need to check why it didn't run for the test files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @lqiu96!