2 * Copyright 2016-2017, Nokia Corporation
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer;
18 import org.junit.Test;
19 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
20 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
22 import java.io.ByteArrayInputStream;
23 import java.io.ByteArrayOutputStream;
24 import java.io.PrintStream;
26 import static junit.framework.TestCase.assertEquals;
27 import static org.mockito.Mockito.when;
28 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CatalogManager.getFileInZip;
31 public class TestOnapVnfPackageBuilder extends TestBase {
34 * The the main reads from standard in and writes to standard out
37 public void testInputStreams() throws Exception {
38 ByteArrayOutputStream bos = new ByteArrayOutputStream();
39 PrintStream actualOut = new PrintStream(bos, true);
40 when(systemFunctions.out()).thenReturn(actualOut);
41 when(systemFunctions.in()).thenReturn(new ByteArrayInputStream(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip")));
42 when(systemFunctions.loadFile("cbam.pre.collectConnectionPoints.js")).thenCallRealMethod();
43 when(systemFunctions.loadFile("cbam.collectConnectionPoints.js")).thenCallRealMethod();
44 when(systemFunctions.loadFile("cbam.post.collectConnectionPoints.js")).thenCallRealMethod();
45 when(systemFunctions.loadFile("TOSCA.meta")).thenCallRealMethod();
46 when(systemFunctions.loadFile("MainServiceTemplate.meta")).thenCallRealMethod();
49 String cbamVnfd = new String(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip.vnfd"));
50 String expectedOnapVnfd = new OnapVnfdBuilder().toOnapVnfd(cbamVnfd);
53 OnapVnfPackageBuilder.main(null);
55 assertFileInZip(bos.toByteArray(), "TOSCA-Metadata/TOSCA.meta", TestUtil.loadFile("TOSCA.meta"));
56 assertFileInZip(bos.toByteArray(), "Definitions/MainServiceTemplate.yaml", expectedOnapVnfd.getBytes());
57 assertFileInZip(bos.toByteArray(), "MainServiceTemplate.yaml", expectedOnapVnfd.getBytes());
58 assertFileInZip(bos.toByteArray(), "MainServiceTemplate.meta", TestUtil.loadFile("MainServiceTemplate.meta"));
59 ByteArrayOutputStream actualModifiedCbamVnfPackage = getFileInZip(new ByteArrayInputStream(bos.toByteArray()), "Artifacts/Deployment/OTHER/cbam.package.zip");
60 byte[] expectedModifiedCbamPackage = new CbamVnfPackageBuilder().toModifiedCbamVnfPackage(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip"), "vnfdloc/a.yaml", new CbamVnfdBuilder().build(cbamVnfd));
61 assertItenticalZips(expectedModifiedCbamPackage, actualModifiedCbamVnfPackage.toByteArray());
66 * Prevents moving the class (customer documentation) must be updated
69 public void testPreventMove() {
70 assertEquals("org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.OnapVnfPackageBuilder", OnapVnfPackageBuilder.class.getCanonicalName());