• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 Google LLC
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *       http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.google.cloud.dns;
18 
19 import com.google.cloud.BaseSerializationTest;
20 import com.google.cloud.NoCredentials;
21 import com.google.cloud.Restorable;
22 import com.google.cloud.ServiceOptions;
23 import com.google.common.collect.ImmutableList;
24 import java.io.Serializable;
25 import java.math.BigInteger;
26 import java.util.concurrent.TimeUnit;
27 
28 public class SerializationTest extends BaseSerializationTest {
29 
30   private static final ZoneInfo FULL_ZONE_INFO =
31       Zone.of("some zone name", "www.example.com", "some descriptions")
32           .toBuilder()
33           .setCreationTimeMillis(132L)
34           .setGeneratedId("123333")
35           .setNameServers(ImmutableList.of("server 1", "server 2"))
36           .setNameServerSet("specificationstring")
37           .build();
38   private static final ZoneInfo PARTIAL_ZONE_INFO =
39       Zone.of("some zone name", "www.example.com", "some descriptions").toBuilder().build();
40   private static final ProjectInfo PARTIAL_PROJECT_INFO =
41       ProjectInfo.newBuilder().setId("13").build();
42   private static final ProjectInfo FULL_PROJECT_INFO =
43       ProjectInfo.newBuilder()
44           .setId("342")
45           .setNumber(new BigInteger("2343245"))
46           .setQuota(new ProjectInfo.Quota(12, 13, 14, 15, 16, 17))
47           .build();
48   private static final Dns.ZoneListOption ZONE_LIST_OPTION =
49       Dns.ZoneListOption.dnsName("www.example.com.");
50   private static final Dns.RecordSetListOption RECORD_SET_LIST_OPTION =
51       Dns.RecordSetListOption.fields(Dns.RecordSetField.TTL);
52   private static final Dns.ChangeRequestListOption CHANGE_REQUEST_LIST_OPTION =
53       Dns.ChangeRequestListOption.fields(Dns.ChangeRequestField.STATUS);
54   private static final Dns.ZoneOption ZONE_OPTION =
55       Dns.ZoneOption.fields(Dns.ZoneField.CREATION_TIME);
56   private static final Dns.ChangeRequestOption CHANGE_REQUEST_OPTION =
57       Dns.ChangeRequestOption.fields(Dns.ChangeRequestField.STATUS);
58   private static final Dns.ProjectOption PROJECT_OPTION =
59       Dns.ProjectOption.fields(Dns.ProjectField.QUOTA);
60   private static final DnsOptions OPTIONS =
61       DnsOptions.newBuilder()
62           .setProjectId("some-unnecessary-project-ID")
63           .setRetrySettings(ServiceOptions.getDefaultRetrySettings())
64           .build();
65   private static final Dns DNS = OPTIONS.getService();
66   private static final Zone FULL_ZONE = new Zone(DNS, new ZoneInfo.BuilderImpl(FULL_ZONE_INFO));
67   private static final Zone PARTIAL_ZONE =
68       new Zone(DNS, new ZoneInfo.BuilderImpl(PARTIAL_ZONE_INFO));
69   private static final ChangeRequestInfo CHANGE_REQUEST_INFO_PARTIAL =
70       ChangeRequest.newBuilder().build();
71   private static final ChangeRequest CHANGE_REQUEST_PARTIAL =
72       new ChangeRequest(
73           DNS, "name", new ChangeRequestInfo.BuilderImpl(CHANGE_REQUEST_INFO_PARTIAL));
74   private static final RecordSet RECORD_SET_PARTIAL =
75       RecordSet.newBuilder("www.www.com", RecordSet.Type.AAAA).build();
76   private static final RecordSet RECORD_SET_COMPLETE =
77       RecordSet.newBuilder("www.sadfa.com", RecordSet.Type.A)
78           .setTtl(12, TimeUnit.HOURS)
79           .addRecord("record")
80           .build();
81   private static final ChangeRequestInfo CHANGE_REQUEST_INFO_COMPLETE =
82       ChangeRequestInfo.newBuilder()
83           .add(RECORD_SET_COMPLETE)
84           .delete(RECORD_SET_PARTIAL)
85           .setStatus(ChangeRequest.Status.PENDING)
86           .setGeneratedId("some id")
87           .setStartTime(132L)
88           .build();
89   private static final ChangeRequest CHANGE_REQUEST_COMPLETE =
90       new ChangeRequest(
91           DNS, "name", new ChangeRequestInfo.BuilderImpl(CHANGE_REQUEST_INFO_COMPLETE));
92 
93   @Override
serializableObjects()94   protected Serializable[] serializableObjects() {
95     DnsOptions options =
96         DnsOptions.newBuilder()
97             .setCredentials(NoCredentials.getInstance())
98             .setProjectId("id1")
99             .build();
100     DnsOptions otherOptions = options.toBuilder().build();
101     return new Serializable[] {
102       FULL_ZONE_INFO,
103       PARTIAL_ZONE_INFO,
104       ZONE_LIST_OPTION,
105       RECORD_SET_LIST_OPTION,
106       CHANGE_REQUEST_LIST_OPTION,
107       ZONE_OPTION,
108       CHANGE_REQUEST_OPTION,
109       PROJECT_OPTION,
110       PARTIAL_PROJECT_INFO,
111       FULL_PROJECT_INFO,
112       OPTIONS,
113       FULL_ZONE,
114       PARTIAL_ZONE,
115       OPTIONS,
116       CHANGE_REQUEST_INFO_PARTIAL,
117       CHANGE_REQUEST_PARTIAL,
118       RECORD_SET_PARTIAL,
119       RECORD_SET_COMPLETE,
120       CHANGE_REQUEST_INFO_COMPLETE,
121       CHANGE_REQUEST_COMPLETE,
122       options,
123       otherOptions
124     };
125   }
126 
127   @Override
restorableObjects()128   protected Restorable<?>[] restorableObjects() {
129     return new Restorable<?>[0];
130   }
131 }
132