Search in sources :

Example 46 with AccountVO

use of com.cloud.user.AccountVO in project cloudstack by apache.

the class AffinityApiUnitTest method setUp.

@Before
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    AccountVO acct = new AccountVO(200L);
    acct.setType(Account.ACCOUNT_TYPE_NORMAL);
    acct.setAccountName("user");
    acct.setDomainId(domainId);
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, acct);
    when(_acctMgr.finalizeOwner((Account) anyObject(), anyString(), anyLong(), anyLong())).thenReturn(acct);
    when(_processor.getType()).thenReturn("mock");
    when(_accountDao.findByIdIncludingRemoved(0L)).thenReturn(acct);
    List<AffinityGroupProcessor> affinityProcessors = new ArrayList<AffinityGroupProcessor>();
    affinityProcessors.add(_processor);
    _affinityService.setAffinityGroupProcessors(affinityProcessors);
    AffinityGroupVO group = new AffinityGroupVO("group1", "mock", "mock group", domainId, 200L, ControlledEntity.ACLType.Account);
    Mockito.when(_affinityGroupDao.persist(Matchers.any(AffinityGroupVO.class))).thenReturn(group);
    Mockito.when(_affinityGroupDao.findById(Matchers.anyLong())).thenReturn(group);
    Mockito.when(_affinityGroupDao.findByAccountAndName(Matchers.anyLong(), Matchers.anyString())).thenReturn(group);
    Mockito.when(_affinityGroupDao.lockRow(Matchers.anyLong(), anyBoolean())).thenReturn(group);
    Mockito.when(_affinityGroupDao.expunge(Matchers.anyLong())).thenReturn(true);
    Mockito.when(_eventDao.persist(Matchers.any(EventVO.class))).thenReturn(new EventVO());
}
Also used : UserVO(com.cloud.user.UserVO) ArrayList(java.util.ArrayList) AccountVO(com.cloud.user.AccountVO) EventVO(com.cloud.event.EventVO) Before(org.junit.Before)

Example 47 with AccountVO

use of com.cloud.user.AccountVO in project cloudstack by apache.

the class AffinityGroupServiceImplTest method setUp.

@Before
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    acct = new AccountVO(200L);
    acct.setType(Account.ACCOUNT_TYPE_NORMAL);
    acct.setAccountName(ACCOUNT_NAME);
    acct.setDomainId(DOMAIN_ID);
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, acct);
    when(_processor.getType()).thenReturn("mock");
    when(_accountDao.findByIdIncludingRemoved(0L)).thenReturn(acct);
    List<AffinityGroupProcessor> affinityProcessors = new ArrayList<AffinityGroupProcessor>();
    affinityProcessors.add(_processor);
    _affinityService.setAffinityGroupProcessors(affinityProcessors);
    AffinityGroupVO group = new AffinityGroupVO(AFFINITY_GROUP_NAME, "mock", "mock group", DOMAIN_ID, 200L, ControlledEntity.ACLType.Account);
    Mockito.when(_affinityGroupDao.persist(Matchers.any(AffinityGroupVO.class))).thenReturn(group);
    Mockito.when(_affinityGroupDao.findById(Matchers.anyLong())).thenReturn(group);
    Mockito.when(_affinityGroupDao.findByAccountAndName(Matchers.anyLong(), Matchers.anyString())).thenReturn(group);
    Mockito.when(_affinityGroupDao.lockRow(Matchers.anyLong(), anyBoolean())).thenReturn(group);
    Mockito.when(_affinityGroupDao.expunge(Matchers.anyLong())).thenReturn(true);
    Mockito.when(_eventDao.persist(Matchers.any(EventVO.class))).thenReturn(new EventVO());
}
Also used : UserVO(com.cloud.user.UserVO) ArrayList(java.util.ArrayList) AccountVO(com.cloud.user.AccountVO) EventVO(com.cloud.event.EventVO) Before(org.junit.Before)

Example 48 with AccountVO

use of com.cloud.user.AccountVO in project cloudstack by apache.

the class ApplicationLoadBalancerTest method setUp.

