Adding domain service

This commit is contained in:
Adam Lowe 2011-12-20 20:32:03 +00:00
parent edf0ce24a2
commit 92d9ee3ff1
17 changed files with 1004 additions and 4 deletions

View File

@ -19,6 +19,7 @@
package org.jclouds.glesys;
import org.jclouds.glesys.features.ArchiveAsyncClient;
import org.jclouds.glesys.features.DomainAsyncClient;
import org.jclouds.glesys.features.IpAsyncClient;
import org.jclouds.glesys.features.ServerAsyncClient;
import org.jclouds.rest.annotations.Delegate;
@ -50,4 +51,11 @@ public interface GleSYSAsyncClient {
*/
@Delegate
ArchiveAsyncClient getArchiveClient();
/**
* Provides asynchronous access to DNS features.
*/
@Delegate
DomainAsyncClient getDomainClient();
}

View File

@ -18,15 +18,15 @@
*/
package org.jclouds.glesys;
import java.util.concurrent.TimeUnit;
import org.jclouds.concurrent.Timeout;
import org.jclouds.glesys.features.ArchiveAsyncClient;
import org.jclouds.glesys.features.ArchiveClient;
import org.jclouds.glesys.features.DomainClient;
import org.jclouds.glesys.features.IpClient;
import org.jclouds.glesys.features.ServerClient;
import org.jclouds.rest.annotations.Delegate;
import java.util.concurrent.TimeUnit;
/**
* Provides synchronous access to GleSYS.
* <p/>
@ -55,4 +55,10 @@ public interface GleSYSClient {
*/
@Delegate
ArchiveClient getArchiveClient();
/**
* Provides synchronous access to DNS features.
*/
@Delegate
DomainClient getDomainClient();
}

View File

@ -24,6 +24,7 @@ import com.google.inject.Provides;
import org.jclouds.glesys.domain.ServerState;
import org.jclouds.glesys.domain.ServerUptime;
import org.jclouds.glesys.functions.internal.CustomDeserializers;
import org.jclouds.glesys.functions.internal.GlesysDateAdapter;
import org.jclouds.json.config.GsonModule;
import org.jclouds.json.config.GsonModule.DateAdapter;
@ -47,7 +48,7 @@ public class GleSYSParserModule extends AbstractModule {
@Override
protected void configure() {
bind(DateAdapter.class).to(GsonModule.Iso8601DateAdapter.class);
bind(DateAdapter.class).to(GlesysDateAdapter.class);
}
}

View File

@ -49,6 +49,7 @@ public class GleSYSRestClientModule extends RestClientModule<GleSYSClient, GleSY
.put(ServerClient.class, ServerAsyncClient.class)//
.put(IpClient.class, IpAsyncClient.class)//
.put(ArchiveClient.class, ArchiveAsyncClient.class)//
.put(DomainClient.class, DomainAsyncClient.class)//
.build();
public GleSYSRestClientModule() {

View File

@ -0,0 +1,129 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.glesys.domain;
import com.google.common.base.Objects;
import com.google.gson.annotations.SerializedName;
import java.util.Date;
/**
* Domain data for a Glesys account.
*
* @author Adam Lowe
*/
public class Domain implements Comparable<Domain> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String domain;
private Date createTime;
private int recordCount;
private boolean glesysNameServer;
public Builder domain(String domain) {
this.domain = domain;
return this;
}
public Builder createTime(Date createTime) {
this.createTime = createTime;
return this;
}
public Builder recordCount(int recordCount) {
this.recordCount = recordCount;
return this;
}
public Builder glesysNameServer(boolean glesysNameServer) {
this.glesysNameServer = glesysNameServer;
return this;
}
public Domain build() {
return new Domain(domain, createTime, recordCount, glesysNameServer);
}
public Builder fromDomain(Domain in) {
return new Builder();
}
}
private final String domain;
@SerializedName("create_time")
private final Date createTime;
@SerializedName("count")
private final int recordCount;
@SerializedName("glesysnameserver")
private final boolean glesysNameServer;
public Domain(String domain, Date createTime, int recordCount, boolean glesysNameServer) {
this.domain = domain;
this.createTime = createTime;
this.recordCount = recordCount;
this.glesysNameServer = glesysNameServer;
}
public String getDomain() {
return domain;
}
public Date getCreateTime() {
return createTime;
}
public int getRecordCount() {
return recordCount;
}
public boolean getGlesysNameServer() {
return glesysNameServer;
}
@Override
public int hashCode() {
return Objects.hashCode(domain);
}
@Override
public int compareTo(Domain other) {
return domain.compareTo(other.getDomain());
}
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof Domain) {
return Objects.equal(domain, ((Domain) object).domain);
} else {
return false;
}
}
@Override
public String toString() {
return String.format("[domain=%s, createTime=%s, count=%d, glesysnameserver=%b]", domain, createTime, recordCount, glesysNameServer);
}
}

