Removing jackson to mitigate cve-2017-4995
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / driver / src / test / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / nokia / packagetransformer / TestOnapVnfPackageBuilder.java
1 /*
2  * Copyright 2016-2017, Nokia Corporation
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer;
17
18 import java.io.ByteArrayInputStream;
19 import java.io.ByteArrayOutputStream;
20 import java.io.PrintStream;
21 import org.junit.Test;
22 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
23 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
24
25 import static junit.framework.TestCase.assertEquals;
26 import static org.mockito.Mockito.when;
27 import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CatalogManager.getFileInZip;
28
29
30 public class TestOnapVnfPackageBuilder extends TestBase {
31
32     /**
33      * The the main reads from standard in and writes to standard out
34      */
35     @Test
36     public void testInputStreams() throws Exception {
37         ByteArrayOutputStream bos = new ByteArrayOutputStream();
38         PrintStream actualOut = new PrintStream(bos, true);
39         when(systemFunctions.out()).thenReturn(actualOut);
40         when(systemFunctions.in()).thenReturn(new ByteArrayInputStream(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip")));
41         when(systemFunctions.loadFile("cbam.pre.collectConnectionPoints.js")).thenCallRealMethod();
42         when(systemFunctions.loadFile("cbam.collectConnectionPoints.js")).thenCallRealMethod();
43         when(systemFunctions.loadFile("cbam.post.collectConnectionPoints.js")).thenCallRealMethod();
44         when(systemFunctions.loadFile("TOSCA.meta")).thenCallRealMethod();
45         when(systemFunctions.loadFile("MainServiceTemplate.meta")).thenCallRealMethod();
46
47
48         String cbamVnfd = new String(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip.vnfd"));
49         String expectedOnapVnfd = new OnapVnfdBuilder().toOnapVnfd(cbamVnfd);
50
51         //when
52         OnapVnfPackageBuilder.main(null);
53         //verify
54         assertFileInZip(bos.toByteArray(), "TOSCA-Metadata/TOSCA.meta", TestUtil.loadFile("TOSCA.meta"));
55         assertFileInZip(bos.toByteArray(), "Definitions/MainServiceTemplate.yaml", expectedOnapVnfd.getBytes());
56         assertFileInZip(bos.toByteArray(), "MainServiceTemplate.yaml", expectedOnapVnfd.getBytes());
57         assertFileInZip(bos.toByteArray(), "MainServiceTemplate.meta", TestUtil.loadFile("MainServiceTemplate.meta"));
58         ByteArrayOutputStream actualModifiedCbamVnfPackage = getFileInZip(new ByteArrayInputStream(bos.toByteArray()), "Artifacts/Deployment/OTHER/cbam.package.zip");
59         byte[] expectedModifiedCbamPackage = new CbamVnfPackageBuilder().toModifiedCbamVnfPackage(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip"), "vnfdloc/a.yaml", new CbamVnfdBuilder().build(cbamVnfd));
60         assertItenticalZips(expectedModifiedCbamPackage, actualModifiedCbamVnfPackage.toByteArray());
61     }
62
63
64     /**
65      * Prevents moving the class (customer documentation) must be updated
66      */
67     @Test
68     public void testPreventMove() {
69         assertEquals("org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.OnapVnfPackageBuilder", OnapVnfPackageBuilder.class.getCanonicalName());
70     }
71
72
73 }