use of com.cloud.user.AccountVO in project cloudstack by apache.
the class QuotaStatementTest method testSendStatement.
@Test
public void testSendStatement() throws UnsupportedEncodingException, MessagingException {
Calendar date = Calendar.getInstance();
AccountVO accountVO = new AccountVO();
accountVO.setId(2L);
accountVO.setDomainId(1L);
Mockito.when(accountDao.findById(Mockito.anyLong())).thenReturn(accountVO);
QuotaAccountVO acc = new QuotaAccountVO(2L);
acc.setQuotaBalance(new BigDecimal(404));
acc.setLastStatementDate(null);
List<QuotaAccountVO> accounts = new ArrayList<>();
accounts.add(acc);
Mockito.when(quotaAcc.listAllQuotaAccount()).thenReturn(accounts);
Mockito.when(quotaUsage.findTotalQuotaUsage(Mockito.anyLong(), Mockito.anyLong(), Mockito.anyInt(), Mockito.any(Date.class), Mockito.any(Date.class))).thenReturn(new BigDecimal(100));
// call real method on send monthly statement
quotaStatement.sendStatement();
Calendar[] period = quotaStatement.statementTime(date, QuotaStatementPeriods.MONTHLY);
if (period != null) {
Mockito.verify(alertManager, Mockito.times(1)).sendQuotaAlert(Mockito.any(QuotaAlertManagerImpl.DeferredQuotaEmail.class));
}
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class InternalLBVMServiceTest method setUp.
@Override
@Before
public void setUp() {
//mock system offering creation as it's used by configure() method called by initComponentsLifeCycle
Mockito.when(_accountMgr.getAccount(1L)).thenReturn(new AccountVO());
ServiceOfferingVO off = new ServiceOfferingVO("alena", 1, 1, 1, 1, 1, false, "alena", Storage.ProvisioningType.THIN, false, false, null, false, VirtualMachine.Type.InternalLoadBalancerVm, false);
off = setId(off, 1);
List<ServiceOfferingVO> list = new ArrayList<ServiceOfferingVO>();
list.add(off);
list.add(off);
Mockito.when(_svcOffDao.createSystemServiceOfferings(Matchers.anyString(), Matchers.anyString(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyBoolean(), Matchers.anyString(), Matchers.any(ProvisioningType.class), Matchers.anyBoolean(), Matchers.anyString(), Matchers.anyBoolean(), Matchers.any(VirtualMachine.Type.class), Matchers.anyBoolean())).thenReturn(list);
ComponentContext.initComponentsLifeCycle();
Mockito.when(_accountMgr.getSystemUser()).thenReturn(new UserVO(1));
Mockito.when(_accountMgr.getSystemAccount()).thenReturn(new AccountVO(2));
Mockito.when(_accountDao.findByIdIncludingRemoved(Matchers.anyLong())).thenReturn(new AccountVO(2));
CallContext.register(_accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
final DomainRouterVO validVm = new DomainRouterVO(validVmId, off.getId(), 1, "alena", 1, HypervisorType.XenServer, 1, 1, 1, 1, false, null, false, false, VirtualMachine.Type.InternalLoadBalancerVm, null);
validVm.setRole(Role.INTERNAL_LB_VM);
final DomainRouterVO nonInternalLbVm = new DomainRouterVO(validVmId, off.getId(), 1, "alena", 1, HypervisorType.XenServer, 1, 1, 1, 1, false, null, false, false, VirtualMachine.Type.DomainRouter, null);
nonInternalLbVm.setRole(Role.VIRTUAL_ROUTER);
Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(validVm);
Mockito.when(_domainRouterDao.findById(nonExistingVmId)).thenReturn(null);
Mockito.when(_domainRouterDao.findById(nonInternalLbVmId)).thenReturn(nonInternalLbVm);
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class InternalLBVMManagerTest method setUp.
@Override
@Before
public void setUp() {
//mock system offering creation as it's used by configure() method called by initComponentsLifeCycle
Mockito.when(_accountMgr.getAccount(1L)).thenReturn(new AccountVO());
ServiceOfferingVO off = new ServiceOfferingVO("alena", 1, 1, 1, 1, 1, false, "alena", Storage.ProvisioningType.THIN, false, false, null, false, VirtualMachine.Type.InternalLoadBalancerVm, false);
off = setId(off, 1);
List<ServiceOfferingVO> list = new ArrayList<ServiceOfferingVO>();
list.add(off);
list.add(off);
Mockito.when(_svcOffDao.createSystemServiceOfferings(Matchers.anyString(), Matchers.anyString(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyInt(), Matchers.anyBoolean(), Matchers.anyString(), Matchers.any(ProvisioningType.class), Matchers.anyBoolean(), Matchers.anyString(), Matchers.anyBoolean(), Matchers.any(VirtualMachine.Type.class), Matchers.anyBoolean())).thenReturn(list);
ComponentContext.initComponentsLifeCycle();
vm = new DomainRouterVO(1L, off.getId(), 1, "alena", 1, HypervisorType.XenServer, 1, 1, 1, 1, false, null, false, false, VirtualMachine.Type.InternalLoadBalancerVm, null);
vm.setRole(Role.INTERNAL_LB_VM);
vm = setId(vm, 1);
vm.setPrivateIpAddress("10.2.2.2");
final NicVO nic = new NicVO("somereserver", 1L, 1L, VirtualMachine.Type.InternalLoadBalancerVm);
nic.setIPv4Address(requestedIp);
final List<DomainRouterVO> emptyList = new ArrayList<DomainRouterVO>();
final List<DomainRouterVO> nonEmptyList = new ArrayList<DomainRouterVO>();
nonEmptyList.add(vm);
Mockito.when(_domainRouterDao.listByNetworkAndRole(invalidNtwkId, Role.INTERNAL_LB_VM)).thenReturn(emptyList);
Mockito.when(_domainRouterDao.listByNetworkAndRole(validNtwkId, Role.INTERNAL_LB_VM)).thenReturn(nonEmptyList);
Mockito.when(_nicDao.findByNtwkIdAndInstanceId(validNtwkId, 1)).thenReturn(nic);
Mockito.when(_nicDao.findByNtwkIdAndInstanceId(invalidNtwkId, 1)).thenReturn(nic);
final Answer answer = new Answer(null, true, null);
final Answer[] answers = new Answer[1];
answers[0] = answer;
try {
Mockito.when(_agentMgr.send(Matchers.anyLong(), Matchers.any(Commands.class))).thenReturn(answers);
} catch (final AgentUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (final OperationTimedoutException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
createNetwork();
Mockito.when(_ntwkModel.getNetwork(Matchers.anyLong())).thenReturn(ntwk);
Mockito.when(_itMgr.toNicTO(Matchers.any(NicProfile.class), Matchers.any(HypervisorType.class))).thenReturn(null);
Mockito.when(_domainRouterDao.findById(Matchers.anyLong())).thenReturn(vm);
final DataCenterVO dc = new DataCenterVO(1L, null, null, null, null, null, null, null, null, null, NetworkType.Advanced, null, null);
Mockito.when(_dcDao.findById(Matchers.anyLong())).thenReturn(dc);
final NetworkOfferingVO networkOfferingVO = new NetworkOfferingVO();
networkOfferingVO.setConcurrentConnections(500);
Mockito.when(_offeringDao.findById(Matchers.anyLong())).thenReturn(networkOfferingVO);
Mockito.when(_domainRouterDao.findById(validVmId)).thenReturn(vm);
Mockito.when(_domainRouterDao.findById(invalidVmId)).thenReturn(null);
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class NuageVspEntityBuilder method buildVspNetwork.
public VspNetwork buildVspNetwork(long domainId, Network network) {
VspNetwork.Builder vspNetworkBuilder = new VspNetwork.Builder().id(network.getId()).uuid(network.getUuid()).name(network.getName()).cidr(network.getCidr()).gateway(network.getGateway());
DomainVO domain = _domainDao.findById(domainId);
VspDomain vspDomain = buildVspDomain(domain);
vspNetworkBuilder.domain(vspDomain);
AccountVO account = _accountDao.findById(network.getAccountId());
if (account != null) {
vspNetworkBuilder.accountUuid(account.getUuid()).accountName(account.getAccountName());
}
NetworkOfferingVO networkOffering = _networkOfferingDao.findById(network.getNetworkOfferingId());
vspNetworkBuilder.egressDefaultPolicy(networkOffering.getEgressDefaultPolicy()).publicAccess(networkOffering.getSupportsPublicAccess());
if (network.getVpcId() != null) {
VpcVO vpc = _vpcDao.findById(network.getVpcId());
vspNetworkBuilder.vpcUuid(vpc.getUuid()).vpcName(vpc.getName()).networkType(VspNetwork.NetworkType.Vpc);
} else {
if (networkOffering.getGuestType() == Network.GuestType.Shared) {
List<VlanVO> vlans = _vlanDao.listVlansByNetworkIdIncludingRemoved(network.getId());
List<VspAddressRange> vspAddressRanges = Lists.transform(vlans, new Function<VlanVO, VspAddressRange>() {
@Nullable
@Override
public VspAddressRange apply(VlanVO vlanVO) {
return new VspAddressRange.Builder().gateway(vlanVO.getVlanGateway()).netmask(vlanVO.getVlanNetmask()).build();
}
});
vspNetworkBuilder.networkType(VspNetwork.NetworkType.Shared).addressRanges(vspAddressRanges);
} else if (_networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.SourceNat) || _networkOfferingServiceMapDao.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.StaticNat)) {
vspNetworkBuilder.networkType(VspNetwork.NetworkType.L3);
} else {
vspNetworkBuilder.networkType(VspNetwork.NetworkType.L2);
}
}
boolean firewallServiceSupported = _networkModel.areServicesSupportedByNetworkOffering(network.getNetworkOfferingId(), Network.Service.Firewall);
vspNetworkBuilder.firewallServiceSupported(firewallServiceSupported);
String preConfiguredDomainTemplateName = NuageVspUtil.getPreConfiguredDomainTemplateName(_configurationDao, _networkDetailsDao, network, networkOffering);
vspNetworkBuilder.domainTemplateName(preConfiguredDomainTemplateName);
if (usesVirtualRouter(networkOffering.getId())) {
try {
List<Pair<String, String>> ipAddressRanges = networkOffering.getGuestType() == Network.GuestType.Shared ? getSharedIpAddressRanges(network.getId()) : getIpAddressRanges(network);
String virtualRouterIp = getVirtualRouterIP(network, ipAddressRanges);
vspNetworkBuilder.virtualRouterIp(virtualRouterIp);
} catch (InsufficientVirtualNetworkCapacityException ex) {
s_logger.error("There is an insufficient network capacity in network " + network.getId(), ex);
throw new CloudRuntimeException("There is an insufficient network capacity in network " + network.getId(), ex);
}
}
return vspNetworkBuilder.build();
}
use of com.cloud.user.AccountVO in project cloudstack by apache.
the class GloboDnsElementTest method setUp.
@Before
public void setUp() throws Exception {
ComponentContext.initComponentsLifeCycle();
acct = new AccountVO(200L);
acct.setType(Account.ACCOUNT_TYPE_NORMAL);
acct.setAccountName("user");
acct.setDomainId(domainId);
user = new UserVO();
user.setUsername("user");
user.setAccountId(acct.getAccountId());
CallContext.register(user, acct);
when(_acctMgr.getSystemAccount()).thenReturn(this.acct);
when(_acctMgr.getSystemUser()).thenReturn(this.user);
}
Aggregations