From 17c6eba167e3f5d9867ae3e452f044208fb138b1 Mon Sep 17 00:00:00 2001 From: Marco Ziccardi Date: Fri, 29 Apr 2016 14:18:21 +0200 Subject: [PATCH] Use BaseSerializationTest in compute's serialization test --- gcloud-java-compute/pom.xml | 7 +++ .../cloud/compute/SerializationTest.java | 55 ++++--------------- 2 files changed, 19 insertions(+), 43 deletions(-) diff --git a/gcloud-java-compute/pom.xml b/gcloud-java-compute/pom.xml index 3fdc63a9ad81..40a09b008076 100644 --- a/gcloud-java-compute/pom.xml +++ b/gcloud-java-compute/pom.xml @@ -34,6 +34,13 @@ + + ${project.groupId} + gcloud-java-core + ${project.version} + test-jar + test + junit junit diff --git a/gcloud-java-compute/src/test/java/com/google/cloud/compute/SerializationTest.java b/gcloud-java-compute/src/test/java/com/google/cloud/compute/SerializationTest.java index b43bbe62d62b..0ef68731183d 100644 --- a/gcloud-java-compute/src/test/java/com/google/cloud/compute/SerializationTest.java +++ b/gcloud-java-compute/src/test/java/com/google/cloud/compute/SerializationTest.java @@ -16,10 +16,9 @@ package com.google.cloud.compute; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotSame; - import com.google.cloud.AuthCredentials; +import com.google.cloud.BaseSerializationTest; +import com.google.cloud.Restorable; import com.google.cloud.RetryParams; import com.google.cloud.compute.AttachedDisk.CreateDiskConfiguration; import com.google.cloud.compute.AttachedDisk.PersistentDiskConfiguration; @@ -28,17 +27,10 @@ import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import org.junit.Test; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.List; -public class SerializationTest { +public class SerializationTest extends BaseSerializationTest { private static final Compute COMPUTE = ComputeOptions.builder().projectId("p").build().service(); private static final Long CREATION_TIMESTAMP = 1453293540000L; @@ -269,27 +261,18 @@ public class SerializationTest { private static final Compute.InstanceAggregatedListOption INSTANCE_AGGREGATED_LIST_OPTION = Compute.InstanceAggregatedListOption.filter(INSTANCE_FILTER); - @Test - public void testServiceOptions() throws Exception { + @Override + protected Serializable[] serializableObjects() { ComputeOptions options = ComputeOptions.builder() .projectId("p1") .authCredentials(AuthCredentials.createForAppEngine()) .build(); - ComputeOptions serializedCopy = serializeAndDeserialize(options); - assertEquals(options, serializedCopy); - - options = options.toBuilder() + ComputeOptions otherOptions = options.toBuilder() .projectId("p2") .retryParams(RetryParams.defaultInstance()) .authCredentials(null) .build(); - serializedCopy = serializeAndDeserialize(options); - assertEquals(options, serializedCopy); - } - - @Test - public void testModelAndRequests() throws Exception { - Serializable[] objects = {DISK_TYPE_ID, DISK_TYPE, MACHINE_TYPE_ID, MACHINE_TYPE, REGION_ID, + return new Serializable[]{DISK_TYPE_ID, DISK_TYPE, MACHINE_TYPE_ID, MACHINE_TYPE, REGION_ID, REGION, ZONE_ID, ZONE, LICENSE_ID, LICENSE, DEPRECATION_STATUS, GLOBAL_OPERATION_ID, REGION_OPERATION_ID, ZONE_OPERATION_ID, GLOBAL_OPERATION, REGION_OPERATION, ZONE_OPERATION, INSTANCE_ID, REGION_FORWARDING_RULE_ID, GLOBAL_FORWARDING_RULE_ID, GLOBAL_ADDRESS_ID, @@ -311,26 +294,12 @@ public void testModelAndRequests() throws Exception { IMAGE_LIST_OPTION, DISK_OPTION, DISK_FILTER, DISK_LIST_OPTION, DISK_AGGREGATED_LIST_OPTION, SUBNETWORK_OPTION, SUBNETWORK_FILTER, SUBNETWORK_LIST_OPTION, SUBNETWORK_AGGREGATED_LIST_OPTION, NETWORK_OPTION, NETWORK_FILTER, NETWORK_LIST_OPTION, - INSTANCE_OPTION, INSTANCE_FILTER, INSTANCE_LIST_OPTION, INSTANCE_AGGREGATED_LIST_OPTION}; - for (Serializable obj : objects) { - Object copy = serializeAndDeserialize(obj); - assertEquals(obj, obj); - assertEquals(obj, copy); - assertNotSame(obj, copy); - assertEquals(copy, copy); - } + INSTANCE_OPTION, INSTANCE_FILTER, INSTANCE_LIST_OPTION, INSTANCE_AGGREGATED_LIST_OPTION, + options, otherOptions}; } - @SuppressWarnings("unchecked") - private T serializeAndDeserialize(T obj) - throws IOException, ClassNotFoundException { - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); - try (ObjectOutputStream output = new ObjectOutputStream(bytes)) { - output.writeObject(obj); - } - try (ObjectInputStream input = - new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) { - return (T) input.readObject(); - } + @Override + protected Restorable[] restorableObjects() { + return null; } }