diff --git a/.githooks/pre-commit b/.githooks/pre-commit index b2ba7fa58f..14cc39fa11 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -101,10 +101,10 @@ then fi fi -# Check tests. +# Check unit tests. if [ $NUM_JAVA_FILES_CHANGED -gt 0 ] then - echo_status "Checking tests..." + echo_status "Checking unit tests..." bazel --batch test --disk_cache="$BAZEL_CACHE_DIR" //src/test/... TEST_STATUS=$? if [ $TEST_STATUS != 0 ] @@ -114,6 +114,19 @@ then fi fi +# Check integration tests. +if [ $NUM_JAVA_FILES_CHANGED -gt 0 ] +then + echo_status "Checking integration tests..." + bazel --batch test --disk_cache="$BAZEL_CACHE_DIR" //test/integration/... + TEST_STATUS=$? + if [ $TEST_STATUS != 0 ] + then + echo_error "Tests failed." "Please fix them and try again." + exit 1 + fi +fi + # Check and fix Bazel format. if [ $NUM_BAZEL_FILES_CHANGED -gt 0 ] then diff --git a/rules_java_gapic/java_gapic.bzl b/rules_java_gapic/java_gapic.bzl index 2bbcd1f0b4..aaf83c62e6 100644 --- a/rules_java_gapic/java_gapic.bzl +++ b/rules_java_gapic/java_gapic.bzl @@ -36,7 +36,7 @@ def _java_gapic_postprocess_srcjar_impl(ctx): zip -r $WORKING_DIR/{output_srcjar_name}.srcjar ./ cd $WORKING_DIR/{output_dir_path}/proto/src/main/java zip -r $WORKING_DIR/{output_srcjar_name}-resource-name.srcjar ./ - cd $WORKING_DIR/{output_dir_path}/proto/src/test/java + cd $WORKING_DIR/{output_dir_path}/src/test/java zip -r $WORKING_DIR/{output_srcjar_name}-tests.srcjar ./ cd $WORKING_DIR mv {output_srcjar_name}.srcjar {output_main} diff --git a/src/main/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposer.java b/src/main/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposer.java index c1e499fbec..564e6dad4f 100644 --- a/src/main/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposer.java +++ b/src/main/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposer.java @@ -1090,21 +1090,25 @@ private static MethodDefinition createToStringMethod( List> tokenHierarchies) { boolean hasVariants = tokenHierarchies.size() > 1; if (!hasVariants) { - String token = getTokenSet(tokenHierarchies).stream().collect(Collectors.toList()).get(0); - String javaTokenVarName = JavaStyle.toLowerCamelCase(token); - Preconditions.checkNotNull( - patternTokenVarExprs.get(token), - String.format( - "No expression found for token %s amongst values %s", - javaTokenVarName, patternTokenVarExprs.toString())); + + List instantiateArgExprs = new ArrayList<>(); + List tokens = getTokenSet(tokenHierarchies).stream().collect(Collectors.toList()); + for (int i = 0; i < tokens.size(); i++) { + String token = tokens.get(i); + Preconditions.checkNotNull( + patternTokenVarExprs.get(token), + String.format( + "No expression found for token %s amongst values %s", + token, patternTokenVarExprs.toString())); + instantiateArgExprs.add(ValueExpr.withValue(StringObjectValue.withValue(token))); + instantiateArgExprs.add(patternTokenVarExprs.get(token)); + } MethodInvocationExpr returnInstantiateExpr = MethodInvocationExpr.builder() .setExprReferenceExpr(templateFinalVarExprs.get(0)) .setMethodName("instantiate") - .setArguments( - ValueExpr.withValue(StringObjectValue.withValue(token)), - patternTokenVarExprs.get(token)) + .setArguments(instantiateArgExprs) .setReturnType(TypeNode.STRING) .build(); return MethodDefinition.builder() diff --git a/src/test/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposerTest.java b/src/test/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposerTest.java index cf29462c31..f29ea0ec7e 100644 --- a/src/test/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposerTest.java +++ b/src/test/java/com/google/api/generator/gapic/composer/ResourceNameHelperClassComposerTest.java @@ -25,13 +25,19 @@ import com.google.api.generator.gapic.protoparser.Parser; import com.google.api.generator.test.framework.Assert; import com.google.api.generator.test.framework.Utils; +import com.google.logging.v2.LogEntryProto; +import com.google.logging.v2.LoggingConfigProto; +import com.google.logging.v2.LoggingMetricsProto; +import com.google.logging.v2.LoggingProto; import com.google.protobuf.Descriptors.FileDescriptor; import com.google.protobuf.Descriptors.ServiceDescriptor; import com.google.showcase.v1beta1.EchoOuterClass; import com.google.showcase.v1beta1.TestingOuterClass; +import google.cloud.CommonResources; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -95,7 +101,6 @@ public void generateResourceNameClass_echoFoobarMultiplePatterns() { ResourceName foobarResname = resourceNames.get("showcase.googleapis.com/Foobar"); assertThat(outputResourceNames).contains(foobarResname); - Service echoProtoService = services.get(0); GapicClass clazz = ResourceNameHelperClassComposer.instance().generate(foobarResname); JavaWriterVisitor visitor = new JavaWriterVisitor(); @@ -105,6 +110,55 @@ public void generateResourceNameClass_echoFoobarMultiplePatterns() { Assert.assertCodeEquals(goldenFilePath, visitor.write()); } + @Test + public void generateResourceNameClass_loggingOnePatternMultipleVariables() { + FileDescriptor serviceFileDescriptor = LoggingConfigProto.getDescriptor(); + ServiceDescriptor serviceDescriptor = serviceFileDescriptor.getServices().get(0); + assertEquals(serviceDescriptor.getName(), "ConfigServiceV2"); + + List protoFiles = + Arrays.asList( + serviceFileDescriptor, + LoggingProto.getDescriptor(), + LogEntryProto.getDescriptor(), + LoggingConfigProto.getDescriptor(), + LoggingMetricsProto.getDescriptor()); + + Map resourceNames = new HashMap<>(); + Map messageTypes = new HashMap<>(); + for (FileDescriptor fileDescriptor : protoFiles) { + resourceNames.putAll(Parser.parseResourceNames(fileDescriptor)); + messageTypes.putAll(Parser.parseMessages(fileDescriptor)); + } + + // Additional resource names. + FileDescriptor commonResourcesFileDescriptor = CommonResources.getDescriptor(); + resourceNames.putAll(Parser.parseResourceNames(commonResourcesFileDescriptor)); + + Set outputResourceNames = new HashSet<>(); + List services = + Parser.parseService( + serviceFileDescriptor, + messageTypes, + resourceNames, + Optional.empty(), + outputResourceNames); + + ResourceName billingAccountLocationResname = + resourceNames.get("logging.googleapis.com/BillingAccountLocation"); + assertThat(outputResourceNames).contains(billingAccountLocationResname); + + GapicClass clazz = + ResourceNameHelperClassComposer.instance().generate(billingAccountLocationResname); + + JavaWriterVisitor visitor = new JavaWriterVisitor(); + clazz.classDefinition().accept(visitor); + Utils.saveCodegenToFile(this.getClass(), "BillingAccountLocationName.golden", visitor.write()); + Path goldenFilePath = + Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "BillingAccountLocationName.golden"); + Assert.assertCodeEquals(goldenFilePath, visitor.write()); + } + @Test public void generateResourceNameClass_testingSessionOnePattern() { FileDescriptor testingFileDescriptor = TestingOuterClass.getDescriptor(); @@ -125,7 +179,6 @@ public void generateResourceNameClass_testingSessionOnePattern() { ResourceName sessionResname = resourceNames.get("showcase.googleapis.com/Session"); assertThat(outputResourceNames).contains(sessionResname); - Service testingProtoService = services.get(0); GapicClass clazz = ResourceNameHelperClassComposer.instance().generate(sessionResname); JavaWriterVisitor visitor = new JavaWriterVisitor(); @@ -134,5 +187,4 @@ public void generateResourceNameClass_testingSessionOnePattern() { Path goldenFilePath = Paths.get(ComposerConstants.GOLDENFILES_DIRECTORY, "SessionName.golden"); Assert.assertCodeEquals(goldenFilePath, visitor.write()); } - // TODO(miraleung): Add more tests for a single pattern. } diff --git a/src/test/java/com/google/api/generator/gapic/composer/goldens/BillingAccountLocationName.golden b/src/test/java/com/google/api/generator/gapic/composer/goldens/BillingAccountLocationName.golden new file mode 100644 index 0000000000..94fd7c738d --- /dev/null +++ b/src/test/java/com/google/api/generator/gapic/composer/goldens/BillingAccountLocationName.golden @@ -0,0 +1,173 @@ +package com.google.logging.v2; + +import com.google.api.pathtemplate.PathTemplate; +import com.google.api.resourcenames.ResourceName; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import javax.annotation.Generated; + +// AUTO-GENERATED DOCUMENTATION AND CLASS. +@Generated("by gapic-generator-java") +public class BillingAccountLocationName implements ResourceName { + private static final PathTemplate BILLING_ACCOUNT_LOCATION = + PathTemplate.createWithoutUrlEncoding( + "billingAccounts/{billing_account}/locations/{location}"); + private volatile Map fieldValuesMap; + private final String billingAccount; + private final String location; + + private BillingAccountLocationName(Builder builder) { + billingAccount = Preconditions.checkNotNull(builder.getBillingAccount()); + location = Preconditions.checkNotNull(builder.getLocation()); + } + + public String getBillingAccount() { + return billingAccount; + } + + public String getLocation() { + return location; + } + + public static Builder newBuilder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder(this); + } + + public static BillingAccountLocationName of(String billingAccount, String location) { + return newBuilder().setBillingAccount(billingAccount).setLocation(location).build(); + } + + public static String format(String billingAccount, String location) { + return newBuilder().setBillingAccount(billingAccount).setLocation(location).build().toString(); + } + + public static BillingAccountLocationName parse(String formattedString) { + if (formattedString.isEmpty()) { + return null; + } + Map matchMap = + BILLING_ACCOUNT_LOCATION.validatedMatch( + formattedString, + "BillingAccountLocationName.parse: formattedString not in valid format"); + return of(matchMap.get("billing_account"), matchMap.get("location")); + } + + public static List parseList(List formattedStrings) { + List list = new ArrayList<>(formattedStrings.size()); + for (String formattedString : formattedStrings) { + list.add(parse(formattedString)); + } + return list; + } + + public static List toStringList(List values) { + List list = new ArrayList<>(values.size()); + for (BillingAccountLocationName value : values) { + if (Objects.isNull(value)) { + list.add(""); + } else { + list.add(value.toString()); + } + } + return list; + } + + public static boolean isParsableFrom(String formattedString) { + return BILLING_ACCOUNT_LOCATION.matches(formattedString); + } + + @Override + public Map getFieldValuesMap() { + if (Objects.isNull(fieldValuesMap)) { + synchronized (this) { + if (Objects.isNull(fieldValuesMap)) { + ImmutableMap.Builder fieldMapBuilder = ImmutableMap.builder(); + if (!Objects.isNull(billingAccount)) { + fieldMapBuilder.put("billing_account", billingAccount); + } + if (!Objects.isNull(location)) { + fieldMapBuilder.put("location", location); + } + fieldValuesMap = fieldMapBuilder.build(); + } + } + } + return fieldValuesMap; + } + + public String getFieldValue(String fieldName) { + return getFieldValuesMap().get(fieldName); + } + + @Override + public String toString() { + return BILLING_ACCOUNT_LOCATION.instantiate( + "billing_account", billingAccount, "location", location); + } + + @Override + public boolean equals(Object o) { + if (o == this) { + return true; + } + if (o != null || getClass() == o.getClass()) { + BillingAccountLocationName that = ((BillingAccountLocationName) o); + return Objects.equals(this.billingAccount, that.billingAccount) + && Objects.equals(this.location, that.location); + } + return false; + } + + @Override + public int hashCode() { + int h = 1; + h *= 1000003; + h ^= Objects.hashCode(billingAccount); + h *= 1000003; + h ^= Objects.hashCode(location); + return h; + } + + /** Builder for billingAccounts/{billing_account}/locations/{location}. */ + public static class Builder { + private String billingAccount; + private String location; + + private Builder() {} + + public String getBillingAccount() { + return billingAccount; + } + + public String getLocation() { + return location; + } + + public Builder setBillingAccount(String billingAccount) { + this.billingAccount = billingAccount; + return this; + } + + public Builder setLocation(String location) { + this.location = location; + return this; + } + + private Builder(BillingAccountLocationName billingAccountLocationName) { + billingAccount = billingAccountLocationName.billingAccount; + location = billingAccountLocationName.location; + } + + public BillingAccountLocationName build() { + return new BillingAccountLocationName(this); + } + } +} diff --git a/test/integration/goldens/asset/AssetServiceClientTest.java b/test/integration/goldens/asset/AssetServiceClientTest.java index 3dc55843af..7c5ab77c2d 100644 --- a/test/integration/goldens/asset/AssetServiceClientTest.java +++ b/test/integration/goldens/asset/AssetServiceClientTest.java @@ -103,7 +103,7 @@ public void exportAssetsTest() throws Exception { ExportAssetsRequest request = ExportAssetsRequest.newBuilder() .setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) - .addAllAssetTypes(new ArrayList<>()) + .addAllAssetTypes(new ArrayList()) .setOutputConfig(OutputConfig.newBuilder().build()) .build(); @@ -134,7 +134,7 @@ public void exportAssetsExceptionTest() throws Exception { ExportAssetsRequest request = ExportAssetsRequest.newBuilder() .setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) - .addAllAssetTypes(new ArrayList<>()) + .addAllAssetTypes(new ArrayList()) .setOutputConfig(OutputConfig.newBuilder().build()) .build(); client.exportAssetsAsync(request).get(); @@ -149,13 +149,15 @@ public void exportAssetsExceptionTest() throws Exception { @Test public void batchGetAssetsHistoryTest() throws Exception { BatchGetAssetsHistoryResponse expectedResponse = - BatchGetAssetsHistoryResponse.newBuilder().addAllAssets(new ArrayList<>()).build(); + BatchGetAssetsHistoryResponse.newBuilder() + .addAllAssets(new ArrayList()) + .build(); mockAssetService.addResponse(expectedResponse); BatchGetAssetsHistoryRequest request = BatchGetAssetsHistoryRequest.newBuilder() .setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) - .addAllAssetNames(new ArrayList<>()) + .addAllAssetNames(new ArrayList()) .setReadTimeWindow(TimeWindow.newBuilder().build()) .build(); @@ -186,7 +188,7 @@ public void batchGetAssetsHistoryExceptionTest() throws Exception { BatchGetAssetsHistoryRequest request = BatchGetAssetsHistoryRequest.newBuilder() .setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) - .addAllAssetNames(new ArrayList<>()) + .addAllAssetNames(new ArrayList()) .setReadTimeWindow(TimeWindow.newBuilder().build()) .build(); client.batchGetAssetsHistory(request); @@ -201,8 +203,8 @@ public void createFeedTest() throws Exception { Feed expectedResponse = Feed.newBuilder() .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) - .addAllAssetNames(new ArrayList<>()) - .addAllAssetTypes(new ArrayList<>()) + .addAllAssetNames(new ArrayList()) + .addAllAssetTypes(new ArrayList()) .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) .build(); mockAssetService.addResponse(expectedResponse); @@ -242,8 +244,8 @@ public void getFeedTest() throws Exception { Feed expectedResponse = Feed.newBuilder() .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) - .addAllAssetNames(new ArrayList<>()) - .addAllAssetTypes(new ArrayList<>()) + .addAllAssetNames(new ArrayList()) + .addAllAssetTypes(new ArrayList()) .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) .build(); mockAssetService.addResponse(expectedResponse); @@ -283,8 +285,8 @@ public void getFeedTest2() throws Exception { Feed expectedResponse = Feed.newBuilder() .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) - .addAllAssetNames(new ArrayList<>()) - .addAllAssetTypes(new ArrayList<>()) + .addAllAssetNames(new ArrayList()) + .addAllAssetTypes(new ArrayList()) .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) .build(); mockAssetService.addResponse(expectedResponse); @@ -322,7 +324,7 @@ public void getFeedExceptionTest2() throws Exception { @Test public void listFeedsTest() throws Exception { ListFeedsResponse expectedResponse = - ListFeedsResponse.newBuilder().addAllFeeds(new ArrayList<>()).build(); + ListFeedsResponse.newBuilder().addAllFeeds(new ArrayList()).build(); mockAssetService.addResponse(expectedResponse); String parent = "parent-995424086"; @@ -360,8 +362,8 @@ public void updateFeedTest() throws Exception { Feed expectedResponse = Feed.newBuilder() .setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()) - .addAllAssetNames(new ArrayList<>()) - .addAllAssetTypes(new ArrayList<>()) + .addAllAssetNames(new ArrayList()) + .addAllAssetTypes(new ArrayList()) .setFeedOutputConfig(FeedOutputConfig.newBuilder().build()) .build(); mockAssetService.addResponse(expectedResponse); diff --git a/test/integration/goldens/logging/BillingAccountLocationName.java b/test/integration/goldens/logging/BillingAccountLocationName.java index 3d108a3a4b..ead5f6cdec 100644 --- a/test/integration/goldens/logging/BillingAccountLocationName.java +++ b/test/integration/goldens/logging/BillingAccountLocationName.java @@ -125,7 +125,8 @@ public String getFieldValue(String fieldName) { @Override public String toString() { - return BILLING_ACCOUNT_LOCATION.instantiate("billing_account", billingAccount); + return BILLING_ACCOUNT_LOCATION.instantiate( + "billing_account", billingAccount, "location", location); } @Override diff --git a/test/integration/goldens/logging/ConfigServiceV2ClientTest.java b/test/integration/goldens/logging/ConfigServiceV2ClientTest.java new file mode 100644 index 0000000000..3643a06e7d --- /dev/null +++ b/test/integration/goldens/logging/ConfigServiceV2ClientTest.java @@ -0,0 +1,2003 @@ +/* + * Copyright 2020 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.logging.v2; + +import static com.google.logging.v2.ConfigServiceV2Client.ListBucketsPagedResponse; +import static com.google.logging.v2.ConfigServiceV2Client.ListExclusionsPagedResponse; +import static com.google.logging.v2.ConfigServiceV2Client.ListSinksPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.testing.LocalChannelProvider; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.api.gax.grpc.testing.MockServiceHelper; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.common.collect.Lists; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Empty; +import com.google.protobuf.FieldMask; +import io.grpc.StatusRuntimeException; +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class ConfigServiceV2ClientTest { + private static MockServiceHelper mockServiceHelper; + private ConfigServiceV2Client client; + private LocalChannelProvider channelProvider; + private static MockConfigServiceV2 mockConfigServiceV2; + + @BeforeClass + public static void startStaticServer() { + mockConfigServiceV2 = new MockConfigServiceV2(); + mockServiceHelper = + new MockServiceHelper( + UUID.randomUUID().toString(), Arrays.asList(mockConfigServiceV2)); + mockServiceHelper.start(); + } + + @AfterClass + public static void stopServer() { + mockServiceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + mockServiceHelper.reset(); + channelProvider = mockServiceHelper.createChannelProvider(); + ConfigServiceV2Settings settings = + ConfigServiceV2Settings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = ConfigServiceV2Client.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } + + @Test + public void listBucketsTest() throws Exception { + LogBucket responsesElement = LogBucket.newBuilder().build(); + ListBucketsResponse expectedResponse = + ListBucketsResponse.newBuilder() + .setNextPageToken("") + .addAllBuckets(Arrays.asList(responsesElement)) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + BillingAccountLocationName parent = + BillingAccountLocationName.of("[BILLING_ACCOUNT]", "[LOCATION]"); + + ListBucketsPagedResponse pagedListResponse = client.listBuckets(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getBucketsList().get(0), resources.get(0)); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListBucketsRequest actualRequest = ((ListBucketsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listBucketsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + BillingAccountLocationName parent = + BillingAccountLocationName.of("[BILLING_ACCOUNT]", "[LOCATION]"); + client.listBuckets(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listBucketsTest2() throws Exception { + LogBucket responsesElement = LogBucket.newBuilder().build(); + ListBucketsResponse expectedResponse = + ListBucketsResponse.newBuilder() + .setNextPageToken("") + .addAllBuckets(Arrays.asList(responsesElement)) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + FolderLocationName parent = FolderLocationName.of("[FOLDER]", "[LOCATION]"); + + ListBucketsPagedResponse pagedListResponse = client.listBuckets(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getBucketsList().get(0), resources.get(0)); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListBucketsRequest actualRequest = ((ListBucketsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listBucketsExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + FolderLocationName parent = FolderLocationName.of("[FOLDER]", "[LOCATION]"); + client.listBuckets(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listBucketsTest3() throws Exception { + LogBucket responsesElement = LogBucket.newBuilder().build(); + ListBucketsResponse expectedResponse = + ListBucketsResponse.newBuilder() + .setNextPageToken("") + .addAllBuckets(Arrays.asList(responsesElement)) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + + ListBucketsPagedResponse pagedListResponse = client.listBuckets(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getBucketsList().get(0), resources.get(0)); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListBucketsRequest actualRequest = ((ListBucketsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listBucketsExceptionTest3() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]"); + client.listBuckets(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listBucketsTest4() throws Exception { + LogBucket responsesElement = LogBucket.newBuilder().build(); + ListBucketsResponse expectedResponse = + ListBucketsResponse.newBuilder() + .setNextPageToken("") + .addAllBuckets(Arrays.asList(responsesElement)) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + OrganizationLocationName parent = OrganizationLocationName.of("[ORGANIZATION]", "[LOCATION]"); + + ListBucketsPagedResponse pagedListResponse = client.listBuckets(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getBucketsList().get(0), resources.get(0)); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListBucketsRequest actualRequest = ((ListBucketsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listBucketsExceptionTest4() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + OrganizationLocationName parent = OrganizationLocationName.of("[ORGANIZATION]", "[LOCATION]"); + client.listBuckets(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listBucketsTest5() throws Exception { + LogBucket responsesElement = LogBucket.newBuilder().build(); + ListBucketsResponse expectedResponse = + ListBucketsResponse.newBuilder() + .setNextPageToken("") + .addAllBuckets(Arrays.asList(responsesElement)) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + String parent = "parent-995424086"; + + ListBucketsPagedResponse pagedListResponse = client.listBuckets(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getBucketsList().get(0), resources.get(0)); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListBucketsRequest actualRequest = ((ListBucketsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listBucketsExceptionTest5() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + String parent = "parent-995424086"; + client.listBuckets(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getBucketTest() throws Exception { + LogBucket expectedResponse = + LogBucket.newBuilder() + .setName( + LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]") + .toString()) + .setDescription("description-1724546052") + .setRetentionDays(1544391896) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + GetBucketRequest request = + GetBucketRequest.newBuilder() + .setName( + LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]") + .toString()) + .build(); + + LogBucket actualResponse = client.getBucket(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetBucketRequest actualRequest = ((GetBucketRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getBucketExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + GetBucketRequest request = + GetBucketRequest.newBuilder() + .setName( + LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]") + .toString()) + .build(); + client.getBucket(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateBucketTest() throws Exception { + LogBucket expectedResponse = + LogBucket.newBuilder() + .setName( + LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]") + .toString()) + .setDescription("description-1724546052") + .setRetentionDays(1544391896) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + UpdateBucketRequest request = + UpdateBucketRequest.newBuilder() + .setName( + LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]") + .toString()) + .setBucket(LogBucket.newBuilder().build()) + .build(); + + LogBucket actualResponse = client.updateBucket(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpdateBucketRequest actualRequest = ((UpdateBucketRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertEquals(request.getBucket(), actualRequest.getBucket()); + Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void updateBucketExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + UpdateBucketRequest request = + UpdateBucketRequest.newBuilder() + .setName( + LogBucketName.ofProjectLocationBucketName("[PROJECT]", "[LOCATION]", "[BUCKET]") + .toString()) + .setBucket(LogBucket.newBuilder().build()) + .build(); + client.updateBucket(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listSinksTest() throws Exception { + LogSink responsesElement = LogSink.newBuilder().build(); + ListSinksResponse expectedResponse = + ListSinksResponse.newBuilder() + .setNextPageToken("") + .addAllSinks(Arrays.asList(responsesElement)) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]"); + + ListSinksPagedResponse pagedListResponse = client.listSinks(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getSinksList().get(0), resources.get(0)); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListSinksRequest actualRequest = ((ListSinksRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listSinksExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]"); + client.listSinks(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listSinksTest2() throws Exception { + LogSink responsesElement = LogSink.newBuilder().build(); + ListSinksResponse expectedResponse = + ListSinksResponse.newBuilder() + .setNextPageToken("") + .addAllSinks(Arrays.asList(responsesElement)) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + FolderName parent = FolderName.of("[FOLDER]"); + + ListSinksPagedResponse pagedListResponse = client.listSinks(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getSinksList().get(0), resources.get(0)); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListSinksRequest actualRequest = ((ListSinksRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listSinksExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + FolderName parent = FolderName.of("[FOLDER]"); + client.listSinks(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listSinksTest3() throws Exception { + LogSink responsesElement = LogSink.newBuilder().build(); + ListSinksResponse expectedResponse = + ListSinksResponse.newBuilder() + .setNextPageToken("") + .addAllSinks(Arrays.asList(responsesElement)) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + + ListSinksPagedResponse pagedListResponse = client.listSinks(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getSinksList().get(0), resources.get(0)); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListSinksRequest actualRequest = ((ListSinksRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listSinksExceptionTest3() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + client.listSinks(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listSinksTest4() throws Exception { + LogSink responsesElement = LogSink.newBuilder().build(); + ListSinksResponse expectedResponse = + ListSinksResponse.newBuilder() + .setNextPageToken("") + .addAllSinks(Arrays.asList(responsesElement)) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + ProjectName parent = ProjectName.of("[PROJECT]"); + + ListSinksPagedResponse pagedListResponse = client.listSinks(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getSinksList().get(0), resources.get(0)); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListSinksRequest actualRequest = ((ListSinksRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listSinksExceptionTest4() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + ProjectName parent = ProjectName.of("[PROJECT]"); + client.listSinks(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listSinksTest5() throws Exception { + LogSink responsesElement = LogSink.newBuilder().build(); + ListSinksResponse expectedResponse = + ListSinksResponse.newBuilder() + .setNextPageToken("") + .addAllSinks(Arrays.asList(responsesElement)) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + String parent = "parent-995424086"; + + ListSinksPagedResponse pagedListResponse = client.listSinks(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getSinksList().get(0), resources.get(0)); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListSinksRequest actualRequest = ((ListSinksRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listSinksExceptionTest5() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + String parent = "parent-995424086"; + client.listSinks(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getSinkTest() throws Exception { + LogSink expectedResponse = + LogSink.newBuilder() + .setName(LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString()) + .setDestination("destination-1429847026") + .setFilter("filter-1274492040") + .setDescription("description-1724546052") + .setDisabled(true) + .setWriterIdentity("writer_identity775638794") + .setIncludeChildren(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]"); + + LogSink actualResponse = client.getSink(sinkName); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetSinkRequest actualRequest = ((GetSinkRequest) actualRequests.get(0)); + + Assert.assertEquals(sinkName.toString(), actualRequest.getSinkName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getSinkExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]"); + client.getSink(sinkName); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getSinkTest2() throws Exception { + LogSink expectedResponse = + LogSink.newBuilder() + .setName(LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString()) + .setDestination("destination-1429847026") + .setFilter("filter-1274492040") + .setDescription("description-1724546052") + .setDisabled(true) + .setWriterIdentity("writer_identity775638794") + .setIncludeChildren(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + String sinkName = "sink_name-1391757129"; + + LogSink actualResponse = client.getSink(sinkName); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetSinkRequest actualRequest = ((GetSinkRequest) actualRequests.get(0)); + + Assert.assertEquals(sinkName, actualRequest.getSinkName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getSinkExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + String sinkName = "sink_name-1391757129"; + client.getSink(sinkName); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createSinkTest() throws Exception { + LogSink expectedResponse = + LogSink.newBuilder() + .setName(LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString()) + .setDestination("destination-1429847026") + .setFilter("filter-1274492040") + .setDescription("description-1724546052") + .setDisabled(true) + .setWriterIdentity("writer_identity775638794") + .setIncludeChildren(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]"); + LogSink sink = LogSink.newBuilder().build(); + + LogSink actualResponse = client.createSink(parent, sink); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateSinkRequest actualRequest = ((CreateSinkRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(sink, actualRequest.getSink()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createSinkExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]"); + LogSink sink = LogSink.newBuilder().build(); + client.createSink(parent, sink); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createSinkTest2() throws Exception { + LogSink expectedResponse = + LogSink.newBuilder() + .setName(LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString()) + .setDestination("destination-1429847026") + .setFilter("filter-1274492040") + .setDescription("description-1724546052") + .setDisabled(true) + .setWriterIdentity("writer_identity775638794") + .setIncludeChildren(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + FolderName parent = FolderName.of("[FOLDER]"); + LogSink sink = LogSink.newBuilder().build(); + + LogSink actualResponse = client.createSink(parent, sink); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateSinkRequest actualRequest = ((CreateSinkRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(sink, actualRequest.getSink()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createSinkExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + FolderName parent = FolderName.of("[FOLDER]"); + LogSink sink = LogSink.newBuilder().build(); + client.createSink(parent, sink); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createSinkTest3() throws Exception { + LogSink expectedResponse = + LogSink.newBuilder() + .setName(LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString()) + .setDestination("destination-1429847026") + .setFilter("filter-1274492040") + .setDescription("description-1724546052") + .setDisabled(true) + .setWriterIdentity("writer_identity775638794") + .setIncludeChildren(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + LogSink sink = LogSink.newBuilder().build(); + + LogSink actualResponse = client.createSink(parent, sink); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateSinkRequest actualRequest = ((CreateSinkRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(sink, actualRequest.getSink()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createSinkExceptionTest3() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + LogSink sink = LogSink.newBuilder().build(); + client.createSink(parent, sink); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createSinkTest4() throws Exception { + LogSink expectedResponse = + LogSink.newBuilder() + .setName(LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString()) + .setDestination("destination-1429847026") + .setFilter("filter-1274492040") + .setDescription("description-1724546052") + .setDisabled(true) + .setWriterIdentity("writer_identity775638794") + .setIncludeChildren(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + ProjectName parent = ProjectName.of("[PROJECT]"); + LogSink sink = LogSink.newBuilder().build(); + + LogSink actualResponse = client.createSink(parent, sink); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateSinkRequest actualRequest = ((CreateSinkRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(sink, actualRequest.getSink()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createSinkExceptionTest4() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + ProjectName parent = ProjectName.of("[PROJECT]"); + LogSink sink = LogSink.newBuilder().build(); + client.createSink(parent, sink); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createSinkTest5() throws Exception { + LogSink expectedResponse = + LogSink.newBuilder() + .setName(LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString()) + .setDestination("destination-1429847026") + .setFilter("filter-1274492040") + .setDescription("description-1724546052") + .setDisabled(true) + .setWriterIdentity("writer_identity775638794") + .setIncludeChildren(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + String parent = "parent-995424086"; + LogSink sink = LogSink.newBuilder().build(); + + LogSink actualResponse = client.createSink(parent, sink); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateSinkRequest actualRequest = ((CreateSinkRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertEquals(sink, actualRequest.getSink()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createSinkExceptionTest5() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + String parent = "parent-995424086"; + LogSink sink = LogSink.newBuilder().build(); + client.createSink(parent, sink); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateSinkTest() throws Exception { + LogSink expectedResponse = + LogSink.newBuilder() + .setName(LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString()) + .setDestination("destination-1429847026") + .setFilter("filter-1274492040") + .setDescription("description-1724546052") + .setDisabled(true) + .setWriterIdentity("writer_identity775638794") + .setIncludeChildren(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]"); + LogSink sink = LogSink.newBuilder().build(); + + LogSink actualResponse = client.updateSink(sinkName, sink); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpdateSinkRequest actualRequest = ((UpdateSinkRequest) actualRequests.get(0)); + + Assert.assertEquals(sinkName.toString(), actualRequest.getSinkName()); + Assert.assertEquals(sink, actualRequest.getSink()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void updateSinkExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]"); + LogSink sink = LogSink.newBuilder().build(); + client.updateSink(sinkName, sink); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateSinkTest2() throws Exception { + LogSink expectedResponse = + LogSink.newBuilder() + .setName(LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString()) + .setDestination("destination-1429847026") + .setFilter("filter-1274492040") + .setDescription("description-1724546052") + .setDisabled(true) + .setWriterIdentity("writer_identity775638794") + .setIncludeChildren(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + String sinkName = "sink_name-1391757129"; + LogSink sink = LogSink.newBuilder().build(); + + LogSink actualResponse = client.updateSink(sinkName, sink); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpdateSinkRequest actualRequest = ((UpdateSinkRequest) actualRequests.get(0)); + + Assert.assertEquals(sinkName, actualRequest.getSinkName()); + Assert.assertEquals(sink, actualRequest.getSink()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void updateSinkExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + String sinkName = "sink_name-1391757129"; + LogSink sink = LogSink.newBuilder().build(); + client.updateSink(sinkName, sink); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateSinkTest3() throws Exception { + LogSink expectedResponse = + LogSink.newBuilder() + .setName(LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString()) + .setDestination("destination-1429847026") + .setFilter("filter-1274492040") + .setDescription("description-1724546052") + .setDisabled(true) + .setWriterIdentity("writer_identity775638794") + .setIncludeChildren(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]"); + LogSink sink = LogSink.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + LogSink actualResponse = client.updateSink(sinkName, sink, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpdateSinkRequest actualRequest = ((UpdateSinkRequest) actualRequests.get(0)); + + Assert.assertEquals(sinkName.toString(), actualRequest.getSinkName()); + Assert.assertEquals(sink, actualRequest.getSink()); + Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void updateSinkExceptionTest3() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]"); + LogSink sink = LogSink.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateSink(sinkName, sink, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateSinkTest4() throws Exception { + LogSink expectedResponse = + LogSink.newBuilder() + .setName(LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]").toString()) + .setDestination("destination-1429847026") + .setFilter("filter-1274492040") + .setDescription("description-1724546052") + .setDisabled(true) + .setWriterIdentity("writer_identity775638794") + .setIncludeChildren(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + String sinkName = "sink_name-1391757129"; + LogSink sink = LogSink.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + LogSink actualResponse = client.updateSink(sinkName, sink, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpdateSinkRequest actualRequest = ((UpdateSinkRequest) actualRequests.get(0)); + + Assert.assertEquals(sinkName, actualRequest.getSinkName()); + Assert.assertEquals(sink, actualRequest.getSink()); + Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void updateSinkExceptionTest4() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + String sinkName = "sink_name-1391757129"; + LogSink sink = LogSink.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateSink(sinkName, sink, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteSinkTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockConfigServiceV2.addResponse(expectedResponse); + + LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]"); + + Empty actualResponse = client.deleteSink(sinkName); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteSinkRequest actualRequest = ((DeleteSinkRequest) actualRequests.get(0)); + + Assert.assertEquals(sinkName.toString(), actualRequest.getSinkName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteSinkExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + LogSinkName sinkName = LogSinkName.ofProjectSinkName("[PROJECT]", "[SINK]"); + client.deleteSink(sinkName); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteSinkTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockConfigServiceV2.addResponse(expectedResponse); + + String sinkName = "sink_name-1391757129"; + + Empty actualResponse = client.deleteSink(sinkName); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteSinkRequest actualRequest = ((DeleteSinkRequest) actualRequests.get(0)); + + Assert.assertEquals(sinkName, actualRequest.getSinkName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteSinkExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + String sinkName = "sink_name-1391757129"; + client.deleteSink(sinkName); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listExclusionsTest() throws Exception { + LogExclusion responsesElement = LogExclusion.newBuilder().build(); + ListExclusionsResponse expectedResponse = + ListExclusionsResponse.newBuilder() + .setNextPageToken("") + .addAllExclusions(Arrays.asList(responsesElement)) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]"); + + ListExclusionsPagedResponse pagedListResponse = client.listExclusions(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getExclusionsList().get(0), resources.get(0)); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListExclusionsRequest actualRequest = ((ListExclusionsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listExclusionsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]"); + client.listExclusions(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listExclusionsTest2() throws Exception { + LogExclusion responsesElement = LogExclusion.newBuilder().build(); + ListExclusionsResponse expectedResponse = + ListExclusionsResponse.newBuilder() + .setNextPageToken("") + .addAllExclusions(Arrays.asList(responsesElement)) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + FolderName parent = FolderName.of("[FOLDER]"); + + ListExclusionsPagedResponse pagedListResponse = client.listExclusions(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getExclusionsList().get(0), resources.get(0)); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListExclusionsRequest actualRequest = ((ListExclusionsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listExclusionsExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + FolderName parent = FolderName.of("[FOLDER]"); + client.listExclusions(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listExclusionsTest3() throws Exception { + LogExclusion responsesElement = LogExclusion.newBuilder().build(); + ListExclusionsResponse expectedResponse = + ListExclusionsResponse.newBuilder() + .setNextPageToken("") + .addAllExclusions(Arrays.asList(responsesElement)) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + + ListExclusionsPagedResponse pagedListResponse = client.listExclusions(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getExclusionsList().get(0), resources.get(0)); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListExclusionsRequest actualRequest = ((ListExclusionsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listExclusionsExceptionTest3() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + client.listExclusions(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listExclusionsTest4() throws Exception { + LogExclusion responsesElement = LogExclusion.newBuilder().build(); + ListExclusionsResponse expectedResponse = + ListExclusionsResponse.newBuilder() + .setNextPageToken("") + .addAllExclusions(Arrays.asList(responsesElement)) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + ProjectName parent = ProjectName.of("[PROJECT]"); + + ListExclusionsPagedResponse pagedListResponse = client.listExclusions(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getExclusionsList().get(0), resources.get(0)); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListExclusionsRequest actualRequest = ((ListExclusionsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listExclusionsExceptionTest4() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + ProjectName parent = ProjectName.of("[PROJECT]"); + client.listExclusions(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listExclusionsTest5() throws Exception { + LogExclusion responsesElement = LogExclusion.newBuilder().build(); + ListExclusionsResponse expectedResponse = + ListExclusionsResponse.newBuilder() + .setNextPageToken("") + .addAllExclusions(Arrays.asList(responsesElement)) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + String parent = "parent-995424086"; + + ListExclusionsPagedResponse pagedListResponse = client.listExclusions(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getExclusionsList().get(0), resources.get(0)); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListExclusionsRequest actualRequest = ((ListExclusionsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listExclusionsExceptionTest5() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + String parent = "parent-995424086"; + client.listExclusions(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getExclusionTest() throws Exception { + LogExclusion expectedResponse = + LogExclusion.newBuilder() + .setName(LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]").toString()) + .setDescription("description-1724546052") + .setFilter("filter-1274492040") + .setDisabled(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]"); + + LogExclusion actualResponse = client.getExclusion(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetExclusionRequest actualRequest = ((GetExclusionRequest) actualRequests.get(0)); + + Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getExclusionExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]"); + client.getExclusion(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getExclusionTest2() throws Exception { + LogExclusion expectedResponse = + LogExclusion.newBuilder() + .setName(LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]").toString()) + .setDescription("description-1724546052") + .setFilter("filter-1274492040") + .setDisabled(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + String name = "name3373707"; + + LogExclusion actualResponse = client.getExclusion(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetExclusionRequest actualRequest = ((GetExclusionRequest) actualRequests.get(0)); + + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getExclusionExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + String name = "name3373707"; + client.getExclusion(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createExclusionTest() throws Exception { + LogExclusion expectedResponse = + LogExclusion.newBuilder() + .setName(LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]").toString()) + .setDescription("description-1724546052") + .setFilter("filter-1274492040") + .setDisabled(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]"); + LogExclusion exclusion = LogExclusion.newBuilder().build(); + + LogExclusion actualResponse = client.createExclusion(parent, exclusion); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateExclusionRequest actualRequest = ((CreateExclusionRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(exclusion, actualRequest.getExclusion()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createExclusionExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]"); + LogExclusion exclusion = LogExclusion.newBuilder().build(); + client.createExclusion(parent, exclusion); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createExclusionTest2() throws Exception { + LogExclusion expectedResponse = + LogExclusion.newBuilder() + .setName(LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]").toString()) + .setDescription("description-1724546052") + .setFilter("filter-1274492040") + .setDisabled(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + FolderName parent = FolderName.of("[FOLDER]"); + LogExclusion exclusion = LogExclusion.newBuilder().build(); + + LogExclusion actualResponse = client.createExclusion(parent, exclusion); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateExclusionRequest actualRequest = ((CreateExclusionRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(exclusion, actualRequest.getExclusion()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createExclusionExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + FolderName parent = FolderName.of("[FOLDER]"); + LogExclusion exclusion = LogExclusion.newBuilder().build(); + client.createExclusion(parent, exclusion); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createExclusionTest3() throws Exception { + LogExclusion expectedResponse = + LogExclusion.newBuilder() + .setName(LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]").toString()) + .setDescription("description-1724546052") + .setFilter("filter-1274492040") + .setDisabled(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + LogExclusion exclusion = LogExclusion.newBuilder().build(); + + LogExclusion actualResponse = client.createExclusion(parent, exclusion); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateExclusionRequest actualRequest = ((CreateExclusionRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(exclusion, actualRequest.getExclusion()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createExclusionExceptionTest3() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + LogExclusion exclusion = LogExclusion.newBuilder().build(); + client.createExclusion(parent, exclusion); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createExclusionTest4() throws Exception { + LogExclusion expectedResponse = + LogExclusion.newBuilder() + .setName(LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]").toString()) + .setDescription("description-1724546052") + .setFilter("filter-1274492040") + .setDisabled(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + ProjectName parent = ProjectName.of("[PROJECT]"); + LogExclusion exclusion = LogExclusion.newBuilder().build(); + + LogExclusion actualResponse = client.createExclusion(parent, exclusion); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateExclusionRequest actualRequest = ((CreateExclusionRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(exclusion, actualRequest.getExclusion()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createExclusionExceptionTest4() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + ProjectName parent = ProjectName.of("[PROJECT]"); + LogExclusion exclusion = LogExclusion.newBuilder().build(); + client.createExclusion(parent, exclusion); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createExclusionTest5() throws Exception { + LogExclusion expectedResponse = + LogExclusion.newBuilder() + .setName(LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]").toString()) + .setDescription("description-1724546052") + .setFilter("filter-1274492040") + .setDisabled(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + String parent = "parent-995424086"; + LogExclusion exclusion = LogExclusion.newBuilder().build(); + + LogExclusion actualResponse = client.createExclusion(parent, exclusion); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateExclusionRequest actualRequest = ((CreateExclusionRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertEquals(exclusion, actualRequest.getExclusion()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createExclusionExceptionTest5() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + String parent = "parent-995424086"; + LogExclusion exclusion = LogExclusion.newBuilder().build(); + client.createExclusion(parent, exclusion); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateExclusionTest() throws Exception { + LogExclusion expectedResponse = + LogExclusion.newBuilder() + .setName(LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]").toString()) + .setDescription("description-1724546052") + .setFilter("filter-1274492040") + .setDisabled(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]"); + LogExclusion exclusion = LogExclusion.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + LogExclusion actualResponse = client.updateExclusion(name, exclusion, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpdateExclusionRequest actualRequest = ((UpdateExclusionRequest) actualRequests.get(0)); + + Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertEquals(exclusion, actualRequest.getExclusion()); + Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void updateExclusionExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]"); + LogExclusion exclusion = LogExclusion.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateExclusion(name, exclusion, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateExclusionTest2() throws Exception { + LogExclusion expectedResponse = + LogExclusion.newBuilder() + .setName(LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]").toString()) + .setDescription("description-1724546052") + .setFilter("filter-1274492040") + .setDisabled(true) + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + String name = "name3373707"; + LogExclusion exclusion = LogExclusion.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + + LogExclusion actualResponse = client.updateExclusion(name, exclusion, updateMask); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpdateExclusionRequest actualRequest = ((UpdateExclusionRequest) actualRequests.get(0)); + + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertEquals(exclusion, actualRequest.getExclusion()); + Assert.assertEquals(updateMask, actualRequest.getUpdateMask()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void updateExclusionExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + String name = "name3373707"; + LogExclusion exclusion = LogExclusion.newBuilder().build(); + FieldMask updateMask = FieldMask.newBuilder().build(); + client.updateExclusion(name, exclusion, updateMask); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteExclusionTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockConfigServiceV2.addResponse(expectedResponse); + + LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]"); + + Empty actualResponse = client.deleteExclusion(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteExclusionRequest actualRequest = ((DeleteExclusionRequest) actualRequests.get(0)); + + Assert.assertEquals(name.toString(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteExclusionExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + LogExclusionName name = LogExclusionName.ofProjectExclusionName("[PROJECT]", "[EXCLUSION]"); + client.deleteExclusion(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteExclusionTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockConfigServiceV2.addResponse(expectedResponse); + + String name = "name3373707"; + + Empty actualResponse = client.deleteExclusion(name); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteExclusionRequest actualRequest = ((DeleteExclusionRequest) actualRequests.get(0)); + + Assert.assertEquals(name, actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteExclusionExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + String name = "name3373707"; + client.deleteExclusion(name); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getCmekSettingsTest() throws Exception { + CmekSettings expectedResponse = + CmekSettings.newBuilder() + .setName(CmekSettingsName.ofProjectName("[PROJECT]").toString()) + .setKmsKeyName("kms_key_name2094986649") + .setServiceAccountId("service_account_id-111486921") + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + GetCmekSettingsRequest request = + GetCmekSettingsRequest.newBuilder() + .setName(CmekSettingsName.ofProjectName("[PROJECT]").toString()) + .build(); + + CmekSettings actualResponse = client.getCmekSettings(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetCmekSettingsRequest actualRequest = ((GetCmekSettingsRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getCmekSettingsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + GetCmekSettingsRequest request = + GetCmekSettingsRequest.newBuilder() + .setName(CmekSettingsName.ofProjectName("[PROJECT]").toString()) + .build(); + client.getCmekSettings(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateCmekSettingsTest() throws Exception { + CmekSettings expectedResponse = + CmekSettings.newBuilder() + .setName(CmekSettingsName.ofProjectName("[PROJECT]").toString()) + .setKmsKeyName("kms_key_name2094986649") + .setServiceAccountId("service_account_id-111486921") + .build(); + mockConfigServiceV2.addResponse(expectedResponse); + + UpdateCmekSettingsRequest request = + UpdateCmekSettingsRequest.newBuilder() + .setName("name3373707") + .setCmekSettings(CmekSettings.newBuilder().build()) + .build(); + + CmekSettings actualResponse = client.updateCmekSettings(request); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockConfigServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpdateCmekSettingsRequest actualRequest = ((UpdateCmekSettingsRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getName(), actualRequest.getName()); + Assert.assertEquals(request.getCmekSettings(), actualRequest.getCmekSettings()); + Assert.assertEquals(request.getUpdateMask(), actualRequest.getUpdateMask()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void updateCmekSettingsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockConfigServiceV2.addException(exception); + + try { + UpdateCmekSettingsRequest request = + UpdateCmekSettingsRequest.newBuilder() + .setName("name3373707") + .setCmekSettings(CmekSettings.newBuilder().build()) + .build(); + client.updateCmekSettings(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/test/integration/goldens/logging/FolderLocationName.java b/test/integration/goldens/logging/FolderLocationName.java index 526f0d1b62..24d56ee303 100644 --- a/test/integration/goldens/logging/FolderLocationName.java +++ b/test/integration/goldens/logging/FolderLocationName.java @@ -123,7 +123,7 @@ public String getFieldValue(String fieldName) { @Override public String toString() { - return FOLDER_LOCATION.instantiate("folder", folder); + return FOLDER_LOCATION.instantiate("folder", folder, "location", location); } @Override diff --git a/test/integration/goldens/logging/LocationName.java b/test/integration/goldens/logging/LocationName.java index 9074b6586d..9bc33a8940 100644 --- a/test/integration/goldens/logging/LocationName.java +++ b/test/integration/goldens/logging/LocationName.java @@ -123,7 +123,7 @@ public String getFieldValue(String fieldName) { @Override public String toString() { - return PROJECT_LOCATION.instantiate("project", project); + return PROJECT_LOCATION.instantiate("project", project, "location", location); } @Override diff --git a/test/integration/goldens/logging/LogMetricName.java b/test/integration/goldens/logging/LogMetricName.java index 104ecc3266..1d7150abad 100644 --- a/test/integration/goldens/logging/LogMetricName.java +++ b/test/integration/goldens/logging/LogMetricName.java @@ -123,7 +123,7 @@ public String getFieldValue(String fieldName) { @Override public String toString() { - return PROJECT_METRIC.instantiate("project", project); + return PROJECT_METRIC.instantiate("project", project, "metric", metric); } @Override diff --git a/test/integration/goldens/logging/LoggingServiceV2ClientTest.java b/test/integration/goldens/logging/LoggingServiceV2ClientTest.java new file mode 100644 index 0000000000..a3a8022c52 --- /dev/null +++ b/test/integration/goldens/logging/LoggingServiceV2ClientTest.java @@ -0,0 +1,575 @@ +/* + * Copyright 2020 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.logging.v2; + +import static com.google.logging.v2.LoggingServiceV2Client.ListLogEntriesPagedResponse; +import static com.google.logging.v2.LoggingServiceV2Client.ListLogsPagedResponse; +import static com.google.logging.v2.LoggingServiceV2Client.ListMonitoredResourceDescriptorsPagedResponse; + +import com.google.api.MonitoredResource; +import com.google.api.MonitoredResourceDescriptor; +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.testing.LocalChannelProvider; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.api.gax.grpc.testing.MockServiceHelper; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.common.collect.Lists; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Empty; +import io.grpc.StatusRuntimeException; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class LoggingServiceV2ClientTest { + private static MockServiceHelper mockServiceHelper; + private static MockLoggingServiceV2 mockLoggingServiceV2; + private LoggingServiceV2Client client; + private LocalChannelProvider channelProvider; + + @BeforeClass + public static void startStaticServer() { + mockLoggingServiceV2 = new MockLoggingServiceV2(); + mockServiceHelper = + new MockServiceHelper( + UUID.randomUUID().toString(), Arrays.asList(mockLoggingServiceV2)); + mockServiceHelper.start(); + } + + @AfterClass + public static void stopServer() { + mockServiceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + mockServiceHelper.reset(); + channelProvider = mockServiceHelper.createChannelProvider(); + LoggingServiceV2Settings settings = + LoggingServiceV2Settings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = LoggingServiceV2Client.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } + + @Test + public void deleteLogTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockLoggingServiceV2.addResponse(expectedResponse); + + LogName logName = LogName.ofProjectLogName("[PROJECT]", "[LOG]"); + + Empty actualResponse = client.deleteLog(logName); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockLoggingServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteLogRequest actualRequest = ((DeleteLogRequest) actualRequests.get(0)); + + Assert.assertEquals(logName.toString(), actualRequest.getLogName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteLogExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockLoggingServiceV2.addException(exception); + + try { + LogName logName = LogName.ofProjectLogName("[PROJECT]", "[LOG]"); + client.deleteLog(logName); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteLogTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockLoggingServiceV2.addResponse(expectedResponse); + + String logName = "log_name2013526694"; + + Empty actualResponse = client.deleteLog(logName); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockLoggingServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteLogRequest actualRequest = ((DeleteLogRequest) actualRequests.get(0)); + + Assert.assertEquals(logName, actualRequest.getLogName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteLogExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockLoggingServiceV2.addException(exception); + + try { + String logName = "log_name2013526694"; + client.deleteLog(logName); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void writeLogEntriesTest() throws Exception { + WriteLogEntriesResponse expectedResponse = WriteLogEntriesResponse.newBuilder().build(); + mockLoggingServiceV2.addResponse(expectedResponse); + + LogName logName = LogName.ofProjectLogName("[PROJECT]", "[LOG]"); + MonitoredResource resource = MonitoredResource.newBuilder().build(); + Map labels = new HashMap<>(); + List entries = new ArrayList<>(); + + WriteLogEntriesResponse actualResponse = + client.writeLogEntries(logName, resource, labels, entries); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockLoggingServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + WriteLogEntriesRequest actualRequest = ((WriteLogEntriesRequest) actualRequests.get(0)); + + Assert.assertEquals(logName.toString(), actualRequest.getLogName()); + Assert.assertEquals(resource, actualRequest.getResource()); + Assert.assertEquals(labels, actualRequest.getLabelsMap()); + Assert.assertEquals(entries, actualRequest.getEntriesList()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void writeLogEntriesExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockLoggingServiceV2.addException(exception); + + try { + LogName logName = LogName.ofProjectLogName("[PROJECT]", "[LOG]"); + MonitoredResource resource = MonitoredResource.newBuilder().build(); + Map labels = new HashMap<>(); + List entries = new ArrayList<>(); + client.writeLogEntries(logName, resource, labels, entries); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void writeLogEntriesTest2() throws Exception { + WriteLogEntriesResponse expectedResponse = WriteLogEntriesResponse.newBuilder().build(); + mockLoggingServiceV2.addResponse(expectedResponse); + + String logName = "log_name2013526694"; + MonitoredResource resource = MonitoredResource.newBuilder().build(); + Map labels = new HashMap<>(); + List entries = new ArrayList<>(); + + WriteLogEntriesResponse actualResponse = + client.writeLogEntries(logName, resource, labels, entries); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockLoggingServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + WriteLogEntriesRequest actualRequest = ((WriteLogEntriesRequest) actualRequests.get(0)); + + Assert.assertEquals(logName, actualRequest.getLogName()); + Assert.assertEquals(resource, actualRequest.getResource()); + Assert.assertEquals(labels, actualRequest.getLabelsMap()); + Assert.assertEquals(entries, actualRequest.getEntriesList()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void writeLogEntriesExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockLoggingServiceV2.addException(exception); + + try { + String logName = "log_name2013526694"; + MonitoredResource resource = MonitoredResource.newBuilder().build(); + Map labels = new HashMap<>(); + List entries = new ArrayList<>(); + client.writeLogEntries(logName, resource, labels, entries); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listLogEntriesTest() throws Exception { + LogEntry responsesElement = LogEntry.newBuilder().build(); + ListLogEntriesResponse expectedResponse = + ListLogEntriesResponse.newBuilder() + .setNextPageToken("") + .addAllEntries(Arrays.asList(responsesElement)) + .build(); + mockLoggingServiceV2.addResponse(expectedResponse); + + List resourceNames = new ArrayList<>(); + String filter = "filter-1274492040"; + String orderBy = "order_by1234304744"; + + ListLogEntriesPagedResponse pagedListResponse = + client.listLogEntries(resourceNames, filter, orderBy); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getEntriesList().get(0), resources.get(0)); + + List actualRequests = mockLoggingServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListLogEntriesRequest actualRequest = ((ListLogEntriesRequest) actualRequests.get(0)); + + Assert.assertEquals(resourceNames, actualRequest.getResourceNamesList()); + Assert.assertEquals(filter, actualRequest.getFilter()); + Assert.assertEquals(orderBy, actualRequest.getOrderBy()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listLogEntriesExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockLoggingServiceV2.addException(exception); + + try { + List resourceNames = new ArrayList<>(); + String filter = "filter-1274492040"; + String orderBy = "order_by1234304744"; + client.listLogEntries(resourceNames, filter, orderBy); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listMonitoredResourceDescriptorsTest() throws Exception { + MonitoredResourceDescriptor responsesElement = MonitoredResourceDescriptor.newBuilder().build(); + ListMonitoredResourceDescriptorsResponse expectedResponse = + ListMonitoredResourceDescriptorsResponse.newBuilder() + .setNextPageToken("") + .addAllResourceDescriptors(Arrays.asList(responsesElement)) + .build(); + mockLoggingServiceV2.addResponse(expectedResponse); + + ListMonitoredResourceDescriptorsRequest request = + ListMonitoredResourceDescriptorsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("page_token1630607433") + .build(); + + ListMonitoredResourceDescriptorsPagedResponse pagedListResponse = + client.listMonitoredResourceDescriptors(request); + + List resources = + Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getResourceDescriptorsList().get(0), resources.get(0)); + + List actualRequests = mockLoggingServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListMonitoredResourceDescriptorsRequest actualRequest = + ((ListMonitoredResourceDescriptorsRequest) actualRequests.get(0)); + + Assert.assertEquals(request.getPageSize(), actualRequest.getPageSize()); + Assert.assertEquals(request.getPageToken(), actualRequest.getPageToken()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listMonitoredResourceDescriptorsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockLoggingServiceV2.addException(exception); + + try { + ListMonitoredResourceDescriptorsRequest request = + ListMonitoredResourceDescriptorsRequest.newBuilder() + .setPageSize(883849137) + .setPageToken("page_token1630607433") + .build(); + client.listMonitoredResourceDescriptors(request); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listLogsTest() throws Exception { + String responsesElement = "responsesElement-318365110"; + ListLogsResponse expectedResponse = + ListLogsResponse.newBuilder() + .setNextPageToken("") + .addAllLogNames(Arrays.asList(responsesElement)) + .build(); + mockLoggingServiceV2.addResponse(expectedResponse); + + BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]"); + + ListLogsPagedResponse pagedListResponse = client.listLogs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getLogNamesList().get(0), resources.get(0)); + + List actualRequests = mockLoggingServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListLogsRequest actualRequest = ((ListLogsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listLogsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockLoggingServiceV2.addException(exception); + + try { + BillingAccountName parent = BillingAccountName.of("[BILLING_ACCOUNT]"); + client.listLogs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listLogsTest2() throws Exception { + String responsesElement = "responsesElement-318365110"; + ListLogsResponse expectedResponse = + ListLogsResponse.newBuilder() + .setNextPageToken("") + .addAllLogNames(Arrays.asList(responsesElement)) + .build(); + mockLoggingServiceV2.addResponse(expectedResponse); + + FolderName parent = FolderName.of("[FOLDER]"); + + ListLogsPagedResponse pagedListResponse = client.listLogs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getLogNamesList().get(0), resources.get(0)); + + List actualRequests = mockLoggingServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListLogsRequest actualRequest = ((ListLogsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listLogsExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockLoggingServiceV2.addException(exception); + + try { + FolderName parent = FolderName.of("[FOLDER]"); + client.listLogs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listLogsTest3() throws Exception { + String responsesElement = "responsesElement-318365110"; + ListLogsResponse expectedResponse = + ListLogsResponse.newBuilder() + .setNextPageToken("") + .addAllLogNames(Arrays.asList(responsesElement)) + .build(); + mockLoggingServiceV2.addResponse(expectedResponse); + + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + + ListLogsPagedResponse pagedListResponse = client.listLogs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getLogNamesList().get(0), resources.get(0)); + + List actualRequests = mockLoggingServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListLogsRequest actualRequest = ((ListLogsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listLogsExceptionTest3() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockLoggingServiceV2.addException(exception); + + try { + OrganizationName parent = OrganizationName.of("[ORGANIZATION]"); + client.listLogs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listLogsTest4() throws Exception { + String responsesElement = "responsesElement-318365110"; + ListLogsResponse expectedResponse = + ListLogsResponse.newBuilder() + .setNextPageToken("") + .addAllLogNames(Arrays.asList(responsesElement)) + .build(); + mockLoggingServiceV2.addResponse(expectedResponse); + + ProjectName parent = ProjectName.of("[PROJECT]"); + + ListLogsPagedResponse pagedListResponse = client.listLogs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getLogNamesList().get(0), resources.get(0)); + + List actualRequests = mockLoggingServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListLogsRequest actualRequest = ((ListLogsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listLogsExceptionTest4() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockLoggingServiceV2.addException(exception); + + try { + ProjectName parent = ProjectName.of("[PROJECT]"); + client.listLogs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listLogsTest5() throws Exception { + String responsesElement = "responsesElement-318365110"; + ListLogsResponse expectedResponse = + ListLogsResponse.newBuilder() + .setNextPageToken("") + .addAllLogNames(Arrays.asList(responsesElement)) + .build(); + mockLoggingServiceV2.addResponse(expectedResponse); + + String parent = "parent-995424086"; + + ListLogsPagedResponse pagedListResponse = client.listLogs(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getLogNamesList().get(0), resources.get(0)); + + List actualRequests = mockLoggingServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListLogsRequest actualRequest = ((ListLogsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listLogsExceptionTest5() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockLoggingServiceV2.addException(exception); + + try { + String parent = "parent-995424086"; + client.listLogs(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/test/integration/goldens/logging/MetricsServiceV2ClientTest.java b/test/integration/goldens/logging/MetricsServiceV2ClientTest.java new file mode 100644 index 0000000000..a8dd5fa867 --- /dev/null +++ b/test/integration/goldens/logging/MetricsServiceV2ClientTest.java @@ -0,0 +1,504 @@ +/* + * Copyright 2020 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.logging.v2; + +import static com.google.logging.v2.MetricsServiceV2Client.ListLogMetricsPagedResponse; + +import com.google.api.gax.core.NoCredentialsProvider; +import com.google.api.gax.grpc.GaxGrpcProperties; +import com.google.api.gax.grpc.testing.LocalChannelProvider; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.api.gax.grpc.testing.MockServiceHelper; +import com.google.api.gax.rpc.ApiClientHeaderProvider; +import com.google.api.gax.rpc.InvalidArgumentException; +import com.google.common.collect.Lists; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Empty; +import io.grpc.StatusRuntimeException; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.UUID; +import javax.annotation.Generated; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Assert; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +@Generated("by gapic-generator-java") +public class MetricsServiceV2ClientTest { + private static MockServiceHelper mockServiceHelper; + private MetricsServiceV2Client client; + private static MockMetricsServiceV2 mockMetricsServiceV2; + private LocalChannelProvider channelProvider; + + @BeforeClass + public static void startStaticServer() { + mockMetricsServiceV2 = new MockMetricsServiceV2(); + mockServiceHelper = + new MockServiceHelper( + UUID.randomUUID().toString(), Arrays.asList(mockMetricsServiceV2)); + mockServiceHelper.start(); + } + + @AfterClass + public static void stopServer() { + mockServiceHelper.stop(); + } + + @Before + public void setUp() throws IOException { + mockServiceHelper.reset(); + channelProvider = mockServiceHelper.createChannelProvider(); + MetricsServiceV2Settings settings = + MetricsServiceV2Settings.newBuilder() + .setTransportChannelProvider(channelProvider) + .setCredentialsProvider(NoCredentialsProvider.create()) + .build(); + client = MetricsServiceV2Client.create(settings); + } + + @After + public void tearDown() throws Exception { + client.close(); + } + + @Test + public void listLogMetricsTest() throws Exception { + LogMetric responsesElement = LogMetric.newBuilder().build(); + ListLogMetricsResponse expectedResponse = + ListLogMetricsResponse.newBuilder() + .setNextPageToken("") + .addAllMetrics(Arrays.asList(responsesElement)) + .build(); + mockMetricsServiceV2.addResponse(expectedResponse); + + ProjectName parent = ProjectName.of("[PROJECT]"); + + ListLogMetricsPagedResponse pagedListResponse = client.listLogMetrics(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getMetricsList().get(0), resources.get(0)); + + List actualRequests = mockMetricsServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListLogMetricsRequest actualRequest = ((ListLogMetricsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listLogMetricsExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMetricsServiceV2.addException(exception); + + try { + ProjectName parent = ProjectName.of("[PROJECT]"); + client.listLogMetrics(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void listLogMetricsTest2() throws Exception { + LogMetric responsesElement = LogMetric.newBuilder().build(); + ListLogMetricsResponse expectedResponse = + ListLogMetricsResponse.newBuilder() + .setNextPageToken("") + .addAllMetrics(Arrays.asList(responsesElement)) + .build(); + mockMetricsServiceV2.addResponse(expectedResponse); + + String parent = "parent-995424086"; + + ListLogMetricsPagedResponse pagedListResponse = client.listLogMetrics(parent); + + List resources = Lists.newArrayList(pagedListResponse.iterateAll()); + + Assert.assertEquals(1, resources.size()); + Assert.assertEquals(expectedResponse.getMetricsList().get(0), resources.get(0)); + + List actualRequests = mockMetricsServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + ListLogMetricsRequest actualRequest = ((ListLogMetricsRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void listLogMetricsExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMetricsServiceV2.addException(exception); + + try { + String parent = "parent-995424086"; + client.listLogMetrics(parent); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getLogMetricTest() throws Exception { + LogMetric expectedResponse = + LogMetric.newBuilder() + .setName(LogMetricName.of("[PROJECT]", "[METRIC]").toString()) + .setDescription("description-1724546052") + .setFilter("filter-1274492040") + .setValueExtractor("value_extractor2047672534") + .putAllLabelExtractors(new HashMap()) + .build(); + mockMetricsServiceV2.addResponse(expectedResponse); + + LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]"); + + LogMetric actualResponse = client.getLogMetric(metricName); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMetricsServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetLogMetricRequest actualRequest = ((GetLogMetricRequest) actualRequests.get(0)); + + Assert.assertEquals(metricName.toString(), actualRequest.getMetricName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getLogMetricExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMetricsServiceV2.addException(exception); + + try { + LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]"); + client.getLogMetric(metricName); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void getLogMetricTest2() throws Exception { + LogMetric expectedResponse = + LogMetric.newBuilder() + .setName(LogMetricName.of("[PROJECT]", "[METRIC]").toString()) + .setDescription("description-1724546052") + .setFilter("filter-1274492040") + .setValueExtractor("value_extractor2047672534") + .putAllLabelExtractors(new HashMap()) + .build(); + mockMetricsServiceV2.addResponse(expectedResponse); + + String metricName = "metric_name-1737602118"; + + LogMetric actualResponse = client.getLogMetric(metricName); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMetricsServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + GetLogMetricRequest actualRequest = ((GetLogMetricRequest) actualRequests.get(0)); + + Assert.assertEquals(metricName, actualRequest.getMetricName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void getLogMetricExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMetricsServiceV2.addException(exception); + + try { + String metricName = "metric_name-1737602118"; + client.getLogMetric(metricName); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createLogMetricTest() throws Exception { + LogMetric expectedResponse = + LogMetric.newBuilder() + .setName(LogMetricName.of("[PROJECT]", "[METRIC]").toString()) + .setDescription("description-1724546052") + .setFilter("filter-1274492040") + .setValueExtractor("value_extractor2047672534") + .putAllLabelExtractors(new HashMap()) + .build(); + mockMetricsServiceV2.addResponse(expectedResponse); + + ProjectName parent = ProjectName.of("[PROJECT]"); + LogMetric metric = LogMetric.newBuilder().build(); + + LogMetric actualResponse = client.createLogMetric(parent, metric); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMetricsServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateLogMetricRequest actualRequest = ((CreateLogMetricRequest) actualRequests.get(0)); + + Assert.assertEquals(parent.toString(), actualRequest.getParent()); + Assert.assertEquals(metric, actualRequest.getMetric()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createLogMetricExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMetricsServiceV2.addException(exception); + + try { + ProjectName parent = ProjectName.of("[PROJECT]"); + LogMetric metric = LogMetric.newBuilder().build(); + client.createLogMetric(parent, metric); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void createLogMetricTest2() throws Exception { + LogMetric expectedResponse = + LogMetric.newBuilder() + .setName(LogMetricName.of("[PROJECT]", "[METRIC]").toString()) + .setDescription("description-1724546052") + .setFilter("filter-1274492040") + .setValueExtractor("value_extractor2047672534") + .putAllLabelExtractors(new HashMap()) + .build(); + mockMetricsServiceV2.addResponse(expectedResponse); + + String parent = "parent-995424086"; + LogMetric metric = LogMetric.newBuilder().build(); + + LogMetric actualResponse = client.createLogMetric(parent, metric); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMetricsServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + CreateLogMetricRequest actualRequest = ((CreateLogMetricRequest) actualRequests.get(0)); + + Assert.assertEquals(parent, actualRequest.getParent()); + Assert.assertEquals(metric, actualRequest.getMetric()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void createLogMetricExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMetricsServiceV2.addException(exception); + + try { + String parent = "parent-995424086"; + LogMetric metric = LogMetric.newBuilder().build(); + client.createLogMetric(parent, metric); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateLogMetricTest() throws Exception { + LogMetric expectedResponse = + LogMetric.newBuilder() + .setName(LogMetricName.of("[PROJECT]", "[METRIC]").toString()) + .setDescription("description-1724546052") + .setFilter("filter-1274492040") + .setValueExtractor("value_extractor2047672534") + .putAllLabelExtractors(new HashMap()) + .build(); + mockMetricsServiceV2.addResponse(expectedResponse); + + LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]"); + LogMetric metric = LogMetric.newBuilder().build(); + + LogMetric actualResponse = client.updateLogMetric(metricName, metric); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMetricsServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpdateLogMetricRequest actualRequest = ((UpdateLogMetricRequest) actualRequests.get(0)); + + Assert.assertEquals(metricName.toString(), actualRequest.getMetricName()); + Assert.assertEquals(metric, actualRequest.getMetric()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void updateLogMetricExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMetricsServiceV2.addException(exception); + + try { + LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]"); + LogMetric metric = LogMetric.newBuilder().build(); + client.updateLogMetric(metricName, metric); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void updateLogMetricTest2() throws Exception { + LogMetric expectedResponse = + LogMetric.newBuilder() + .setName(LogMetricName.of("[PROJECT]", "[METRIC]").toString()) + .setDescription("description-1724546052") + .setFilter("filter-1274492040") + .setValueExtractor("value_extractor2047672534") + .putAllLabelExtractors(new HashMap()) + .build(); + mockMetricsServiceV2.addResponse(expectedResponse); + + String metricName = "metric_name-1737602118"; + LogMetric metric = LogMetric.newBuilder().build(); + + LogMetric actualResponse = client.updateLogMetric(metricName, metric); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMetricsServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + UpdateLogMetricRequest actualRequest = ((UpdateLogMetricRequest) actualRequests.get(0)); + + Assert.assertEquals(metricName, actualRequest.getMetricName()); + Assert.assertEquals(metric, actualRequest.getMetric()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void updateLogMetricExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMetricsServiceV2.addException(exception); + + try { + String metricName = "metric_name-1737602118"; + LogMetric metric = LogMetric.newBuilder().build(); + client.updateLogMetric(metricName, metric); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteLogMetricTest() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockMetricsServiceV2.addResponse(expectedResponse); + + LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]"); + + Empty actualResponse = client.deleteLogMetric(metricName); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMetricsServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteLogMetricRequest actualRequest = ((DeleteLogMetricRequest) actualRequests.get(0)); + + Assert.assertEquals(metricName.toString(), actualRequest.getMetricName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteLogMetricExceptionTest() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMetricsServiceV2.addException(exception); + + try { + LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]"); + client.deleteLogMetric(metricName); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } + + @Test + public void deleteLogMetricTest2() throws Exception { + Empty expectedResponse = Empty.newBuilder().build(); + mockMetricsServiceV2.addResponse(expectedResponse); + + String metricName = "metric_name-1737602118"; + + Empty actualResponse = client.deleteLogMetric(metricName); + Assert.assertEquals(expectedResponse, actualResponse); + + List actualRequests = mockMetricsServiceV2.getRequests(); + Assert.assertEquals(1, actualRequests.size()); + DeleteLogMetricRequest actualRequest = ((DeleteLogMetricRequest) actualRequests.get(0)); + + Assert.assertEquals(metricName, actualRequest.getMetricName()); + Assert.assertTrue( + channelProvider.isHeaderSent( + ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), + GaxGrpcProperties.getDefaultApiClientHeaderPattern())); + } + + @Test + public void deleteLogMetricExceptionTest2() throws Exception { + StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT); + mockMetricsServiceV2.addException(exception); + + try { + String metricName = "metric_name-1737602118"; + client.deleteLogMetric(metricName); + Assert.fail("No exception raised"); + } catch (InvalidArgumentException e) { + // Expected exception. + } + } +} diff --git a/test/integration/goldens/logging/MockConfigServiceV2.java b/test/integration/goldens/logging/MockConfigServiceV2.java new file mode 100644 index 0000000000..8ce4ce6170 --- /dev/null +++ b/test/integration/goldens/logging/MockConfigServiceV2.java @@ -0,0 +1,59 @@ +/* + * Copyright 2020 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.logging.v2; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.protobuf.AbstractMessage; +import io.grpc.ServerServiceDefinition; +import java.util.List; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockConfigServiceV2 implements MockGrpcService { + private final MockConfigServiceV2Impl serviceImpl; + + public MockConfigServiceV2() { + serviceImpl = new MockConfigServiceV2Impl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void addResponse(AbstractMessage response) { + serviceImpl.addResponse(response); + } + + @Override + public void addException(Exception exception) { + serviceImpl.addException(exception); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/test/integration/goldens/logging/MockConfigServiceV2Impl.java b/test/integration/goldens/logging/MockConfigServiceV2Impl.java new file mode 100644 index 0000000000..d414b55b49 --- /dev/null +++ b/test/integration/goldens/logging/MockConfigServiceV2Impl.java @@ -0,0 +1,281 @@ +/* + * Copyright 2020 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.logging.v2; + +import com.google.api.core.BetaApi; +import com.google.logging.v2.ConfigServiceV2Grpc.ConfigServiceV2ImplBase; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Empty; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockConfigServiceV2Impl extends ConfigServiceV2ImplBase { + private List requests; + private Queue responses; + + public MockConfigServiceV2Impl() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + public List getRequests() { + return requests; + } + + public void addResponse(AbstractMessage response) { + responses.add(response); + } + + public void setResponses(List responses) { + this.responses = new LinkedList(responses); + } + + public void addException(Exception exception) { + responses.add(exception); + } + + public void reset() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + @Override + public void listBuckets( + ListBucketsRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ListBucketsResponse) { + requests.add(request); + responseObserver.onNext(((ListBucketsResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void getBucket(GetBucketRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof LogBucket) { + requests.add(request); + responseObserver.onNext(((LogBucket) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void updateBucket( + UpdateBucketRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof LogBucket) { + requests.add(request); + responseObserver.onNext(((LogBucket) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void listSinks( + ListSinksRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ListSinksResponse) { + requests.add(request); + responseObserver.onNext(((ListSinksResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void getSink(GetSinkRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof LogSink) { + requests.add(request); + responseObserver.onNext(((LogSink) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void createSink(CreateSinkRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof LogSink) { + requests.add(request); + responseObserver.onNext(((LogSink) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void updateSink(UpdateSinkRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof LogSink) { + requests.add(request); + responseObserver.onNext(((LogSink) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void deleteSink(DeleteSinkRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Empty) { + requests.add(request); + responseObserver.onNext(((Empty) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void listExclusions( + ListExclusionsRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ListExclusionsResponse) { + requests.add(request); + responseObserver.onNext(((ListExclusionsResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void getExclusion( + GetExclusionRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof LogExclusion) { + requests.add(request); + responseObserver.onNext(((LogExclusion) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void createExclusion( + CreateExclusionRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof LogExclusion) { + requests.add(request); + responseObserver.onNext(((LogExclusion) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void updateExclusion( + UpdateExclusionRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof LogExclusion) { + requests.add(request); + responseObserver.onNext(((LogExclusion) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void deleteExclusion( + DeleteExclusionRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Empty) { + requests.add(request); + responseObserver.onNext(((Empty) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void getCmekSettings( + GetCmekSettingsRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof CmekSettings) { + requests.add(request); + responseObserver.onNext(((CmekSettings) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void updateCmekSettings( + UpdateCmekSettingsRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof CmekSettings) { + requests.add(request); + responseObserver.onNext(((CmekSettings) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } +} diff --git a/test/integration/goldens/logging/MockLoggingServiceV2.java b/test/integration/goldens/logging/MockLoggingServiceV2.java new file mode 100644 index 0000000000..ac83c2a646 --- /dev/null +++ b/test/integration/goldens/logging/MockLoggingServiceV2.java @@ -0,0 +1,59 @@ +/* + * Copyright 2020 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.logging.v2; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.protobuf.AbstractMessage; +import io.grpc.ServerServiceDefinition; +import java.util.List; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockLoggingServiceV2 implements MockGrpcService { + private final MockLoggingServiceV2Impl serviceImpl; + + public MockLoggingServiceV2() { + serviceImpl = new MockLoggingServiceV2Impl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void addResponse(AbstractMessage response) { + serviceImpl.addResponse(response); + } + + @Override + public void addException(Exception exception) { + serviceImpl.addException(exception); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/test/integration/goldens/logging/MockLoggingServiceV2Impl.java b/test/integration/goldens/logging/MockLoggingServiceV2Impl.java new file mode 100644 index 0000000000..4068b7d7f4 --- /dev/null +++ b/test/integration/goldens/logging/MockLoggingServiceV2Impl.java @@ -0,0 +1,135 @@ +/* + * Copyright 2020 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.logging.v2; + +import com.google.api.core.BetaApi; +import com.google.logging.v2.LoggingServiceV2Grpc.LoggingServiceV2ImplBase; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Empty; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockLoggingServiceV2Impl extends LoggingServiceV2ImplBase { + private List requests; + private Queue responses; + + public MockLoggingServiceV2Impl() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + public List getRequests() { + return requests; + } + + public void addResponse(AbstractMessage response) { + responses.add(response); + } + + public void setResponses(List responses) { + this.responses = new LinkedList(responses); + } + + public void addException(Exception exception) { + responses.add(exception); + } + + public void reset() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + @Override + public void deleteLog(DeleteLogRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Empty) { + requests.add(request); + responseObserver.onNext(((Empty) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void writeLogEntries( + WriteLogEntriesRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof WriteLogEntriesResponse) { + requests.add(request); + responseObserver.onNext(((WriteLogEntriesResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void listLogEntries( + ListLogEntriesRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ListLogEntriesResponse) { + requests.add(request); + responseObserver.onNext(((ListLogEntriesResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void listMonitoredResourceDescriptors( + ListMonitoredResourceDescriptorsRequest request, + StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ListMonitoredResourceDescriptorsResponse) { + requests.add(request); + responseObserver.onNext(((ListMonitoredResourceDescriptorsResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void listLogs(ListLogsRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ListLogsResponse) { + requests.add(request); + responseObserver.onNext(((ListLogsResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } +} diff --git a/test/integration/goldens/logging/MockMetricsServiceV2.java b/test/integration/goldens/logging/MockMetricsServiceV2.java new file mode 100644 index 0000000000..f172c4faf8 --- /dev/null +++ b/test/integration/goldens/logging/MockMetricsServiceV2.java @@ -0,0 +1,59 @@ +/* + * Copyright 2020 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.logging.v2; + +import com.google.api.core.BetaApi; +import com.google.api.gax.grpc.testing.MockGrpcService; +import com.google.protobuf.AbstractMessage; +import io.grpc.ServerServiceDefinition; +import java.util.List; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockMetricsServiceV2 implements MockGrpcService { + private final MockMetricsServiceV2Impl serviceImpl; + + public MockMetricsServiceV2() { + serviceImpl = new MockMetricsServiceV2Impl(); + } + + @Override + public List getRequests() { + return serviceImpl.getRequests(); + } + + @Override + public void addResponse(AbstractMessage response) { + serviceImpl.addResponse(response); + } + + @Override + public void addException(Exception exception) { + serviceImpl.addException(exception); + } + + @Override + public ServerServiceDefinition getServiceDefinition() { + return serviceImpl.bindService(); + } + + @Override + public void reset() { + serviceImpl.reset(); + } +} diff --git a/test/integration/goldens/logging/MockMetricsServiceV2Impl.java b/test/integration/goldens/logging/MockMetricsServiceV2Impl.java new file mode 100644 index 0000000000..b371b623f1 --- /dev/null +++ b/test/integration/goldens/logging/MockMetricsServiceV2Impl.java @@ -0,0 +1,136 @@ +/* + * Copyright 2020 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.logging.v2; + +import com.google.api.core.BetaApi; +import com.google.logging.v2.MetricsServiceV2Grpc.MetricsServiceV2ImplBase; +import com.google.protobuf.AbstractMessage; +import com.google.protobuf.Empty; +import io.grpc.stub.StreamObserver; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; +import javax.annotation.Generated; + +@BetaApi +@Generated("by gapic-generator-java") +public class MockMetricsServiceV2Impl extends MetricsServiceV2ImplBase { + private List requests; + private Queue responses; + + public MockMetricsServiceV2Impl() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + public List getRequests() { + return requests; + } + + public void addResponse(AbstractMessage response) { + responses.add(response); + } + + public void setResponses(List responses) { + this.responses = new LinkedList(responses); + } + + public void addException(Exception exception) { + responses.add(exception); + } + + public void reset() { + requests = new ArrayList<>(); + responses = new LinkedList<>(); + } + + @Override + public void listLogMetrics( + ListLogMetricsRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof ListLogMetricsResponse) { + requests.add(request); + responseObserver.onNext(((ListLogMetricsResponse) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void getLogMetric( + GetLogMetricRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof LogMetric) { + requests.add(request); + responseObserver.onNext(((LogMetric) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void createLogMetric( + CreateLogMetricRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof LogMetric) { + requests.add(request); + responseObserver.onNext(((LogMetric) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void updateLogMetric( + UpdateLogMetricRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof LogMetric) { + requests.add(request); + responseObserver.onNext(((LogMetric) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } + + @Override + public void deleteLogMetric( + DeleteLogMetricRequest request, StreamObserver responseObserver) { + Object response = responses.remove(); + if (response instanceof Empty) { + requests.add(request); + responseObserver.onNext(((Empty) response)); + responseObserver.onCompleted(); + } else if (response instanceof Exception) { + responseObserver.onError(((Exception) response)); + } else { + responseObserver.onError(new IllegalArgumentException("Unrecognized response type")); + } + } +} diff --git a/test/integration/goldens/logging/OrganizationLocationName.java b/test/integration/goldens/logging/OrganizationLocationName.java index 08dbc40fd5..2f9cde61d8 100644 --- a/test/integration/goldens/logging/OrganizationLocationName.java +++ b/test/integration/goldens/logging/OrganizationLocationName.java @@ -123,7 +123,7 @@ public String getFieldValue(String fieldName) { @Override public String toString() { - return ORGANIZATION_LOCATION.instantiate("organization", organization); + return ORGANIZATION_LOCATION.instantiate("organization", organization, "location", location); } @Override diff --git a/test/integration/goldens/redis/CloudRedisClientTest.java b/test/integration/goldens/redis/CloudRedisClientTest.java index 6e37f465ec..6261e6a2f6 100644 --- a/test/integration/goldens/redis/CloudRedisClientTest.java +++ b/test/integration/goldens/redis/CloudRedisClientTest.java @@ -179,7 +179,7 @@ public void getInstanceTest() throws Exception { Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) .setDisplayName("display_name1615086568") - .putAllLabels(new HashMap<>()) + .putAllLabels(new HashMap()) .setLocationId("location_id552319461") .setAlternativeLocationId("alternative_location_id-718920621") .setRedisVersion("redis_version-685310444") @@ -188,7 +188,7 @@ public void getInstanceTest() throws Exception { .setPort(3446913) .setCurrentLocationId("current_location_id1312712735") .setStatusMessage("status_message-239442758") - .putAllRedisConfigs(new HashMap<>()) + .putAllRedisConfigs(new HashMap()) .setMemorySizeGb(34199707) .setAuthorizedNetwork("authorized_network-1733809270") .setPersistenceIamIdentity("persistence_iam_identity1061944584") @@ -231,7 +231,7 @@ public void getInstanceTest2() throws Exception { Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) .setDisplayName("display_name1615086568") - .putAllLabels(new HashMap<>()) + .putAllLabels(new HashMap()) .setLocationId("location_id552319461") .setAlternativeLocationId("alternative_location_id-718920621") .setRedisVersion("redis_version-685310444") @@ -240,7 +240,7 @@ public void getInstanceTest2() throws Exception { .setPort(3446913) .setCurrentLocationId("current_location_id1312712735") .setStatusMessage("status_message-239442758") - .putAllRedisConfigs(new HashMap<>()) + .putAllRedisConfigs(new HashMap()) .setMemorySizeGb(34199707) .setAuthorizedNetwork("authorized_network-1733809270") .setPersistenceIamIdentity("persistence_iam_identity1061944584") @@ -283,7 +283,7 @@ public void createInstanceTest() throws Exception { Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) .setDisplayName("display_name1615086568") - .putAllLabels(new HashMap<>()) + .putAllLabels(new HashMap()) .setLocationId("location_id552319461") .setAlternativeLocationId("alternative_location_id-718920621") .setRedisVersion("redis_version-685310444") @@ -292,7 +292,7 @@ public void createInstanceTest() throws Exception { .setPort(3446913) .setCurrentLocationId("current_location_id1312712735") .setStatusMessage("status_message-239442758") - .putAllRedisConfigs(new HashMap<>()) + .putAllRedisConfigs(new HashMap()) .setMemorySizeGb(34199707) .setAuthorizedNetwork("authorized_network-1733809270") .setPersistenceIamIdentity("persistence_iam_identity1061944584") @@ -349,7 +349,7 @@ public void createInstanceTest2() throws Exception { Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) .setDisplayName("display_name1615086568") - .putAllLabels(new HashMap<>()) + .putAllLabels(new HashMap()) .setLocationId("location_id552319461") .setAlternativeLocationId("alternative_location_id-718920621") .setRedisVersion("redis_version-685310444") @@ -358,7 +358,7 @@ public void createInstanceTest2() throws Exception { .setPort(3446913) .setCurrentLocationId("current_location_id1312712735") .setStatusMessage("status_message-239442758") - .putAllRedisConfigs(new HashMap<>()) + .putAllRedisConfigs(new HashMap()) .setMemorySizeGb(34199707) .setAuthorizedNetwork("authorized_network-1733809270") .setPersistenceIamIdentity("persistence_iam_identity1061944584") @@ -415,7 +415,7 @@ public void updateInstanceTest() throws Exception { Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) .setDisplayName("display_name1615086568") - .putAllLabels(new HashMap<>()) + .putAllLabels(new HashMap()) .setLocationId("location_id552319461") .setAlternativeLocationId("alternative_location_id-718920621") .setRedisVersion("redis_version-685310444") @@ -424,7 +424,7 @@ public void updateInstanceTest() throws Exception { .setPort(3446913) .setCurrentLocationId("current_location_id1312712735") .setStatusMessage("status_message-239442758") - .putAllRedisConfigs(new HashMap<>()) + .putAllRedisConfigs(new HashMap()) .setMemorySizeGb(34199707) .setAuthorizedNetwork("authorized_network-1733809270") .setPersistenceIamIdentity("persistence_iam_identity1061944584") @@ -478,7 +478,7 @@ public void upgradeInstanceTest() throws Exception { Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) .setDisplayName("display_name1615086568") - .putAllLabels(new HashMap<>()) + .putAllLabels(new HashMap()) .setLocationId("location_id552319461") .setAlternativeLocationId("alternative_location_id-718920621") .setRedisVersion("redis_version-685310444") @@ -487,7 +487,7 @@ public void upgradeInstanceTest() throws Exception { .setPort(3446913) .setCurrentLocationId("current_location_id1312712735") .setStatusMessage("status_message-239442758") - .putAllRedisConfigs(new HashMap<>()) + .putAllRedisConfigs(new HashMap()) .setMemorySizeGb(34199707) .setAuthorizedNetwork("authorized_network-1733809270") .setPersistenceIamIdentity("persistence_iam_identity1061944584") @@ -541,7 +541,7 @@ public void upgradeInstanceTest2() throws Exception { Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) .setDisplayName("display_name1615086568") - .putAllLabels(new HashMap<>()) + .putAllLabels(new HashMap()) .setLocationId("location_id552319461") .setAlternativeLocationId("alternative_location_id-718920621") .setRedisVersion("redis_version-685310444") @@ -550,7 +550,7 @@ public void upgradeInstanceTest2() throws Exception { .setPort(3446913) .setCurrentLocationId("current_location_id1312712735") .setStatusMessage("status_message-239442758") - .putAllRedisConfigs(new HashMap<>()) + .putAllRedisConfigs(new HashMap()) .setMemorySizeGb(34199707) .setAuthorizedNetwork("authorized_network-1733809270") .setPersistenceIamIdentity("persistence_iam_identity1061944584") @@ -604,7 +604,7 @@ public void importInstanceTest() throws Exception { Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) .setDisplayName("display_name1615086568") - .putAllLabels(new HashMap<>()) + .putAllLabels(new HashMap()) .setLocationId("location_id552319461") .setAlternativeLocationId("alternative_location_id-718920621") .setRedisVersion("redis_version-685310444") @@ -613,7 +613,7 @@ public void importInstanceTest() throws Exception { .setPort(3446913) .setCurrentLocationId("current_location_id1312712735") .setStatusMessage("status_message-239442758") - .putAllRedisConfigs(new HashMap<>()) + .putAllRedisConfigs(new HashMap()) .setMemorySizeGb(34199707) .setAuthorizedNetwork("authorized_network-1733809270") .setPersistenceIamIdentity("persistence_iam_identity1061944584") @@ -667,7 +667,7 @@ public void exportInstanceTest() throws Exception { Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) .setDisplayName("display_name1615086568") - .putAllLabels(new HashMap<>()) + .putAllLabels(new HashMap()) .setLocationId("location_id552319461") .setAlternativeLocationId("alternative_location_id-718920621") .setRedisVersion("redis_version-685310444") @@ -676,7 +676,7 @@ public void exportInstanceTest() throws Exception { .setPort(3446913) .setCurrentLocationId("current_location_id1312712735") .setStatusMessage("status_message-239442758") - .putAllRedisConfigs(new HashMap<>()) + .putAllRedisConfigs(new HashMap()) .setMemorySizeGb(34199707) .setAuthorizedNetwork("authorized_network-1733809270") .setPersistenceIamIdentity("persistence_iam_identity1061944584") @@ -730,7 +730,7 @@ public void failoverInstanceTest() throws Exception { Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) .setDisplayName("display_name1615086568") - .putAllLabels(new HashMap<>()) + .putAllLabels(new HashMap()) .setLocationId("location_id552319461") .setAlternativeLocationId("alternative_location_id-718920621") .setRedisVersion("redis_version-685310444") @@ -739,7 +739,7 @@ public void failoverInstanceTest() throws Exception { .setPort(3446913) .setCurrentLocationId("current_location_id1312712735") .setStatusMessage("status_message-239442758") - .putAllRedisConfigs(new HashMap<>()) + .putAllRedisConfigs(new HashMap()) .setMemorySizeGb(34199707) .setAuthorizedNetwork("authorized_network-1733809270") .setPersistenceIamIdentity("persistence_iam_identity1061944584") @@ -795,7 +795,7 @@ public void failoverInstanceTest2() throws Exception { Instance.newBuilder() .setName(InstanceName.of("[PROJECT]", "[LOCATION]", "[INSTANCE]").toString()) .setDisplayName("display_name1615086568") - .putAllLabels(new HashMap<>()) + .putAllLabels(new HashMap()) .setLocationId("location_id552319461") .setAlternativeLocationId("alternative_location_id-718920621") .setRedisVersion("redis_version-685310444") @@ -804,7 +804,7 @@ public void failoverInstanceTest2() throws Exception { .setPort(3446913) .setCurrentLocationId("current_location_id1312712735") .setStatusMessage("status_message-239442758") - .putAllRedisConfigs(new HashMap<>()) + .putAllRedisConfigs(new HashMap()) .setMemorySizeGb(34199707) .setAuthorizedNetwork("authorized_network-1733809270") .setPersistenceIamIdentity("persistence_iam_identity1061944584") diff --git a/test/integration/goldens/redis/InstanceName.java b/test/integration/goldens/redis/InstanceName.java index f2fb7dfe5a..ac6e5b1ce5 100644 --- a/test/integration/goldens/redis/InstanceName.java +++ b/test/integration/goldens/redis/InstanceName.java @@ -138,7 +138,8 @@ public String getFieldValue(String fieldName) { @Override public String toString() { - return PROJECT_LOCATION_INSTANCE.instantiate("project", project); + return PROJECT_LOCATION_INSTANCE.instantiate( + "project", project, "location", location, "instance", instance); } @Override diff --git a/test/integration/goldens/redis/LocationName.java b/test/integration/goldens/redis/LocationName.java index d781b0b94b..89cad0d585 100644 --- a/test/integration/goldens/redis/LocationName.java +++ b/test/integration/goldens/redis/LocationName.java @@ -123,7 +123,7 @@ public String getFieldValue(String fieldName) { @Override public String toString() { - return PROJECT_LOCATION.instantiate("project", project); + return PROJECT_LOCATION.instantiate("project", project, "location", location); } @Override