Skip to content
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

[ggj][infra][4/5]feat: add goldens update bazel rules for Asset API #397

Merged
merged 9 commits into from
Oct 28, 2020
7 changes: 7 additions & 0 deletions test/integration/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ golden_update(
data = ["//test/integration/goldens/redis:goldens_files"],
)

golden_update(
name = "asset_update",
target = ":asset_java_gapic",
data = ["//test/integration/goldens/asset:goldens_files"],
)

####################################################
# API Library Rules
####################################################
Expand Down Expand Up @@ -94,3 +100,4 @@ java_gapic_library(
"@com_google_googleapis//google/logging/v2:logging_java_proto",
],
)

45 changes: 24 additions & 21 deletions test/integration/goldens/asset/AssetServiceClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package com.google.cloud.asset.v1;

import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllIamPoliciesPagedResponse;
import static com.google.cloud.asset.v1.AssetServiceClient.SearchAllResourcesPagedResponse;

import com.google.api.gax.core.NoCredentialsProvider;
import com.google.api.gax.grpc.GaxGrpcProperties;
import com.google.api.gax.grpc.testing.LocalChannelProvider;
Expand Down Expand Up @@ -83,7 +86,7 @@ public void tearDown() throws Exception {
}

@Test
public void exportAssetsTest() {
public void exportAssetsTest() throws Exception {
ExportAssetsResponse expectedResponse =
ExportAssetsResponse.newBuilder()
.setOutputConfig(OutputConfig.newBuilder().build())
Expand All @@ -99,7 +102,7 @@ public void exportAssetsTest() {

ExportAssetsRequest request =
ExportAssetsRequest.newBuilder()
.setParent(ProjectName.of("[PROJECT]").toString())
.setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString())
.addAllAssetTypes(new ArrayList<>())
.setOutputConfig(OutputConfig.newBuilder().build())
.build();
Expand Down Expand Up @@ -130,7 +133,7 @@ public void exportAssetsExceptionTest() throws Exception {
try {
ExportAssetsRequest request =
ExportAssetsRequest.newBuilder()
.setParent(ProjectName.of("[PROJECT]").toString())
.setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString())
.addAllAssetTypes(new ArrayList<>())
.setOutputConfig(OutputConfig.newBuilder().build())
.build();
Expand All @@ -144,14 +147,14 @@ public void exportAssetsExceptionTest() throws Exception {
}

@Test
public void batchGetAssetsHistoryTest() {
public void batchGetAssetsHistoryTest() throws Exception {
BatchGetAssetsHistoryResponse expectedResponse =
BatchGetAssetsHistoryResponse.newBuilder().addAllAssets(new ArrayList<>()).build();
mockAssetService.addResponse(expectedResponse);

BatchGetAssetsHistoryRequest request =
BatchGetAssetsHistoryRequest.newBuilder()
.setParent(ProjectName.of("[PROJECT]").toString())
.setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString())
.addAllAssetNames(new ArrayList<>())
.setReadTimeWindow(TimeWindow.newBuilder().build())
.build();
Expand Down Expand Up @@ -182,7 +185,7 @@ public void batchGetAssetsHistoryExceptionTest() throws Exception {
try {
BatchGetAssetsHistoryRequest request =
BatchGetAssetsHistoryRequest.newBuilder()
.setParent(ProjectName.of("[PROJECT]").toString())
.setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString())
.addAllAssetNames(new ArrayList<>())
.setReadTimeWindow(TimeWindow.newBuilder().build())
.build();
Expand All @@ -194,7 +197,7 @@ public void batchGetAssetsHistoryExceptionTest() throws Exception {
}

@Test
public void createFeedTest() {
public void createFeedTest() throws Exception {
Feed expectedResponse =
Feed.newBuilder()
.setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString())
Expand Down Expand Up @@ -235,7 +238,7 @@ public void createFeedExceptionTest() throws Exception {
}

@Test
public void getFeedTest() {
public void getFeedTest() throws Exception {
Feed expectedResponse =
Feed.newBuilder()
.setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString())
Expand Down Expand Up @@ -276,7 +279,7 @@ public void getFeedExceptionTest() throws Exception {
}

@Test
public void getFeedTest2() {
public void getFeedTest2() throws Exception {
Feed expectedResponse =
Feed.newBuilder()
.setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString())
Expand Down Expand Up @@ -317,7 +320,7 @@ public void getFeedExceptionTest2() throws Exception {
}

@Test
public void listFeedsTest() {
public void listFeedsTest() throws Exception {
ListFeedsResponse expectedResponse =
ListFeedsResponse.newBuilder().addAllFeeds(new ArrayList<>()).build();
mockAssetService.addResponse(expectedResponse);
Expand Down Expand Up @@ -353,7 +356,7 @@ public void listFeedsExceptionTest() throws Exception {
}

@Test
public void updateFeedTest() {
public void updateFeedTest() throws Exception {
Feed expectedResponse =
Feed.newBuilder()
.setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString())
Expand Down Expand Up @@ -394,7 +397,7 @@ public void updateFeedExceptionTest() throws Exception {
}

@Test
public void deleteFeedTest() {
public void deleteFeedTest() throws Exception {
Empty expectedResponse = Empty.newBuilder().build();
mockAssetService.addResponse(expectedResponse);

Expand Down Expand Up @@ -429,7 +432,7 @@ public void deleteFeedExceptionTest() throws Exception {
}

@Test
public void deleteFeedTest2() {
public void deleteFeedTest2() throws Exception {
Empty expectedResponse = Empty.newBuilder().build();
mockAssetService.addResponse(expectedResponse);

Expand Down Expand Up @@ -464,26 +467,26 @@ public void deleteFeedExceptionTest2() throws Exception {
}

@Test
public void searchAllResourcesTest() {
public void searchAllResourcesTest() throws Exception {
ResourceSearchResult responsesElement = ResourceSearchResult.newBuilder().build();
SearchAllResourcesResponse expectedResponse =
SearchAllResourcesResponse.newBuilder()
.setNextPageToken("")
.addAllResponses(Arrays.asList(responsesElement))
.addAllResults(Arrays.asList(responsesElement))
.build();
mockAssetService.addResponse(expectedResponse);

String scope = "scope109264468";
String query = "query107944136";
List<String> assetTypes = new ArrayList<>();

SearchAllResourcesResponse pagedListResponse =
SearchAllResourcesPagedResponse pagedListResponse =
client.searchAllResources(scope, query, assetTypes);

List<ResourceSearchResult> resources = Lists.newArrayList(pagedListResponse.iterateAll());

Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getResponsesList().get(0), resources.get(0));
Assert.assertEquals(expectedResponse.getResultsList().get(0), resources.get(0));

List<AbstractMessage> actualRequests = mockAssetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
Expand Down Expand Up @@ -515,24 +518,24 @@ public void searchAllResourcesExceptionTest() throws Exception {
}

@Test
public void searchAllIamPoliciesTest() {
public void searchAllIamPoliciesTest() throws Exception {
IamPolicySearchResult responsesElement = IamPolicySearchResult.newBuilder().build();
SearchAllIamPoliciesResponse expectedResponse =
SearchAllIamPoliciesResponse.newBuilder()
.setNextPageToken("")
.addAllResponses(Arrays.asList(responsesElement))
.addAllResults(Arrays.asList(responsesElement))
.build();
mockAssetService.addResponse(expectedResponse);

String scope = "scope109264468";
String query = "query107944136";

SearchAllIamPoliciesResponse pagedListResponse = client.searchAllIamPolicies(scope, query);
SearchAllIamPoliciesPagedResponse pagedListResponse = client.searchAllIamPolicies(scope, query);

List<IamPolicySearchResult> resources = Lists.newArrayList(pagedListResponse.iterateAll());

Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getResponsesList().get(0), resources.get(0));
Assert.assertEquals(expectedResponse.getResultsList().get(0), resources.get(0));

List<AbstractMessage> actualRequests = mockAssetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
Expand Down
18 changes: 9 additions & 9 deletions test/integration/goldens/asset/FeedName.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@ public static FeedName of(String project, String feed) {
}

@BetaApi("The static create methods are not stable yet and may be changed in the future.")
public static FeedName ofProjectFeedBuilder(String project, String feed) {
public static FeedName ofProjectFeedName(String project, String feed) {
return newBuilder().setProject(project).setFeed(feed).build();
}

@BetaApi("The static create methods are not stable yet and may be changed in the future.")
public static FeedName ofFolderFeedBuilder(String folder, String feed) {
public static FeedName ofFolderFeedName(String folder, String feed) {
return newFolderFeedBuilder().setFolder(folder).setFeed(feed).build();
}

@BetaApi("The static create methods are not stable yet and may be changed in the future.")
public static FeedName ofOrganizationFeedBuilder(String organization, String feed) {
public static FeedName ofOrganizationFeedName(String organization, String feed) {
return newOrganizationFeedBuilder().setOrganization(organization).setFeed(feed).build();
}

Expand All @@ -132,17 +132,17 @@ public static String format(String project, String feed) {
}

@BetaApi("The static format methods are not stable yet and may be changed in the future.")
public static String formatProjectFeedBuilder(String project, String feed) {
public static String formatProjectFeedName(String project, String feed) {
return newBuilder().setProject(project).setFeed(feed).build().toString();
}

@BetaApi("The static format methods are not stable yet and may be changed in the future.")
public static String formatFolderFeedBuilder(String folder, String feed) {
public static String formatFolderFeedName(String folder, String feed) {
return newFolderFeedBuilder().setFolder(folder).setFeed(feed).build().toString();
}

@BetaApi("The static format methods are not stable yet and may be changed in the future.")
public static String formatOrganizationFeedBuilder(String organization, String feed) {
public static String formatOrganizationFeedName(String organization, String feed) {
return newOrganizationFeedBuilder()
.setOrganization(organization)
.setFeed(feed)
Expand All @@ -156,13 +156,13 @@ public static FeedName parse(String formattedString) {
}
if (PROJECT_FEED.matches(formattedString)) {
Map<String, String> matchMap = PROJECT_FEED.match(formattedString);
return ofProjectFeedBuilder(matchMap.get("project"), matchMap.get("feed"));
return ofProjectFeedName(matchMap.get("project"), matchMap.get("feed"));
} else if (FOLDER_FEED.matches(formattedString)) {
Map<String, String> matchMap = FOLDER_FEED.match(formattedString);
return ofFolderFeedBuilder(matchMap.get("folder"), matchMap.get("feed"));
return ofFolderFeedName(matchMap.get("folder"), matchMap.get("feed"));
} else if (ORGANIZATION_FEED.matches(formattedString)) {
Map<String, String> matchMap = ORGANIZATION_FEED.match(formattedString);
return ofOrganizationFeedBuilder(matchMap.get("organization"), matchMap.get("feed"));
return ofOrganizationFeedName(matchMap.get("organization"), matchMap.get("feed"));
}
throw new ValidationException("FeedName.parse: formattedString not in valid format");
}
Expand Down
Loading