public void testAddQuery() { assertEquals(uriBuilder("http://localhost:8080/client/api").addQuery("response", "json").toString(), "http://localhost:8080/client/api?response=json"); assertEquals( uriBuilder(URI.create("http://localhost:8080/client/api")).addQuery("response", "json") .addQuery("command", "queryAsyncJobResult").build().toString(), "http://localhost:8080/client/api?response=json&command=queryAsyncJobResult"); } }
@Test(dataProvider = "strings") public void testReplaceQueryIsEncoded(String key) { assertEquals(uriBuilder("/redirect").addQuery("foo", key).toString(), "/redirect?foo=" + key); assertEquals(uriBuilder("/redirect").addQuery("foo", key).build().toString(), "/redirect?foo=" + urlEncode(key, '/', ',')); }
public void testAddQuery() { assertEquals(uriBuilder("http://localhost:8080/client/api").addQuery("response", "json").toString(), "http://localhost:8080/client/api?response=json"); assertEquals( uriBuilder(URI.create("http://localhost:8080/client/api")).addQuery("response", "json") .addQuery("command", "queryAsyncJobResult").build().toString(), "http://localhost:8080/client/api?response=json&command=queryAsyncJobResult"); } }
public void testListCustomerImage_404() throws Exception { server.enqueue(response404()); assertTrue(api.getServerImageApi().listCustomerImages().concat().isEmpty()); assertSent(HttpMethod.GET, getCustomerImageUrl().toString()); }
public void testListOperatingSystemsWithPagination() throws Exception { server.enqueue(jsonResponse("/operatingSystems-page1.json")); server.enqueue(jsonResponse("/operatingSystems-page2.json")); Iterable<OperatingSystem> operatingSystems = api.getInfrastructureApi().listOperatingSystems().concat(); consumeIterableAndAssertAdditionalPagesRequested(operatingSystems, 33, 1); assertSent(HttpMethod.GET, expectedListOperatingSystemsUriBuilder().toString()); assertSent(HttpMethod.GET, expectedListOperatingSystemsWithPaginationUriBuilder(2).toString()); }
@Test public void testListTagKeysWithPagination() throws Exception { server.enqueue(jsonResponse("/tagkeys-page1.json")); server.enqueue(jsonResponse("/tagkeys-page2.json")); ImmutableList<TagKey> tagKeys = api.getTagApi().listTagKeys().concat().toList(); consumeIterableAndAssertAdditionalPagesRequested(tagKeys, 18, 0); assertSent(GET, expectedListTagKeysUriBuilder().toString()); assertSent(GET, addPageNumberToUriBuilder(expectedListTagKeysUriBuilder(), 2, true).toString()); }
@Test public void testListTagKeys() throws Exception { server.enqueue(jsonResponse("/tagkeys.json")); ImmutableList<TagKey> tagKeys = api.getTagApi().listTagKeys().concat().toList(); assertNotNull(tagKeys); assertEquals(9, tagKeys.size()); assertSent(GET, expectedListTagKeysUriBuilder().toString()); }
public void testScheme() { assertEquals(uriBuilder("https://foo.com:8080").scheme("http").toString(), "http://foo.com:8080"); assertEquals(uriBuilder("https://foo.com:8080").scheme("http").build().toString(), "http://foo.com:8080"); assertEquals(uriBuilder("https://api.github.com/repos/user?foo=bar&kung=fu").scheme("http").toString(), "http://api.github.com/repos/user?foo=bar&kung=fu"); assertEquals(uriBuilder("https://api.github.com/repos/user?foo=bar&kung=fu").scheme("http").build().toString(), "http://api.github.com/repos/user?foo=bar&kung=fu"); assertEquals(uriBuilder("https://api.github.com/repos/{user}").scheme("http").toString(), "http://api.github.com/repos/{user}"); assertEquals(uriBuilder("https://api.github.com/repos/{user}").scheme("http").build(templateParams) .toASCIIString(), "http://api.github.com/repos/bob"); }
public void testListServers() throws Exception { server.enqueue(jsonResponse("/servers.json")); List<Server> servers = serverApi().listServers().concat().toList(); Uris.UriBuilder uriBuilder = getListServerUriBuilder(); assertSent(GET, uriBuilder.toString()); assertEquals(servers.size(), 1); for (Server s : servers) { assertNotNull(s); } }
public void testListDatacentersWithDatcenterFiltering() throws Exception { server.enqueue(jsonResponse("/datacenters.json")); Iterable<Datacenter> listedDatacenters = api.getInfrastructureApi() .listDatacenters(IdListFilters.Builder.ids(this.datacenters)); assertEquals(size(listedDatacenters), 1); // Force the PagedIterable to advance assertEquals(server.getRequestCount(), 2); assertSent(HttpMethod.GET, addZonesToUriBuilder(DATACENTER_ID_QUERY_PARAM, expectedListDatacentersUriBuilder()).toString()); }
public void testListDatacenters() throws Exception { server.enqueue(jsonResponse("/datacenters.json")); Iterable<Datacenter> listedDatacenters = api.getInfrastructureApi().listDatacenters().concat(); assertEquals(size(listedDatacenters), 1); // Force the PagedIterable to advance assertEquals(server.getRequestCount(), 2); assertSent(HttpMethod.GET, expectedListDatacentersUriBuilder().toString()); }
@Test public void testListTagsWithPagination() throws Exception { server.enqueue(jsonResponse("/tags-page1.json")); server.enqueue(jsonResponse("/tags-page2.json")); ImmutableList<Tag> tags = api.getTagApi().listTags().concat().toList(); consumeIterableAndAssertAdditionalPagesRequested(tags, 8, 0); assertSent(GET, expectedListTagsUriBuilder().toString()); assertSent(GET, addPageNumberToUriBuilder(expectedListTagsUriBuilder(), 2, true).toString()); }
public void testListVlanssWithPagination() throws Exception { server.enqueue(jsonResponse("/vlans-page1.json")); server.enqueue(jsonResponse("/vlans-page2.json")); Iterable<Vlan> vlans = api().listVlans("12345").concat().toList(); consumeIterableAndAssertAdditionalPagesRequested(vlans, 20, 0); assertSent(HttpMethod.GET, expectedListVlansRulesUriBuilder().toString()); assertSent(HttpMethod.GET, addPageNumberToUriBuilder(expectedListVlansRulesUriBuilder(), 2, false).toString()); }
public void testListCustomerImageWithDatacenterFiltering() throws Exception { server.enqueue(jsonResponse("/customerImages.json")); Iterable<CustomerImage> customerImages = api.getServerImageApi().listCustomerImages(datacenterId(datacenters)); assertEquals(size(customerImages), 1); assertEquals(server.getRequestCount(), 2); assertSent(HttpMethod.GET, addZonesToUriBuilder("datacenterId", getCustomerImageUrl()).toString()); }
public void testListOsImageWithDatacenterIdFiltering() throws Exception { server.enqueue(jsonResponse("/osImages.json")); Iterable<OsImage> osImages = api.getServerImageApi().listOsImages(datacenterId(datacenters)).toList(); assertEquals(size(osImages), 1); assertEquals(server.getRequestCount(), 2); assertSent(HttpMethod.GET, addZonesToUriBuilder("datacenterId", getOsImageUrl()).toString()); }
public void testListOsImage() throws Exception { server.enqueue(jsonResponse("/osImages.json")); Iterable<OsImage> osImages = api.getServerImageApi().listOsImages().concat(); assertEquals(size(osImages), 1); assertEquals(server.getRequestCount(), 2); assertSent(HttpMethod.GET, getOsImageUrl().toString()); }
public void testGetOsImage_404() throws Exception { server.enqueue(response404()); OsImage osImage = api.getServerImageApi().getOsImage("id"); assertNull(osImage); assertSent(HttpMethod.GET, getOsImageUrl().appendPath("/id").toString()); }
@Test public void testListTags() throws Exception { server.enqueue(jsonResponse("/tags.json")); ImmutableList<Tag> tags = api.getTagApi().listTags().concat().toList(); assertNotNull(tags); assertEquals(4, tags.size()); assertSent(GET, expectedListTagsUriBuilder().toString()); }
public void testHost() { assertEquals(uriBuilder("https://foo.com:8080").host("robots").toString(), "https://robots:8080"); assertEquals(uriBuilder("https://foo.com:8080").host("robots").build().toString(), "https://robots:8080"); assertEquals(uriBuilder("https://api.github.com/repos/user?foo=bar&kung=fu").host("robots").toString(), "https://robots/repos/user?foo=bar&kung=fu"); assertEquals(uriBuilder("https://api.github.com/repos/user?foo=bar&kung=fu").host("robots").build().toString(), "https://robots/repos/user?foo=bar&kung=fu"); assertEquals(uriBuilder("https://api.github.com/repos/{user}").host("robots").toString(), "https://robots/repos/{user}"); assertEquals(uriBuilder("https://api.github.com/repos/{user}").host("robots").build(templateParams) .toASCIIString(), "https://robots/repos/bob"); }
public void testScheme() { assertEquals(uriBuilder("https://foo.com:8080").scheme("http").toString(), "http://foo.com:8080"); assertEquals(uriBuilder("https://foo.com:8080").scheme("http").build().toString(), "http://foo.com:8080"); assertEquals(uriBuilder("https://api.github.com/repos/user?foo=bar&kung=fu").scheme("http").toString(), "http://api.github.com/repos/user?foo=bar&kung=fu"); assertEquals(uriBuilder("https://api.github.com/repos/user?foo=bar&kung=fu").scheme("http").build().toString(), "http://api.github.com/repos/user?foo=bar&kung=fu"); assertEquals(uriBuilder("https://api.github.com/repos/{user}").scheme("http").toString(), "http://api.github.com/repos/{user}"); assertEquals(uriBuilder("https://api.github.com/repos/{user}").scheme("http").build(templateParams) .toASCIIString(), "http://api.github.com/repos/bob"); }