Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored the serialization test to use the base test #783

Merged
merged 1 commit into from
Mar 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions gcloud-java-dns/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>gcloud-java-core</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,17 @@

package com.google.gcloud.dns;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;

import com.google.common.collect.ImmutableList;
import com.google.gcloud.AuthCredentials;
import com.google.gcloud.BaseSerializationTest;
import com.google.gcloud.Restorable;
import com.google.gcloud.RetryParams;

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.math.BigInteger;
import java.util.concurrent.TimeUnit;

public class SerializationTest {
public class SerializationTest extends BaseSerializationTest {

private static final ZoneInfo FULL_ZONE_INFO = Zone.of("some zone name", "www.example.com",
"some descriptions").toBuilder()
Expand Down Expand Up @@ -86,31 +79,24 @@ public class SerializationTest {
.startTimeMillis(132L)
.build();

@Test
public void testModelAndRequests() throws Exception {
Serializable[] objects = {FULL_ZONE_INFO, PARTIAL_ZONE_INFO, ZONE_LIST_OPTION,
@Override
protected Serializable[] serializableObjects() {
DnsOptions options = DnsOptions.builder()
.authCredentials(AuthCredentials.createForAppEngine())
.projectId("id1")
.build();
DnsOptions otherOptions = options.toBuilder()
.authCredentials(null)
.build();
return new Serializable[]{FULL_ZONE_INFO, PARTIAL_ZONE_INFO, ZONE_LIST_OPTION,
DNS_REOCRD_LIST_OPTION, CHANGE_REQUEST_LIST_OPTION, ZONE_OPTION, CHANGE_REQUEST_OPTION,
PROJECT_OPTION, PARTIAL_PROJECT_INFO, FULL_PROJECT_INFO, OPTIONS, FULL_ZONE, PARTIAL_ZONE,
OPTIONS, CHANGE_REQUEST_PARTIAL, DNS_RECORD_PARTIAL, DNS_RECORD_COMPLETE,
CHANGE_REQUEST_COMPLETE};
for (Serializable obj : objects) {
Object copy = serializeAndDeserialize(obj);
assertEquals(obj, obj);
assertEquals(obj, copy);
assertNotSame(obj, copy);
assertEquals(copy, copy);
}
CHANGE_REQUEST_COMPLETE, options, otherOptions};
}

@SuppressWarnings("unchecked")
private <T> 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 new Restorable<?>[0];
}
}