/** * It tests the creation o subnetwork and its json representation. * * @throws Exception */ @Test public void testCreateSubNetworkInstance() throws Exception { NetworkInstance network = new NetworkInstance(NETWORK_NAME, VDC, REGION); network.setIdNetwork(ID); SubNetworkInstance subNetwork = new SubNetworkInstance(SUBNETWORK_NAME, VDC, REGION); subNetwork.setIdSubNet(ID); network.addSubNet(subNetwork); assertEquals(subNetwork.toJson(), SUBNETWORK_STRING); assertEquals(network.toAddInterfaceJson(), ADDINTERFACE); }
/** * Test add the same subneto. * * @throws Exception */ @Test public void testAddtheSameSubNet() throws Exception { NetworkInstance network = new NetworkInstance(NETWORK_NAME, VDC, REGION); network.setIdNetwork(ID); SubNetworkInstance subNetwork = new SubNetworkInstance(SUBNETWORK_NAME, VDC, REGION, CIDR_ID); subNetwork.setIdSubNet(ID); network.addSubNet(subNetwork); network.addSubNet(subNetwork); assertEquals(network.getSubNets().size(), 1); }
/** * It tests the creation of a router subnetwork and its json representation. * * @throws Exception */ @Test public void testCreateRouter() throws Exception { NetworkInstance network = new NetworkInstance(NETWORK_NAME, VDC, REGION); network.setIdNetwork(ID); SubNetworkInstance subNetwork = new SubNetworkInstance(SUBNETWORK_NAME, VDC, REGION); subNetwork.setIdSubNet(ID); network.addSubNet(subNetwork); RouterInstance router = new RouterInstance(ID, ROUTER_NAME); router.setIdRouter(ID); network.addRouter(router); assertEquals(router.toJson(), ROUTER_STRING); assertEquals(network.toAddInterfaceJson(), ADDINTERFACE); }
/** * Create a network instance test. * * @throws Exception */ @Test public void testCreateInstanceNetwork() throws Exception { Network network = new Network(NETWORK_NAME, VDC, REGION); SubNetwork subNet = new SubNetwork(SUBNETWORK_NAME, VDC, REGION); network.addSubNet(subNet); NetworkInstance networkInstance = network.toNetworkInstance(); assertEquals(networkInstance.getNetworkName(), NETWORK_NAME); assertEquals(networkInstance.toJson(), NETWORK_STRING); assertEquals(networkInstance.getSubNets().size(), 1); for (SubNetworkInstance subNet2 : networkInstance.getSubNets()) { assertEquals(subNet2.getName(), SUBNETWORK_NAME); } }
/** * Clone subnet instances. * * @throws Exception */ @Test public void testCloneSubNetInstances() throws Exception { NetworkInstance network = new NetworkInstance(NETWORK_NAME, VDC, REGION); network.setIdNetwork(ID); SubNetworkInstance subNetwork = new SubNetworkInstance(SUBNETWORK_NAME, VDC, REGION); subNetwork.setIdSubNet(ID); network.addSubNet(subNetwork); Set<SubNetworkInstance> subNets = network.cloneSubNets(); assertEquals(subNets.size(), 1); for (SubNetworkInstance subNet : subNets) { assertEquals(subNet.getName(), SUBNETWORK_NAME); assertEquals(subNet.getCidr(), CIDR); } }
/** * Update subNet instance. * * @throws Exception */ @Test public void testUpdateSubNetInstance() throws Exception { NetworkInstance network = new NetworkInstance(NETWORK_NAME, VDC, REGION); SubNetworkInstance subnet = new SubNetworkInstance(SUBNETWORK_NAME, VDC, REGION, CIDR_ID); subnet.setId(new Long(ID)); network.addSubNet(subnet); SubNetworkInstance subnet2 = new SubNetworkInstance(SUBNETWORK_NAME, VDC, REGION, CIDR_ID); subnet2.setId(new Long(ID)); subnet2.setIdNetwork(ID); network.updateSubNet(subnet2); assertEquals(network.getSubNets().size(), 1); for (SubNetworkInstance subNet : network.getSubNets()) { assertEquals(subNet.getName(), SUBNETWORK_NAME); assertEquals(subNet.getCidr(), CIDR); assertEquals(subNet.getIdNetwork(), ID); } }
/** * Test the creation of a network from json file. * * @throws Exception */ @Test public void testSubNetFromJSon() throws Exception { String payload = "\n" + "\n" + " {\n" + " \"name\": \"dd\",\n" + " \"enable_dhcp\": true,\n" + " \"network_id\": \"33cb6d12-3792-4ff7-8abe-8f948ce60a4d\",\n" + " \"tenant_id\": \"00000000000000000000000000000046\",\n" + " \"dns_nameservers\":\n" + " [\n" + " ],\n" + " \"allocation_pools\":\n" + " [\n" + " {\n" + " \"start\": \"12.1.0.2\",\n" + " \"end\": \"12.1.0.254\"\n" + " }\n" + " ],\n" + " \"host_routes\":\n" + " [\n" + " ],\n" + " \"ip_version\": 4,\n" + " \"gateway_ip\": \"12.1.0.1\",\n" + " \"cidr\": \"12.1.0.0/24\",\n" + " \"id\": \"6959446a-204b-4e68-a5d2-f7a3ef5a442a\"\n" + " }\n" + "\n"; JSONObject jsonNet = new JSONObject(payload); SubNetworkInstance subnet = SubNetworkInstance.fromJson(jsonNet, "region"); assertEquals(subnet.getIdNetwork(), "33cb6d12-3792-4ff7-8abe-8f948ce60a4d"); assertEquals(subnet.getIdSubNet(), "6959446a-204b-4e68-a5d2-f7a3ef5a442a"); assertEquals(subnet.getName(), "dd"); assertEquals(subnet.getCidr(), "12.1.0.0/24"); assertEquals(subnet.getRegion(), "region"); }