View File

@ -0,0 +1,149 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.glesys.domain;
import com.google.common.base.Objects;
/**
* DNS record data.
*
* @author Adam Lowe
*/
public class DomainRecord implements Comparable<DomainRecord> {
public static Builder builder() {
return new Builder();
}
public static class Builder {
private String id;
private String zone;
private String host;
private String type;
private String data;
private int ttl;
public Builder id(String id) {
this.id = id;
return this;
}
public Builder zone(String zone) {
this.zone = zone;
return this;
}
public Builder host(String host) {
this.host = host;
return this;
}
public Builder type(String type) {
this.type = type;
return this;
}
public Builder data(String data) {
this.data = data;
return this;
}
public Builder ttl(int ttl) {
this.ttl = ttl;
return this;
}
public DomainRecord build() {
return new DomainRecord(id, zone, host, type, data, ttl);
}
public Builder fromDomainRecord(DomainRecord in) {
return new Builder().id(in.getId()).zone(in.getZone()).host(in.getHost()).type(in.getType()).data(in.getData()).ttl(in.getTtl());
}
}
private final String id;
private final String zone;
private final String host;
private final String type;
private final String data;
private final int ttl;
public DomainRecord(String id, String zone, String host, String type, String data, int ttl) {
this.id = id;
this.zone = zone;
this.host = host;
this.type = type;
this.data = data;
this.ttl = ttl;
}
public String getId() {
return id;
}
public String getZone() {
return zone;
}
public String getHost() {
return host;
}
public String getType() {
return type;
}
public String getData() {
return data;
}
public int getTtl() {
return ttl;
}
@Override
public int compareTo(DomainRecord other) {
return id.compareTo(other.getId());
}
@Override
public int hashCode() {
return Objects.hashCode(id);
}
@Override
public boolean equals(Object object) {
if (this == object) {
return true;
}
if (object instanceof DomainRecord) {
DomainRecord other = (DomainRecord) object;
return Objects.equal(id, other.id);
} else {
return false;
}
}
@Override
public String toString() {
return String.format("[id=%s, zone=%s, host=%s, type=%s, data=%s, ttl=%d]", id, zone, host, type, data, ttl);
}
}

View File

@ -0,0 +1,99 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.glesys.features;
import com.google.common.util.concurrent.ListenableFuture;
import org.jclouds.glesys.domain.Domain;
import org.jclouds.glesys.domain.DomainRecord;
import org.jclouds.glesys.options.DomainOptions;
import org.jclouds.glesys.options.DomainRecordAddOptions;
import org.jclouds.glesys.options.DomainRecordModifyOptions;
import org.jclouds.http.filters.BasicAuthentication;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SelectJson;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import java.util.Set;
/**
* Provides asynchronous access to Domain (DNS) data via the Glesys REST API.
* <p/>
*
* @author Adam Lowe
* @see DomainClient
* @see <a href="https://customer.glesys.com/api.php" />
*/
@RequestFilters(BasicAuthentication.class)
public interface DomainAsyncClient {
/**
* @see org.jclouds.glesys.features.DomainClient#listDomains
*/
@POST
@Path("/domain/list/format/json")
@SelectJson("domains")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Set<Domain>> listDomains();
/**
* @see DomainClient#addDomain
*/
@POST
@Path("/domain/add/format/json")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Void> addDomain(@FormParam("name") String domain, DomainOptions... options);
/**
* @see DomainClient#editDomain
*/
@POST
@Path("/domain/add/format/json")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Void> editDomain(@FormParam("domain") String domain, DomainOptions... options);
@POST
@Path("/domain/delete/format/json")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Void> deleteDomain(@FormParam("domain") String domain);
@GET
@Path("/domain/list_records/domain/{domain}/format/json")
@SelectJson("records")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Set<DomainRecord>> listRecords(@PathParam("domain") String domain);
@POST
@Path("/domain/add_record/format/json")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Void> addRecord(@FormParam("domain") String domain, @FormParam("host") String host,
@FormParam("type") String type, @FormParam("data") String data,
DomainRecordAddOptions... options);
@POST
@Path("/domain/update_record/format/json")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Void> editRecord(@FormParam("record_id") String record_id, DomainRecordModifyOptions... options);
@POST
@Path("/domain/delete_record/format/json")
@Consumes(MediaType.APPLICATION_JSON)
ListenableFuture<Void> deleteRecord(@FormParam("record_id") String recordId);
}

