From b1860bf091fa89b332f3bd6efd1888cd70c24ef7 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Tue, 19 Jul 2016 14:41:50 +0200 Subject: [PATCH] Add SerializationTest for logging and minor fixes (#1116) --- .../com/google/cloud/SerializationTest.java | 15 ++- gcloud-java-logging/pom.xml | 7 ++ .../com/google/cloud/logging/HttpRequest.java | 2 +- .../com/google/cloud/logging/LoggingTest.java | 89 +++++++++++++++++ .../com/google/cloud/logging/MetricTest.java | 72 +++++++------- .../cloud/logging/SerializationTest.java | 98 +++++++++++++++++++ .../com/google/cloud/logging/SinkTest.java | 76 +++++++------- 7 files changed, 285 insertions(+), 74 deletions(-) create mode 100644 gcloud-java-logging/src/test/java/com/google/cloud/logging/LoggingTest.java create mode 100644 gcloud-java-logging/src/test/java/com/google/cloud/logging/SerializationTest.java diff --git a/gcloud-java-core/src/test/java/com/google/cloud/SerializationTest.java b/gcloud-java-core/src/test/java/com/google/cloud/SerializationTest.java index 53baa57b96ca..77f56ed3ddc9 100644 --- a/gcloud-java-core/src/test/java/com/google/cloud/SerializationTest.java +++ b/gcloud-java-core/src/test/java/com/google/cloud/SerializationTest.java @@ -16,8 +16,11 @@ package com.google.cloud; +import com.google.cloud.MonitoredResourceDescriptor.LabelDescriptor; +import com.google.cloud.MonitoredResourceDescriptor.LabelDescriptor.ValueType; import com.google.cloud.ServiceAccountSigner.SigningException; import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -39,6 +42,15 @@ public class SerializationTest extends BaseSerializationTest { private static final SomeIamPolicy SOME_IAM_POLICY = new SomeIamPolicy.Builder().build(); private static final WaitForOption CHECKING_PERIOD = WaitForOption.checkEvery(42, TimeUnit.SECONDS); + private static final LabelDescriptor LABEL_DESCRIPTOR = + new LabelDescriptor("project_id", ValueType.STRING, "The project id"); + private static final MonitoredResourceDescriptor MONITORED_RESOURCE_DESCRIPTOR = + MonitoredResourceDescriptor.builder("global") + .labels(ImmutableList.of(LABEL_DESCRIPTOR)) + .build(); + private static final MonitoredResource MONITORED_RESOURCE = MonitoredResource.builder("global") + .labels(ImmutableMap.of("project_id", "project")) + .build(); private static final String JSON_KEY = "{\n" + " \"private_key_id\": \"somekeyid\",\n" + " \"private_key\": \"-----BEGIN PRIVATE KEY-----\\nMIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggS" @@ -91,7 +103,8 @@ public Builder toBuilder() { @Override protected Serializable[] serializableObjects() { return new Serializable[]{BASE_SERVICE_EXCEPTION, EXCEPTION_HANDLER, IDENTITY, PAGE, - RETRY_PARAMS, SOME_IAM_POLICY, SIGNING_EXCEPTION, CHECKING_PERIOD}; + RETRY_PARAMS, SOME_IAM_POLICY, SIGNING_EXCEPTION, CHECKING_PERIOD, LABEL_DESCRIPTOR, + MONITORED_RESOURCE_DESCRIPTOR, MONITORED_RESOURCE}; } @Override diff --git a/gcloud-java-logging/pom.xml b/gcloud-java-logging/pom.xml index 6d45a03ba9bb..c91845a85456 100644 --- a/gcloud-java-logging/pom.xml +++ b/gcloud-java-logging/pom.xml @@ -47,6 +47,13 @@ auto-value 1.1 + + ${project.groupId} + gcloud-java-core + ${project.version} + test-jar + test + junit junit diff --git a/gcloud-java-logging/src/main/java/com/google/cloud/logging/HttpRequest.java b/gcloud-java-logging/src/main/java/com/google/cloud/logging/HttpRequest.java index 706ed81816f0..c1c0e41e121b 100644 --- a/gcloud-java-logging/src/main/java/com/google/cloud/logging/HttpRequest.java +++ b/gcloud-java-logging/src/main/java/com/google/cloud/logging/HttpRequest.java @@ -53,7 +53,7 @@ public final class HttpRequest implements Serializable { /** * The HTTP request method. */ - enum RequestMethod { + public enum RequestMethod { GET, HEAD, PUT, diff --git a/gcloud-java-logging/src/test/java/com/google/cloud/logging/LoggingTest.java b/gcloud-java-logging/src/test/java/com/google/cloud/logging/LoggingTest.java new file mode 100644 index 000000000000..5c05185ad268 --- /dev/null +++ b/gcloud-java-logging/src/test/java/com/google/cloud/logging/LoggingTest.java @@ -0,0 +1,89 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * 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 + * + * http://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.cloud.logging; + +import static com.google.cloud.logging.Logging.EntryListOption; +import static com.google.cloud.logging.Logging.SortingField; +import static com.google.cloud.logging.Logging.SortingOrder; +import static com.google.cloud.logging.Logging.WriteOption; +import static org.junit.Assert.assertEquals; + +import com.google.cloud.MonitoredResource; +import com.google.cloud.logging.Logging.ListOption; +import com.google.common.collect.ImmutableMap; + +import org.junit.Test; + +import java.util.Map; + +public class LoggingTest { + + private static final int PAGE_SIZE = 42; + private static final String PAGE_TOKEN = "page token"; + private static final String FILTER = "filter"; + private static final Map LABELS = ImmutableMap.of("key", "value"); + private static final String LOG_NAME = "logName"; + private static final MonitoredResource RESOURCE = + MonitoredResource.of("global", ImmutableMap.of("project_id", "p")); + + @Test + public void testListOption() { + // page token + ListOption listOption = ListOption.pageToken(PAGE_TOKEN); + assertEquals(PAGE_TOKEN, listOption.value()); + assertEquals(ListOption.OptionType.PAGE_TOKEN, listOption.optionType()); + // page size + listOption = ListOption.pageSize(PAGE_SIZE); + assertEquals(PAGE_SIZE, listOption.value()); + assertEquals(ListOption.OptionType.PAGE_SIZE, listOption.optionType()); + } + + @Test + public void testEntryListOption() { + EntryListOption listOption = EntryListOption.pageToken(PAGE_TOKEN); + assertEquals(PAGE_TOKEN, listOption.value()); + assertEquals(EntryListOption.OptionType.PAGE_TOKEN, listOption.optionType()); + // page size + listOption = EntryListOption.pageSize(PAGE_SIZE); + assertEquals(PAGE_SIZE, listOption.value()); + assertEquals(EntryListOption.OptionType.PAGE_SIZE, listOption.optionType()); + // filter + listOption = EntryListOption.filter(FILTER); + assertEquals(FILTER, listOption.value()); + assertEquals(EntryListOption.OptionType.FILTER, listOption.optionType()); + // sort order + listOption = EntryListOption.sortOrder(SortingField.TIMESTAMP, SortingOrder.ASCENDING); + assertEquals("timestamp asc", listOption.value()); + assertEquals(EntryListOption.OptionType.ORDER_BY, listOption.optionType()); + listOption = EntryListOption.sortOrder(SortingField.TIMESTAMP, SortingOrder.DESCENDING); + assertEquals("timestamp desc", listOption.value()); + assertEquals(EntryListOption.OptionType.ORDER_BY, listOption.optionType()); + } + + @Test + public void testWriteOption() { + WriteOption writeOption = WriteOption.labels(LABELS); + assertEquals(LABELS, writeOption.value()); + assertEquals(WriteOption.OptionType.LABELS, writeOption.optionType()); + writeOption = WriteOption.logName(LOG_NAME); + assertEquals(LOG_NAME, writeOption.value()); + assertEquals(WriteOption.OptionType.LOG_NAME, writeOption.optionType()); + writeOption = WriteOption.resource(RESOURCE); + assertEquals(RESOURCE, writeOption.value()); + assertEquals(WriteOption.OptionType.RESOURCE, writeOption.optionType()); + } +} diff --git a/gcloud-java-logging/src/test/java/com/google/cloud/logging/MetricTest.java b/gcloud-java-logging/src/test/java/com/google/cloud/logging/MetricTest.java index 2a60fec15d15..31a51b2f35c0 100644 --- a/gcloud-java-logging/src/test/java/com/google/cloud/logging/MetricTest.java +++ b/gcloud-java-logging/src/test/java/com/google/cloud/logging/MetricTest.java @@ -46,30 +46,30 @@ public class MetricTest { .build(); private final Logging serviceMockReturnsOptions = createStrictMock(Logging.class); private final LoggingOptions mockOptions = createMock(LoggingOptions.class); - private Logging pubsub; + private Logging logging; private Metric expectedMetric; private Metric metric; private void initializeExpectedMetric(int optionsCalls) { expect(serviceMockReturnsOptions.options()).andReturn(mockOptions).times(optionsCalls); replay(serviceMockReturnsOptions); - pubsub = createStrictMock(Logging.class); + logging = createStrictMock(Logging.class); expectedMetric = new Metric(serviceMockReturnsOptions, new Metric.BuilderImpl(METRIC_INFO)); } private void initializeMetric() { - metric = new Metric(pubsub, new Metric.BuilderImpl(METRIC_INFO)); + metric = new Metric(logging, new Metric.BuilderImpl(METRIC_INFO)); } @After public void tearDown() throws Exception { - verify(pubsub, serviceMockReturnsOptions); + verify(logging, serviceMockReturnsOptions); } @Test public void testBuilder() { initializeExpectedMetric(2); - replay(pubsub); + replay(logging); MetricInfo builtMetric = expectedMetric.toBuilder() .name(NEW_NAME) .filter(NEW_FILTER) @@ -83,7 +83,7 @@ public void testBuilder() { @Test public void testToBuilder() { initializeExpectedMetric(2); - replay(pubsub); + replay(logging); compareMetric(expectedMetric, expectedMetric.toBuilder().build()); } @@ -93,9 +93,9 @@ public void testReload() { MetricInfo updatedInfo = METRIC_INFO.toBuilder().filter(NEW_FILTER).build(); Metric expectedMetric = new Metric(serviceMockReturnsOptions, new MetricInfo.BuilderImpl(updatedInfo)); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.getMetric(NAME)).andReturn(expectedMetric); - replay(pubsub); + expect(logging.options()).andReturn(mockOptions); + expect(logging.getMetric(NAME)).andReturn(expectedMetric); + replay(logging); initializeMetric(); Metric updatedMetric = metric.reload(); compareMetric(expectedMetric, updatedMetric); @@ -104,9 +104,9 @@ public void testReload() { @Test public void testReloadNull() { initializeExpectedMetric(1); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.getMetric(NAME)).andReturn(null); - replay(pubsub); + expect(logging.options()).andReturn(mockOptions); + expect(logging.getMetric(NAME)).andReturn(null); + replay(logging); initializeMetric(); assertNull(metric.reload()); } @@ -116,10 +116,10 @@ public void testReloadAsync() throws ExecutionException, InterruptedException { initializeExpectedMetric(2); MetricInfo updatedInfo = METRIC_INFO.toBuilder().filter(NEW_FILTER).build(); Metric expectedMetric = new Metric(serviceMockReturnsOptions, new MetricInfo.BuilderImpl(updatedInfo)); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.getMetricAsync(NAME)) + expect(logging.options()).andReturn(mockOptions); + expect(logging.getMetricAsync(NAME)) .andReturn(Futures.immediateFuture(expectedMetric)); - replay(pubsub); + replay(logging); initializeMetric(); Metric updatedMetric = metric.reloadAsync().get(); compareMetric(expectedMetric, updatedMetric); @@ -128,9 +128,9 @@ public void testReloadAsync() throws ExecutionException, InterruptedException { @Test public void testReloadAsyncNull() throws ExecutionException, InterruptedException { initializeExpectedMetric(1); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.getMetricAsync(NAME)).andReturn(Futures.immediateFuture(null)); - replay(pubsub); + expect(logging.options()).andReturn(mockOptions); + expect(logging.getMetricAsync(NAME)).andReturn(Futures.immediateFuture(null)); + replay(logging); initializeMetric(); assertNull(metric.reloadAsync().get()); } @@ -140,9 +140,9 @@ public void testUpdate() { initializeExpectedMetric(2); MetricInfo updatedInfo = METRIC_INFO.toBuilder().filter(NEW_FILTER).build(); Metric expectedMetric = new Metric(serviceMockReturnsOptions, new MetricInfo.BuilderImpl(updatedInfo)); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.update(updatedInfo)).andReturn(expectedMetric); - replay(pubsub); + expect(logging.options()).andReturn(mockOptions); + expect(logging.update(updatedInfo)).andReturn(expectedMetric); + replay(logging); initializeMetric(); Metric updatedMetric = metric.update(updatedInfo); compareMetric(expectedMetric, updatedMetric); @@ -153,9 +153,9 @@ public void testUpdateAsync() throws ExecutionException, InterruptedException { initializeExpectedMetric(2); MetricInfo updatedInfo = METRIC_INFO.toBuilder().filter(NEW_FILTER).build(); Metric expectedMetric = new Metric(serviceMockReturnsOptions, new MetricInfo.BuilderImpl(updatedInfo)); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.updateAsync(updatedInfo)).andReturn(Futures.immediateFuture(expectedMetric)); - replay(pubsub); + expect(logging.options()).andReturn(mockOptions); + expect(logging.updateAsync(updatedInfo)).andReturn(Futures.immediateFuture(expectedMetric)); + replay(logging); initializeMetric(); Metric updatedMetric = metric.updateAsync(updatedInfo).get(); compareMetric(expectedMetric, updatedMetric); @@ -164,9 +164,9 @@ public void testUpdateAsync() throws ExecutionException, InterruptedException { @Test public void testDeleteTrue() { initializeExpectedMetric(1); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.deleteMetric(NAME)).andReturn(true); - replay(pubsub); + expect(logging.options()).andReturn(mockOptions); + expect(logging.deleteMetric(NAME)).andReturn(true); + replay(logging); initializeMetric(); assertTrue(metric.delete()); } @@ -174,9 +174,9 @@ public void testDeleteTrue() { @Test public void testDeleteFalse() { initializeExpectedMetric(1); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.deleteMetric(NAME)).andReturn(false); - replay(pubsub); + expect(logging.options()).andReturn(mockOptions); + expect(logging.deleteMetric(NAME)).andReturn(false); + replay(logging); initializeMetric(); assertFalse(metric.delete()); } @@ -184,9 +184,9 @@ public void testDeleteFalse() { @Test public void testDeleteAsyncTrue() throws ExecutionException, InterruptedException { initializeExpectedMetric(1); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.deleteMetricAsync(NAME)).andReturn(Futures.immediateFuture(true)); - replay(pubsub); + expect(logging.options()).andReturn(mockOptions); + expect(logging.deleteMetricAsync(NAME)).andReturn(Futures.immediateFuture(true)); + replay(logging); initializeMetric(); assertTrue(metric.deleteAsync().get()); } @@ -194,9 +194,9 @@ public void testDeleteAsyncTrue() throws ExecutionException, InterruptedExceptio @Test public void testDeleteAsyncFalse() throws ExecutionException, InterruptedException { initializeExpectedMetric(1); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.deleteMetricAsync(NAME)).andReturn(Futures.immediateFuture(false)); - replay(pubsub); + expect(logging.options()).andReturn(mockOptions); + expect(logging.deleteMetricAsync(NAME)).andReturn(Futures.immediateFuture(false)); + replay(logging); initializeMetric(); assertFalse(metric.deleteAsync().get()); } diff --git a/gcloud-java-logging/src/test/java/com/google/cloud/logging/SerializationTest.java b/gcloud-java-logging/src/test/java/com/google/cloud/logging/SerializationTest.java new file mode 100644 index 000000000000..2cd728c8f910 --- /dev/null +++ b/gcloud-java-logging/src/test/java/com/google/cloud/logging/SerializationTest.java @@ -0,0 +1,98 @@ +/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * 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 + * + * http://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.cloud.logging; + +import com.google.cloud.AuthCredentials; +import com.google.cloud.BaseSerializationTest; +import com.google.cloud.MonitoredResource; +import com.google.cloud.Restorable; +import com.google.cloud.logging.Logging.EntryListOption; +import com.google.cloud.logging.Logging.ListOption; +import com.google.cloud.logging.Logging.SortingField; +import com.google.cloud.logging.Logging.SortingOrder; +import com.google.cloud.logging.Logging.WriteOption; +import com.google.cloud.logging.Payload.JsonPayload; +import com.google.cloud.logging.Payload.ProtoPayload; +import com.google.cloud.logging.Payload.StringPayload; +import com.google.cloud.logging.SinkInfo.Destination.BucketDestination; +import com.google.cloud.logging.SinkInfo.Destination.DatasetDestination; +import com.google.cloud.logging.SinkInfo.Destination.TopicDestination; +import com.google.common.collect.ImmutableMap; +import com.google.protobuf.Any; +import com.google.protobuf.Empty; + +import java.io.Serializable; + +public class SerializationTest extends BaseSerializationTest { + + private static final Logging LOGGING = LoggingOptions.builder() + .projectId("p") + .authCredentials(AuthCredentials.noAuth()) + .host("localhost") + .build().service(); + private static final HttpRequest HTTP_REQUEST = HttpRequest.builder() + .requestMethod(HttpRequest.RequestMethod.GET) + .status(404) + .build(); + private static final Operation OPERATION = Operation.of("id", "producer"); + private static final StringPayload STRING_PAYLOAD = StringPayload.of("payload"); + private static final JsonPayload JSON_PAYLOAD = + JsonPayload.of(ImmutableMap.of("key", "val")); + private static final ProtoPayload PROTO_PAYLOAD = + ProtoPayload.of(Any.pack(Empty.getDefaultInstance())); + private static final LogEntry ENTRY = LogEntry.of(STRING_PAYLOAD); + private static final MetricInfo METRIC_INFO = + MetricInfo.of("metric", "logName=projects/my-projectid/logs/syslog"); + private static final Metric METRIC = new Metric(LOGGING, new Metric.BuilderImpl(METRIC_INFO)); + private static final BucketDestination BUCKET_DESTINATION = BucketDestination.of("bucket"); + private static final DatasetDestination DATASET_DESTINATION = + DatasetDestination.of("project", "dataset"); + private static final TopicDestination TOPIC_DESTINATION = TopicDestination.of("project", "topic"); + private static final SinkInfo SINK_INFO = SinkInfo.of("sink", BUCKET_DESTINATION); + private static final Sink SINK = new Sink(LOGGING, new Sink.BuilderImpl(SINK_INFO)); + private static final ListOption PAGE_TOKEN_OPTION = ListOption.pageToken("token"); + private static final ListOption PAGE_SIZE_OPTION = ListOption.pageSize(42); + private static final WriteOption LABELS_OPTION = + WriteOption.labels(ImmutableMap.of("key", "val")); + private static final WriteOption LOG_OPTION = + WriteOption.labels(ImmutableMap.of("key", "val")); + private static final WriteOption RESOURCE_OPTION = + WriteOption.resource(MonitoredResource.of("global", ImmutableMap.of("project_id", "p"))); + private static final EntryListOption ENTRY_PAGE_TOKEN_OPTION = EntryListOption.pageToken("token"); + private static final EntryListOption ENTRY_PAGE_SIZE_OPTION = EntryListOption.pageSize(42); + private static final EntryListOption ENTRY_FILTER_OPTION = EntryListOption.filter("filter"); + private static final EntryListOption ENTRY_SORT_ORDER_OPTION = + EntryListOption.sortOrder(SortingField.TIMESTAMP, SortingOrder.ASCENDING); + + @Override + protected Serializable[] serializableObjects() { + LoggingOptions options = LoggingOptions.builder() + .projectId("p1") + .initialTimeout(1234) + .build(); + return new Serializable[]{options, HTTP_REQUEST, OPERATION, STRING_PAYLOAD, JSON_PAYLOAD, + PROTO_PAYLOAD, ENTRY, METRIC_INFO, METRIC, BUCKET_DESTINATION, DATASET_DESTINATION, + TOPIC_DESTINATION, SINK_INFO, SINK, PAGE_TOKEN_OPTION, PAGE_SIZE_OPTION, LABELS_OPTION, + LOG_OPTION, RESOURCE_OPTION, ENTRY_PAGE_TOKEN_OPTION, ENTRY_PAGE_SIZE_OPTION, + ENTRY_FILTER_OPTION, ENTRY_SORT_ORDER_OPTION}; + } + + @Override + protected Restorable[] restorableObjects() { + return null; + } +} diff --git a/gcloud-java-logging/src/test/java/com/google/cloud/logging/SinkTest.java b/gcloud-java-logging/src/test/java/com/google/cloud/logging/SinkTest.java index cb2e1f51c740..84dea59de977 100644 --- a/gcloud-java-logging/src/test/java/com/google/cloud/logging/SinkTest.java +++ b/gcloud-java-logging/src/test/java/com/google/cloud/logging/SinkTest.java @@ -54,30 +54,30 @@ public class SinkTest { .build(); private final Logging serviceMockReturnsOptions = createStrictMock(Logging.class); private final LoggingOptions mockOptions = createMock(LoggingOptions.class); - private Logging pubsub; + private Logging logging; private Sink expectedSink; private Sink sink; private void initializeExpectedSink(int optionsCalls) { expect(serviceMockReturnsOptions.options()).andReturn(mockOptions).times(optionsCalls); replay(serviceMockReturnsOptions); - pubsub = createStrictMock(Logging.class); + logging = createStrictMock(Logging.class); expectedSink = new Sink(serviceMockReturnsOptions, new Sink.BuilderImpl(SINK_INFO)); } private void initializeSink() { - sink = new Sink(pubsub, new Sink.BuilderImpl(SINK_INFO)); + sink = new Sink(logging, new Sink.BuilderImpl(SINK_INFO)); } @After public void tearDown() throws Exception { - verify(pubsub, serviceMockReturnsOptions); + verify(logging, serviceMockReturnsOptions); } @Test public void testBuilder() { initializeExpectedSink(2); - replay(pubsub); + replay(logging); SinkInfo builtSink = expectedSink.toBuilder() .name(NEW_NAME) .filter(NEW_FILTER) @@ -93,7 +93,7 @@ public void testBuilder() { @Test public void testToBuilder() { initializeExpectedSink(2); - replay(pubsub); + replay(logging); compareSink(expectedSink, expectedSink.toBuilder().build()); } @@ -103,9 +103,9 @@ public void testReload() { SinkInfo updatedInfo = SINK_INFO.toBuilder().filter(NEW_FILTER).build(); Sink expectedSink = new Sink(serviceMockReturnsOptions, new SinkInfo.BuilderImpl(updatedInfo)); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.getSink(NAME)).andReturn(expectedSink); - replay(pubsub); + expect(logging.options()).andReturn(mockOptions); + expect(logging.getSink(NAME)).andReturn(expectedSink); + replay(logging); initializeSink(); Sink updatedSink = sink.reload(); compareSink(expectedSink, updatedSink); @@ -114,9 +114,9 @@ public void testReload() { @Test public void testReloadNull() { initializeExpectedSink(1); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.getSink(NAME)).andReturn(null); - replay(pubsub); + expect(logging.options()).andReturn(mockOptions); + expect(logging.getSink(NAME)).andReturn(null); + replay(logging); initializeSink(); assertNull(sink.reload()); } @@ -126,10 +126,10 @@ public void testReloadAsync() throws ExecutionException, InterruptedException { initializeExpectedSink(2); SinkInfo updatedInfo = SINK_INFO.toBuilder().filter(NEW_FILTER).build(); Sink expectedSink = new Sink(serviceMockReturnsOptions, new SinkInfo.BuilderImpl(updatedInfo)); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.getSinkAsync(NAME)) + expect(logging.options()).andReturn(mockOptions); + expect(logging.getSinkAsync(NAME)) .andReturn(Futures.immediateFuture(expectedSink)); - replay(pubsub); + replay(logging); initializeSink(); Sink updatedSink = sink.reloadAsync().get(); compareSink(expectedSink, updatedSink); @@ -138,9 +138,9 @@ public void testReloadAsync() throws ExecutionException, InterruptedException { @Test public void testReloadAsyncNull() throws ExecutionException, InterruptedException { initializeExpectedSink(1); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.getSinkAsync(NAME)).andReturn(Futures.immediateFuture(null)); - replay(pubsub); + expect(logging.options()).andReturn(mockOptions); + expect(logging.getSinkAsync(NAME)).andReturn(Futures.immediateFuture(null)); + replay(logging); initializeSink(); assertNull(sink.reloadAsync().get()); } @@ -150,9 +150,9 @@ public void testUpdate() { initializeExpectedSink(2); SinkInfo updatedInfo = SINK_INFO.toBuilder().filter(NEW_FILTER).build(); Sink expectedSink = new Sink(serviceMockReturnsOptions, new SinkInfo.BuilderImpl(updatedInfo)); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.update(updatedInfo)).andReturn(expectedSink); - replay(pubsub); + expect(logging.options()).andReturn(mockOptions); + expect(logging.update(updatedInfo)).andReturn(expectedSink); + replay(logging); initializeSink(); Sink updatedSink = sink.update(updatedInfo); compareSink(expectedSink, updatedSink); @@ -163,9 +163,9 @@ public void testUpdateAsync() throws ExecutionException, InterruptedException { initializeExpectedSink(2); SinkInfo updatedInfo = SINK_INFO.toBuilder().filter(NEW_FILTER).build(); Sink expectedSink = new Sink(serviceMockReturnsOptions, new SinkInfo.BuilderImpl(updatedInfo)); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.updateAsync(updatedInfo)).andReturn(Futures.immediateFuture(expectedSink)); - replay(pubsub); + expect(logging.options()).andReturn(mockOptions); + expect(logging.updateAsync(updatedInfo)).andReturn(Futures.immediateFuture(expectedSink)); + replay(logging); initializeSink(); Sink updatedSink = sink.updateAsync(updatedInfo).get(); compareSink(expectedSink, updatedSink); @@ -174,9 +174,9 @@ public void testUpdateAsync() throws ExecutionException, InterruptedException { @Test public void testDeleteTrue() { initializeExpectedSink(1); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.deleteSink(NAME)).andReturn(true); - replay(pubsub); + expect(logging.options()).andReturn(mockOptions); + expect(logging.deleteSink(NAME)).andReturn(true); + replay(logging); initializeSink(); assertTrue(sink.delete()); } @@ -184,9 +184,9 @@ public void testDeleteTrue() { @Test public void testDeleteFalse() { initializeExpectedSink(1); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.deleteSink(NAME)).andReturn(false); - replay(pubsub); + expect(logging.options()).andReturn(mockOptions); + expect(logging.deleteSink(NAME)).andReturn(false); + replay(logging); initializeSink(); assertFalse(sink.delete()); } @@ -194,9 +194,9 @@ public void testDeleteFalse() { @Test public void testDeleteAsyncTrue() throws ExecutionException, InterruptedException { initializeExpectedSink(1); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.deleteSinkAsync(NAME)).andReturn(Futures.immediateFuture(true)); - replay(pubsub); + expect(logging.options()).andReturn(mockOptions); + expect(logging.deleteSinkAsync(NAME)).andReturn(Futures.immediateFuture(true)); + replay(logging); initializeSink(); assertTrue(sink.deleteAsync().get()); } @@ -204,9 +204,9 @@ public void testDeleteAsyncTrue() throws ExecutionException, InterruptedExceptio @Test public void testDeleteAsyncFalse() throws ExecutionException, InterruptedException { initializeExpectedSink(1); - expect(pubsub.options()).andReturn(mockOptions); - expect(pubsub.deleteSinkAsync(NAME)).andReturn(Futures.immediateFuture(false)); - replay(pubsub); + expect(logging.options()).andReturn(mockOptions); + expect(logging.deleteSinkAsync(NAME)).andReturn(Futures.immediateFuture(false)); + replay(logging); initializeSink(); assertFalse(sink.deleteAsync().get()); } @@ -214,6 +214,10 @@ public void testDeleteAsyncFalse() throws ExecutionException, InterruptedExcepti private void compareSink(Sink expected, Sink value) { assertEquals(expected, value); assertEquals(expected.name(), value.name()); + assertEquals(expected.destination(), value.destination()); + assertEquals(expected.filter(), value.filter()); + assertEquals(expected.versionFormat(), value.versionFormat()); assertEquals(expected.hashCode(), value.hashCode()); + assertEquals(expected.toString(), value.toString()); } }