@Override public LowLevelHttpRequest buildRequest(String method, String url) throws IOException { callCount ++; if (!HttpMethods.GET.equals(method) || !expectedUrl.equals(url)) { // Throw RuntimeException to fail the test. throw new RuntimeException(); } return new MockLowLevelHttpRequest() { @Override public LowLevelHttpResponse execute() throws IOException { MockLowLevelHttpResponse response = new MockLowLevelHttpResponse(); response.setStatusCode(HttpStatusCodes.STATUS_CODE_OK); response.setContentType(Json.MEDIA_TYPE); response.setContent(jsonResponse); return response; } }; }
public OAuthAccessToken build() throws IOException { Url = new GenericUrl(config.getAccessTokenUrl()); transport = new ApacheHttpTransport(); HttpRequestFactory requestFactory = transport.createRequestFactory(); request = requestFactory.buildRequest(HttpMethods.GET, Url, null); HttpHeaders headers = new HttpHeaders(); headers.setUserAgent(config.getUserAgent()); headers.setAccept(config.getAccept()); request.setHeaders(headers); createRefreshParameters().intercept(request); return this; }
@Test public void testGetTemplate() throws DnsimpleException, IOException { Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/templates/1", HttpMethods.GET, new HttpHeaders(), null, resource("getTemplate/success.http")); String accountId = "1010"; String templateId = "1"; GetTemplateResponse response = client.templates.getTemplate(accountId, templateId); Template template = response.getData(); assertEquals(1, template.getId().intValue()); assertEquals(1010, template.getAccountId().intValue()); assertEquals("Alpha", template.getName()); assertEquals("alpha", template.getShortName()); assertEquals("An alpha template.", template.getDescription()); assertEquals("2016-03-22T11:08:58Z", template.getCreatedAt()); assertEquals("2016-03-22T11:08:58Z", template.getUpdatedAt()); }
@Test public void testRegisterDomain() throws DnsimpleException, IOException { String accountId = "1010"; String name = "example.com"; HashMap<String, Object> attributes = new HashMap<String, Object>(); attributes.put("registrant_id", "10"); Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/registrations", HttpMethods.POST, new HttpHeaders(), attributes, resource("registerDomain/success.http")); RegisterDomainResponse response = client.registrar.registerDomain(accountId, name, attributes); DomainRegistration registration = response.getData(); assertEquals(1, registration.getId().intValue()); assertEquals(999, registration.getDomainId().intValue()); assertEquals(2, registration.getRegistrantId().intValue()); assertEquals("new", registration.getState()); assertFalse(registration.hasAutoRenew()); assertFalse(registration.hasWhoisPrivacy()); assertEquals("2016-12-09T19:35:31Z", registration.getCreatedAt()); assertEquals("2016-12-09T19:35:31Z", registration.getUpdatedAt()); }
@Test public void testGetWhoisPrivacy() throws DnsimpleException, IOException { String accountId = "1010"; String domainId = "example.com"; Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/whois_privacy", HttpMethods.GET, new HttpHeaders(), null, resource("getWhoisPrivacy/success.http")); GetWhoisPrivacyResponse response = client.registrar.getWhoisPrivacy(accountId, domainId); WhoisPrivacy whoisPrivacy = response.getData(); assertEquals(1, whoisPrivacy.getId().intValue()); assertEquals(2, whoisPrivacy.getDomainId().intValue()); assertEquals("2017-02-13", whoisPrivacy.getExpiresOn()); assertTrue(whoisPrivacy.getEnabled().booleanValue()); assertEquals("2016-02-13T14:34:50Z", whoisPrivacy.getCreatedAt()); assertEquals("2016-02-13T14:34:52Z", whoisPrivacy.getUpdatedAt()); }
@Test public void testGetTemplateRecord() throws DnsimpleException, IOException { Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/templates/1/records/301", HttpMethods.GET, resource("getTemplateRecord/success.http")); String accountId = "1010"; String templateId = "1"; String recordId = "301"; GetTemplateRecordResponse response = client.templates.getTemplateRecord(accountId, templateId, recordId); TemplateRecord record = response.getData(); assertEquals(301, record.getId().intValue()); assertEquals(268, record.getTemplateId().intValue()); assertEquals("", record.getName()); assertEquals("mx.example.com", record.getContent()); assertEquals(600, record.getTtl().intValue()); assertEquals(10, record.getPriority().intValue()); assertEquals("MX", record.getType()); assertEquals("2016-05-03T08:03:26Z", record.getCreatedAt()); assertEquals("2016-05-03T08:03:26Z", record.getUpdatedAt()); }
@Test public void testGetDomainDelegation() throws DnsimpleException, IOException { String accountId = "1010"; String domainId = "example.com"; Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/delegation", HttpMethods.GET, resource("getDomainDelegation/success.http")); GetDomainDelegationResponse response = client.registrar.getDomainDelegation(accountId, domainId); List<String> delegatedTo = response.getData(); assertEquals(4, delegatedTo.size()); assertEquals("ns1.dnsimple.com", delegatedTo.get(0)); assertEquals("ns2.dnsimple.com", delegatedTo.get(1)); assertEquals("ns3.dnsimple.com", delegatedTo.get(2)); assertEquals("ns4.dnsimple.com", delegatedTo.get(3)); }
@Test public void testChangeDomainDelegation() throws DnsimpleException, IOException { String accountId = "1010"; String domainId = "example.com"; List<String> nameServerNames = new ArrayList<String>(); nameServerNames.add("ns1.example.com"); Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/delegation", HttpMethods.PUT, new HttpHeaders(), nameServerNames, resource("changeDomainDelegation/success.http")); ChangeDomainDelegationResponse response = client.registrar.changeDomainDelegation(accountId, domainId, nameServerNames); List<String> delegatedTo = response.getData(); assertEquals("ns1.dnsimple.com", delegatedTo.get(0)); assertEquals("ns2.dnsimple.com", delegatedTo.get(1)); assertEquals("ns3.dnsimple.com", delegatedTo.get(2)); assertEquals("ns4.dnsimple.com", delegatedTo.get(3)); }
@Test public void testChangeDomainDelegationToVanity() throws DnsimpleException, IOException { String accountId = "1010"; String domainId = "example.com"; List<String> nameServerNames = new ArrayList<String>(); nameServerNames.add("ns1.example.com"); nameServerNames.add("ns2.example.com"); Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/delegation/vanity", HttpMethods.PUT, new HttpHeaders(), nameServerNames, resource("changeDomainDelegationToVanity/success.http")); ChangeDomainDelegationToVanityResponse response = client.registrar.changeDomainDelegationToVanity(accountId, domainId, nameServerNames); List<NameServer> delegatedTo = response.getData(); assertEquals(2, delegatedTo.size()); NameServer nameServer = delegatedTo.get(0); assertEquals("ns1.example.com", nameServer.getName()); assertEquals("127.0.0.1", nameServer.getIpv4()); assertEquals("::1", nameServer.getIpv6()); assertEquals("2016-07-11T09:40:19Z", nameServer.getCreatedAt()); assertEquals("2016-07-11T09:40:19Z", nameServer.getUpdatedAt()); }
@Test public void testGetCertificate() throws DnsimpleException, IOException { Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/domains/weppos.net/certificates/1", HttpMethods.GET, resource("getCertificate/success.http")); String accountId = "1010"; String domainId = "weppos.net"; String certificateId = "1"; GetCertificateResponse response = client.certificates.getCertificate(accountId, domainId, certificateId); Certificate certificate = response.getData(); assertEquals(1, certificate.getId().intValue()); assertEquals(2, certificate.getDomainId().intValue()); assertEquals("www", certificate.getName()); assertEquals("www.weppos.net", certificate.getCommonName()); assertEquals(1, certificate.getYears().intValue()); assertEquals("-----BEGIN CERTIFICATE REQUEST-----\nMIICljCCAX4CAQAwGTEXMBUGA1UEAwwOd3d3LndlcHBvcy5uZXQwggEiMA0GCSqG\nSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC3MJwx9ahBG3kAwRjQdRvYZqtovUaxY6jp\nhd09975gO+2eYPDbc1yhNftVJ4KBT0zdEqzX0CwIlxE1MsnZ2YOsC7IJO531hMBp\ndBxM4tSG07xPz70AVUi9rY6YCUoJHmxoFbclpHFbtXZocR393WyzUK8047uM2mlz\n03AZKcMdyfeuo2/9TcxpTSCkklGqwqS9wtTogckaDHJDoBunAkMioGfOSMe7Yi6E\nYRtG4yPJYsDaq2yPJWV8+i0PFR1Wi5RCnPt0YdQWstHuZrxABi45+XVkzKtz3TUc\nYxrvPBucVa6uzd953u8CixNFkiOefvb/dajsv1GIwH6/Cvc1ftz1AgMBAAGgODA2\nBgkqhkiG9w0BCQ4xKTAnMCUGA1UdEQQeMByCDnd3dy53ZXBwb3MubmV0ggp3ZXBw\nb3MubmV0MA0GCSqGSIb3DQEBCwUAA4IBAQCDnVBO9RdJX0eFeZzlv5c8yG8duhKP\nl0Vl+V88fJylb/cbNj9qFPkKTK0vTXmS2XUFBChKPtLucp8+Z754UswX+QCsdc7U\nTTSG0CkyilcSubdZUERGej1XfrVQhrokk7Fu0Jh3BdT6REP0SIDTpA8ku/aRQiAp\np+h19M37S7+w/DMGDAq2LSX8jOpJ1yIokRDyLZpmwyLxutC21DXMGoJ3xZeUFrUT\nqRNwzkn2dJzgTrPkzhaXalUBqv+nfXHqHaWljZa/O0NVCFrHCdTdd53/6EE2Yabv\nq5SFTkRCpaxrvM/7a8Tr4ixD1/VKD6rw3+WC00000000000000000000\n-----END CERTIFICATE REQUEST-----\n", certificate.getCsr()); assertEquals("issued", certificate.getState()); assertEquals("letsencrypt", certificate.getAuthorityIdentifier()); assertEquals("2016-06-11T18:47:08Z", certificate.getCreatedAt()); assertEquals("2016-06-11T18:47:37Z", certificate.getUpdatedAt()); assertEquals("2016-09-09", certificate.getExpiresOn()); }
@Test public void testDownloadCertificate() throws DnsimpleException, IOException { Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/domains/weppos.net/certificates/1/download", HttpMethods.GET, resource("downloadCertificate/success.http")); String accountId = "1010"; String domainId = "weppos.net"; String certificateId = "1"; DownloadCertificateResponse response = client.certificates.downloadCertificate(accountId, domainId, certificateId); CertificateBundle certificateBundle = response.getData(); assertEquals(null, certificateBundle.getPrivateKey()); assertEquals("-----BEGIN CERTIFICATE-----\nMIIE7TCCA9WgAwIBAgITAPpTe4O3vjuQ9L4gLsogi/ukujANBgkqhkiG9w0BAQsF\nADAiMSAwHgYDVQQDDBdGYWtlIExFIEludGVybWVkaWF0ZSBYMTAeFw0xNjA2MTEx\nNzQ4MDBaFw0xNjA5MDkxNzQ4MDBaMBkxFzAVBgNVBAMTDnd3dy53ZXBwb3MubmV0\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtzCcMfWoQRt5AMEY0HUb\n2GaraL1GsWOo6YXdPfe+YDvtnmDw23NcoTX7VSeCgU9M3RKs19AsCJcRNTLJ2dmD\nrAuyCTud9YTAaXQcTOLUhtO8T8+9AFVIva2OmAlKCR5saBW3JaRxW7V2aHEd/d1s\ns1CvNOO7jNppc9NwGSnDHcn3rqNv/U3MaU0gpJJRqsKkvcLU6IHJGgxyQ6AbpwJD\nIqBnzkjHu2IuhGEbRuMjyWLA2qtsjyVlfPotDxUdVouUQpz7dGHUFrLR7ma8QAYu\nOfl1ZMyrc901HGMa7zwbnFWurs3fed7vAosTRZIjnn72/3Wo7L9RiMB+vwr3NX7c\n9QIDAQABo4ICIzCCAh8wDgYDVR0PAQH/BAQDAgWgMB0GA1UdJQQWMBQGCCsGAQUF\nBwMBBggrBgEFBQcDAjAMBgNVHRMBAf8EAjAAMB0GA1UdDgQWBBRh9q/3Zxbk4yA/\nt7j+8xA+rkiZBTAfBgNVHSMEGDAWgBTAzANGuVggzFxycPPhLssgpvVoOjB4Bggr\nBgEFBQcBAQRsMGowMwYIKwYBBQUHMAGGJ2h0dHA6Ly9vY3NwLnN0Zy1pbnQteDEu\nbGV0c2VuY3J5cHQub3JnLzAzBggrBgEFBQcwAoYnaHR0cDovL2NlcnQuc3RnLWlu\ndC14MS5sZXRzZW5jcnlwdC5vcmcvMCUGA1UdEQQeMByCCndlcHBvcy5uZXSCDnd3\ndy53ZXBwb3MubmV0MIH+BgNVHSAEgfYwgfMwCAYGZ4EMAQIBMIHmBgsrBgEEAYLf\nEwEBATCB1jAmBggrBgEFBQcCARYaaHR0cDovL2Nwcy5sZXRzZW5jcnlwdC5vcmcw\ngasGCCsGAQUFBwICMIGeDIGbVGhpcyBDZXJ0aWZpY2F0ZSBtYXkgb25seSBiZSBy\nZWxpZWQgdXBvbiBieSBSZWx5aW5nIFBhcnRpZXMgYW5kIG9ubHkgaW4gYWNjb3Jk\nYW5jZSB3aXRoIHRoZSBDZXJ0aWZpY2F0ZSBQb2xpY3kgZm91bmQgYXQgaHR0cHM6\nLy9sZXRzZW5jcnlwdC5vcmcvcmVwb3NpdG9yeS8wDQYJKoZIhvcNAQELBQADggEB\nAEqMdWrmdIyQxthWsX3iHmM2h/wXwEesD0VIaA+Pq4mjwmKBkoPSmHGQ/O4v8RaK\nB6gl8v+qmvCwwqC1SkBmm+9C2yt/P6WhAiA/DD+WppYgJWfcz2lEKrgufFlHPukB\nDzE0mJDuXm09QTApWlaTZWYfWKY50T5uOT/rs+OwGFFCO/8o7v5AZRAHos6uzjvq\nAtFZj/FEnXXMjSSlQ7YKTXToVpnAYH4e3/UMsi6/O4orkVz82ZfhKwMWHV8dXlRw\ntQaemFWTjGPgSLXJAtQO30DgNJBHX/fJEaHv6Wy8TF3J0wOGpzGbOwaTX8YAmEzC\nlzzjs+clg5MN5rd1g4POJtU=\n-----END CERTIFICATE-----\n", certificateBundle.getServerCertificate()); assertTrue(Data.isNull(certificateBundle.getRootCertificate())); assertEquals(1, certificateBundle.getIntermediateCertificates().size()); assertEquals("-----BEGIN CERTIFICATE-----\nMIIEqzCCApOgAwIBAgIRAIvhKg5ZRO08VGQx8JdhT+UwDQYJKoZIhvcNAQELBQAw\nGjEYMBYGA1UEAwwPRmFrZSBMRSBSb290IFgxMB4XDTE2MDUyMzIyMDc1OVoXDTM2\nMDUyMzIyMDc1OVowIjEgMB4GA1UEAwwXRmFrZSBMRSBJbnRlcm1lZGlhdGUgWDEw\nggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDtWKySDn7rWZc5ggjz3ZB0\n8jO4xti3uzINfD5sQ7Lj7hzetUT+wQob+iXSZkhnvx+IvdbXF5/yt8aWPpUKnPym\noLxsYiI5gQBLxNDzIec0OIaflWqAr29m7J8+NNtApEN8nZFnf3bhehZW7AxmS1m0\nZnSsdHw0Fw+bgixPg2MQ9k9oefFeqa+7Kqdlz5bbrUYV2volxhDFtnI4Mh8BiWCN\nxDH1Hizq+GKCcHsinDZWurCqder/afJBnQs+SBSL6MVApHt+d35zjBD92fO2Je56\ndhMfzCgOKXeJ340WhW3TjD1zqLZXeaCyUNRnfOmWZV8nEhtHOFbUCU7r/KkjMZO9\nAgMBAAGjgeMwgeAwDgYDVR0PAQH/BAQDAgGGMBIGA1UdEwEB/wQIMAYBAf8CAQAw\nHQYDVR0OBBYEFMDMA0a5WCDMXHJw8+EuyyCm9Wg6MHoGCCsGAQUFBwEBBG4wbDA0\nBggrBgEFBQcwAYYoaHR0cDovL29jc3Auc3RnLXJvb3QteDEubGV0c2VuY3J5cHQu\nb3JnLzA0BggrBgEFBQcwAoYoaHR0cDovL2NlcnQuc3RnLXJvb3QteDEubGV0c2Vu\nY3J5cHQub3JnLzAfBgNVHSMEGDAWgBTBJnSkikSg5vogKNhcI5pFiBh54DANBgkq\nhkiG9w0BAQsFAAOCAgEABYSu4Il+fI0MYU42OTmEj+1HqQ5DvyAeyCA6sGuZdwjF\nUGeVOv3NnLyfofuUOjEbY5irFCDtnv+0ckukUZN9lz4Q2YjWGUpW4TTu3ieTsaC9\nAFvCSgNHJyWSVtWvB5XDxsqawl1KzHzzwr132bF2rtGtazSqVqK9E07sGHMCf+zp\nDQVDVVGtqZPHwX3KqUtefE621b8RI6VCl4oD30Olf8pjuzG4JKBFRFclzLRjo/h7\nIkkfjZ8wDa7faOjVXx6n+eUQ29cIMCzr8/rNWHS9pYGGQKJiY2xmVC9h12H99Xyf\nzWE9vb5zKP3MVG6neX1hSdo7PEAb9fqRhHkqVsqUvJlIRmvXvVKTwNCP3eCjRCCI\nPTAvjV+4ni786iXwwFYNz8l3PmPLCyQXWGohnJ8iBm+5nk7O2ynaPVW0U2W+pt2w\nSVuvdDM5zGv2f9ltNWUiYZHJ1mmO97jSY/6YfdOUH66iRtQtDkHBRdkNBsMbD+Em\n2TgBldtHNSJBfB3pm9FblgOcJ0FSWcUDWJ7vO0+NTXlgrRofRT6pVywzxVo6dND0\nWzYlTWeUVsO40xJqhgUQRER9YLOLxJ0O6C8i0xFxAMKOtSdodMB3RIwt7RFQ0uyt\nn5Z5MqkYhlMI3J1tPRTp1nEt9fyGspBOO05gi148Qasp+3N+svqKomoQglNoAxU=\n-----END CERTIFICATE-----", certificateBundle.getIntermediateCertificates().get(0)); }
@Test public void testGetTldExtendedAttributes() throws DnsimpleException, IOException { Client client = mockAndExpectClient("https://api.dnsimple.com/v2/tlds/uk/extended_attributes", HttpMethods.GET, new HttpHeaders(), null, resource("getTldExtendedAttributes/success.http")); String tldString = "uk"; GetTldExtendedAttributesResponse response = client.tlds.getTldExtendedAttributes(tldString); List<TldExtendedAttribute> extendedAttributes = response.getData(); assertEquals(4, extendedAttributes.size()); assertEquals("uk_legal_type", extendedAttributes.get(0).getName()); assertEquals("Legal type of registrant contact", extendedAttributes.get(0).getDescription()); assertEquals(false, extendedAttributes.get(0).getRequired().booleanValue()); List<TldExtendedAttributeOption> options = extendedAttributes.get(0).getOptions(); assertEquals(17, options.size()); assertEquals("UK Individual", options.get(0).getTitle()); assertEquals("IND", options.get(0).getValue()); assertEquals("UK Individual (our default value)", options.get(0).getDescription()); }
@Test public void testExchangeAuthorizationForToken() throws DnsimpleException, IOException { String clientId = "super-client-id"; String clientSecret = "super-client-secret"; String code = "super-code"; HashMap<String, Object> attributes = new HashMap<String, Object>(); attributes.put("code", code); attributes.put("client_id", clientId); attributes.put("client_secret", clientSecret); attributes.put("grant_type", "authorization_code"); Client client = mockAndExpectClient("https://api.dnsimple.com/v2/oauth/access_token", HttpMethods.POST, new HttpHeaders(), attributes, resource("oauthAccessToken/success.http")); OauthToken token = client.oauth.exchangeAuthorizationForToken(code, clientId, clientSecret); assertEquals("zKQ7OLqF5N1gylcJweA9WodA000BUNJD", token.getAccessToken()); assertEquals("Bearer", token.getTokenType()); assertTrue(Data.isNull(token.getScope())); assertEquals(1, token.getAccountId().intValue()); }
@Test public void testAuthorizationHeader() throws DnsimpleException, IOException { HttpHeaders headers = getDefaultHeaders(); headers.setAuthorization("Bearer " + TEST_ACCESS_TOKEN); Client client = mockAndExpectClient("https://api.dnsimple.com/v2/accounts", HttpMethods.GET, headers, null, resource("listAccounts/success-account.http")); client.accounts.listAccounts(); }
@Test public void testUserAgentHeader() throws DnsimpleException, IOException { HttpHeaders headers = getDefaultHeaders(); headers.setUserAgent("my-user-agent dnsimple-java/0.3.0 Google-HTTP-Java-Client/1.20.0 (gzip)"); Client client = mockAndExpectClient("https://api.dnsimple.com/v2/accounts", HttpMethods.GET, headers, null, resource("listAccounts/success-account.http")); client.setUserAgent("my-user-agent"); client.accounts.listAccounts(); }
@Test public void testCreateZoneRecordSendsCorrectRequest() throws DnsimpleException, IOException { String accountId = "1010"; String zoneId = "example.com"; HttpHeaders headers = new HttpHeaders(); headers.setContentType("application/json"); HashMap<String, Object> attributes = new HashMap<String, Object>(); attributes.put("name", "www"); Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/zones/example.com/records", HttpMethods.POST, headers, attributes, resource("createZoneRecord/created.http")); client.zones.createZoneRecord(accountId, zoneId, attributes); }
@Test public void testUpdateZoneRecordProducesZoneRecord() throws DnsimpleException, IOException { String accountId = "1"; String zoneId = "example.com"; String recordId = "2"; HashMap<String, Object> attributes = new HashMap<String, Object>(); attributes.put("name", "www"); Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1/zones/example.com/records/2", HttpMethods.PATCH, new HttpHeaders(), attributes, resource("updateZoneRecord/success.http")); UpdateZoneRecordResponse response = client.zones.updateZoneRecord(accountId, zoneId, recordId, attributes); ZoneRecord record = response.getData(); assertEquals(5, record.getId().intValue()); }
@Test public void testDeleteZoneRecord() throws DnsimpleException, IOException { Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1/zones/example.com/records/2", HttpMethods.DELETE, new HttpHeaders(), null, resource("deleteZoneRecord/success.http")); String accountId = "1"; String zoneId = "example.com"; String recordId = "2"; DeleteZoneRecordResponse response = client.zones.deleteZoneRecord(accountId, zoneId, recordId); assertEquals(null, response.getData()); }
@Test public void testApplyService() throws DnsimpleException, IOException { HashMap<String, Object> settings = new HashMap<String, Object>(); Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/domains/example.com/services/2", HttpMethods.POST, new HttpHeaders(), settings, resource("applyService/success.http")); String accountId = "1010"; String domainId = "example.com"; String serviceId = "2"; ApplyServiceResponse response = client.services.applyService(accountId, domainId, serviceId, settings); assertEquals(null, response.getData()); }
@Test public void testUnapplyService() throws DnsimpleException, IOException { Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/domains/example.com/services/2", HttpMethods.DELETE, resource("unapplyService/success.http")); String accountId = "1010"; String domainId = "example.com"; String serviceId = "2"; UnapplyServiceResponse response = client.services.unapplyService(accountId, domainId, serviceId); assertEquals(null, response.getData()); }
@Test public void testCreateTemplateSendsCorrectRequest() throws DnsimpleException, IOException { String accountId = "1010"; HashMap<String, Object> attributes = new HashMap<String, Object>(); attributes.put("name", "A Template"); attributes.put("short_name", "a_template"); Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/templates", HttpMethods.POST, new HashMap<String, Object>(), attributes, resource("createTemplate/created.http")); client.templates.createTemplate(accountId, attributes); }
@Test public void testUpdateTemplate() throws DnsimpleException, IOException { String accountId = "1010"; String templateId = "1"; HashMap<String, Object> attributes = new HashMap<String, Object>(); attributes.put("name", "A Template"); attributes.put("short_name", "a_template"); Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/templates/1", HttpMethods.PATCH, new HttpHeaders(), attributes, resource("updateTemplate/success.http")); UpdateTemplateResponse response = client.templates.updateTemplate(accountId, templateId, attributes); Template template = response.getData(); assertEquals(1, template.getId().intValue()); }
@Test public void testDeleteTemplate() throws DnsimpleException, IOException { Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/templates/1", HttpMethods.DELETE, resource("deleteTemplate/success.http")); String accountId = "1010"; String templateId = "1"; DeleteTemplateResponse response = client.templates.deleteTemplate(accountId, templateId); assertEquals(null, response.getData()); }
@Test public void testApplyTemplate() throws DnsimpleException, IOException { Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/domains/example.com/templates/1", HttpMethods.POST, resource("applyTemplate/success.http")); String accountId = "1010"; String templateId = "1"; String domainId = "example.com"; ApplyTemplateResponse response = client.templates.applyTemplate(accountId, templateId, domainId); assertEquals(null, response.getData()); }
@Test public void testCheckDomain() throws DnsimpleException, IOException { String accountId = "1010"; String name = "ruby.codes"; Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/ruby.codes/check", HttpMethods.GET, new HttpHeaders(), null, resource("checkDomain/success.http")); CheckDomainResponse response = client.registrar.checkDomain(accountId, name); DomainAvailability availability = response.getData(); assertEquals(name, availability.getDomainName()); assertTrue(availability.getAvailable().booleanValue()); assertTrue(availability.getPremium().booleanValue()); }
@Test public void testRenewDomain() throws DnsimpleException, IOException { String accountId = "1010"; String name = "example.com"; HashMap<String, Object> attributes = new HashMap<String, Object>(); attributes.put("period", "3"); Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/renewals", HttpMethods.POST, new HttpHeaders(), attributes, resource("renewDomain/success.http")); RenewDomainResponse response = client.registrar.renewDomain(accountId, name, attributes); DomainRenewal domainRenewal = response.getData(); assertEquals(1, domainRenewal.getId().intValue()); }
@Test(expected=DnsimpleException.class) public void testRenewDomainTooSoon() throws DnsimpleException, IOException { String accountId = "1010"; String name = "example.com"; HashMap<String, Object> attributes = new HashMap<String, Object>(); attributes.put("period", "3"); Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/renewals", HttpMethods.POST, new HttpHeaders(), attributes, resource("renewDomain/error-tooearly.http")); client.registrar.renewDomain(accountId, name, attributes); }
@Test public void testTransferDomain() throws DnsimpleException, IOException { String accountId = "1010"; String name = "example.com"; HashMap<String, Object> attributes = new HashMap<String, Object>(); attributes.put("registrant_id", "1"); attributes.put("auth_info", "x1y2z3"); Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/transfers", HttpMethods.POST, new HttpHeaders(), attributes, resource("transferDomain/success.http")); TransferDomainResponse response = client.registrar.transferDomain(accountId, name, attributes); DomainTransfer transfer = response.getData(); assertEquals(1, transfer.getId().intValue()); }
@Test(expected=DnsimpleException.class) public void testTransferDomainAlreadyInDnsimple() throws DnsimpleException, IOException { String accountId = "1010"; String name = "example.com"; HashMap<String, Object> attributes = new HashMap<String, Object>(); attributes.put("registrant_id", "1"); attributes.put("auth_info", "x1y2z3"); Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/transfers", HttpMethods.POST, new HttpHeaders(), attributes, resource("transferDomain/error-indnsimple.http")); client.registrar.transferDomain(accountId, name, attributes); }
@Test(expected=DnsimpleException.class) public void testTransferDomainAuthInfoRequired() throws DnsimpleException, IOException { String accountId = "1010"; String name = "example.com"; HashMap<String, Object> attributes = new HashMap<String, Object>(); attributes.put("registrant_id", "1"); Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/transfers", HttpMethods.POST, new HttpHeaders(), attributes, resource("transferDomain/error-missing-authcode.http")); client.registrar.transferDomain(accountId, name, attributes); }
@Test public void testTransferDomainOut() throws DnsimpleException, IOException { String accountId = "1010"; String name = "example.com"; Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/authorize_transfer_out", HttpMethods.POST, new HttpHeaders(), null, resource("authorizeDomainTransferOut/success.http")); TransferDomainOutResponse response = client.registrar.transferDomainOut(accountId, name); assertEquals(null, response.getData()); }
@Test public void testDisableVanityNameServers() throws DnsimpleException, IOException { String accountId = "1010"; String domainId = "example.com"; Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/vanity/example.com", HttpMethods.DELETE, resource("disableVanityNameServers/success.http")); DisableVanityNameServersResponse response = client.vanityNameServers.disableVanityNameServers(accountId, domainId); assertEquals(null, response.getData()); }
@Test public void testEnableWhoisPrivacyAlreadyPurchased() throws DnsimpleException, IOException { String accountId = "1010"; String domainId = "example.com"; Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/whois_privacy", HttpMethods.PUT, new HttpHeaders(), null, resource("enableWhoisPrivacy/success.http")); EnableWhoisPrivacyResponse response = client.registrar.enableWhoisPrivacy(accountId, domainId); }
@Test public void testEnableWhoisPrivacyNewlyPurchased() throws DnsimpleException, IOException { String accountId = "1010"; String domainId = "example.com"; Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/whois_privacy", HttpMethods.PUT, new HttpHeaders(), null, resource("enableWhoisPrivacy/created.http")); EnableWhoisPrivacyResponse response = client.registrar.enableWhoisPrivacy(accountId, domainId); WhoisPrivacy whoisPrivacy = response.getData(); assertEquals(1, whoisPrivacy.getId().intValue()); }
@Test public void testDisableWhoisPrivacyNewlyPurchased() throws DnsimpleException, IOException { String accountId = "1010"; String domainId = "example.com"; Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/whois_privacy", HttpMethods.DELETE, new HttpHeaders(), null, resource("disableWhoisPrivacy/success.http")); DisableWhoisPrivacyResponse response = client.registrar.disableWhoisPrivacy(accountId, domainId); WhoisPrivacy whoisPrivacy = response.getData(); assertEquals(1, whoisPrivacy.getId().intValue()); }
@Test public void testRemoveCollaborator() throws DnsimpleException, IOException { Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1/domains/example.com/collaborators/100", HttpMethods.DELETE, resource("removeCollaborator/success.http")); String accountId = "1"; String domainId = "example.com"; String collaboratorId = "100"; RemoveCollaboratorResponse response = client.domains.removeCollaborator(accountId, domainId, collaboratorId); assertEquals(null, response.getData()); }
@Test public void testCreateTemplateRecordSendsCorrectRequest() throws DnsimpleException, IOException { String accountId = "1010"; String templateId = "1"; HashMap<String, Object> attributes = new HashMap<String, Object>(); attributes.put("name", "www"); attributes.put("content", "example.com"); Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/templates/1/records", HttpMethods.POST, new HashMap<String, Object>(), attributes, resource("createTemplateRecord/created.http")); client.templates.createTemplateRecord(accountId, templateId, attributes); }
@Test public void testDeleteTemplateRecord() throws DnsimpleException, IOException { Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/templates/1/records/300", HttpMethods.DELETE, resource("deleteTemplateRecord/success.http")); String accountId = "1010"; String templateId = "1"; String recordId = "300"; DeleteTemplateRecordResponse response = client.templates.deleteTemplateRecord(accountId, templateId, recordId); assertEquals(null, response.getData()); }
@Test public void testChangeDomainDelegationFromVanity() throws DnsimpleException, IOException { String accountId = "1010"; String domainId = "example.com"; Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/delegation/vanity", HttpMethods.DELETE, resource("changeDomainDelegationFromVanity/success.http")); ChangeDomainDelegationFromVanityResponse response = client.registrar.changeDomainDelegationFromVanity(accountId, domainId); assertEquals(null, response.getData()); }
@Test public void testEnableAutoRenewal() throws DnsimpleException, IOException { String accountId = "1010"; String domainId = "example.com"; Client client = mockAndExpectClient("https://api.dnsimple.com/v2/1010/registrar/domains/example.com/auto_renewal", HttpMethods.PUT, new HttpHeaders(), null, resource("enableDomainAutoRenewal/success.http")); EnableAutoRenewalResponse response = client.registrar.enableAutoRenewal(accountId, domainId); assertEquals(null, response.getData()); }