From 025301d08b061482c1f046d562bf017c8cbcfe8d Mon Sep 17 00:00:00 2001 From: ChrisC Date: Tue, 31 Jan 2017 11:40:03 +0100 Subject: Initial OpenECOMP MSO commit Change-Id: Ia6a7574859480717402cc2f22534d9973a78fa6d Signed-off-by: ChrisC --- .../mso/adapters/network/NetworkAdapterTest.java | 266 +++++++++++++++++++++ 1 file changed, 266 insertions(+) create mode 100644 adapters/mso-network-adapter/src/test/java/org/openecomp/mso/adapters/network/NetworkAdapterTest.java (limited to 'adapters/mso-network-adapter/src/test/java/org/openecomp') diff --git a/adapters/mso-network-adapter/src/test/java/org/openecomp/mso/adapters/network/NetworkAdapterTest.java b/adapters/mso-network-adapter/src/test/java/org/openecomp/mso/adapters/network/NetworkAdapterTest.java new file mode 100644 index 0000000000..41cc3f5533 --- /dev/null +++ b/adapters/mso-network-adapter/src/test/java/org/openecomp/mso/adapters/network/NetworkAdapterTest.java @@ -0,0 +1,266 @@ +/*- + * ============LICENSE_START======================================================= + * OPENECOMP - MSO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.mso.adapters.network; + + +import static org.junit.Assert.assertTrue; + +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import javax.xml.ws.Holder; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; + +import org.openecomp.mso.adapters.network.exceptions.NetworkException; +import org.openecomp.mso.db.catalog.CatalogDatabase; +import org.openecomp.mso.db.catalog.beans.NetworkResource; +import org.openecomp.mso.entity.MsoRequest; +import org.openecomp.mso.openstack.beans.NetworkStatus; +import org.openecomp.mso.openstack.beans.Subnet; +import org.openecomp.mso.openstack.beans.NetworkRollback; + +public class NetworkAdapterTest { + + @Mock + private static MsoNetworkAdapterImpl adapter; + + @Mock + private static CatalogDatabase db; + + @BeforeClass + public static final void prepare () { + adapter = Mockito.spy (new MsoNetworkAdapterImpl ()); + db = Mockito.mock (CatalogDatabase.class); + NetworkResource networkResource = new NetworkResource (); + networkResource.setNetworkType ("PROVIDER"); + networkResource.setNeutronNetworkType ("PROVIDER"); + networkResource.setId (1); + networkResource.setOrchestrationMode ("toto"); + Mockito.when (db.getNetworkResource ("PROVIDER")).thenReturn (networkResource); + Mockito.when (adapter.getCatalogDb()).thenReturn (db); + } + + @Test + public void createTest () { + + List vlans = new LinkedList <> (); + vlans.add (1); + vlans.add (2); + List subnets = new LinkedList <> (); + subnets.add (new Subnet ()); + MsoRequest msoRequest = new MsoRequest (); + Holder networkId = new Holder <> (); + Holder neutronNetworkId = new Holder <> (); + Holder > subnetIdMap = new Holder <> (); + Holder rollback = new Holder <> (); + try { + adapter.createNetwork ("toto", + "tenant", + "PROVIDER", + "networkName", + "physicalNetworkName", + vlans, + Boolean.TRUE, + Boolean.TRUE, + subnets, + msoRequest, + networkId, + neutronNetworkId, + subnetIdMap, + rollback); + } catch (NetworkException e) { + assertTrue (e.getMessage ().contains ("Configuration Error")); + } + } + + @Test + public void createTest2 () { + List vlans = new LinkedList <> (); + vlans.add (1); + vlans.add (2); + List subnets = new LinkedList <> (); + List routeTargets = new LinkedList <> (); + subnets.add (new Subnet ()); + List policyFqdns = new LinkedList <> (); + policyFqdns.add("pfqdn1"); + policyFqdns.add("pfqdn2"); + List routeTableFqdns = new LinkedList <> (); + routeTableFqdns.add("rtfqdn1"); + routeTableFqdns.add("rtfqdn2"); + MsoRequest msoRequest = new MsoRequest (); + Holder networkId = new Holder <> (); + Holder neutronNetworkId = new Holder <> (); + Holder > subnetIdMap = new Holder <> (); + Holder rollback = new Holder <> (); + Holder networkFqdn= new Holder <> (); + try { + adapter.createNetworkContrail ("toto", + "tenant", + "PROVIDER", + "networkName", + routeTargets, + "shared", + "external", + Boolean.TRUE, + Boolean.TRUE, + subnets, + policyFqdns, + routeTableFqdns, + msoRequest, + networkId, + neutronNetworkId, + networkFqdn, + subnetIdMap, + rollback); + } catch (NetworkException e) { + assertTrue (e.getMessage ().contains ("Configuration Error")); + } + } + + @Test + public void updateTest () { + List vlans = new LinkedList <> (); + vlans.add (1); + vlans.add (2); + List subnets = new LinkedList <> (); + subnets.add (new Subnet ()); + MsoRequest msoRequest = new MsoRequest (); + Holder > subnetIdMap = new Holder <> (); + Holder rollback = new Holder <> (); + try { + adapter.updateNetwork ("toto", + "tenant", + "PROVIDER", + "networkId", + "networkName", + "physicalNetworkName", + vlans, + subnets, + msoRequest, + subnetIdMap, + rollback); + } catch (NetworkException e) { + assertTrue (e.getMessage ().contains ("Configuration Error")); + } + } + + @Test + public void updateTest2 () { + List vlans = new LinkedList <> (); + vlans.add (1); + vlans.add (2); + List subnets = new LinkedList <> (); + List routeTargets = new LinkedList <> (); + subnets.add (new Subnet ()); + List policyFqdns = new LinkedList <> (); + policyFqdns.add("pfqdn1"); + List routeTableFqdns = new LinkedList <> (); + routeTableFqdns.add("rtfqdn1"); + routeTableFqdns.add("rtfqdn2"); + MsoRequest msoRequest = new MsoRequest (); + Holder > subnetIdMap = new Holder <> (); + Holder rollback = new Holder <> (); + try { + adapter.updateNetworkContrail ("toto", + "tenant", + "PROVIDER", + "networkId", + "networkName", + routeTargets, + "shared", + "external", + subnets, + policyFqdns, + routeTableFqdns, + msoRequest, + subnetIdMap, + rollback); + } catch (NetworkException e) { + assertTrue (e.getMessage ().contains ("Configuration Error")); + } + } + + @Test + public void queryTest () { + Holder > vlans = new Holder <> (); + Holder status = new Holder <> (); + MsoRequest msoRequest = new MsoRequest (); + Holder networkId = new Holder <> (); + Holder result = new Holder <> (); + Holder neutronNetworkId = new Holder <> (); + Holder > subnetIdMap = new Holder <> (); + try { + adapter.queryNetwork (null, + "tenant", + "networkName", + msoRequest, + result, + networkId, + neutronNetworkId, + status, + vlans, + subnetIdMap); + } catch (NetworkException e) { + assertTrue (e.getMessage ().contains ("Missing mandatory parameter")); + } + } + + @Test + public void queryTest2 () { + Holder > routeTargets = new Holder <> (); + Holder status = new Holder <> (); + MsoRequest msoRequest = new MsoRequest (); + Holder networkId = new Holder <> (); + Holder result = new Holder <> (); + Holder neutronNetworkId = new Holder <> (); + Holder > subnetIdMap = new Holder <> (); + try { + adapter.queryNetworkContrail (null, + "tenant", + "networkName", + msoRequest, + result, + networkId, + neutronNetworkId, + status, + routeTargets, + subnetIdMap); + } catch (NetworkException e) { + assertTrue (e.getMessage ().contains ("Missing mandatory parameter")); + } + } + + @Test + public void deleteTest () { + Holder networkDeleted = new Holder<> (); + MsoRequest msoRequest = new MsoRequest (); + try { + adapter.deleteNetwork ("toto", "tenant", "PROVIDER", "networkId", msoRequest, networkDeleted); + } catch (NetworkException e) { + assertTrue (e.getMessage ().contains ("Configuration Error")); + } + } +} -- cgit 1.2.3-korg