1616
1717package com .google .cloud .compute ;
1818
19- import static org .junit .Assert .assertEquals ;
20- import static org .junit .Assert .assertNotSame ;
21-
2219import com .google .cloud .AuthCredentials ;
20+ import com .google .cloud .BaseSerializationTest ;
21+ import com .google .cloud .Restorable ;
2322import com .google .cloud .RetryParams ;
2423import com .google .cloud .compute .AttachedDisk .CreateDiskConfiguration ;
2524import com .google .cloud .compute .AttachedDisk .PersistentDiskConfiguration ;
2827import com .google .common .collect .ImmutableList ;
2928import com .google .common .collect .ImmutableMap ;
3029
31- import org .junit .Test ;
32-
33- import java .io .ByteArrayInputStream ;
34- import java .io .ByteArrayOutputStream ;
35- import java .io .IOException ;
36- import java .io .ObjectInputStream ;
37- import java .io .ObjectOutputStream ;
3830import java .io .Serializable ;
3931import java .util .List ;
4032
41- public class SerializationTest {
33+ public class SerializationTest extends BaseSerializationTest {
4234
4335 private static final Compute COMPUTE = ComputeOptions .builder ().projectId ("p" ).build ().service ();
4436 private static final Long CREATION_TIMESTAMP = 1453293540000L ;
@@ -269,27 +261,18 @@ public class SerializationTest {
269261 private static final Compute .InstanceAggregatedListOption INSTANCE_AGGREGATED_LIST_OPTION =
270262 Compute .InstanceAggregatedListOption .filter (INSTANCE_FILTER );
271263
272- @ Test
273- public void testServiceOptions () throws Exception {
264+ @ Override
265+ protected Serializable [] serializableObjects () {
274266 ComputeOptions options = ComputeOptions .builder ()
275267 .projectId ("p1" )
276268 .authCredentials (AuthCredentials .createForAppEngine ())
277269 .build ();
278- ComputeOptions serializedCopy = serializeAndDeserialize (options );
279- assertEquals (options , serializedCopy );
280-
281- options = options .toBuilder ()
270+ ComputeOptions otherOptions = options .toBuilder ()
282271 .projectId ("p2" )
283272 .retryParams (RetryParams .defaultInstance ())
284273 .authCredentials (null )
285274 .build ();
286- serializedCopy = serializeAndDeserialize (options );
287- assertEquals (options , serializedCopy );
288- }
289-
290- @ Test
291- public void testModelAndRequests () throws Exception {
292- Serializable [] objects = {DISK_TYPE_ID , DISK_TYPE , MACHINE_TYPE_ID , MACHINE_TYPE , REGION_ID ,
275+ return new Serializable []{DISK_TYPE_ID , DISK_TYPE , MACHINE_TYPE_ID , MACHINE_TYPE , REGION_ID ,
293276 REGION , ZONE_ID , ZONE , LICENSE_ID , LICENSE , DEPRECATION_STATUS , GLOBAL_OPERATION_ID ,
294277 REGION_OPERATION_ID , ZONE_OPERATION_ID , GLOBAL_OPERATION , REGION_OPERATION , ZONE_OPERATION ,
295278 INSTANCE_ID , REGION_FORWARDING_RULE_ID , GLOBAL_FORWARDING_RULE_ID , GLOBAL_ADDRESS_ID ,
@@ -311,26 +294,12 @@ public void testModelAndRequests() throws Exception {
311294 IMAGE_LIST_OPTION , DISK_OPTION , DISK_FILTER , DISK_LIST_OPTION , DISK_AGGREGATED_LIST_OPTION ,
312295 SUBNETWORK_OPTION , SUBNETWORK_FILTER , SUBNETWORK_LIST_OPTION ,
313296 SUBNETWORK_AGGREGATED_LIST_OPTION , NETWORK_OPTION , NETWORK_FILTER , NETWORK_LIST_OPTION ,
314- INSTANCE_OPTION , INSTANCE_FILTER , INSTANCE_LIST_OPTION , INSTANCE_AGGREGATED_LIST_OPTION };
315- for (Serializable obj : objects ) {
316- Object copy = serializeAndDeserialize (obj );
317- assertEquals (obj , obj );
318- assertEquals (obj , copy );
319- assertNotSame (obj , copy );
320- assertEquals (copy , copy );
321- }
297+ INSTANCE_OPTION , INSTANCE_FILTER , INSTANCE_LIST_OPTION , INSTANCE_AGGREGATED_LIST_OPTION ,
298+ options , otherOptions };
322299 }
323300
324- @ SuppressWarnings ("unchecked" )
325- private <T > T serializeAndDeserialize (T obj )
326- throws IOException , ClassNotFoundException {
327- ByteArrayOutputStream bytes = new ByteArrayOutputStream ();
328- try (ObjectOutputStream output = new ObjectOutputStream (bytes )) {
329- output .writeObject (obj );
330- }
331- try (ObjectInputStream input =
332- new ObjectInputStream (new ByteArrayInputStream (bytes .toByteArray ()))) {
333- return (T ) input .readObject ();
334- }
301+ @ Override
302+ protected Restorable <?>[] restorableObjects () {
303+ return null ;
335304 }
336305}
0 commit comments