View File

@ -0,0 +1,105 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.glesys.features;
import org.jclouds.concurrent.Timeout;
import org.jclouds.glesys.domain.Domain;
import org.jclouds.glesys.domain.DomainRecord;
import org.jclouds.glesys.options.DomainOptions;
import org.jclouds.glesys.options.DomainRecordAddOptions;
import org.jclouds.glesys.options.DomainRecordModifyOptions;
import java.util.Set;
import java.util.concurrent.TimeUnit;
/**
* Provides synchronous access to Invoice requests.
* <p/>
*
* @author Adam Lowe
* @see InvoiceAsyncClient
* @see <a href="https://customer.glesys.com/api.php" />
*/
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
public interface DomainClient {
/**
* Get a list of all invoices for this account.
*
* @return an account's associated invoice objects.
*/
Set<Domain> listDomains();
/**
* Add a domain to the Glesys dns-system
*
* @param domain the name of the domain to add.
*/
void addDomain(String domain, DomainOptions... options);
/**
* Add a domain to the Glesys dns-system
*
* @param domain the name of the domain to add.
*/
void editDomain(String domain, DomainOptions... options);
/**
* Remove a domain to the Glesys dns-system
*
* @param domain the name of the domain to remove
*/
void deleteDomain(String domain);
/**
* Retrieve the DNS records for a given domain
*
* @param domain the name of the domain to retrieve records for
*/
Set<DomainRecord> listRecords(String domain);
/**
* Add a DNS Record
*
* @param domain
* @param host
* @param type
* @param data
* @param options optional settings for the record
*/
void addRecord(String domain, String host, String type, String data, DomainRecordAddOptions... options);
/**
* Modify a specific DNS Record
*
* @param recordId the id for the record to edit
* @param options the settings to change
* @see #listRecords to retrieve the necessary ids
*/
void editRecord(String recordId, DomainRecordModifyOptions... options);
/**
* Delete a DNS record
*
* @param recordId the id for the record to delete
* @see #listRecords to retrieve the necessary ids
*/
void deleteRecord(String recordId);
}

View File

