forked from apache/cloudstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add test for Ipv4SubnetForGuestNetworkCmd and BgpPeerCmd
- Loading branch information
1 parent
b53fed8
commit 56a9bd7
Showing
21 changed files
with
830 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...g/apache/cloudstack/api/command/admin/network/CreateIpv4SubnetForGuestNetworkCmdTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.cloudstack.api.command.admin.network; | ||
|
||
import com.cloud.event.EventTypes; | ||
|
||
import org.apache.cloudstack.api.response.Ipv4SubnetForGuestNetworkResponse; | ||
import org.apache.cloudstack.network.Ipv4GuestSubnetNetworkMap; | ||
import org.apache.cloudstack.network.RoutedIpv4Manager; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class CreateIpv4SubnetForGuestNetworkCmdTest { | ||
|
||
RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); | ||
|
||
@Test | ||
public void testCreateIpv4SubnetForGuestNetworkCmd() { | ||
Long parentId = 1L; | ||
String subnet = "192.168.1.0/24"; | ||
Integer cidrSize = 26; | ||
|
||
CreateIpv4SubnetForGuestNetworkCmd cmd = new CreateIpv4SubnetForGuestNetworkCmd(); | ||
ReflectionTestUtils.setField(cmd, "parentId", parentId); | ||
ReflectionTestUtils.setField(cmd, "subnet", subnet); | ||
ReflectionTestUtils.setField(cmd, "cidrSize", cidrSize); | ||
ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); | ||
|
||
Assert.assertEquals(parentId, cmd.getParentId()); | ||
Assert.assertEquals(subnet, cmd.getSubnet()); | ||
Assert.assertEquals(cidrSize, cmd.getCidrSize()); | ||
Assert.assertEquals(1L, cmd.getEntityOwnerId()); | ||
Assert.assertEquals(EventTypes.EVENT_IP4_GUEST_SUBNET_CREATE, cmd.getEventType()); | ||
Assert.assertEquals(String.format("Creating guest IPv4 subnet %s in zone subnet=%s", subnet, parentId), cmd.getEventDescription()); | ||
|
||
Ipv4GuestSubnetNetworkMap ipv4GuestSubnetNetworkMap = Mockito.mock(Ipv4GuestSubnetNetworkMap.class); | ||
Mockito.when(routedIpv4Manager.createIpv4SubnetForGuestNetwork(cmd)).thenReturn(ipv4GuestSubnetNetworkMap); | ||
|
||
Ipv4SubnetForGuestNetworkResponse response = Mockito.mock(Ipv4SubnetForGuestNetworkResponse.class); | ||
Mockito.when(routedIpv4Manager.createIpv4SubnetForGuestNetworkResponse(ipv4GuestSubnetNetworkMap)).thenReturn(response); | ||
|
||
try { | ||
cmd.execute(); | ||
} catch (Exception ignored) { | ||
} | ||
|
||
Assert.assertEquals(response, cmd.getResponseObject()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...g/apache/cloudstack/api/command/admin/network/DeleteIpv4SubnetForGuestNetworkCmdTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.cloudstack.api.command.admin.network; | ||
|
||
import com.cloud.event.EventTypes; | ||
|
||
import org.apache.cloudstack.api.response.SuccessResponse; | ||
import org.apache.cloudstack.network.RoutedIpv4Manager; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class DeleteIpv4SubnetForGuestNetworkCmdTest { | ||
|
||
RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); | ||
|
||
@Test | ||
public void testDeleteIpv4SubnetForGuestNetworkCmd() { | ||
Long id = 1L; | ||
|
||
DeleteIpv4SubnetForGuestNetworkCmd cmd = new DeleteIpv4SubnetForGuestNetworkCmd(); | ||
ReflectionTestUtils.setField(cmd, "id", id); | ||
ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); | ||
|
||
Assert.assertEquals(id, cmd.getId()); | ||
Assert.assertEquals(1L, cmd.getEntityOwnerId()); | ||
Assert.assertEquals(EventTypes.EVENT_IP4_GUEST_SUBNET_DELETE, cmd.getEventType()); | ||
Assert.assertEquals(String.format("Deleting guest IPv4 subnet %s", id), cmd.getEventDescription()); | ||
|
||
Mockito.when(routedIpv4Manager.deleteIpv4SubnetForGuestNetwork(cmd)).thenReturn(true); | ||
|
||
try { | ||
cmd.execute(); | ||
} catch (Exception ignored) { | ||
} | ||
|
||
Assert.assertTrue(cmd.getResponseObject() instanceof SuccessResponse); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...rg/apache/cloudstack/api/command/admin/network/ListIpv4SubnetsForGuestNetworkCmdTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.cloudstack.api.command.admin.network; | ||
|
||
import org.apache.cloudstack.api.response.Ipv4SubnetForGuestNetworkResponse; | ||
import org.apache.cloudstack.api.response.ListResponse; | ||
import org.apache.cloudstack.network.Ipv4GuestSubnetNetworkMap; | ||
import org.apache.cloudstack.network.RoutedIpv4Manager; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ListIpv4SubnetsForGuestNetworkCmdTest { | ||
|
||
RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); | ||
|
||
@Test | ||
public void testListIpv4SubnetsForGuestNetworkCmd() { | ||
Long id = 1L; | ||
Long zoneId = 2L; | ||
Long parentId = 2L; | ||
String subnet = "192.168.1.0/24"; | ||
Long networkId = 10L; | ||
Long vpcId = 11L; | ||
|
||
ListIpv4SubnetsForGuestNetworkCmd cmd = new ListIpv4SubnetsForGuestNetworkCmd(); | ||
ReflectionTestUtils.setField(cmd, "id", id); | ||
ReflectionTestUtils.setField(cmd, "zoneId", zoneId); | ||
ReflectionTestUtils.setField(cmd, "subnet", subnet); | ||
ReflectionTestUtils.setField(cmd, "parentId", parentId); | ||
ReflectionTestUtils.setField(cmd,"networkId", networkId); | ||
ReflectionTestUtils.setField(cmd,"vpcId", vpcId); | ||
ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); | ||
|
||
Assert.assertEquals(id, cmd.getId()); | ||
Assert.assertEquals(zoneId, cmd.getZoneId()); | ||
Assert.assertEquals(subnet, cmd.getSubnet()); | ||
Assert.assertEquals(networkId, cmd.getNetworkId()); | ||
Assert.assertEquals(vpcId, cmd.getVpcId()); | ||
Assert.assertEquals(parentId, cmd.getParentId()); | ||
|
||
Assert.assertEquals(0L, cmd.getEntityOwnerId()); | ||
|
||
Ipv4GuestSubnetNetworkMap ipv4GuestSubnetNetworkMap = Mockito.mock(Ipv4GuestSubnetNetworkMap.class); | ||
List<Ipv4GuestSubnetNetworkMap> ipv4GuestSubnetNetworkMaps = Arrays.asList(ipv4GuestSubnetNetworkMap); | ||
Mockito.when(routedIpv4Manager.listIpv4GuestSubnetsForGuestNetwork(cmd)).thenReturn(ipv4GuestSubnetNetworkMaps); | ||
|
||
Ipv4SubnetForGuestNetworkResponse response = Mockito.mock(Ipv4SubnetForGuestNetworkResponse.class); | ||
Mockito.when(routedIpv4Manager.createIpv4SubnetForGuestNetworkResponse(ipv4GuestSubnetNetworkMap)).thenReturn(response); | ||
|
||
try { | ||
cmd.execute(); | ||
} catch (Exception ignored) { | ||
} | ||
|
||
Assert.assertTrue(cmd.getResponseObject() instanceof ListResponse); | ||
ListResponse listResponse = (ListResponse) cmd.getResponseObject(); | ||
Assert.assertEquals(1, (int) listResponse.getCount()); | ||
Assert.assertEquals(response, listResponse.getResponses().get(0)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
.../org/apache/cloudstack/api/command/admin/network/bgp/ChangeBgpPeersForNetworkCmdTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.cloudstack.api.command.admin.network.bgp; | ||
|
||
import com.cloud.event.EventTypes; | ||
|
||
import com.cloud.network.Network; | ||
import org.apache.cloudstack.api.ResponseGenerator; | ||
import org.apache.cloudstack.api.ResponseObject; | ||
import org.apache.cloudstack.api.response.NetworkResponse; | ||
import org.apache.cloudstack.network.RoutedIpv4Manager; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
import org.springframework.test.util.ReflectionTestUtils; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ChangeBgpPeersForNetworkCmdTest { | ||
|
||
RoutedIpv4Manager routedIpv4Manager = Mockito.spy(RoutedIpv4Manager.class); | ||
|
||
ResponseGenerator _responseGenerator = Mockito.spy(ResponseGenerator.class); | ||
|
||
@Test | ||
public void testChangeBgpPeersForNetworkCmd() { | ||
Long networkId = 10L; | ||
List<Long> bgpPeerIds = Arrays.asList(20L, 21L); | ||
|
||
ChangeBgpPeersForNetworkCmd cmd = new ChangeBgpPeersForNetworkCmd(); | ||
ReflectionTestUtils.setField(cmd, "networkId", networkId); | ||
ReflectionTestUtils.setField(cmd, "bgpPeerIds", bgpPeerIds); | ||
ReflectionTestUtils.setField(cmd,"routedIpv4Manager", routedIpv4Manager); | ||
ReflectionTestUtils.setField(cmd,"_responseGenerator", _responseGenerator); | ||
|
||
Assert.assertEquals(networkId, cmd.getNetworkId()); | ||
Assert.assertEquals(bgpPeerIds, cmd.getBgpPeerIds()); | ||
Assert.assertEquals(1L, cmd.getEntityOwnerId()); | ||
Assert.assertEquals(EventTypes.EVENT_NETWORK_BGP_PEER_UPDATE, cmd.getEventType()); | ||
Assert.assertEquals(String.format("Changing Bgp Peers for network %s", networkId), cmd.getEventDescription()); | ||
|
||
Network network = Mockito.mock(Network.class); | ||
Mockito.when(routedIpv4Manager.changeBgpPeersForNetwork(cmd)).thenReturn(network); | ||
|
||
NetworkResponse response = Mockito.mock(NetworkResponse.class); | ||
Mockito.when(_responseGenerator.createNetworkResponse(ResponseObject.ResponseView.Full, network)).thenReturn(response); | ||
|
||
try { | ||
cmd.execute(); | ||
} catch (Exception ignored) { | ||
} | ||
|
||
Assert.assertEquals(response, cmd.getResponseObject()); | ||
} | ||
} |
Oops, something went wrong.