Search in sources :

Example 6 with VlanDao

use of com.cloud.dc.dao.VlanDao in project cloudstack by apache.

the class NetworkModelTest method testGetSourceNatIpAddressForGuestNetwork.

@Test
public void testGetSourceNatIpAddressForGuestNetwork() {
    NetworkModelImpl modelImpl = new NetworkModelImpl();
    IPAddressDao ipAddressDao = mock(IPAddressDao.class);
    modelImpl._ipAddressDao = ipAddressDao;
    List<IPAddressVO> fakeList = new ArrayList<IPAddressVO>();
    IPAddressVO fakeIp = new IPAddressVO(new Ip("75.75.75.75"), 1, 0xaabbccddeeffL, 10, false);
    fakeList.add(fakeIp);
    SearchBuilder<IPAddressVO> fakeSearch = mock(SearchBuilder.class);
    modelImpl.IpAddressSearch = fakeSearch;
    VlanDao fakeVlanDao = mock(VlanDao.class);
    when(fakeVlanDao.findById(anyLong())).thenReturn(mock(VlanVO.class));
    modelImpl._vlanDao = fakeVlanDao;
    when(fakeSearch.create()).thenReturn(mock(SearchCriteria.class));
    when(ipAddressDao.search(any(SearchCriteria.class), (Filter) org.mockito.Matchers.isNull())).thenReturn(fakeList);
    when(ipAddressDao.findById(anyLong())).thenReturn(fakeIp);
    Account fakeAccount = mock(Account.class);
    when(fakeAccount.getId()).thenReturn(1L);
    Network fakeNetwork = mock(Network.class);
    when(fakeNetwork.getId()).thenReturn(1L);
    PublicIpAddress answer = modelImpl.getSourceNatIpAddressForGuestNetwork(fakeAccount, fakeNetwork);
    Assert.assertNull(answer);
    IPAddressVO fakeIp2 = new IPAddressVO(new Ip("76.75.75.75"), 1, 0xaabb10ddeeffL, 10, true);
    fakeList.add(fakeIp2);
    when(ipAddressDao.findById(anyLong())).thenReturn(fakeIp2);
    answer = modelImpl.getSourceNatIpAddressForGuestNetwork(fakeAccount, fakeNetwork);
    Assert.assertNotNull(answer);
    Assert.assertEquals(answer.getAddress().addr(), "76.75.75.75");
}
Also used : Account(com.cloud.user.Account) VlanDao(com.cloud.dc.dao.VlanDao) IPAddressDao(com.cloud.network.dao.IPAddressDao) Ip(com.cloud.utils.net.Ip) ArrayList(java.util.ArrayList) SearchCriteria(com.cloud.utils.db.SearchCriteria) IPAddressVO(com.cloud.network.dao.IPAddressVO) VlanVO(com.cloud.dc.VlanVO) Test(org.junit.Test)

Aggregations

VlanDao (com.cloud.dc.dao.VlanDao)6 ArrayList (java.util.ArrayList)6 VlanVO (com.cloud.dc.VlanVO)5 ApiConnector (net.juniper.contrail.api.ApiConnector)4 IOException (java.io.IOException)3 VirtualNetworkPolicyType (net.juniper.contrail.api.types.VirtualNetworkPolicyType)3 VnSubnetsType (net.juniper.contrail.api.types.VnSubnetsType)3 IPAddressDao (com.cloud.network.dao.IPAddressDao)2 Account (com.cloud.user.Account)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 List (java.util.List)2 ObjectReference (net.juniper.contrail.api.ObjectReference)2 NetworkIpam (net.juniper.contrail.api.types.NetworkIpam)2 SubnetType (net.juniper.contrail.api.types.SubnetType)2 VirtualNetwork (net.juniper.contrail.api.types.VirtualNetwork)2 DataCenter (com.cloud.dc.DataCenter)1 DataCenterDao (com.cloud.dc.dao.DataCenterDao)1 HostPodDao (com.cloud.dc.dao.HostPodDao)1 InsufficientAddressCapacityException (com.cloud.exception.InsufficientAddressCapacityException)1 InternalErrorException (com.cloud.exception.InternalErrorException)1