use of com.cloud.user.AccountVO in project cloudstack by apache.
the class MockAccountManager method createAccount.
@Override
public Account createAccount(String accountName, short accountType, Long roleId, Long domainId, String networkDomain, Map<String, String> details, String uuid) {
final AccountVO account = new AccountVO(accountName, domainId, networkDomain, accountType, roleId, uuid);
Transaction.execute(new TransactionCallbackNoReturn() {
@Override
public void doInTransactionWithoutResult(TransactionStatus status) {
_accountDao.persist(account);
_resourceCountDao.createResourceCounts(account.getId(), ResourceLimit.ResourceOwnerType.Account);
}
});
return account;
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class ActionEventUtilsTest method testPopulateFirstClassEntities.
@Test
public void testPopulateFirstClassEntities() {
AccountVO account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
account.setId(ACCOUNT_ID);
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
Mockito.when(accountDao.findById(ACCOUNT_ID)).thenReturn(account);
Mockito.when(userDao.findById(USER_ID)).thenReturn(user);
CallContext.register(user, account);
//Inject some entity UUIDs into the call context
String instanceUuid = UUID.randomUUID().toString();
String ipUuid = UUID.randomUUID().toString();
CallContext.current().putContextParameter(VirtualMachine.class, instanceUuid);
CallContext.current().putContextParameter(IpAddress.class, ipUuid);
ActionEventUtils.onActionEvent(USER_ID, ACCOUNT_ID, account.getDomainId(), "StaticNat", "Test event");
//Assertions
Assert.assertNotEquals(publishedEvents.size(), 0);
Assert.assertEquals(publishedEvents.size(), 1);
Event event = publishedEvents.get(0);
Assert.assertNotNull(event.getDescription());
JsonObject json = new JsonParser().parse(event.getDescription()).getAsJsonObject();
Assert.assertTrue(json.has("VirtualMachine"));
Assert.assertTrue(json.has("IpAddress"));
Assert.assertEquals(json.get("VirtualMachine").getAsString(), instanceUuid);
Assert.assertEquals(json.get("IpAddress").getAsString(), ipUuid);
CallContext.unregister();
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class FakeCmdWithRoleAdmin method testHandleWithUnknownParams.
@Test
public void testHandleWithUnknownParams() throws ResourceAllocationException {
// Prepare
final String unknownParamKey = "unknownParam";
final BaseCmd cmd = new FakeCmd();
final Map<String, String> params = new HashMap<String, String>();
params.put(ApiConstants.COMMAND, "");
params.put("addedParam", "");
params.put(unknownParamKey, "");
Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, account);
// Execute
try {
driveTest(cmd, params);
} finally {
CallContext.unregister();
}
// Assert
assertTrue("There should be error msg, since there is one unknown parameter", loggerOutput.contains(unknownParamKey));
assertTrue("There should be error msg containing the correct command name", loggerOutput.contains(FAKE_CMD_NAME));
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class FakeCmdWithRoleAdmin method testHandle.
@Test
public void testHandle() throws ResourceAllocationException {
// Prepare
final BaseCmd cmd = new FakeCmd();
final Map<String, String> params = new HashMap<String, String>();
params.put(ApiConstants.COMMAND, "");
params.put(ApiConstants.ACCOUNT_ID, "");
params.put(ApiConstants.CTX_START_EVENT_ID, "");
params.put(ApiConstants.COMMAND, "");
params.put(ApiConstants.CMD_EVENT_TYPE, "");
params.put(ApiConstants.USERNAME, "");
params.put(ApiConstants.USER_ID, "");
params.put(ApiConstants.PASSWORD, "");
params.put(ApiConstants.DOMAIN, "");
params.put(ApiConstants.DOMAIN_ID, "");
params.put(ApiConstants.DOMAIN__ID, "");
params.put(ApiConstants.SESSIONKEY, "");
params.put(ApiConstants.RESPONSE, "");
params.put(ApiConstants.PAGE, "");
params.put(ApiConstants.USER_API_KEY, "");
params.put(ApiConstants.API_KEY, "");
params.put(ApiConstants.PAGE_SIZE, "");
params.put(ApiConstants.HTTPMETHOD, "");
params.put(ApiConstants.SIGNATURE, "");
params.put(ApiConstants.CTX_ACCOUNT_ID, "");
params.put(ApiConstants.CTX_START_EVENT_ID, "");
// Make sure it's case insensitive
params.put(ApiConstants.CTX_START_EVENT_ID, "");
params.put(ApiConstants.CTX_START_EVENT_ID.toLowerCase(), "");
params.put(ApiConstants.CTX_USER_ID.toUpperCase(), "");
params.put(ApiConstants.CTX_USER_ID, "");
params.put(ApiConstants.UUID, "");
params.put(ApiConstants.ID, "");
params.put("_", "");
params.put("addedParam", "");
Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
CallContext.register(user, account);
// Execute
try {
driveTest(cmd, params);
} finally {
CallContext.unregister();
}
// Assert
assertEquals("There should be no errors since there are no unknown parameters for this command class", null, loggerOutput);
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class VirtualRouterElementTest method mockMgrs.
/**
* @param networks
* @param offerings
* @throws ConcurrentOperationException
*/
private void mockMgrs() throws ConcurrentOperationException {
final Service service = Service.Connectivity;
testNetwork.setState(Network.State.Implementing);
testNetwork.setTrafficType(TrafficType.Guest);
when(_networkMdl.isProviderEnabledInPhysicalNetwork(0L, "VirtualRouter")).thenReturn(true);
when(_networkMdl.isProviderSupportServiceInNetwork(testNetwork.getId(), service, Network.Provider.VirtualRouter)).thenReturn(true);
when(_networkMdl.isProviderForNetwork(Network.Provider.VirtualRouter, 0L)).thenReturn(true);
when(testVMProfile.getType()).thenReturn(VirtualMachine.Type.User);
when(testVMProfile.getHypervisorType()).thenReturn(HypervisorType.XenServer);
final List<NetworkVO> networks = new ArrayList<NetworkVO>(1);
networks.add(testNetwork);
final List<NetworkOfferingVO> offerings = new ArrayList<NetworkOfferingVO>(1);
offerings.add(testOffering);
doReturn(offerings).when(_networkModel).getSystemAccountNetworkOfferings(NetworkOffering.SystemControlNetwork);
doReturn(networks).when(_networkMgr).setupNetwork(any(Account.class), any(NetworkOffering.class), any(DeploymentPlan.class), any(String.class), any(String.class), anyBoolean());
// being anti-social and testing my own case first
doReturn(HypervisorType.XenServer).when(_resourceMgr).getDefaultHypervisor(anyLong());
doReturn(new AccountVO()).when(_accountMgr).getAccount(testNetwork.getAccountId());
}
Aggregations