Fix automatic package conversion
[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 java.util.Base64;
22 import org.junit.Test;
23 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
24 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
25
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;
29
30
31 public class TestOnapVnfPackageBuilder extends TestBase {
32
33     /**
34      * The the main reads from standard in and writes to standard out
35      */
36     @Test
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.mf")).thenCallRealMethod();
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(), "MainServiceTemplate.yaml", expectedOnapVnfd.getBytes());
56         assertFileInZip(bos.toByteArray(), "MainServiceTemplate.mf", TestUtil.loadFile("MainServiceTemplate.mf"));
57         ByteArrayOutputStream actualModifiedCbamVnfPackage = getFileInZip(new ByteArrayInputStream(bos.toByteArray()), "Artifacts/Deployment/OTHER/cbam.package.zip");
58         byte[] expectedModifiedCbamPackage = new CbamVnfPackageBuilder().toModifiedCbamVnfPackage(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip"), "vnfdloc/a.yaml", new CbamVnfdBuilder().build(cbamVnfd));
59         assertItenticalZips(expectedModifiedCbamPackage, actualModifiedCbamVnfPackage.toByteArray());
60     }
61
62
63     /**
64      * Prevents moving the class (customer documentation) must be updated
65      */
66     @Test
67     public void testPreventMove() {
68         assertEquals("b3JnLm9uYXAudmZjLm5mdm8uZHJpdmVyLnZuZm0uc3ZuZm0ubm9raWEucGFja2FnZXRyYW5zZm9ybWVyLk9uYXBWbmZQYWNrYWdlQnVpbGRlcg==", Base64.getEncoder().encodeToString(OnapVnfPackageBuilder.class.getCanonicalName().getBytes()));
69     }
70
71
72 }