@ -0,0 +1,39 @@
package org.jclouds.glesys.functions.internal;
import com.google.gson.*;
import org.jclouds.json.config.GsonModule;
import javax.inject.Singleton;
import java.lang.reflect.Type;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* Parser for Glesys Date formats
*
* @author Adam Lowe
*/
@Singleton
public class GlesysDateAdapter implements GsonModule.DateAdapter {
private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) {
synchronized (dateFormat) {
return new JsonPrimitive(dateFormat.format(src));
}
}
public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
throws JsonParseException {
String toParse = json.getAsJsonPrimitive().getAsString();
try {
synchronized (dateFormat) {
return dateFormat.parse(toParse);
}
} catch (ParseException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -0,0 +1,101 @@
package org.jclouds.glesys.options;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* @author Adam Lowe
*/
public class DomainOptions extends BaseHttpRequestOptions {
public static class Builder {
/**
* @see DomainOptions#primaryNameServer
*/
public static DomainOptions primaryNameServer(String primaryNameServer) {
DomainOptions options = new DomainOptions();
return options.primaryNameServer(primaryNameServer);
}
/**
* @see DomainOptions#responsiblePerson
*/
public static DomainOptions responsiblePerson(String responsiblePerson) {
DomainOptions options = new DomainOptions();
return options.responsiblePerson(responsiblePerson);
}
/**
* @see DomainOptions#ttl
*/
public static DomainOptions ttl(int ttl) {
DomainOptions options = new DomainOptions();
return options.ttl(ttl);
}
/**
* @see DomainOptions#refresh
*/
public static DomainOptions refresh(String refresh) {
DomainOptions options = new DomainOptions();
return options.refresh(refresh);
}
/**
* @see DomainOptions#retry
*/
public static DomainOptions retry(String retry) {
DomainOptions options = new DomainOptions();
return options.retry(retry);
}
/**
* @see DomainOptions#expire
*/
public static DomainOptions expire(String expire) {
DomainOptions options = new DomainOptions();
return options.expire(expire);
}
/**
* @see DomainOptions#minimum
*/
public static DomainOptions minimum(String minimum) {
DomainOptions options = new DomainOptions();
return options.minimum(minimum);
}
}
public DomainOptions primaryNameServer(String primaryNameServer) {
formParameters.put("primary_ns", primaryNameServer);
return this;
}
public DomainOptions responsiblePerson(String responsiblePerson) {
formParameters.put("resp_person", responsiblePerson);
return this;
}
public DomainOptions ttl(int ttl) {
formParameters.put("ttl", Integer.toString(ttl));
return this;
}
public DomainOptions refresh(String refresh) {
formParameters.put("refresh", refresh);
return this;
}
public DomainOptions retry(String retry) {
formParameters.put("retry", retry);
return this;
}
public DomainOptions expire(String expire) {
formParameters.put("primary_ns", expire);
return this;
}
public DomainOptions minimum(String minimum) {
formParameters.put("minimum", minimum);
return this;
}
}

View File

@ -0,0 +1,43 @@
package org.jclouds.glesys.options;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* @author Adam Lowe
*/
public class DomainRecordAddOptions extends BaseHttpRequestOptions {
public static class Builder {
/**
* @see DomainRecordAddOptions#ttl
*/
public static DomainRecordAddOptions ttl(int ttl) {
DomainRecordAddOptions options = new DomainRecordAddOptions();
return options.ttl(ttl);
}
/**
* @see DomainRecordAddOptions#mxPriority
*/
public static DomainRecordAddOptions mxPriority(String mxPriority) {
DomainRecordAddOptions options = new DomainRecordAddOptions();
return options.mxPriority(mxPriority);
}
}
public DomainRecordAddOptions host(String host) {
formParameters.put("host", host);
return this;
}
public DomainRecordAddOptions ttl(int ttl) {
formParameters.put("ttl", Integer.toString(ttl));
return this;
}
public DomainRecordAddOptions mxPriority(String mxPriority) {
formParameters.put("mx_priority", mxPriority);
return this;
}
}

View File

@ -0,0 +1,65 @@
package org.jclouds.glesys.options;
/**
* @author Adam Lowe
*/
public class DomainRecordModifyOptions extends DomainRecordAddOptions {
public static class Builder {
/**
* @see org.jclouds.glesys.options.DomainRecordAddOptions#host
*/
public static DomainRecordModifyOptions host(String host) {
DomainRecordModifyOptions options = new DomainRecordModifyOptions();
return options.host(host);
}
/**
* @see org.jclouds.glesys.options.DomainRecordModifyOptions#type
*/
public static DomainRecordModifyOptions type(String type) {
DomainRecordModifyOptions options = new DomainRecordModifyOptions();
return options.type(type);
}
/**
* @see org.jclouds.glesys.options.DomainRecordModifyOptions#data
*/
public static DomainRecordModifyOptions data(String data) {
DomainRecordModifyOptions options = new DomainRecordModifyOptions();
return options.data(data);
}
/**
* @see org.jclouds.glesys.options.DomainRecordModifyOptions#ttl
*/
public static DomainRecordModifyOptions ttl(int ttl) {
DomainRecordModifyOptions options = new DomainRecordModifyOptions();
return DomainRecordModifyOptions.class.cast(options.ttl(ttl));
}
/**
* @see org.jclouds.glesys.options.DomainRecordModifyOptions#mxPriority
*/
public static DomainRecordModifyOptions mxPriority(String mxPriority) {
DomainRecordModifyOptions options = new DomainRecordModifyOptions();
return DomainRecordModifyOptions.class.cast(options.mxPriority(mxPriority));
}
}
public DomainRecordModifyOptions host(String host) {
formParameters.put("host", host);
return this;
}
public DomainRecordModifyOptions type(String type) {
formParameters.put("type", type);
return this;
}
public DomainRecordModifyOptions data(String data) {
formParameters.put("data", data);
return this;
}
}

View File

@ -0,0 +1,106 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.glesys.features;
import com.google.common.base.Predicate;
import org.jclouds.glesys.domain.DomainRecord;
import org.jclouds.predicates.RetryablePredicate;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import static org.testng.Assert.assertTrue;
/**
* Tests behavior of {@code DomainClient}
*
* @author Adam Lowe
*/
@Test(groups = "live", testName = "DomainClientLiveTest")
public class DomainClientLiveTest extends BaseGleSYSClientLiveTest {
@BeforeGroups(groups = {"live"})
public void setupClient() {
super.setupClient();
client = context.getApi().getDomainClient();
domainCounter = new RetryablePredicate<Integer>(
new Predicate<Integer>() {
public boolean apply(Integer value) {
return client.listDomains().size() == value;
}
}, 30, 1, TimeUnit.SECONDS);
recordCounter = new RetryablePredicate<Integer>(
new Predicate<Integer>() {
public boolean apply(Integer value) {
return client.listRecords(testDomain).size() == value;
}
}, 30, 1, TimeUnit.SECONDS);
}
@AfterGroups(groups = {"live"})
public void tearDown() {
int before = client.listDomains().size();
client.deleteDomain(testDomain);
assertTrue(domainCounter.apply(before - 1));
super.tearDown();
}
private DomainClient client;
private String testDomain = "glesystest.jclouds.org";
private String testRecordId;
private RetryablePredicate<Integer> domainCounter;
private RetryablePredicate<Integer> recordCounter;
@Test
public void testCreateDomain() throws Exception {
try {
client.deleteDomain(testDomain);
} catch (Exception ex) {
}
int before = client.listDomains().size();
client.addDomain(testDomain);
assertTrue(domainCounter.apply(before + 1));
}
@Test(dependsOnMethods = "testCreateDomain")
public void testCreateRecord() throws Exception {
int before = client.listRecords(testDomain).size();
client.addRecord(testDomain, "test", "A", "127.0.0.1");
assertTrue(recordCounter.apply(before + 1));
}
@Test(dependsOnMethods = "testCreateRecord")
public void testDeleteRecord() throws Exception {
Set<DomainRecord> domainRecords = client.listRecords(testDomain);
int before = domainRecords.size();
client.deleteRecord(domainRecords.iterator().next().getId());
assertTrue(recordCounter.apply(before - 1));
}
}

View File

@ -0,0 +1,70 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.glesys.parse;
import com.google.common.collect.Sets;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.jclouds.glesys.config.GleSYSParserModule;
import org.jclouds.glesys.domain.Domain;
import org.jclouds.json.BaseSetParserTest;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Set;
import static org.testng.Assert.fail;
/**
* @author Adam Lowe
*/
@Test(groups = "unit", testName = "ParseDomainListTest")
public class ParseDomainListTest extends BaseSetParserTest<Domain> {
@Override
public String resource() {
return "/domain_list.json";
}
@Override
@SelectJson("domains")
@Consumes(MediaType.APPLICATION_JSON)
public Set<Domain> expected() {
Date creationTime = null;
try {
creationTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2011-12-20 10:58:51");
} catch (ParseException e) {
fail("Bad dates!");
}
Domain domain = Domain.builder().domain("adamlowe.net").createTime(creationTime).recordCount(9).glesysNameServer(false).build();
return Sets.newHashSet(domain);
}
protected Injector injector() {
return Guice.createInjector(new GleSYSParserModule(), new GsonModule());
}
}

View File

@ -0,0 +1,76 @@
/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jclouds.glesys.parse;
import com.google.common.collect.ImmutableSortedSet;
import com.google.common.collect.Sets;
import com.google.inject.Guice;
import com.google.inject.Injector;
import org.jclouds.glesys.config.GleSYSParserModule;
import org.jclouds.glesys.domain.Domain;
import org.jclouds.glesys.domain.DomainRecord;
import org.jclouds.json.BaseSetParserTest;
import org.jclouds.json.config.GsonModule;
import org.jclouds.rest.annotations.SelectJson;
import org.testng.annotations.Test;
import javax.ws.rs.Consumes;
import javax.ws.rs.core.MediaType;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.Set;
import static org.testng.Assert.fail;
/**
* @author Adam Lowe
*/
@Test(groups = "unit", testName = "ParseDomainRecordListTest")
public class ParseDomainRecordListTest extends BaseSetParserTest<DomainRecord> {
@Override
public String resource() {
return "/domain_list_records.json";
}
@Override
@SelectJson("records")
@Consumes(MediaType.APPLICATION_JSON)
public Set<DomainRecord> expected() {
return ImmutableSortedSet.copyOf(
Arrays.asList(
DomainRecord.builder().id("213227").zone("adamlowe.net").host("@").type("NS").data("ns1.namesystem.se.").ttl(3600).build(),
DomainRecord.builder().id("213228").zone("adamlowe.net").host("@").type("NS").data("ns2.namesystem.se.").ttl(3600).build(),
DomainRecord.builder().id("213229").zone("adamlowe.net").host("@").type("NS").data("ns3.namesystem.se.").ttl(3600).build(),
DomainRecord.builder().id("213230").zone("adamlowe.net").host("@").type("A").data("127.0.0.1").ttl(3600).build(),
DomainRecord.builder().id("213231").zone("adamlowe.net").host("www").type("A").data("127.0.0.1").ttl(3600).build(),
DomainRecord.builder().id("213232").zone("adamlowe.net").host("mail").type("A").data("79.99.4.40").ttl(3600).build(),
DomainRecord.builder().id("213233").zone("adamlowe.net").host("@").type("MX").data("mx01.glesys.se.").ttl(3600).build(),
DomainRecord.builder().id("213234").zone("adamlowe.net").host("@").type("MX").data("mx02.glesys.se.").ttl(3600).build(),
DomainRecord.builder().id("213235").zone("adamlowe.net").host("@").type("TXT").data("v=spf1 include:spf.glesys.se -all").ttl(3600).build()
));
}
protected Injector injector() {
return Guice.createInjector(new GleSYSParserModule(), new GsonModule());
}
}

View File

@ -0,0 +1 @@
{"response":{"status":{"code":"200","text":"OK"},"domains":[{"domain":"adamlowe.net","create_time":"2011-12-20 10:58:51","count":"9","glesysnameserver":false}],"debug":{"input":[]}}}

View File

@ -0,0 +1 @@
{"response":{"status":{"code":"200","text":"OK"},"records":[{"id":"213227","zone":"adamlowe.net","host":"@","type":"NS","data":"ns1.namesystem.se.","ttl":"3600"},{"id":"213228","zone":"adamlowe.net","host":"@","type":"NS","data":"ns2.namesystem.se.","ttl":"3600"},{"id":"213229","zone":"adamlowe.net","host":"@","type":"NS","data":"ns3.namesystem.se.","ttl":"3600"},{"id":"213230","zone":"adamlowe.net","host":"@","type":"A","data":"127.0.0.1","ttl":"3600"},{"id":"213231","zone":"adamlowe.net","host":"www","type":"A","data":"127.0.0.1","ttl":"3600"},{"id":"213232","zone":"adamlowe.net","host":"mail","type":"A","data":"79.99.4.40","ttl":"3600"},{"id":"213233","zone":"adamlowe.net","host":"@","type":"MX","data":"mx01.glesys.se.","ttl":"3600"},{"id":"213234","zone":"adamlowe.net","host":"@","type":"MX","data":"mx02.glesys.se.","ttl":"3600"},{"id":"213235","zone":"adamlowe.net","host":"@","type":"TXT","data":"v=spf1 include:spf.glesys.se -all","ttl":"3600"}],"debug":{"input":{"domain":"adamlowe.net"}}}}