mirror of https://github.com/apache/jclouds.git
Added a few more negative tests
This commit is contained in:
parent
6afe98304c
commit
3ea37bbbe3
|
@ -2,12 +2,14 @@ package org.jclouds.cloudstack.predicates;
|
||||||
|
|
||||||
import org.jclouds.cloudstack.domain.Account;
|
import org.jclouds.cloudstack.domain.Account;
|
||||||
import org.jclouds.cloudstack.domain.User;
|
import org.jclouds.cloudstack.domain.User;
|
||||||
|
import org.testng.annotations.DataProvider;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import static org.jclouds.cloudstack.predicates.UserPredicates.apiKeyEquals;
|
import static org.jclouds.cloudstack.predicates.UserPredicates.apiKeyEquals;
|
||||||
import static org.jclouds.cloudstack.predicates.UserPredicates.isAdminAccount;
|
import static org.jclouds.cloudstack.predicates.UserPredicates.isAdminAccount;
|
||||||
import static org.jclouds.cloudstack.predicates.UserPredicates.isDomainAdminAccount;
|
import static org.jclouds.cloudstack.predicates.UserPredicates.isDomainAdminAccount;
|
||||||
import static org.jclouds.cloudstack.predicates.UserPredicates.isUserAccount;
|
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.assertFalse;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
@ -27,12 +29,23 @@ public class UserPredicatesTest {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@DataProvider(name = "accountType")
|
||||||
public void testIsUserAccount() {
|
public Object[][] getAccountTypes() {
|
||||||
User adminUser = User.builder().accountType(Account.Type.ADMIN).build();
|
return new Object[][] {
|
||||||
assertFalse(isUserAccount().apply(adminUser));
|
/* Type ID, isUser, isDomainAdmin, isAdmin */
|
||||||
assertFalse(isDomainAdminAccount().apply(adminUser));
|
{Account.Type.USER, true, false, false},
|
||||||
assertTrue(isAdminAccount().apply(adminUser));
|
{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);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,14 @@ package org.jclouds.cloudstack.predicates;
|
||||||
import org.jclouds.cloudstack.CloudStackClient;
|
import org.jclouds.cloudstack.CloudStackClient;
|
||||||
import org.jclouds.cloudstack.domain.VirtualMachine;
|
import org.jclouds.cloudstack.domain.VirtualMachine;
|
||||||
import org.jclouds.cloudstack.features.VirtualMachineClient;
|
import org.jclouds.cloudstack.features.VirtualMachineClient;
|
||||||
|
import org.testng.annotations.BeforeMethod;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.createMock;
|
import static org.easymock.EasyMock.createMock;
|
||||||
import static org.easymock.EasyMock.expect;
|
import static org.easymock.EasyMock.expect;
|
||||||
import static org.easymock.EasyMock.replay;
|
import static org.easymock.EasyMock.replay;
|
||||||
import static org.easymock.EasyMock.verify;
|
import static org.easymock.EasyMock.verify;
|
||||||
|
import static org.testng.Assert.assertFalse;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,22 +38,37 @@ import static org.testng.Assert.assertTrue;
|
||||||
@Test(groups = "unit", testName = "VirtualMachineDestroyedTest")
|
@Test(groups = "unit", testName = "VirtualMachineDestroyedTest")
|
||||||
public class VirtualMachineDestroyedTest {
|
public class VirtualMachineDestroyedTest {
|
||||||
|
|
||||||
@Test
|
CloudStackClient client;
|
||||||
public void testWaitForVirtualMachineToBeDestroyed() {
|
VirtualMachineClient virtualMachineClient;
|
||||||
CloudStackClient client = createMock(CloudStackClient.class);
|
|
||||||
VirtualMachineClient virtualMachineClient = createMock(VirtualMachineClient.class);
|
|
||||||
|
|
||||||
long virtualMachineId = 229;
|
|
||||||
VirtualMachine virtualMachine = VirtualMachine.builder().
|
|
||||||
id(virtualMachineId).state(VirtualMachine.State.DESTROYED).build();
|
|
||||||
|
|
||||||
|
@BeforeMethod
|
||||||
|
public void setUp() {
|
||||||
|
client = createMock(CloudStackClient.class);
|
||||||
|
virtualMachineClient = createMock(VirtualMachineClient.class);
|
||||||
expect(client.getVirtualMachineClient()).andReturn(virtualMachineClient);
|
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);
|
replay(client, virtualMachineClient);
|
||||||
|
|
||||||
assertTrue(new VirtualMachineDestroyed(client).apply(virtualMachine));
|
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);
|
verify(client, virtualMachineClient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,12 +22,14 @@ package org.jclouds.cloudstack.predicates;
|
||||||
import org.jclouds.cloudstack.CloudStackClient;
|
import org.jclouds.cloudstack.CloudStackClient;
|
||||||
import org.jclouds.cloudstack.domain.VirtualMachine;
|
import org.jclouds.cloudstack.domain.VirtualMachine;
|
||||||
import org.jclouds.cloudstack.features.VirtualMachineClient;
|
import org.jclouds.cloudstack.features.VirtualMachineClient;
|
||||||
|
import org.testng.annotations.BeforeMethod;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import static org.easymock.EasyMock.createMock;
|
import static org.easymock.EasyMock.createMock;
|
||||||
import static org.easymock.EasyMock.expect;
|
import static org.easymock.EasyMock.expect;
|
||||||
import static org.easymock.EasyMock.replay;
|
import static org.easymock.EasyMock.replay;
|
||||||
import static org.easymock.EasyMock.verify;
|
import static org.easymock.EasyMock.verify;
|
||||||
|
import static org.testng.Assert.assertFalse;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,21 +38,33 @@ import static org.testng.Assert.assertTrue;
|
||||||
@Test(groups = "unit", testName = "VirtualMachineExpungedTest")
|
@Test(groups = "unit", testName = "VirtualMachineExpungedTest")
|
||||||
public class 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
|
@Test
|
||||||
public void testWaitForVirtualMachineToBeExpunged() {
|
public void testWaitForVirtualMachineToBeExpunged() {
|
||||||
CloudStackClient client = createMock(CloudStackClient.class);
|
VirtualMachine virtualMachine = VirtualMachine.builder().id(229L).build();
|
||||||
VirtualMachineClient virtualMachineClient = createMock(VirtualMachineClient.class);
|
expect(virtualMachineClient.getVirtualMachine(virtualMachine.getId())).andReturn(null);
|
||||||
|
|
||||||
long virtualMachineId = 229;
|
|
||||||
VirtualMachine virtualMachine = VirtualMachine.builder().id(virtualMachineId).build();
|
|
||||||
|
|
||||||
expect(client.getVirtualMachineClient()).andReturn(virtualMachineClient);
|
|
||||||
expect(virtualMachineClient.getVirtualMachine(virtualMachineId)).andReturn(null);
|
|
||||||
|
|
||||||
replay(client, virtualMachineClient);
|
replay(client, virtualMachineClient);
|
||||||
|
|
||||||
assertTrue(new VirtualMachineExpunged(client).apply(virtualMachine));
|
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);
|
verify(client, virtualMachineClient);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue