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]fix: update asset goldens for integration test #395

Merged
merged 1 commit into from
Oct 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 65 additions & 6 deletions test/integration/goldens/asset/AssetServiceClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@

@Generated("by gapic-generator-java")
public class AssetServiceClientTest {
public static MockServiceHelper mockServiceHelper;
public AssetServiceClient client;
public LocalChannelProvider channelProvider;
public static MockAssetService mockAssetService;
private static MockServiceHelper mockServiceHelper;
private AssetServiceClient client;
private LocalChannelProvider channelProvider;
private static MockAssetService mockAssetService;

@BeforeClass
public static void startStaticServer() {
Expand Down Expand Up @@ -96,17 +96,21 @@ public void exportAssetsTest() {
.setResponse(Any.pack(expectedResponse))
.build();
mockAssetService.addResponse(resultOperation);

ExportAssetsRequest request =
ExportAssetsRequest.newBuilder()
.setParent(ProjectName.of("[PROJECT]").toString())
.addAllAssetTypes(new ArrayList<>())
.setOutputConfig(OutputConfig.newBuilder().build())
.build();

ExportAssetsResponse actualResponse = client.exportAssetsAsync(request).get();
Assert.assertEquals(expectedResponse, actualResponse);

List<AbstractMessage> actualRequests = mockAssetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ExportAssetsRequest actualRequest = ((ExportAssetsRequest) actualRequests.get(0));

Assert.assertEquals(request.getParent(), actualRequest.getParent());
Assert.assertEquals(request.getReadTime(), actualRequest.getReadTime());
Assert.assertEquals(request.getAssetTypesList(), actualRequest.getAssetTypesList());
Expand All @@ -122,6 +126,7 @@ public void exportAssetsTest() {
public void exportAssetsExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockAssetService.addException(exception);

try {
ExportAssetsRequest request =
ExportAssetsRequest.newBuilder()
Expand All @@ -143,18 +148,22 @@ public void batchGetAssetsHistoryTest() {
BatchGetAssetsHistoryResponse expectedResponse =
BatchGetAssetsHistoryResponse.newBuilder().addAllAssets(new ArrayList<>()).build();
mockAssetService.addResponse(expectedResponse);

BatchGetAssetsHistoryRequest request =
BatchGetAssetsHistoryRequest.newBuilder()
.setParent(ProjectName.of("[PROJECT]").toString())
.addAllAssetNames(new ArrayList<>())
.setReadTimeWindow(TimeWindow.newBuilder().build())
.build();

BatchGetAssetsHistoryResponse actualResponse = client.batchGetAssetsHistory(request);
Assert.assertEquals(expectedResponse, actualResponse);

List<AbstractMessage> actualRequests = mockAssetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
BatchGetAssetsHistoryRequest actualRequest =
((BatchGetAssetsHistoryRequest) actualRequests.get(0));

Assert.assertEquals(request.getParent(), actualRequest.getParent());
Assert.assertEquals(request.getAssetNamesList(), actualRequest.getAssetNamesList());
Assert.assertEquals(request.getContentType(), actualRequest.getContentType());
Expand All @@ -169,6 +178,7 @@ public void batchGetAssetsHistoryTest() {
public void batchGetAssetsHistoryExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockAssetService.addException(exception);

try {
BatchGetAssetsHistoryRequest request =
BatchGetAssetsHistoryRequest.newBuilder()
Expand All @@ -193,12 +203,16 @@ public void createFeedTest() {
.setFeedOutputConfig(FeedOutputConfig.newBuilder().build())
.build();
mockAssetService.addResponse(expectedResponse);

String parent = "parent-995424086";

Feed actualResponse = client.createFeed(parent);
Assert.assertEquals(expectedResponse, actualResponse);

List<AbstractMessage> actualRequests = mockAssetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateFeedRequest actualRequest = ((CreateFeedRequest) actualRequests.get(0));

Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(
channelProvider.isHeaderSent(
Expand All @@ -210,6 +224,7 @@ public void createFeedTest() {
public void createFeedExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockAssetService.addException(exception);

try {
String parent = "parent-995424086";
client.createFeed(parent);
Expand All @@ -229,12 +244,16 @@ public void getFeedTest() {
.setFeedOutputConfig(FeedOutputConfig.newBuilder().build())
.build();
mockAssetService.addResponse(expectedResponse);

FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]");

Feed actualResponse = client.getFeed(name);
Assert.assertEquals(expectedResponse, actualResponse);

List<AbstractMessage> actualRequests = mockAssetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetFeedRequest actualRequest = ((GetFeedRequest) actualRequests.get(0));

Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(
channelProvider.isHeaderSent(
Expand All @@ -246,6 +265,7 @@ public void getFeedTest() {
public void getFeedExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockAssetService.addException(exception);

try {
FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]");
client.getFeed(name);
Expand All @@ -265,12 +285,16 @@ public void getFeedTest2() {
.setFeedOutputConfig(FeedOutputConfig.newBuilder().build())
.build();
mockAssetService.addResponse(expectedResponse);

String name = "name3373707";

Feed actualResponse = client.getFeed(name);
Assert.assertEquals(expectedResponse, actualResponse);

List<AbstractMessage> actualRequests = mockAssetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetFeedRequest actualRequest = ((GetFeedRequest) actualRequests.get(0));

Assert.assertEquals(name, actualRequest.getName());
Assert.assertTrue(
channelProvider.isHeaderSent(
Expand All @@ -282,6 +306,7 @@ public void getFeedTest2() {
public void getFeedExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockAssetService.addException(exception);

try {
String name = "name3373707";
client.getFeed(name);
Expand All @@ -296,12 +321,16 @@ public void listFeedsTest() {
ListFeedsResponse expectedResponse =
ListFeedsResponse.newBuilder().addAllFeeds(new ArrayList<>()).build();
mockAssetService.addResponse(expectedResponse);

String parent = "parent-995424086";

ListFeedsResponse actualResponse = client.listFeeds(parent);
Assert.assertEquals(expectedResponse, actualResponse);

List<AbstractMessage> actualRequests = mockAssetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListFeedsRequest actualRequest = ((ListFeedsRequest) actualRequests.get(0));

Assert.assertEquals(parent, actualRequest.getParent());
Assert.assertTrue(
channelProvider.isHeaderSent(
Expand All @@ -313,6 +342,7 @@ public void listFeedsTest() {
public void listFeedsExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockAssetService.addException(exception);

try {
String parent = "parent-995424086";
client.listFeeds(parent);
Expand All @@ -332,12 +362,16 @@ public void updateFeedTest() {
.setFeedOutputConfig(FeedOutputConfig.newBuilder().build())
.build();
mockAssetService.addResponse(expectedResponse);

Feed feed = Feed.newBuilder().build();

Feed actualResponse = client.updateFeed(feed);
Assert.assertEquals(expectedResponse, actualResponse);

List<AbstractMessage> actualRequests = mockAssetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
UpdateFeedRequest actualRequest = ((UpdateFeedRequest) actualRequests.get(0));

Assert.assertEquals(feed, actualRequest.getFeed());
Assert.assertTrue(
channelProvider.isHeaderSent(
Expand All @@ -349,6 +383,7 @@ public void updateFeedTest() {
public void updateFeedExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockAssetService.addException(exception);

try {
Feed feed = Feed.newBuilder().build();
client.updateFeed(feed);
Expand All @@ -362,12 +397,16 @@ public void updateFeedExceptionTest() throws Exception {
public void deleteFeedTest() {
Empty expectedResponse = Empty.newBuilder().build();
mockAssetService.addResponse(expectedResponse);

FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]");

Empty actualResponse = client.deleteFeed(name);
Assert.assertEquals(expectedResponse, actualResponse);

List<AbstractMessage> actualRequests = mockAssetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
DeleteFeedRequest actualRequest = ((DeleteFeedRequest) actualRequests.get(0));

Assert.assertEquals(name.toString(), actualRequest.getName());
Assert.assertTrue(
channelProvider.isHeaderSent(
Expand All @@ -379,6 +418,7 @@ public void deleteFeedTest() {
public void deleteFeedExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockAssetService.addException(exception);

try {
FeedName name = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]");
client.deleteFeed(name);
Expand All @@ -392,12 +432,16 @@ public void deleteFeedExceptionTest() throws Exception {
public void deleteFeedTest2() {
Empty expectedResponse = Empty.newBuilder().build();
mockAssetService.addResponse(expectedResponse);

String name = "name3373707";

Empty actualResponse = client.deleteFeed(name);
Assert.assertEquals(expectedResponse, actualResponse);

List<AbstractMessage> actualRequests = mockAssetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
DeleteFeedRequest actualRequest = ((DeleteFeedRequest) actualRequests.get(0));

Assert.assertEquals(name, actualRequest.getName());
Assert.assertTrue(
channelProvider.isHeaderSent(
Expand All @@ -409,6 +453,7 @@ public void deleteFeedTest2() {
public void deleteFeedExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockAssetService.addException(exception);

try {
String name = "name3373707";
client.deleteFeed(name);
Expand All @@ -427,17 +472,23 @@ public void searchAllResourcesTest() {
.addAllResponses(Arrays.asList(responsesElement))
.build();
mockAssetService.addResponse(expectedResponse);

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

SearchAllResourcesResponse pagedListResponse =
client.searchAllResources(scope, query, assetTypes);
resources = Lists.newArrayList(pagedListResponse.iterateAll());

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

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

List<AbstractMessage> actualRequests = mockAssetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
SearchAllResourcesRequest actualRequest = ((SearchAllResourcesRequest) actualRequests.get(0));

Assert.assertEquals(scope, actualRequest.getScope());
Assert.assertEquals(query, actualRequest.getQuery());
Assert.assertEquals(assetTypes, actualRequest.getAssetTypesList());
Expand All @@ -451,6 +502,7 @@ public void searchAllResourcesTest() {
public void searchAllResourcesExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockAssetService.addException(exception);

try {
String scope = "scope109264468";
String query = "query107944136";
Expand All @@ -471,16 +523,22 @@ public void searchAllIamPoliciesTest() {
.addAllResponses(Arrays.asList(responsesElement))
.build();
mockAssetService.addResponse(expectedResponse);

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

SearchAllIamPoliciesResponse pagedListResponse = client.searchAllIamPolicies(scope, query);
resources = Lists.newArrayList(pagedListResponse.iterateAll());

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

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

List<AbstractMessage> actualRequests = mockAssetService.getRequests();
Assert.assertEquals(1, actualRequests.size());
SearchAllIamPoliciesRequest actualRequest =
((SearchAllIamPoliciesRequest) actualRequests.get(0));

Assert.assertEquals(scope, actualRequest.getScope());
Assert.assertEquals(query, actualRequest.getQuery());
Assert.assertTrue(
Expand All @@ -493,6 +551,7 @@ public void searchAllIamPoliciesTest() {
public void searchAllIamPoliciesExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockAssetService.addException(exception);

try {
String scope = "scope109264468";
String query = "query107944136";
Expand Down
Loading