Added a few more negative tests

This commit is contained in:
andreisavu 2011-11-29 18:19:33 +02:00
parent 6afe98304c
commit 3ea37bbbe3
3 changed files with 69 additions and 25 deletions

View File

@ -2,12 +2,14 @@ package org.jclouds.cloudstack.predicates;
import org.jclouds.cloudstack.domain.Account;
import org.jclouds.cloudstack.domain.User;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.jclouds.cloudstack.predicates.UserPredicates.apiKeyEquals;
import static org.jclouds.cloudstack.predicates.UserPredicates.isAdminAccount;
import static org.jclouds.cloudstack.predicates.UserPredicates.isDomainAdminAccount;
import static org.jclouds.cloudstack.predicates.UserPredicates.isUserAccount;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
@ -27,12 +29,23 @@ public class UserPredicatesTest {
));
}
@Test
public void testIsUserAccount() {
User adminUser = User.builder().accountType(Account.Type.ADMIN).build();
assertFalse(isUserAccount().apply(adminUser));
assertFalse(isDomainAdminAccount().apply(adminUser));
assertTrue(isAdminAccount().apply(adminUser));
@DataProvider(name = "accountType")
public Object[][] getAccountTypes() {
return new Object[][] {
/* Type ID, isUser, isDomainAdmin, isAdmin */
{Account.Type.USER, true, false, false},
{Account.Type.DOMAIN_ADMIN, false, true, false},
{Account.Type.ADMIN, false, false, true},
{Account.Type.UNRECOGNIZED, false, false, false}
};
}
@Test(dataProvider = "accountType")
public void testAccountType(Account.Type type, boolean isUser, boolean isDomainAdmin, boolean isAdmin) {
User testUser = User.builder().accountType(type).build();
assertEquals(isUserAccount().apply(testUser), isUser);
assertEquals(isDomainAdminAccount().apply(testUser), isDomainAdmin);
assertEquals(isAdminAccount().apply(testUser), isAdmin);
}
}

View File

@ -22,12 +22,14 @@ package org.jclouds.cloudstack.predicates;
import org.jclouds.cloudstack.CloudStackClient;
import org.jclouds.cloudstack.domain.VirtualMachine;
import org.jclouds.cloudstack.features.VirtualMachineClient;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
/**
@ -36,22 +38,37 @@ import static org.testng.Assert.assertTrue;
@Test(groups = "unit", testName = "VirtualMachineDestroyedTest")
public class VirtualMachineDestroyedTest {
@Test
public void testWaitForVirtualMachineToBeDestroyed() {
CloudStackClient client = createMock(CloudStackClient.class);
VirtualMachineClient virtualMachineClient = createMock(VirtualMachineClient.class);
long virtualMachineId = 229;
VirtualMachine virtualMachine = VirtualMachine.builder().
id(virtualMachineId).state(VirtualMachine.State.DESTROYED).build();
CloudStackClient client;
VirtualMachineClient virtualMachineClient;
@BeforeMethod
public void setUp() {
client = createMock(CloudStackClient.class);
virtualMachineClient = createMock(VirtualMachineClient.class);
expect(client.getVirtualMachineClient()).andReturn(virtualMachineClient);
expect(virtualMachineClient.getVirtualMachine(virtualMachineId)).andReturn(virtualMachine);
}
@Test
public void testIsDestroyed() {
VirtualMachine virtualMachine = VirtualMachine.builder().
id(229).state(VirtualMachine.State.DESTROYED).build();
expect(virtualMachineClient.getVirtualMachine(virtualMachine.getId())).andReturn(virtualMachine);
replay(client, virtualMachineClient);
assertTrue(new VirtualMachineDestroyed(client).apply(virtualMachine));
verify(client, virtualMachineClient);
}
@Test
public void testStillRunning() {
VirtualMachine virtualMachine = VirtualMachine.builder().
id(229).state(VirtualMachine.State.RUNNING).build();
expect(virtualMachineClient.getVirtualMachine(virtualMachine.getId())).andReturn(virtualMachine);
replay(client, virtualMachineClient);
assertFalse(new VirtualMachineDestroyed(client).apply(virtualMachine));
verify(client, virtualMachineClient);
}
}

View File

@ -22,12 +22,14 @@ package org.jclouds.cloudstack.predicates;
import org.jclouds.cloudstack.CloudStackClient;
import org.jclouds.cloudstack.domain.VirtualMachine;
import org.jclouds.cloudstack.features.VirtualMachineClient;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import static org.easymock.EasyMock.createMock;
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.replay;
import static org.easymock.EasyMock.verify;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
/**
@ -36,21 +38,33 @@ import static org.testng.Assert.assertTrue;
@Test(groups = "unit", testName = "VirtualMachineExpungedTest")
public class VirtualMachineExpungedTest {
CloudStackClient client;
VirtualMachineClient virtualMachineClient;
@BeforeMethod
public void setUp() {
client = createMock(CloudStackClient.class);
virtualMachineClient = createMock(VirtualMachineClient.class);
expect(client.getVirtualMachineClient()).andReturn(virtualMachineClient);
}
@Test
public void testWaitForVirtualMachineToBeExpunged() {
CloudStackClient client = createMock(CloudStackClient.class);
VirtualMachineClient virtualMachineClient = createMock(VirtualMachineClient.class);
long virtualMachineId = 229;
VirtualMachine virtualMachine = VirtualMachine.builder().id(virtualMachineId).build();
expect(client.getVirtualMachineClient()).andReturn(virtualMachineClient);
expect(virtualMachineClient.getVirtualMachine(virtualMachineId)).andReturn(null);
VirtualMachine virtualMachine = VirtualMachine.builder().id(229L).build();
expect(virtualMachineClient.getVirtualMachine(virtualMachine.getId())).andReturn(null);
replay(client, virtualMachineClient);
assertTrue(new VirtualMachineExpunged(client).apply(virtualMachine));
verify(client, virtualMachineClient);
}
@Test
public void testNoRemovedYet() {
VirtualMachine virtualMachine = VirtualMachine.builder().id(229L).build();
expect(virtualMachineClient.getVirtualMachine(virtualMachine.getId())).andReturn(virtualMachine);
replay(client, virtualMachineClient);
assertFalse(new VirtualMachineExpunged(client).apply(virtualMachine));
verify(client, virtualMachineClient);
}
}