From d4ee0c786ca2cc27b35fdfaa7d9d53718fa0bd20 Mon Sep 17 00:00:00 2001 From: Denes Nemeth Date: Thu, 31 May 2018 13:59:34 +0200 Subject: Fix template generation for R2 Change-Id: Ibf53ee4f203f248c930611812f3eb248e3023be8 Signed-off-by: Denes Nemeth Issue-ID: VFC-728 --- .../driver/vnfm/svnfm/nokia/FullUnitTestSuite.java | 8 +- .../TestOnapAbstractVnfdBuilder.java | 33 +++++++++ .../packagetransformer/TestOnapR1VnfdBuilder.java | 77 ++++++++++++++++++++ .../packagetransformer/TestOnapR2VnfdBuilder.java | 8 +- .../TestOnapVnfPackageBuilder.java | 53 +++++++++++++- .../packagetransformer/TestOnapVnfdBuilder.java | 85 ---------------------- .../vnfm/svnfm/nokia/restapi/TestConverterApi.java | 25 ++++++- 7 files changed, 191 insertions(+), 98 deletions(-) create mode 100644 nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapAbstractVnfdBuilder.java create mode 100644 nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapR1VnfdBuilder.java delete mode 100644 nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java (limited to 'nokiav2/driver/src/test/java/org/onap/vfc') diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/FullUnitTestSuite.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/FullUnitTestSuite.java index 69e3482c..b37d95ff 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/FullUnitTestSuite.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/FullUnitTestSuite.java @@ -28,10 +28,7 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.TestSdcPackageProvi import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.direct.notification.*; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.so.TestSoLifecycleManager; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.vfc.*; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.TestCbamVnfPackageBuilder; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.TestCbamVnfdBuilder; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.TestOnapVnfPackageBuilder; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.TestOnapVnfdBuilder; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.*; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi.*; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.TestRealConfig; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring.TestServletInitializer; @@ -70,7 +67,8 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.TestReportedA TestVfcNotificationSender.class, TestCbamVnfdBuilder.class, - TestOnapVnfdBuilder.class, + TestOnapR1VnfdBuilder.class, + TestOnapR2VnfdBuilder.class, TestCbamVnfPackageBuilder.class, TestOnapVnfPackageBuilder.class, diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapAbstractVnfdBuilder.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapAbstractVnfdBuilder.java new file mode 100644 index 00000000..0d2c348c --- /dev/null +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapAbstractVnfdBuilder.java @@ -0,0 +1,33 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * 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. + */ +package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer; + +import org.junit.Test; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; + +import static junit.framework.TestCase.assertEquals; + +public class TestOnapAbstractVnfdBuilder extends TestBase { + + @Test + public void indent() { + assertEquals(" x", OnapAbstractVnfdBuilder.indent("x", 2)); + assertEquals(" x\n", OnapAbstractVnfdBuilder.indent("x\n", 2)); + assertEquals(" x\n y", OnapAbstractVnfdBuilder.indent("x\ny", 2)); + assertEquals(" x\n y\n", OnapAbstractVnfdBuilder.indent("x\ny\n", 2)); + assertEquals(" \n", OnapAbstractVnfdBuilder.indent("\n", 2)); + } +} diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapR1VnfdBuilder.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapR1VnfdBuilder.java new file mode 100644 index 00000000..8c0e8a46 --- /dev/null +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapR1VnfdBuilder.java @@ -0,0 +1,77 @@ +/* + * Copyright 2016-2017, Nokia Corporation + * + * 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. + */ +package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer; + +import java.util.NoSuchElementException; +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; + +import static junit.framework.TestCase.assertEquals; +import static junit.framework.TestCase.fail; +import static org.mockito.Mockito.verify; +import static org.springframework.test.util.ReflectionTestUtils.setField; + + +public class TestOnapR1VnfdBuilder extends TestBase { + private OnapR1VnfdBuilder packageTransformer = new OnapR1VnfdBuilder(); + + + @Before + public void init() { + setField(OnapAbstractVnfdBuilder.class, "logger", logger); + setField(OnapR1VnfdBuilder.class, "logger", logger); + } + + /** + * Test empty VNFD conversion + */ + @Test + public void testEmpty() { + assertEquals(new String(TestUtil.loadFile("unittests/packageconverter/empty.vnfd.onap.yaml")), packageTransformer.toOnapVnfd(new String(TestUtil.loadFile("unittests/packageconverter/empty.vnfd.cbam.yaml")))); + } + + /** + * Test all Tosca nodes conversions for successful scenario + */ + @Test + public void testNodes() { + assertEquals(new String(TestUtil.loadFile("unittests/packageconverter/nodes.vnfd.onap.yaml")), packageTransformer.toOnapVnfd(new String(TestUtil.loadFile("unittests/packageconverter/nodes.vnfd.cbam.yaml")))); + verify(logger).warn("The {} ecp does not have an internal connection point", "myEcpWithoutIcp"); + verify(logger).warn("The {} ecp does not have an requirements section", "ecpWithIcpWithOutRequirements"); + verify(logger).warn("The {} internal connection point of the {} ecp does not have a VDU", "icpWithoutVdu", "myEcpWithoutIcpWithoutVdu"); + verify(logger).warn("The {} internal connection point of the {} ecp does not have a requirements section", "icpWithOutRequiements", "myEcpWithoutIcpWithoutIcpReq"); + verify(logger).warn("The {} internal connection point does not have a VDU", "icpWithOutVdu"); + verify(logger).warn("The {} internal connection point does not have a requirements section", "icpWithOutRequiements"); + verify(logger).warn("The {} internal connection point does not have a VL", "icpWithOutVl"); + verify(logger).warn("The {} type is not converted", "tosca.nodes.nfv.Unknown"); + } + + /** + * if a node refers to a non existing node it results in a failure + */ + @Test + public void testInconsistentVnfd() { + try { + packageTransformer.toOnapVnfd(new String(TestUtil.loadFile("unittests/packageconverter/nodes.vnfd.inconsistent.cbam.yaml"))); + fail(); + } catch (NoSuchElementException e) { + assertEquals("The VNFD does not have a node called myComputeMissing but required by an other node", e.getMessage()); + } + } + +} diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapR2VnfdBuilder.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapR2VnfdBuilder.java index 6916d382..a8f6a645 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapR2VnfdBuilder.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapR2VnfdBuilder.java @@ -23,6 +23,7 @@ import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; import static junit.framework.TestCase.assertEquals; import static junit.framework.TestCase.fail; +import static org.mockito.Mockito.verify; import static org.springframework.test.util.ReflectionTestUtils.setField; @@ -32,7 +33,8 @@ public class TestOnapR2VnfdBuilder extends TestBase { @Before public void init() { - setField(OnapVnfdBuilder.class, "logger", logger); + setField(OnapAbstractVnfdBuilder.class, "logger", logger); + setField(OnapR2VnfdBuilder.class, "logger", logger); } @@ -50,14 +52,14 @@ public class TestOnapR2VnfdBuilder extends TestBase { @Test public void testNodes() { assertEquals(new String(TestUtil.loadFile("unittests/packageconverter/nodes.vnfd.onap.v2.yaml")), packageTransformer.toOnapVnfd(new String(TestUtil.loadFile("unittests/packageconverter/nodes.vnfd.cbam.yaml")))); - /* verify(logger).warn("The {} ecp does not have an internal connection point", "myEcpWithoutIcp"); + verify(logger).warn("The {} ecp does not have an internal connection point", "myEcpWithoutIcp"); verify(logger).warn("The {} ecp does not have an requirements section", "ecpWithIcpWithOutRequirements"); verify(logger).warn("The {} internal connection point of the {} ecp does not have a VDU", "icpWithoutVdu", "myEcpWithoutIcpWithoutVdu"); verify(logger).warn("The {} internal connection point of the {} ecp does not have a requirements section", "icpWithOutRequiements", "myEcpWithoutIcpWithoutIcpReq"); verify(logger).warn("The {} internal connection point does not have a VDU", "icpWithOutVdu"); verify(logger).warn("The {} internal connection point does not have a requirements section", "icpWithOutRequiements"); verify(logger).warn("The {} internal connection point does not have a VL", "icpWithOutVl"); - verify(logger).warn("The {} type is not converted", "tosca.nodes.nfv.Unknown")*/ + verify(logger).warn("The {} type is not converted", "tosca.nodes.nfv.Unknown"); } /** diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfPackageBuilder.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfPackageBuilder.java index 55949ab0..d2a92556 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfPackageBuilder.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfPackageBuilder.java @@ -46,10 +46,10 @@ public class TestOnapVnfPackageBuilder extends TestBase { when(systemFunctions.loadFile("MainServiceTemplate.mf")).thenCallRealMethod(); String cbamVnfd = new String(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip.vnfd")); - String expectedOnapVnfd = new OnapVnfdBuilder().toOnapVnfd(cbamVnfd); + String expectedOnapVnfd = new OnapR1VnfdBuilder().toOnapVnfd(cbamVnfd); //when - OnapR1VnfPackageBuilder.main(null); + OnapVnfPackageBuilder.main(null); //verify assertFileInZip(bos.toByteArray(), "TOSCA-Metadata/TOSCA.meta", TestUtil.loadFile("TOSCA.meta")); assertFileInZip(bos.toByteArray(), "MainServiceTemplate.yaml", expectedOnapVnfd.getBytes()); @@ -59,13 +59,60 @@ public class TestOnapVnfPackageBuilder extends TestBase { assertItenticalZips(expectedModifiedCbamPackage, actualModifiedCbamVnfPackage.toByteArray()); } + /** + * Test conversion for V1 package + */ + @Test + public void testConversionViaV1() throws Exception { + when(systemFunctions.loadFile("cbam.pre.collectConnectionPoints.js")).thenCallRealMethod(); + when(systemFunctions.loadFile("cbam.collectConnectionPoints.js")).thenCallRealMethod(); + when(systemFunctions.loadFile("cbam.post.collectConnectionPoints.js")).thenCallRealMethod(); + when(systemFunctions.loadFile("TOSCA.meta")).thenCallRealMethod(); + when(systemFunctions.loadFile("MainServiceTemplate.mf")).thenCallRealMethod(); + + String cbamVnfd = new String(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip.vnfd")); + String expectedOnapVnfd = new OnapR1VnfdBuilder().toOnapVnfd(cbamVnfd); + //when + byte[] convertedPackage = new OnapVnfPackageBuilder().covert(new ByteArrayInputStream(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip")), SupportedOnapPackageVersions.V1); + //verify + assertFileInZip(convertedPackage, "TOSCA-Metadata/TOSCA.meta", TestUtil.loadFile("TOSCA.meta")); + assertFileInZip(convertedPackage, "MainServiceTemplate.yaml", expectedOnapVnfd.getBytes()); + assertFileInZip(convertedPackage, "MainServiceTemplate.mf", TestUtil.loadFile("MainServiceTemplate.mf")); + ByteArrayOutputStream actualModifiedCbamVnfPackage = getFileInZip(new ByteArrayInputStream(convertedPackage), "Artifacts/Deployment/OTHER/cbam.package.zip"); + byte[] expectedModifiedCbamPackage = new CbamVnfPackageBuilder().toModifiedCbamVnfPackage(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip"), "vnfdloc/a.yaml", new CbamVnfdBuilder().build(cbamVnfd)); + assertItenticalZips(expectedModifiedCbamPackage, actualModifiedCbamVnfPackage.toByteArray()); + } + + /** + * Test conversion for V2 package + */ + @Test + public void testConversionViaV2() throws Exception { + when(systemFunctions.loadFile("cbam.pre.collectConnectionPoints.js")).thenCallRealMethod(); + when(systemFunctions.loadFile("cbam.collectConnectionPoints.js")).thenCallRealMethod(); + when(systemFunctions.loadFile("cbam.post.collectConnectionPoints.js")).thenCallRealMethod(); + when(systemFunctions.loadFile("TOSCA.meta")).thenCallRealMethod(); + when(systemFunctions.loadFile("MainServiceTemplate.mf")).thenCallRealMethod(); + + String cbamVnfd = new String(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip.vnfd")); + String expectedOnapVnfd = new OnapR2VnfdBuilder().toOnapVnfd(cbamVnfd); + //when + byte[] convertedPackage = new OnapVnfPackageBuilder().covert(new ByteArrayInputStream(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip")), SupportedOnapPackageVersions.V2); + //verify + assertFileInZip(convertedPackage, "TOSCA-Metadata/TOSCA.meta", TestUtil.loadFile("TOSCA.meta")); + assertFileInZip(convertedPackage, "MainServiceTemplate.yaml", expectedOnapVnfd.getBytes()); + assertFileInZip(convertedPackage, "MainServiceTemplate.mf", TestUtil.loadFile("MainServiceTemplate.mf")); + ByteArrayOutputStream actualModifiedCbamVnfPackage = getFileInZip(new ByteArrayInputStream(convertedPackage), "Artifacts/Deployment/OTHER/cbam.package.zip"); + byte[] expectedModifiedCbamPackage = new CbamVnfPackageBuilder().toModifiedCbamVnfPackage(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip"), "vnfdloc/a.yaml", new CbamVnfdBuilder().build(cbamVnfd)); + assertItenticalZips(expectedModifiedCbamPackage, actualModifiedCbamVnfPackage.toByteArray()); + } /** * Prevents moving the class (customer documentation) must be updated */ @Test public void testPreventMove() { - assertEquals("b3JnLm9uYXAudmZjLm5mdm8uZHJpdmVyLnZuZm0uc3ZuZm0ubm9raWEucGFja2FnZXRyYW5zZm9ybWVyLk9uYXBSMVZuZlBhY2thZ2VCdWlsZGVy", Base64.getEncoder().encodeToString(OnapR1VnfPackageBuilder.class.getCanonicalName().getBytes())); + assertEquals("b3JnLm9uYXAudmZjLm5mdm8uZHJpdmVyLnZuZm0uc3ZuZm0ubm9raWEucGFja2FnZXRyYW5zZm9ybWVyLk9uYXBWbmZQYWNrYWdlQnVpbGRlcg==", Base64.getEncoder().encodeToString(OnapVnfPackageBuilder.class.getCanonicalName().getBytes())); } diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java deleted file mode 100644 index a97ee4f1..00000000 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfdBuilder.java +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2016-2017, Nokia Corporation - * - * 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. - */ -package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer; - -import java.util.NoSuchElementException; -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; - -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.fail; -import static org.mockito.Mockito.verify; -import static org.springframework.test.util.ReflectionTestUtils.setField; - - -public class TestOnapVnfdBuilder extends TestBase { - private OnapVnfdBuilder packageTransformer = new OnapVnfdBuilder(); - - - @Before - public void init() { - setField(OnapVnfdBuilder.class, "logger", logger); - } - - @Test - public void indent() { - assertEquals(" x", packageTransformer.indent("x", 2)); - assertEquals(" x\n", packageTransformer.indent("x\n", 2)); - assertEquals(" x\n y", packageTransformer.indent("x\ny", 2)); - assertEquals(" x\n y\n", packageTransformer.indent("x\ny\n", 2)); - assertEquals(" \n", packageTransformer.indent("\n", 2)); - } - - /** - * Test empty VNFD conversion - */ - @Test - public void testEmpty() { - assertEquals(new String(TestUtil.loadFile("unittests/packageconverter/empty.vnfd.onap.yaml")), packageTransformer.toOnapVnfd(new String(TestUtil.loadFile("unittests/packageconverter/empty.vnfd.cbam.yaml")))); - } - - /** - * Test all Tosca nodes conversions for successful scenario - */ - @Test - public void testNodes() { - assertEquals(new String(TestUtil.loadFile("unittests/packageconverter/nodes.vnfd.onap.yaml")), packageTransformer.toOnapVnfd(new String(TestUtil.loadFile("unittests/packageconverter/nodes.vnfd.cbam.yaml")))); - verify(logger).warn("The {} ecp does not have an internal connection point", "myEcpWithoutIcp"); - verify(logger).warn("The {} ecp does not have an requirements section", "ecpWithIcpWithOutRequirements"); - verify(logger).warn("The {} internal connection point of the {} ecp does not have a VDU", "icpWithoutVdu", "myEcpWithoutIcpWithoutVdu"); - verify(logger).warn("The {} internal connection point of the {} ecp does not have a requirements section", "icpWithOutRequiements", "myEcpWithoutIcpWithoutIcpReq"); - verify(logger).warn("The {} internal connection point does not have a VDU", "icpWithOutVdu"); - verify(logger).warn("The {} internal connection point does not have a requirements section", "icpWithOutRequiements"); - verify(logger).warn("The {} internal connection point does not have a VL", "icpWithOutVl"); - verify(logger).warn("The {} type is not converted", "tosca.nodes.nfv.Unknown"); - } - - /** - * if a node refers to a non existing node it results in a failure - */ - @Test - public void testInconsitentVnfd() { - try { - packageTransformer.toOnapVnfd(new String(TestUtil.loadFile("unittests/packageconverter/nodes.vnfd.inconsistent.cbam.yaml"))); - fail(); - } catch (NoSuchElementException e) { - assertEquals("The VNFD does not have a node called myComputeMissing but required by an other node", e.getMessage()); - } - } - -} diff --git a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java index 48d2cab0..99fd203a 100644 --- a/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java +++ b/nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java @@ -31,7 +31,7 @@ import org.mockito.Mock; import org.mockito.Mockito; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.CbamVnfPackageBuilder; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.CbamVnfdBuilder; -import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.OnapVnfdBuilder; +import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.OnapR1VnfdBuilder; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase; import org.springframework.http.HttpHeaders; @@ -88,7 +88,7 @@ public class TestConverterApi extends TestBase { private void verifyVnfPackageWritterToOutputStream(ByteArrayOutputStream bos) throws Exception { String cbamVnfd = new String(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip.vnfd")); - String expectedOnapVnfd = new OnapVnfdBuilder().toOnapVnfd(cbamVnfd); + String expectedOnapVnfd = new OnapR1VnfdBuilder().toOnapVnfd(cbamVnfd); assertFileInZip(bos.toByteArray(), "TOSCA-Metadata/TOSCA.meta", TestUtil.loadFile("TOSCA.meta")); assertFileInZip(bos.toByteArray(), "MainServiceTemplate.yaml", expectedOnapVnfd.getBytes()); assertFileInZip(bos.toByteArray(), "MainServiceTemplate.mf", TestUtil.loadFile("MainServiceTemplate.mf")); @@ -133,6 +133,27 @@ public class TestConverterApi extends TestBase { } } + /** + * error is propagated if unable to extract version from HTTP request + */ + @Test + public void testUnableToExtractVersion() throws Exception { + IOException expectedException = new IOException(); + Part part = Mockito.mock(Part.class); + when(part.getInputStream()).thenReturn(new ByteArrayInputStream(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip"))); + when(httpRequest.getPart("fileToUpload")).thenReturn(part); + when(httpRequest.getPart("version")).thenThrow(expectedException); + when(part.getInputStream()).thenReturn(new ByteArrayInputStream("V1".getBytes())); + try { + converterApi.convert(httpResponse, httpRequest); + fail(); + } catch (Exception e) { + verify(logger).error("Unable to determine the desired ONAP package version", expectedException); + assertEquals("Unable to determine the desired ONAP package version", e.getMessage()); + assertEquals(expectedException, e.getCause()); + } + } + /** * error is propagated if unable to extract package from HTTP request */ -- cgit 1.2.3-korg