diff options
author | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2018-07-30 15:56:09 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2018-07-31 11:09:25 -0400 |
commit | 5a6a6de6f1a26a1897e4917a0df613e25a24eb70 (patch) | |
tree | 59a968f27b4b603aacc9d5e7b51fb598aeec5321 /adapters/mso-adapters-rest-interface/src/test/java/org/onap | |
parent | b6dc38501f3b746426b42d9de4cc883d894149e8 (diff) |
Containerization feature of SO
Change-Id: I95381232eeefcd247a66a5cec370a8ce1c288e18
Issue-ID: SO-670
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'adapters/mso-adapters-rest-interface/src/test/java/org/onap')
17 files changed, 1049 insertions, 0 deletions
diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/adapters/BeansTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/adapters/BeansTest.java new file mode 100644 index 0000000000..e3474009c9 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/adapters/BeansTest.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 Huawei 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.onap.so.adapters; + +import org.junit.Test; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.PojoClassFilter; +import com.openpojo.reflection.filters.FilterNonConcrete; +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.rule.impl.SetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + + +public class BeansTest { + private PojoClassFilter filterTestClasses = new FilterTestClasses(); + + @Test + public void pojoStructure() { + test("org.onap.so.adapters.nwrest"); + test("org.onap.so.adapters.sdncrest"); + test("org.onap.so.adapters.tenantrest"); + test("org.onap.so.adapters.vnfrest"); + test("org.onap.so.adapters.network.beans"); + test("org.onap.so.openstack.beans"); + } + + private void test(String pojoPackage) { + Validator validator = ValidatorBuilder.create() + .with(new GetterMustExistRule()) + .with(new SetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + validator.validate(pojoPackage, new FilterPackageInfo(), filterTestClasses, new FilterNonConcrete()); + } + + private static class FilterTestClasses implements PojoClassFilter { + public boolean include(PojoClass pojoClass) { + return !pojoClass.getSourcePath().contains("/test-classes/"); + } + } +}
\ No newline at end of file diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/adapters/network/mappers/ContrailSubnetMappersTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/adapters/network/mappers/ContrailSubnetMappersTest.java new file mode 100644 index 0000000000..240074bca7 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/adapters/network/mappers/ContrailSubnetMappersTest.java @@ -0,0 +1,236 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.adapters.network.mappers; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.junit.Test; +import org.onap.so.adapters.network.beans.ContrailSubnet; +import org.onap.so.adapters.network.beans.ContrailSubnetHostRoute; +import org.onap.so.adapters.network.beans.ContrailSubnetHostRoutes; +import org.onap.so.adapters.network.beans.ContrailSubnetIp; +import org.onap.so.adapters.network.beans.ContrailSubnetPool; +import org.onap.so.openstack.beans.HostRoute; +import org.onap.so.openstack.beans.Pool; +import org.onap.so.openstack.beans.Subnet; + +public class ContrailSubnetMappersTest { + + + + @Test + public void contrailSubnetHostRouteMapperTest() { + HostRoute hostRoute = new HostRoute(); + hostRoute.setNextHop("hop"); + hostRoute.setPrefix("prefix"); + ContrailSubnetHostRouteMapper mapper = new ContrailSubnetHostRouteMapper(hostRoute); + ContrailSubnetHostRoute cshr = mapper.map(); + assertEquals("hop", cshr.getNextHop()); + assertEquals("prefix", cshr.getPrefix()); + } + + @Test + public void contrailSubnetPoolMapperTest() { + Pool pool = new Pool(); + pool.setStart("start"); + pool.setEnd("end"); + ContrailSubnetPoolMapper mapper = new ContrailSubnetPoolMapper(pool); + ContrailSubnetPool csPool = mapper.map(); + assertEquals("start", csPool.getStart()); + assertEquals("end", csPool.getEnd()); + } + + @Test + public void checkIsNullOrEmpty() { + ContrailSubnetMapper mapper = new ContrailSubnetMapper(null); + assertEquals(true, mapper.isNullOrEmpty("")); + assertEquals(true, mapper.isNullOrEmpty(null)); + assertEquals(false, mapper.isNullOrEmpty("hello")); + } + + @Test + public void createSubnetTestValidCidr() { + Subnet subnet = new Subnet(); + subnet.setCidr("test/value"); + ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet); + ContrailSubnet result = mapper.map(); + + assertEquals("test",result.getSubnet().getIpPrefix()); + assertEquals("value", result.getSubnet().getIpPrefixLen()); + } + + @Test + public void createSubnetTestInvalidCidr() { + Subnet subnet = new Subnet(); + subnet.setCidr("test"); + ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet); + ContrailSubnet result = mapper.map(); + assertEquals(null, result.getSubnet().getIpPrefix()); + assertEquals(null, result.getSubnet().getIpPrefixLen()); + + } + + @Test + public void createSubnetTestNullCidr() { + Subnet subnet = new Subnet(); + ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet); + ContrailSubnet result = mapper.map(); + assertEquals(null, result.getSubnet().getIpPrefix()); + assertEquals(null, result.getSubnet().getIpPrefixLen()); + } + + @Test + public void createContrailSubnetPoolTest() { + List<Pool> pools = new ArrayList<>(); + Pool pool1 = new Pool(); + pool1.setStart("start1"); + pool1.setEnd("end1"); + Pool pool2 = new Pool(); + pool2.setStart("start2"); + pool2.setEnd("end2"); + pools.add(pool1); + pools.add(pool2); + + Subnet subnet = new Subnet(); + subnet.setAllocationPools(pools); + ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet); + ContrailSubnet result = mapper.map(); + List<ContrailSubnetPool> cspools = result.getAllocationPools(); + assertEquals(2, cspools.size()); + assertEquals("start2", cspools.get(1).getStart()); + assertEquals("end2", cspools.get(1).getEnd()); + } + + @Test + public void createContrailSubnetPoolInvalidTest() { + List<Pool> pools = new ArrayList<>(); + Pool pool1 = new Pool(); + pool1.setStart("start1"); + pool1.setEnd("end1"); + Pool pool2 = new Pool(); + pool2.setStart("start2"); + pools.add(pool1); + pools.add(pool2); + + Subnet subnet = new Subnet(); + subnet.setAllocationPools(pools); + ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet); + ContrailSubnet result = mapper.map(); + List<ContrailSubnetPool> cspools = result.getAllocationPools(); + assertEquals(1, cspools.size()); + assertEquals("start1", cspools.get(0).getStart()); + assertEquals("end1", cspools.get(0).getEnd()); + } + + @Test + public void createContrailSubnetPoolEmptyTest() { + + Subnet subnet = new Subnet(); + ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet); + ContrailSubnet result = mapper.map(); + List<ContrailSubnetPool> cspools = result.getAllocationPools(); + assertEquals(true, cspools.isEmpty()); + + } + + @Test + public void createContrailSubnetHostRoutesTest() { + List<HostRoute> hostRoutes = new ArrayList<>(); + HostRoute hostRoute1 = new HostRoute(); + hostRoute1.setNextHop("next-hop1"); + hostRoute1.setPrefix("prefix1"); + HostRoute hostRoute2 = new HostRoute(); + hostRoute2.setNextHop("next-hop2"); + hostRoute2.setPrefix("prefix2"); + hostRoutes.add(hostRoute1); + hostRoutes.add(hostRoute2); + + Subnet subnet = new Subnet(); + subnet.setHostRoutes(hostRoutes); + ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet); + ContrailSubnet result = mapper.map(); + ContrailSubnetHostRoutes routes = result.getHostRoutes(); + assertEquals(2, routes.getHostRoutes().size()); + assertEquals("next-hop2", routes.getHostRoutes().get(1).getNextHop()); + assertEquals("prefix2", routes.getHostRoutes().get(1).getPrefix()); + } + + @Test + public void createContrailSubnetHostRoutesMissingFieldTest() { + List<HostRoute> hostRoutes = new ArrayList<>(); + HostRoute hostRoute1 = new HostRoute(); + hostRoute1.setNextHop("next-hop1"); + HostRoute hostRoute2 = new HostRoute(); + hostRoute2.setNextHop("next-hop2"); + hostRoute2.setPrefix("prefix2"); + hostRoutes.add(hostRoute1); + hostRoutes.add(hostRoute2); + + Subnet subnet = new Subnet(); + subnet.setHostRoutes(hostRoutes); + ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet); + ContrailSubnet result = mapper.map(); + ContrailSubnetHostRoutes routes = result.getHostRoutes(); + assertEquals(2, routes.getHostRoutes().size()); + assertEquals("next-hop1", routes.getHostRoutes().get(0).getNextHop()); + assertEquals("prefix2", routes.getHostRoutes().get(1).getPrefix()); + } + + @Test + public void createContrailSubnetHostRoutesEmptyTest() { + List<HostRoute> hostRoutes = new ArrayList<>(); + Subnet subnet = new Subnet(); + subnet.setHostRoutes(hostRoutes); + ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet); + ContrailSubnet result = mapper.map(); + ContrailSubnetHostRoutes routes = result.getHostRoutes(); + assertEquals(true, routes.getHostRoutes().isEmpty()); + } + + @Test + public void getSubnetNameTest() { + Subnet subnet = new Subnet(); + subnet.setSubnetName("name"); + ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet); + assertEquals("if subnetName is populated map", "name", mapper.getSubnetName(subnet)); + subnet = new Subnet(); + subnet.setSubnetId("id"); + mapper = new ContrailSubnetMapper(subnet); + assertEquals("choose id when name is null", "id", mapper.getSubnetName(subnet)); + subnet = new Subnet(); + mapper = new ContrailSubnetMapper(subnet); + assertEquals("expect null", null, mapper.getSubnetName(subnet)); + } + @Test + public void mapRemainingFields() { + Subnet subnet = new Subnet(); + subnet.setEnableDHCP(true); + subnet.setGatewayIp("gateway-ip"); + ContrailSubnetMapper mapper = new ContrailSubnetMapper(subnet); + ContrailSubnet result = mapper.map(); + assertEquals(true, result.isEnableDhcp()); + assertEquals("gateway-ip", result.getDefaultGateway()); + } +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/adapters/nwrest/NetworkRequestTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/adapters/nwrest/NetworkRequestTest.java new file mode 100644 index 0000000000..08851c2ce9 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/adapters/nwrest/NetworkRequestTest.java @@ -0,0 +1,50 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.adapters.nwrest; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +public class NetworkRequestTest { + + + @Test + public void isSynchronousTrue() { + CreateNetworkRequest networkResponse = new CreateNetworkRequest(); + assertEquals(true, networkResponse.isSynchronous()); + //flip synchronous to false in the background + networkResponse.setNotificationUrl("testtest"); + assertEquals(false, networkResponse.isSynchronous()); + networkResponse.setNotificationUrl(""); + assertEquals(true, networkResponse.isSynchronous()); + } + + @Test + public void isContrailRequest() { + CreateNetworkRequest networkResponse = new CreateNetworkRequest(); + assertEquals(false, networkResponse.isContrailRequest()); + networkResponse.setNetworkTechnology(NetworkTechnology.CONTRAIL); + assertEquals(false, networkResponse.isContrailRequest()); + networkResponse.setContrailNetwork(new ContrailNetwork()); + assertEquals(true, networkResponse.isContrailRequest()); + } +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/adapters/vdu/BeansTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/adapters/vdu/BeansTest.java new file mode 100644 index 0000000000..e681d43256 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/adapters/vdu/BeansTest.java @@ -0,0 +1,56 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 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.onap.so.adapters.vdu; + +import org.junit.Test; + +import com.openpojo.reflection.PojoClass; +import com.openpojo.reflection.PojoClassFilter; +import com.openpojo.reflection.filters.FilterPackageInfo; +import com.openpojo.validation.Validator; +import com.openpojo.validation.ValidatorBuilder; +import com.openpojo.validation.rule.impl.GetterMustExistRule; +import com.openpojo.validation.test.impl.GetterTester; +import com.openpojo.validation.test.impl.SetterTester; + +public class BeansTest { + + private PojoClassFilter filterTestClasses = new FilterTestClasses(); + + @Test + public void pojoStructure() { + test("org.onap.so.adapters.vdu"); + } + + private void test(String pojoPackage) { + Validator validator = ValidatorBuilder.create() + .with(new GetterMustExistRule()) + .with(new SetterTester()) + .with(new GetterTester()) + .build(); + validator.validate(pojoPackage, new FilterPackageInfo(), filterTestClasses); + } + private static class FilterTestClasses implements PojoClassFilter { + public boolean include(PojoClass pojoClass) { + return !pojoClass.getSourcePath().contains("/test-classes/"); + } + } +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoAdapterExceptionTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoAdapterExceptionTest.java new file mode 100644 index 0000000000..28a4a8302f --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoAdapterExceptionTest.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.onap.so.openstack.exceptions; + +import org.junit.Test; +import org.junit.Assert; + +public class MsoAdapterExceptionTest { + + @Test + public void testConstructor() { + MsoAdapterException msoAdapterException = new MsoAdapterException("test"); + Assert.assertEquals("test",msoAdapterException.getMessage()); + Assert.assertEquals(MsoExceptionCategory.INTERNAL, msoAdapterException.category); + } + + @Test + public void testOverloadedConstructor() { + MsoAdapterException msoAdapterException = new MsoAdapterException("test" , new Throwable()); + Assert.assertEquals("test",msoAdapterException.getMessage()); + Assert.assertEquals(MsoExceptionCategory.INTERNAL, msoAdapterException.category); + Assert.assertNotNull(msoAdapterException.getCause()); + } + +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoCloudIdentityNotFoundTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoCloudIdentityNotFoundTest.java new file mode 100644 index 0000000000..e7befed71a --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoCloudIdentityNotFoundTest.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.onap.so.openstack.exceptions; + +import org.junit.Test; +import org.junit.Assert; + +public class MsoCloudIdentityNotFoundTest { + + @Test + public void testConstructor() { + MsoCloudIdentityNotFound msoCloudIdentityNotFound = new MsoCloudIdentityNotFound(); + Assert.assertEquals("Cloud Identity not found",msoCloudIdentityNotFound.getMessage()); + Assert.assertEquals("Cloud Identity not found",msoCloudIdentityNotFound.toString()); + Assert.assertEquals(MsoExceptionCategory.USERDATA, msoCloudIdentityNotFound.category); + } + + @Test + public void testOverloadedConstructor() { + MsoCloudIdentityNotFound msoCloudIdentityNotFound = new MsoCloudIdentityNotFound("test"); + Assert.assertEquals("Cloud Identity [test] not found",msoCloudIdentityNotFound.getMessage()); + Assert.assertEquals("Cloud Identity [test] not found",msoCloudIdentityNotFound.toString()); + Assert.assertEquals(MsoExceptionCategory.USERDATA, msoCloudIdentityNotFound.category); + } + +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoCloudSiteNotFoundTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoCloudSiteNotFoundTest.java new file mode 100644 index 0000000000..c75a66e100 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoCloudSiteNotFoundTest.java @@ -0,0 +1,43 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.onap.so.openstack.exceptions; + +import org.junit.Test; +import org.junit.Assert; + +public class MsoCloudSiteNotFoundTest { + + @Test + public void testConstructor() { + MsoCloudSiteNotFound msoCloudSiteNotFound = new MsoCloudSiteNotFound(); + Assert.assertEquals("Cloud site not found",msoCloudSiteNotFound.getMessage()); + Assert.assertEquals("Cloud site not found",msoCloudSiteNotFound.toString()); + Assert.assertEquals(MsoExceptionCategory.USERDATA, msoCloudSiteNotFound.category); + } + + @Test + public void testOverloadedConstructor() { + MsoCloudSiteNotFound msoCloudSiteNotFound = new MsoCloudSiteNotFound("test"); + Assert.assertEquals("Cloud Site [test] not found",msoCloudSiteNotFound.getMessage()); + Assert.assertEquals("Cloud Site [test] not found",msoCloudSiteNotFound.toString()); + Assert.assertEquals(MsoExceptionCategory.USERDATA, msoCloudSiteNotFound.category); + } + +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoIOExceptionTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoIOExceptionTest.java new file mode 100644 index 0000000000..e257e52cd4 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoIOExceptionTest.java @@ -0,0 +1,42 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.onap.so.openstack.exceptions; + +import org.junit.Test; +import org.junit.Assert; + +public class MsoIOExceptionTest { + + @Test + public void testConstructor() { + MsoIOException msoIOException = new MsoIOException("test"); + Assert.assertEquals("test",msoIOException.getMessage()); + Assert.assertEquals(MsoExceptionCategory.IO, msoIOException.category); + } + + @Test + public void testOverloadedConstructor() { + MsoIOException msoIOException = new MsoIOException("test", new Throwable()); + Assert.assertEquals("test",msoIOException.getMessage()); + Assert.assertEquals(MsoExceptionCategory.IO, msoIOException.category); + Assert.assertNotNull(msoIOException.getCause()); + } + +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoNetworkAlreadyExistsTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoNetworkAlreadyExistsTest.java new file mode 100644 index 0000000000..96ff89c094 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoNetworkAlreadyExistsTest.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.onap.so.openstack.exceptions; + +import org.junit.Test; +import org.junit.Assert; + +public class MsoNetworkAlreadyExistsTest { + + @Test + public void testConstructor() { + MsoNetworkAlreadyExists msoNetworkAlreadyExists = new MsoNetworkAlreadyExists("test","test","test"); + Assert.assertEquals("Stack test already exists in Tenant test in Cloud test",msoNetworkAlreadyExists.getMessage()); + Assert.assertEquals("409 Conflict: Stack test already exists in Tenant test in Cloud test",msoNetworkAlreadyExists.toString()); + } + +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoNetworkNotFoundTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoNetworkNotFoundTest.java new file mode 100644 index 0000000000..5991e55915 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoNetworkNotFoundTest.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.onap.so.openstack.exceptions; + +import org.junit.Test; +import org.junit.Assert; + +public class MsoNetworkNotFoundTest { + + @Test + public void testConstructor() { + MsoNetworkNotFound msoNetworkNotFound =new MsoNetworkNotFound("test","test","test"); + Assert.assertEquals("Network test does not exist in Cloud/Tenant test/test",msoNetworkNotFound.getMessage()); + Assert.assertEquals("404 Not Found: Network test does not exist in Cloud/Tenant test/test",msoNetworkNotFound.toString()); + } + +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoOpenstackExceptionTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoOpenstackExceptionTest.java new file mode 100644 index 0000000000..7bdb2283e8 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoOpenstackExceptionTest.java @@ -0,0 +1,46 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.onap.so.openstack.exceptions; + +import org.junit.Test; +import org.junit.Assert; + +public class MsoOpenstackExceptionTest { + + @Test + public void testConstructor() { + MsoOpenstackException msoOpenstackException= new MsoOpenstackException(404,"test","test"); + Assert.assertEquals("test",msoOpenstackException.getMessage()); + Assert.assertEquals("404 test: test",msoOpenstackException.toString()); + Assert.assertEquals(MsoExceptionCategory.OPENSTACK, msoOpenstackException.category); + } + + @Test + public void testOverloadedConstructor() { + MsoOpenstackException msoOpenstackExceptionEx= new MsoOpenstackException(404,"test","test",new Exception()); + Assert.assertEquals("test",msoOpenstackExceptionEx.getMessage()); + Assert.assertEquals("404 test: test",msoOpenstackExceptionEx.toString()); + Assert.assertEquals(MsoExceptionCategory.OPENSTACK, msoOpenstackExceptionEx.category); + Assert.assertNotNull(msoOpenstackExceptionEx.getCause()); + + } + +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoStackAlreadyExistsTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoStackAlreadyExistsTest.java new file mode 100644 index 0000000000..4b44f0db93 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoStackAlreadyExistsTest.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.onap.so.openstack.exceptions; + +import org.junit.Assert; +import org.junit.Test; + +public class MsoStackAlreadyExistsTest { + + @Test + public void testConstructor() { + MsoStackAlreadyExists msoStackAlreadyExists = new MsoStackAlreadyExists("test", "test", "test"); + Assert.assertEquals("Stack test already exists in Tenant test in Cloud test",msoStackAlreadyExists.getMessage()); + Assert.assertEquals("409 Conflict: Stack test already exists in Tenant test in Cloud test",msoStackAlreadyExists.toString()); + } +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoStackNotFoundTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoStackNotFoundTest.java new file mode 100644 index 0000000000..8ce5a33cc4 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoStackNotFoundTest.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.onap.so.openstack.exceptions; + +import org.junit.Assert; +import org.junit.Test; + +public class MsoStackNotFoundTest { + + @Test + public void testConstructor() { + MsoStackNotFound msoStackNotFound = new MsoStackNotFound("test", "test", "test"); + Assert.assertEquals("Stack test does not exist in Cloud/Tenant test/test",msoStackNotFound.getMessage()); + Assert.assertEquals("404 Not Found: Stack test does not exist in Cloud/Tenant test/test",msoStackNotFound.toString()); + } +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoTenantAlreadyExistsTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoTenantAlreadyExistsTest.java new file mode 100644 index 0000000000..5999a587a5 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoTenantAlreadyExistsTest.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.onap.so.openstack.exceptions; + +import org.junit.Assert; +import org.junit.Test; + +public class MsoTenantAlreadyExistsTest { + + @Test + public void testConstructor() { + MsoTenantAlreadyExists msoTenantAlreadyExists = new MsoTenantAlreadyExists("test","test"); + Assert.assertEquals("Tenant test already exists in Cloud test",msoTenantAlreadyExists.getMessage()); + Assert.assertEquals("409 Conflict: Tenant test already exists in Cloud test",msoTenantAlreadyExists.toString()); + } +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoTenantNotFoundTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoTenantNotFoundTest.java new file mode 100644 index 0000000000..23df616573 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/exceptions/MsoTenantNotFoundTest.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2018 Huawei 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.onap.so.openstack.exceptions; + +import org.junit.Assert; +import org.junit.Test; + +public class MsoTenantNotFoundTest { + + @Test + public void testConstructor() { + MsoTenantNotFound msoTenantNotFound = new MsoTenantNotFound("test","test"); + Assert.assertEquals("Tenant test does not exist in Cloud test",msoTenantNotFound.getMessage()); + Assert.assertEquals("404 Not Found: Tenant test does not exist in Cloud test",msoTenantNotFound.toString()); + } + +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/mappers/NetworkInfoMapperTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/mappers/NetworkInfoMapperTest.java new file mode 100644 index 0000000000..90e15f8ba5 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/mappers/NetworkInfoMapperTest.java @@ -0,0 +1,124 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.openstack.mappers; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import org.javatuples.Pair; +import org.junit.Test; +import org.onap.so.openstack.beans.NetworkInfo; +import org.onap.so.openstack.beans.NetworkStatus; + +import com.woorea.openstack.quantum.model.Network; +import com.woorea.openstack.quantum.model.Segment; + +public class NetworkInfoMapperTest { + + @Test + public void checkNetworkStatusMap() { + NetworkInfoMapper mapper = new NetworkInfoMapper(new Network()); + assertEquals(NetworkStatus.ACTIVE, mapper.mapStatus("ACTIVE")); + assertEquals(NetworkStatus.BUILD, mapper.mapStatus("BUILD")); + assertEquals(NetworkStatus.ERROR, mapper.mapStatus("ERROR")); + assertEquals(NetworkStatus.DOWN, mapper.mapStatus("DOWN")); + assertEquals(NetworkStatus.UNKNOWN, mapper.mapStatus("NOT IN MAP")); + assertEquals(NetworkStatus.UNKNOWN, mapper.mapStatus(null)); + } + + @Test + public void checkLocateVlanInformationNoSegments() { + Network network = new Network(); + network.setProviderPhysicalNetwork("test-physical-network"); + network.setProviderNetworkType("vlan"); + network.setProviderSegmentationId(2); + NetworkInfoMapper mapper = new NetworkInfoMapper(network); + NetworkInfo result = mapper.map(); + assertEquals("test-physical-network", result.getProvider()); + assertEquals(1, result.getVlans().size()); + assertEquals(2, result.getVlans().get(0).intValue()); + } + + @Test + public void checkLocateVlanInformationSegments() { + Network network = new Network(); + addSegments(network); + + NetworkInfoMapper mapper = new NetworkInfoMapper(network); + NetworkInfo result = mapper.map(); + assertEquals("type1", result.getProvider()); + assertEquals(2, result.getVlans().size()); + assertEquals(Arrays.asList(1, 2).toString(), result.getVlans().toString()); + } + + @Test + public void checkLocateVlanInformationSegmentsAndPhysical() { + Network network = new Network(); + addSegments(network); + network.setProviderPhysicalNetwork("test-physical-network"); + network.setProviderNetworkType("vlan"); + network.setProviderSegmentationId(2); + NetworkInfoMapper mapper = new NetworkInfoMapper(network); + NetworkInfo result = mapper.map(); + assertEquals("test-physical-network", result.getProvider()); + assertEquals(1, result.getVlans().size()); + assertEquals(2, result.getVlans().get(0).intValue()); + } + + @Test + public void nullNetwork() { + NetworkInfoMapper mapper = new NetworkInfoMapper(null); + assertEquals(NetworkStatus.NOTFOUND, mapper.map().getStatus()); + } + + @Test + public void mapFields() { + Network network = new Network(); + network.setId("id"); + network.setName("name"); + network.setSubnets(Arrays.asList("string1", "string2")); + NetworkInfoMapper mapper = new NetworkInfoMapper(network); + NetworkInfo mapped = mapper.map(); + assertEquals("name", mapped.getName()); + assertEquals("id", mapped.getId()); + assertEquals(network.getSubnets(), mapped.getSubnets()); + } + + private Network addSegments(Network network) { + List<Segment> segments = new ArrayList<>(); + Segment segment1 = new Segment(); + segment1.setProviderPhysicalNetwork("type1"); + segment1.setProviderNetworkType("vlan"); + segment1.setProviderSegmentationId(1); + segments.add(segment1); + Segment segment2 = new Segment(); + segment2.setProviderPhysicalNetwork("type2"); + segment2.setProviderNetworkType("vlan"); + segment2.setProviderSegmentationId(2); + segments.add(segment2); + network.setSegments(segments); + return network; + } +} diff --git a/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/mappers/StackInfoMapperTest.java b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/mappers/StackInfoMapperTest.java new file mode 100644 index 0000000000..f01745f8c1 --- /dev/null +++ b/adapters/mso-adapters-rest-interface/src/test/java/org/onap/so/openstack/mappers/StackInfoMapperTest.java @@ -0,0 +1,94 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * 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.onap.so.openstack.mappers; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.onap.so.openstack.beans.HeatStatus; +import org.onap.so.openstack.beans.StackInfo; + +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.woorea.openstack.heat.model.Stack; + +public class StackInfoMapperTest { + + private static final String PATH = "src/test/resources/"; + @Test + public void nullStack() { + StackInfoMapper mapper = new StackInfoMapper(null); + assertEquals(HeatStatus.NOTFOUND, mapper.map().getStatus()); + } + + @Test + public void checkHeatStatusMap() { + StackInfoMapper mapper = new StackInfoMapper(null); + assertEquals(HeatStatus.BUILDING, mapper.mapStatus("CREATE_IN_PROGRESS")); + assertEquals(HeatStatus.CREATED, mapper.mapStatus("CREATE_COMPLETE")); + assertEquals(HeatStatus.FAILED, mapper.mapStatus("CREATE_FAILED")); + assertEquals(HeatStatus.DELETING, mapper.mapStatus("DELETE_IN_PROGRESS")); + assertEquals(HeatStatus.NOTFOUND, mapper.mapStatus("DELETE_COMPLETE")); + assertEquals(HeatStatus.FAILED, mapper.mapStatus("DELETE_FAILED")); + assertEquals(HeatStatus.UPDATING, mapper.mapStatus("UPDATE_IN_PROGRESS")); + assertEquals(HeatStatus.FAILED, mapper.mapStatus("UPDATE_FAILED")); + assertEquals(HeatStatus.UPDATED, mapper.mapStatus("UPDATE_COMPLETE")); + assertEquals(HeatStatus.INIT, mapper.mapStatus(null)); + assertEquals(HeatStatus.UNKNOWN, mapper.mapStatus("status-not-there")); + } + + @Test + public void checkOutputToMap() throws JsonParseException, JsonMappingException, IOException { + ObjectMapper jacksonMapper = new ObjectMapper(); + Stack sample = jacksonMapper.readValue(this.getJson("stack-example.json"), Stack.class); + StackInfoMapper mapper = new StackInfoMapper(sample); + StackInfo result = mapper.map(); + Map<String, Object> map = result.getOutputs(); + assertEquals(true, map.containsKey("key2")); + assertEquals("value1", map.get("key1")); + } + + @Test + public void mapRemainingFields() { + Stack stack = new Stack(); + stack.setStackName("name"); + stack.setId("id"); + stack.setStackStatusReason("message"); + stack.setParameters(new HashMap<String, Object>()); + StackInfoMapper mapper = new StackInfoMapper(stack); + StackInfo info = mapper.map(); + assertEquals("name", info.getName()); + assertEquals("name/id", info.getCanonicalName()); + assertEquals("message", info.getStatusMessage()); + assertEquals(stack.getParameters(), info.getParameters()); + } + + private String getJson(String filename) throws IOException { + return new String(Files.readAllBytes(Paths.get(PATH + filename))); + } +} |