Author: adietish
Date: 2010-10-22 17:40:19 -0400 (Fri, 22 Oct 2010)
New Revision: 26012
Modified:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/InstanceMockIntegrationTest.java
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/MockIntegrationTestSetup.java
Log:
[JBIDE-7401] fixed start/stop-instance by changing to POST request [JBIDE-7371] added
tests
Modified:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/InstanceMockIntegrationTest.java
===================================================================
---
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/InstanceMockIntegrationTest.java 2010-10-22
21:30:49 UTC (rev 26011)
+++
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/InstanceMockIntegrationTest.java 2010-10-22
21:40:19 UTC (rev 26012)
@@ -29,7 +29,12 @@
import org.junit.Test;
/**
- * Integration tests for instances.
+ * Integration tests for instance related methods in {@link DeltaCloudClient}.
+ *
+ * @see DeltaCloudClient#listInstances()
+ * @see DeltaCloudClient#createInstance(String)
+ * @see DeltaCloudClient#destroyInstance(String)
+ * @see DeltaCloudClient#startInstance(String)
*/
public class InstanceMockIntegrationTest {
@@ -54,9 +59,11 @@
*/
@Test
public void listContainsTestInstance() throws DeltaCloudClientException {
- List<Instance> instances = testSetup.getClient().listInstances();
+ DeltaCloudClient client = testSetup.getClient();
+ List<Instance> instances = client.listInstances();
assertTrue(instances.size() > 0);
- assertNotNull(testSetup.getInstanceById(testSetup.getTestInstance().getId(),
testSetup.getClient()));
+ Instance testInstance = testSetup.getTestInstance();
+ assertNotNull(testSetup.getInstanceById(testInstance.getId(), client));
}
@Test
@@ -72,16 +79,11 @@
, testInstance.getRealmId()
, testInstance.getProfileId()
, testInstance.getMemory()
+ , testInstance.getPrivateAddresses()
+ , testInstance.getPublicAddresses()
, instance);
}
- @Test
- public void listInstanceFromWebUI() throws DeltaCloudClientException {
- Instance testInstance = testSetup.getClient().listInstances("inst0");
- assertInstance("Mock Instance With Profile Change", "mockuser",
"img1", "us", "m1-large", "12288 MB",
- testInstance);
- }
-
@Test(expected = DeltaCloudClientException.class)
public void listDestroyedInstanceThrowsException() throws DeltaCloudClientException {
Instance testInstance = testSetup.getTestInstance();
@@ -90,18 +92,21 @@
}
private void assertInstance(String name, String owner, String ImageId, String realmId,
String profile,
- String memory, Instance instance) {
+ String memory, List<String> privateAddresses, List<String>
publicAddresses, Instance instance) {
assertNotNull(instance);
assertEquals(name, instance.getName());
assertEquals(owner, instance.getOwnerId());
assertEquals(realmId, instance.getRealmId());
assertEquals(profile, instance.getProfileId());
assertEquals(memory, instance.getMemory());
+ assertTrue(privateAddresses.equals(instance.getPrivateAddresses()));
+ assertTrue(publicAddresses.equals(instance.getPublicAddresses()));
}
-
+
@Test(expected = DeltaCloudClientException.class)
public void cannotDestroyIfNotAuthenticated() throws MalformedURLException,
DeltaCloudClientException {
- DeltaCloudClient unauthenticatedClient = new
DeltaCloudClient(MockIntegrationTestSetup.DELTACLOUD_URL, "badUser",
"badPassword");
+ DeltaCloudClient unauthenticatedClient = new
DeltaCloudClient(MockIntegrationTestSetup.DELTACLOUD_URL,
+ "badUser", "badPassword");
Image image = testSetup.getFirstImage(unauthenticatedClient);
unauthenticatedClient.createInstance(image.getId());
}
@@ -121,10 +126,10 @@
}
@Test(expected = DeltaCloudClientException.class)
- public void createInstance_DeltaCloudExceptionOnUnknowsImageId() throws
DeltaCloudClientException {
+ public void cannotDestroyUnknownImageId() throws DeltaCloudClientException {
testSetup.getClient().createInstance("dummy");
}
-
+
@Test
public void canDestroy() throws DeltaCloudClientException {
Image image = testSetup.getFirstImage(testSetup.getClient());
@@ -133,8 +138,29 @@
assertNull(testSetup.getInstanceById(instance.getId(), testSetup.getClient()));
}
- @Test(expected=DeltaCloudClientException.class)
+ @Test(expected = DeltaCloudClientException.class)
public void destroyThrowExceptionOnUnknowInstanceId() throws DeltaCloudClientException
{
testSetup.getClient().destroyInstance("dummy");
}
+
+ @Test
+ public void canShutdownInstance() throws DeltaCloudClientException {
+ Instance testInstance = testSetup.getTestInstance();
+ DeltaCloudClient client = testSetup.getClient();
+ client.shutdownInstance(testInstance.getId());
+ testInstance = client.listInstances(testInstance.getId()); // reload!
+ assertEquals(State.STOPPED, testInstance.getState());
+ }
+
+ @Test
+ public void canStartInstance() throws DeltaCloudClientException {
+ Instance testInstance = testSetup.getTestInstance();
+ DeltaCloudClient client = testSetup.getClient();
+ if (testInstance.getState() == State.RUNNING) {
+ client.shutdownInstance(testInstance.getId());
+ }
+ client.startInstance(testInstance.getId());
+ testInstance = client.listInstances(testInstance.getId());
+ assertEquals(State.RUNNING, testInstance.getState());
+ }
}
Modified:
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/MockIntegrationTestSetup.java
===================================================================
---
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/MockIntegrationTestSetup.java 2010-10-22
21:30:49 UTC (rev 26011)
+++
trunk/deltacloud/tests/org.jboss.tools.deltacloud.test/src/org/jboss/tools/internal/deltacloud/test/MockIntegrationTestSetup.java 2010-10-22
21:40:19 UTC (rev 26012)
@@ -39,8 +39,13 @@
ensureDeltaCloudIsRunning();
this.client = new DeltaCloudClient(DELTACLOUD_URL, DELTACLOUD_USER,
DELTACLOUD_PASSWORD);
Image image = getFirstImage(client);
+ this.testInstance = createTestInstance(image);
+ }
+
+ private Instance createTestInstance(Image image) throws DeltaCloudClientException {
assertNotNull(image);
- this.testInstance = client.createInstance(image.getId());
+ Instance instance = client.createInstance(image.getId());
+ return instance;
}
public void ensureDeltaCloudIsRunning() throws IOException {