|
16 | 16 |
|
17 | 17 | package com.google.gcloud.dns; |
18 | 18 |
|
19 | | -import static org.junit.Assert.assertEquals; |
20 | | -import static org.junit.Assert.assertNotSame; |
21 | | - |
22 | 19 | import com.google.common.collect.ImmutableList; |
| 20 | +import com.google.gcloud.AuthCredentials; |
| 21 | +import com.google.gcloud.BaseSerializationTest; |
| 22 | +import com.google.gcloud.Restorable; |
23 | 23 | import com.google.gcloud.RetryParams; |
24 | 24 |
|
25 | | -import org.junit.Test; |
26 | | - |
27 | | -import java.io.ByteArrayInputStream; |
28 | | -import java.io.ByteArrayOutputStream; |
29 | | -import java.io.IOException; |
30 | | -import java.io.ObjectInputStream; |
31 | | -import java.io.ObjectOutputStream; |
32 | 25 | import java.io.Serializable; |
33 | 26 | import java.math.BigInteger; |
34 | 27 | import java.util.concurrent.TimeUnit; |
35 | 28 |
|
36 | | -public class SerializationTest { |
| 29 | +public class SerializationTest extends BaseSerializationTest { |
37 | 30 |
|
38 | 31 | private static final ZoneInfo FULL_ZONE_INFO = Zone.of("some zone name", "www.example.com", |
39 | 32 | "some descriptions").toBuilder() |
@@ -86,31 +79,24 @@ public class SerializationTest { |
86 | 79 | .startTimeMillis(132L) |
87 | 80 | .build(); |
88 | 81 |
|
89 | | - @Test |
90 | | - public void testModelAndRequests() throws Exception { |
91 | | - Serializable[] objects = {FULL_ZONE_INFO, PARTIAL_ZONE_INFO, ZONE_LIST_OPTION, |
| 82 | + @Override |
| 83 | + protected Serializable[] serializableObjects() { |
| 84 | + DnsOptions options = DnsOptions.builder() |
| 85 | + .authCredentials(AuthCredentials.createForAppEngine()) |
| 86 | + .projectId("ds1") |
| 87 | + .build(); |
| 88 | + DnsOptions otherOptions = options.toBuilder() |
| 89 | + .authCredentials(null) |
| 90 | + .build(); |
| 91 | + return new Serializable[]{FULL_ZONE_INFO, PARTIAL_ZONE_INFO, ZONE_LIST_OPTION, |
92 | 92 | DNS_REOCRD_LIST_OPTION, CHANGE_REQUEST_LIST_OPTION, ZONE_OPTION, CHANGE_REQUEST_OPTION, |
93 | 93 | PROJECT_OPTION, PARTIAL_PROJECT_INFO, FULL_PROJECT_INFO, OPTIONS, FULL_ZONE, PARTIAL_ZONE, |
94 | 94 | OPTIONS, CHANGE_REQUEST_PARTIAL, DNS_RECORD_PARTIAL, DNS_RECORD_COMPLETE, |
95 | | - CHANGE_REQUEST_COMPLETE}; |
96 | | - for (Serializable obj : objects) { |
97 | | - Object copy = serializeAndDeserialize(obj); |
98 | | - assertEquals(obj, obj); |
99 | | - assertEquals(obj, copy); |
100 | | - assertNotSame(obj, copy); |
101 | | - assertEquals(copy, copy); |
102 | | - } |
| 95 | + CHANGE_REQUEST_COMPLETE, options, otherOptions}; |
103 | 96 | } |
104 | 97 |
|
105 | | - @SuppressWarnings("unchecked") |
106 | | - private <T> T serializeAndDeserialize(T obj) throws IOException, ClassNotFoundException { |
107 | | - ByteArrayOutputStream bytes = new ByteArrayOutputStream(); |
108 | | - try (ObjectOutputStream output = new ObjectOutputStream(bytes)) { |
109 | | - output.writeObject(obj); |
110 | | - } |
111 | | - try (ObjectInputStream input = |
112 | | - new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) { |
113 | | - return (T) input.readObject(); |
114 | | - } |
| 98 | + @Override |
| 99 | + protected Restorable<?>[] restorableObjects() { |
| 100 | + return new Restorable<?>[0]; |
115 | 101 | } |
116 | 102 | } |
0 commit comments