@Override
@Before
public void setUp() {
    ComponentContext.initComponentsLifeCycle();
    //mockito for .getApplicationLoadBalancer tests
    Mockito.when(_lbDao.findById(1L)).thenReturn(new ApplicationLoadBalancerRuleVO());
    Mockito.when(_lbDao.findById(2L)).thenReturn(null);
    //mockito for .deleteApplicationLoadBalancer tests
    Mockito.when(_lbService.deleteLoadBalancerRule(existingLbId, true)).thenReturn(true);
    Mockito.when(_lbService.deleteLoadBalancerRule(nonExistingLbId, true)).thenReturn(false);
    //mockito for .createApplicationLoadBalancer tests
    NetworkVO guestNetwork = new NetworkVO(TrafficType.Guest, null, null, 1, null, 1, 1L, false);
    setId(guestNetwork, validGuestNetworkId);
    guestNetwork.setCidr("10.1.1.1/24");
    NetworkVO publicNetwork = new NetworkVO(TrafficType.Public, null, null, 1, null, 1, 1L, false);
    Mockito.when(_ntwkModel.getNetwork(validGuestNetworkId)).thenReturn(guestNetwork);
    Mockito.when(_ntwkModel.getNetwork(invalidGuestNetworkId)).thenReturn(null);
    Mockito.when(_ntwkModel.getNetwork(validPublicNetworkId)).thenReturn(publicNetwork);
    Mockito.when(_accountMgr.getAccount(validAccountId)).thenReturn(new AccountVO());
    Mockito.when(_accountMgr.getAccount(invalidAccountId)).thenReturn(null);
    Mockito.when(_ntwkModel.areServicesSupportedInNetwork(validGuestNetworkId, Service.Lb)).thenReturn(true);
    Mockito.when(_ntwkModel.areServicesSupportedInNetwork(invalidGuestNetworkId, Service.Lb)).thenReturn(false);
    ApplicationLoadBalancerRuleVO lbRule = new ApplicationLoadBalancerRuleVO("new", "new", 22, 22, "roundrobin", validGuestNetworkId, validAccountId, 1L, new Ip(validRequestedIp), validGuestNetworkId, Scheme.Internal);
    Mockito.when(_lbDao.persist(Matchers.any(ApplicationLoadBalancerRuleVO.class))).thenReturn(lbRule);
    Mockito.when(_lbMgr.validateLbRule(Matchers.any(LoadBalancingRule.class))).thenReturn(true);
    Mockito.when(_firewallDao.setStateToAdd(Matchers.any(FirewallRuleVO.class))).thenReturn(true);
    Mockito.when(_accountMgr.getSystemUser()).thenReturn(new UserVO(1));
    Mockito.when(_accountMgr.getSystemAccount()).thenReturn(new AccountVO(2));
    CallContext.register(_accountMgr.getSystemUser(), _accountMgr.getSystemAccount());
    Mockito.when(_ntwkModel.areServicesSupportedInNetwork(Matchers.anyLong(), Matchers.any(Network.Service.class))).thenReturn(true);
    Map<Network.Capability, String> caps = new HashMap<Network.Capability, String>();
    caps.put(Capability.SupportedProtocols, NetUtils.TCP_PROTO);
    Mockito.when(_ntwkModel.getNetworkServiceCapabilities(Matchers.anyLong(), Matchers.any(Network.Service.class))).thenReturn(caps);
    Mockito.when(_lbDao.countBySourceIp(new Ip(validRequestedIp), validGuestNetworkId)).thenReturn(1L);
}
Also used : ApplicationLoadBalancerRuleVO(org.apache.cloudstack.lb.ApplicationLoadBalancerRuleVO) NetworkVO(com.cloud.network.dao.NetworkVO) LoadBalancingRule(com.cloud.network.lb.LoadBalancingRule) Capability(com.cloud.network.Network.Capability) HashMap(java.util.HashMap) Ip(com.cloud.utils.net.Ip) NetworkOrchestrationService(org.apache.cloudstack.engine.orchestration.service.NetworkOrchestrationService) Service(com.cloud.network.Network.Service) LoadBalancingRulesService(com.cloud.network.lb.LoadBalancingRulesService) AccountVO(com.cloud.user.AccountVO) FirewallRuleVO(com.cloud.network.rules.FirewallRuleVO) UserVO(com.cloud.user.UserVO) Network(com.cloud.network.Network) Before(org.junit.Before)

Example 49 with AccountVO

use of com.cloud.user.AccountVO in project cloudstack by apache.

the class CertServiceTest method runUploadSslCertExpiredCert.

