diff --git a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalConfigurationClientExpectTest.java b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalConfigurationClientExpectTest.java index 25aba8d71a..913f0219fa 100644 --- a/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalConfigurationClientExpectTest.java +++ b/apis/cloudstack/src/test/java/org/jclouds/cloudstack/features/GlobalConfigurationClientExpectTest.java @@ -21,6 +21,7 @@ package org.jclouds.cloudstack.features; import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableSet; import org.jclouds.cloudstack.CloudStackClient; +import org.jclouds.cloudstack.CloudStackContext; import org.jclouds.cloudstack.CloudStackGlobalClient; import org.jclouds.cloudstack.domain.AsyncCreateResponse; import org.jclouds.cloudstack.domain.ConfigurationEntry; @@ -43,11 +44,7 @@ import static org.testng.Assert.assertNull; * @author Andrei Savu */ @Test(groups = "unit", testName = "GlobalConfigurationClientExpectTest") -public class GlobalConfigurationClientExpectTest extends BaseRestClientExpectTest { - - public GlobalConfigurationClientExpectTest() { - provider = "cloudstack"; - } +public class GlobalConfigurationClientExpectTest extends BaseCloudStackRestClientExpectTest { @Test public void testListConfigurationEntriesWhenResponseIs2xx() { @@ -55,8 +52,8 @@ public class GlobalConfigurationClientExpectTest extends BaseRestClientExpectTes HttpRequest.builder() .method("GET") .endpoint( - URI.create("http://localhost:8080/client/api?response=json&command=listFirewallRules&" + - "apiKey=identity&signature=MktZKKH3USVKiC9SlYTSHMCaCcg%3D")) + URI.create("http://localhost:8080/client/api?response=json&" + + "command=listConfigurations&apiKey=identity&signature=FUQCDbc4TH2S%2B7ExDgrOCqKI2bw%3D")) .headers( ImmutableMultimap.builder() .put("Accept", "application/json") @@ -65,8 +62,7 @@ public class GlobalConfigurationClientExpectTest extends BaseRestClientExpectTes HttpResponse.builder() .statusCode(200) .payload(payloadFromResource("/listconfigurationsresponse.json")) - .build()) - .getConfigurationClient(); + .build()); assertEquals(client.listConfigurationEntries(), ImmutableSet.of( @@ -76,4 +72,76 @@ public class GlobalConfigurationClientExpectTest extends BaseRestClientExpectTes .description("If agent load balancing enabled in cluster setup").build() )); } + + @Test + public void testListConfigurationEntriesEmptyOn404() { + GlobalConfigurationClient client = requestSendsResponse( + HttpRequest.builder() + .method("GET") + .endpoint( + URI.create("http://localhost:8080/client/api?response=json&" + + "command=listConfigurations&apiKey=identity&signature=FUQCDbc4TH2S%2B7ExDgrOCqKI2bw%3D")) + .headers( + ImmutableMultimap.builder() + .put("Accept", "application/json") + .build()) + .build(), + HttpResponse.builder() + .statusCode(404) + .build()); + + assertEquals(client.listConfigurationEntries(), ImmutableSet.of()); + } + + @Test + public void testUpdateConfigurationEntryWhenResponseIs2xx() { + GlobalConfigurationClient client = requestSendsResponse( + HttpRequest.builder() + .method("GET") + .endpoint( + URI.create("http://localhost:8080/client/api?response=json&" + + "command=updateConfiguration&name=expunge.delay&value=11&" + + "apiKey=identity&signature=I2yG35EhfgIXYObeLfU3cvf%2BPeE%3D")) + .headers( + ImmutableMultimap.builder() + .put("Accept", "application/json") + .build()) + .build(), + HttpResponse.builder() + .statusCode(200) + .payload(payloadFromResource("/updateconfigurationsresponse.json")) + .build()); + + assertEquals(client.updateConfigurationEntry("expunge.delay", "11"), + ConfigurationEntry.builder().category("Advanced").name("expunge.delay").value("11") + .description("Determines how long (in seconds) to wait before actually expunging " + + "destroyed vm. The default value = the default value of expunge.interval").build() + ); + } + + @Test + public void testUpdateConfigurationEntryNullOn404() { + GlobalConfigurationClient client = requestSendsResponse( + HttpRequest.builder() + .method("GET") + .endpoint( + URI.create("http://localhost:8080/client/api?response=json&" + + "command=updateConfiguration&name=expunge.delay&value=11&" + + "apiKey=identity&signature=I2yG35EhfgIXYObeLfU3cvf%2BPeE%3D")) + .headers( + ImmutableMultimap.builder() + .put("Accept", "application/json") + .build()) + .build(), + HttpResponse.builder() + .statusCode(404) + .build()); + + assertNull(client.updateConfigurationEntry("expunge.delay", "11")); + } + + @Override + protected GlobalConfigurationClient clientFrom(CloudStackContext context) { + return context.getGlobalContext().getApi().getConfigurationClient(); + } } \ No newline at end of file diff --git a/apis/cloudstack/src/test/resources/updateconfigurationsresponse.json b/apis/cloudstack/src/test/resources/updateconfigurationsresponse.json new file mode 100644 index 0000000000..6013bd559d --- /dev/null +++ b/apis/cloudstack/src/test/resources/updateconfigurationsresponse.json @@ -0,0 +1,2 @@ +{ "updateconfigurationresponse" : { "configuration" : + {"category":"Advanced","name":"expunge.delay","value":"11","description":"Determines how long (in seconds) to wait before actually expunging destroyed vm. The default value = the default value of expunge.interval"} } } \ No newline at end of file