Search in sources :

Example 76 with AccountVO

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;
}
Also used : TransactionStatus(com.cloud.utils.db.TransactionStatus) TransactionCallbackNoReturn(com.cloud.utils.db.TransactionCallbackNoReturn) AccountVO(com.cloud.user.AccountVO)

Example 77 with AccountVO

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();
}
Also used : UserVO(com.cloud.user.UserVO) Event(org.apache.cloudstack.framework.events.Event) JsonObject(com.google.gson.JsonObject) AccountVO(com.cloud.user.AccountVO) JsonParser(com.google.gson.JsonParser) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 78 with AccountVO

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));
}
Also used : Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) HashMap(java.util.HashMap) BaseCmd(org.apache.cloudstack.api.BaseCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 79 with AccountVO

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);
}
Also used : Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) HashMap(java.util.HashMap) BaseCmd(org.apache.cloudstack.api.BaseCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 80 with AccountVO

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());
}
Also used : Account(com.cloud.user.Account) NetworkVO(com.cloud.network.dao.NetworkVO) NetworkOffering(com.cloud.offering.NetworkOffering) ArrayList(java.util.ArrayList) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) NetworkOfferingVO(com.cloud.offerings.NetworkOfferingVO) DeploymentPlan(com.cloud.deploy.DeploymentPlan) AccountVO(com.cloud.user.AccountVO)

Aggregations

AccountVO (com.cloud.user.AccountVO)139 Account (com.cloud.user.Account)65 Test (org.junit.Test)52 UserVO (com.cloud.user.UserVO)44 Field (java.lang.reflect.Field)41 ArrayList (java.util.ArrayList)40 DomainVO (com.cloud.domain.DomainVO)32 AccountManager (com.cloud.user.AccountManager)27 Before (org.junit.Before)22 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)21 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)21 Date (java.util.Date)16 QuotaAccountVO (org.apache.cloudstack.quota.vo.QuotaAccountVO)16 DomainDao (com.cloud.domain.dao.DomainDao)14 SslCertDao (com.cloud.network.dao.SslCertDao)14 AgentManager (com.cloud.agent.AgentManager)13 IPAddressDao (com.cloud.network.dao.IPAddressDao)13 LoadBalancerDao (com.cloud.network.dao.LoadBalancerDao)13 NetworkDao (com.cloud.network.dao.NetworkDao)13 NetworkVO (com.cloud.network.dao.NetworkVO)13