@Test
public void runUploadSslCertExpiredCert() throws IOException, IllegalAccessException, NoSuchFieldException {
    // Reading appropritate files
    final String certFile = URLDecoder.decode(getClass().getResource("/certs/expired_cert.crt").getFile(), Charset.defaultCharset().name());
    final String keyFile = URLDecoder.decode(getClass().getResource("/certs/rsa_self_signed.key").getFile(), Charset.defaultCharset().name());
    final String cert = readFileToString(new File(certFile));
    final String key = readFileToString(new File(keyFile));
    final CertServiceImpl certService = new CertServiceImpl();
    //setting mock objects
    certService._accountMgr = Mockito.mock(AccountManager.class);
    final Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
    when(certService._accountMgr.getAccount(Matchers.anyLong())).thenReturn(account);
    certService._domainDao = Mockito.mock(DomainDao.class);
    final DomainVO domain = new DomainVO("networkdomain", 1L, 1L, "networkdomain");
    when(certService._domainDao.findByIdIncludingRemoved(Matchers.anyLong())).thenReturn(domain);
    certService._sslCertDao = Mockito.mock(SslCertDao.class);
    when(certService._sslCertDao.persist(Matchers.any(SslCertVO.class))).thenReturn(new SslCertVO());
    //creating the command
    final UploadSslCertCmd uploadCmd = new UploadSslCertCmdExtn();
    final Class<?> klazz = uploadCmd.getClass().getSuperclass();
    final Field certField = klazz.getDeclaredField("cert");
    certField.setAccessible(true);
    certField.set(uploadCmd, cert);
    final Field keyField = klazz.getDeclaredField("key");
    keyField.setAccessible(true);
    keyField.set(uploadCmd, key);
    try {
        certService.uploadSslCert(uploadCmd);
        Assert.fail("Given an expired certificate, upload should fail");
    } catch (final Exception e) {
        System.out.println(e.getMessage());
        Assert.assertTrue(e.getMessage().contains("Parsing certificate/key failed: NotAfter:"));
    }
}
Also used : Account(com.cloud.user.Account) SslCertDao(com.cloud.network.dao.SslCertDao) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) AccountVO(com.cloud.user.AccountVO) IOException(java.io.IOException) DomainVO(com.cloud.domain.DomainVO) Field(java.lang.reflect.Field) SslCertVO(com.cloud.network.dao.SslCertVO) DomainDao(com.cloud.domain.dao.DomainDao) AccountManager(com.cloud.user.AccountManager) UploadSslCertCmd(org.apache.cloudstack.api.command.user.loadbalancer.UploadSslCertCmd) File(java.io.File) Test(org.junit.Test)

Example 50 with AccountVO

use of com.cloud.user.AccountVO in project cloudstack by apache.

the class CertServiceTest method runUploadSslCertNotX509.

@Test
public void runUploadSslCertNotX509() throws IOException, IllegalAccessException, NoSuchFieldException {
    // Reading appropritate files
    final String certFile = URLDecoder.decode(getClass().getResource("/certs/non_x509_pem.crt").getFile(), Charset.defaultCharset().name());
    final String keyFile = URLDecoder.decode(getClass().getResource("/certs/rsa_self_signed.key").getFile(), Charset.defaultCharset().name());
    final String cert = readFileToString(new File(certFile));
    final String key = readFileToString(new File(keyFile));
    final CertServiceImpl certService = new CertServiceImpl();
    //setting mock objects
    certService._accountMgr = Mockito.mock(AccountManager.class);
    final Account account = new AccountVO("testaccount", 1, "networkdomain", (short) 0, UUID.randomUUID().toString());
    when(certService._accountMgr.getAccount(Matchers.anyLong())).thenReturn(account);
    certService._domainDao = Mockito.mock(DomainDao.class);
    final DomainVO domain = new DomainVO("networkdomain", 1L, 1L, "networkdomain");
    when(certService._domainDao.findByIdIncludingRemoved(Matchers.anyLong())).thenReturn(domain);
    certService._sslCertDao = Mockito.mock(SslCertDao.class);
    when(certService._sslCertDao.persist(Matchers.any(SslCertVO.class))).thenReturn(new SslCertVO());
    //creating the command
    final UploadSslCertCmd uploadCmd = new UploadSslCertCmdExtn();
    final Class<?> klazz = uploadCmd.getClass().getSuperclass();
    final Field certField = klazz.getDeclaredField("cert");
    certField.setAccessible(true);
    certField.set(uploadCmd, cert);
    final Field keyField = klazz.getDeclaredField("key");
    keyField.setAccessible(true);
    keyField.set(uploadCmd, key);
    try {
        certService.uploadSslCert(uploadCmd);
        Assert.fail("Given a Certificate which is not X509, upload should fail");
    } catch (final Exception e) {
        Assert.assertTrue(e.getMessage().contains("Expected X509 certificate"));
    }
}
Also used : Account(com.cloud.user.Account) SslCertDao(com.cloud.network.dao.SslCertDao) FileUtils.readFileToString(org.apache.commons.io.FileUtils.readFileToString) AccountVO(com.cloud.user.AccountVO) IOException(java.io.IOException) DomainVO(com.cloud.domain.DomainVO) Field(java.lang.reflect.Field) SslCertVO(com.cloud.network.dao.SslCertVO) DomainDao(com.cloud.domain.dao.DomainDao) AccountManager(com.cloud.user.AccountManager) UploadSslCertCmd(org.apache.cloudstack.api.command.user.loadbalancer.UploadSslCertCmd) File(java.io.File) Test(org.junit.Test)

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