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 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;
 
  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.mf")).thenCallRealMethod();
 
  48         String cbamVnfd = new String(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip.vnfd"));
 
  49         String expectedOnapVnfd = new OnapVnfdBuilder().toOnapVnfd(cbamVnfd);
 
  52         OnapR1VnfPackageBuilder.main(null);
 
  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());
 
  64      * Prevents moving the class (customer documentation) must be updated
 
  67     public void testPreventMove() {
 
  68         assertEquals("b3JnLm9uYXAudmZjLm5mdm8uZHJpdmVyLnZuZm0uc3ZuZm0ubm9raWEucGFja2FnZXRyYW5zZm9ybWVyLk9uYXBSMVZuZlBhY2thZ2VCdWlsZGVy", Base64.getEncoder().encodeToString(OnapR1VnfPackageBuilder.class.getCanonicalName().getBytes()));