Fix automatic package conversion 59/42059/3
authorDenes Nemeth <denes.nemeth@nokia.com>
Tue, 10 Apr 2018 20:48:30 +0000 (22:48 +0200)
committerDenes Nemeth <denes.nemeth@nokia.com>
Tue, 10 Apr 2018 22:05:42 +0000 (00:05 +0200)
Issue-ID: VFC-728
Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com>
Change-Id: Ie015f2e5406329f16e74ab8abd44060dfc44148a

13 files changed:
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/NokiaSvnfmApplication.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/OnapVnfPackageBuilder.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/ConverterApi.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/SystemFunctions.java
nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManager.java
nokiav2/driver/src/main/resources/MainServiceTemplate.mf [moved from nokiav2/driver/src/main/resources/MainServiceTemplate.meta with 100% similarity]
nokiav2/driver/src/main/resources/TOSCA.meta
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/TestNokiaSvnfmApplication.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/packagetransformer/TestOnapVnfPackageBuilder.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/TestConverterApi.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/TestSystemFunctions.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestCbamRestApiProvider.java
nokiav2/driver/src/test/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/TestDriverProperties.java

index ceb0335..23c2e4b 100644 (file)
@@ -18,14 +18,10 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia;
 
 import java.util.concurrent.Callable;
 import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.JobManager;
 import org.slf4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.context.event.ApplicationReadyEvent;
 import org.springframework.context.ApplicationListener;
@@ -71,7 +67,7 @@ public class NokiaSvnfmApplication {
         private ExecutorService executorService = newCachedThreadPool();
 
         @Autowired
-        SelfRegistrationTrigger(SelfRegistrationManager selfRegistrationManager, JobManager jobManager){
+        SelfRegistrationTrigger(SelfRegistrationManager selfRegistrationManager, JobManager jobManager) {
             this.jobManager = jobManager;
             this.selfRegistrationManager = selfRegistrationManager;
         }
@@ -90,13 +86,12 @@ public class NokiaSvnfmApplication {
                 return true;
             };
             executorService.submit(() -> {
-                while(!jobManager.isPreparingForShutDown()){
-                    try{
+                while (!jobManager.isPreparingForShutDown()) {
+                    try {
                         executorService.submit(singleRegistration).get();
                         //registration successful
                         return;
-                    }
-                    catch (Exception e){
+                    } catch (Exception e) {
                         logger.warn("Unable to execute self registration process", e);
                     }
                     systemFunctions().sleep(5000);
@@ -117,7 +112,7 @@ public class NokiaSvnfmApplication {
         private final JobManager jobManager;
 
         @Autowired
-        SelfDeRegistrationTrigger(SelfRegistrationManager selfRegistrationManager, JobManager jobManager){
+        SelfDeRegistrationTrigger(SelfRegistrationManager selfRegistrationManager, JobManager jobManager) {
             this.jobManager = jobManager;
             this.selfRegistrationManager = selfRegistrationManager;
         }
index 00977e4..2a05877 100644 (file)
@@ -71,11 +71,9 @@ public class OnapVnfPackageBuilder {
         out.putNextEntry(new ZipEntry("MainServiceTemplate.yaml"));
         out.write(onapVnfd.getBytes());
         out.closeEntry();
-        out.putNextEntry(new ZipEntry("Definitions/MainServiceTemplate.yaml"));
-        out.write(onapVnfd.getBytes());
         out.closeEntry();
-        out.putNextEntry(new ZipEntry("MainServiceTemplate.meta"));
-        out.write(systemFunctions().loadFile("MainServiceTemplate.meta"));
+        out.putNextEntry(new ZipEntry("MainServiceTemplate.mf"));
+        out.write(systemFunctions().loadFile("MainServiceTemplate.mf"));
         out.closeEntry();
         out.close();
         return result.toByteArray();
index 7ae05f5..da07ef2 100644 (file)
@@ -59,7 +59,7 @@ public class ConverterApi {
         logger.info("REST: convert package");
         byte[] content;
         try {
-            Part part = request.getParts().iterator().next();
+            Part part = request.getPart("fileToUpload");
             content = ByteStreams.toByteArray(part.getInputStream());
         } catch (Exception e) {
             throw buildFatalFailure(logger, "Unable to extract package from REST parameters", e);
index 87a4d56..468761c 100644 (file)
@@ -166,7 +166,7 @@ public class SystemFunctions {
      * @param clazz the main source of the Spring application
      * @return a new Spring application
      */
-    public SpringApplication newSpringApplication(Class clazz){
+    public SpringApplication newSpringApplication(Class clazz) {
         return new SpringApplication(clazz);
     }
 }
\ No newline at end of file
index e97f634..5624327 100644 (file)
@@ -100,7 +100,7 @@ public class JobManager {
     /**
      * @return is the component preparing for shutdown
      */
-    public boolean isPreparingForShutDown(){
+    public boolean isPreparingForShutDown() {
         return preparingForShutDown;
     }
 
index 5cb6447..bba95d1 100644 (file)
@@ -1,4 +1,4 @@
 TOSCA-Meta-Version: 1.0
 CSAR-Version: 1.0
 Created-By: Kuku
-Entry-Definitions: Definitions/MainServiceTemplate.yaml
+Entry-Definitions: MainServiceTemplate.yaml
index c6586c2..b4eed27 100644 (file)
@@ -17,27 +17,21 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia;
 
 import java.util.HashSet;
 import java.util.Set;
-import junit.framework.TestCase;
 import org.junit.Before;
 import org.junit.Test;
-import org.mockito.*;
+import org.mockito.InOrder;
+import org.mockito.Mock;
+import org.mockito.Mockito;
 import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.TestUtil;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.JobManager;
 import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.TestBase;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.Useless;
-import org.slf4j.Logger;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.context.event.ApplicationReadyEvent;
 import org.springframework.context.event.ContextClosedEvent;
-import org.springframework.test.util.ReflectionTestUtils;
 
-import static junit.framework.TestCase.assertEquals;
-import static junit.framework.TestCase.assertTrue;
-import static junit.framework.TestCase.fail;
+import static junit.framework.TestCase.*;
 import static org.mockito.Mockito.*;
 import static org.springframework.test.util.ReflectionTestUtils.setField;
 
@@ -80,15 +74,13 @@ public class TestNokiaSvnfmApplication extends TestBase {
         selfRegistrationTriggerer.onApplicationEvent(event);
         //verify
         boolean success = false;
-        while(!success)
-        {
+        while (!success) {
             try {
                 verify(selfRegistrationManager).register();
                 verify(logger).info("Self registration started");
                 verify(logger).info("Self registration finished");
                 success = true;
-            }
-            catch (Error e){
+            } catch (Error e) {
 
             }
             Thread.sleep(10);
@@ -141,7 +133,7 @@ public class TestNokiaSvnfmApplication extends TestBase {
         doAnswer(new Answer() {
             @Override
             public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
-                if(expectedException.size() == 0){
+                if (expectedException.size() == 0) {
                     RuntimeException e = new RuntimeException();
                     expectedException.add(e);
                     throw e;
@@ -155,14 +147,14 @@ public class TestNokiaSvnfmApplication extends TestBase {
         //verify
         //wait for the registration to succeed
         boolean success = false;
-        while(!success){
-            try{
+        while (!success) {
+            try {
                 verify(logger).info("Self registration finished");
                 success = true;
                 Thread.sleep(10);
+            } catch (Exception e2) {
+            } catch (Error e) {
             }
-            catch (Exception e2){}
-            catch (Error e){}
         }
         verify(logger, times(2)).info("Self registration started");
         verify(logger).error("Self registration failed", expectedException.iterator().next());
@@ -203,7 +195,7 @@ public class TestNokiaSvnfmApplication extends TestBase {
      */
     @Test
     public void useless() throws Exception {
-        String[] args = new String [0];
+        String[] args = new String[0];
         SpringApplication springApplicaiton = Mockito.mock(SpringApplication.class);
         SystemFunctions systemFunctions = SystemFunctions.systemFunctions();
         when(this.systemFunctions.newSpringApplication(NokiaSvnfmApplication.class)).thenReturn(springApplicaiton);
index 8ba697d..1abb432 100644 (file)
@@ -18,6 +18,7 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.PrintStream;
+import java.util.Base64;
 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;
@@ -42,8 +43,7 @@ public class TestOnapVnfPackageBuilder extends TestBase {
         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.meta")).thenCallRealMethod();
-
+        when(systemFunctions.loadFile("MainServiceTemplate.mf")).thenCallRealMethod();
 
         String cbamVnfd = new String(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip.vnfd"));
         String expectedOnapVnfd = new OnapVnfdBuilder().toOnapVnfd(cbamVnfd);
@@ -52,9 +52,8 @@ public class TestOnapVnfPackageBuilder extends TestBase {
         OnapVnfPackageBuilder.main(null);
         //verify
         assertFileInZip(bos.toByteArray(), "TOSCA-Metadata/TOSCA.meta", TestUtil.loadFile("TOSCA.meta"));
-        assertFileInZip(bos.toByteArray(), "Definitions/MainServiceTemplate.yaml", expectedOnapVnfd.getBytes());
         assertFileInZip(bos.toByteArray(), "MainServiceTemplate.yaml", expectedOnapVnfd.getBytes());
-        assertFileInZip(bos.toByteArray(), "MainServiceTemplate.meta", TestUtil.loadFile("MainServiceTemplate.meta"));
+        assertFileInZip(bos.toByteArray(), "MainServiceTemplate.mf", TestUtil.loadFile("MainServiceTemplate.mf"));
         ByteArrayOutputStream actualModifiedCbamVnfPackage = getFileInZip(new ByteArrayInputStream(bos.toByteArray()), "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());
@@ -66,7 +65,7 @@ public class TestOnapVnfPackageBuilder extends TestBase {
      */
     @Test
     public void testPreventMove() {
-        assertEquals("org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.OnapVnfPackageBuilder", OnapVnfPackageBuilder.class.getCanonicalName());
+        assertEquals("b3JnLm9uYXAudmZjLm5mdm8uZHJpdmVyLnZuZm0uc3ZuZm0ubm9raWEucGFja2FnZXRyYW5zZm9ybWVyLk9uYXBWbmZQYWNrYWdlQnVpbGRlcg==", Base64.getEncoder().encodeToString(OnapVnfPackageBuilder.class.getCanonicalName().getBytes()));
     }
 
 
index 8f8cc8c..d8db622 100644 (file)
@@ -16,7 +16,6 @@
 
 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi;
 
-import com.google.common.collect.Lists;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -72,11 +71,11 @@ public class TestConverterApi extends TestBase {
         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.meta")).thenCallRealMethod();
+        when(systemFunctions.loadFile("MainServiceTemplate.mf")).thenCallRealMethod();
         when(httpResponse.getOutputStream()).thenReturn(new DelegatingServletOutputStream(actualOut));
         Part part = Mockito.mock(Part.class);
         when(part.getInputStream()).thenReturn(new ByteArrayInputStream(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip")));
-        when(httpRequest.getParts()).thenReturn(Lists.newArrayList(part));
+        when(httpRequest.getPart("fileToUpload")).thenReturn(part);
         //when
         converterApi.convert(httpResponse, httpRequest);
         //verify
@@ -91,9 +90,8 @@ public class TestConverterApi extends TestBase {
         String cbamVnfd = new String(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip.vnfd"));
         String expectedOnapVnfd = new OnapVnfdBuilder().toOnapVnfd(cbamVnfd);
         assertFileInZip(bos.toByteArray(), "TOSCA-Metadata/TOSCA.meta", TestUtil.loadFile("TOSCA.meta"));
-        assertFileInZip(bos.toByteArray(), "Definitions/MainServiceTemplate.yaml", expectedOnapVnfd.getBytes());
         assertFileInZip(bos.toByteArray(), "MainServiceTemplate.yaml", expectedOnapVnfd.getBytes());
-        assertFileInZip(bos.toByteArray(), "MainServiceTemplate.meta", TestUtil.loadFile("MainServiceTemplate.meta"));
+        assertFileInZip(bos.toByteArray(), "MainServiceTemplate.mf", TestUtil.loadFile("MainServiceTemplate.mf"));
         ByteArrayOutputStream actualModifiedCbamVnfPackage = getFileInZip(new ByteArrayInputStream(bos.toByteArray()), "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());
@@ -121,7 +119,7 @@ public class TestConverterApi extends TestBase {
     @Test
     public void testUnableToExtractPackageToBeConverted() throws Exception {
         IOException expectedException = new IOException();
-        when(httpRequest.getParts()).thenThrow(expectedException);
+        when(httpRequest.getPart("fileToUpload")).thenThrow(expectedException);
         try {
             converterApi.convert(httpResponse, httpRequest);
             fail();
@@ -139,7 +137,7 @@ public class TestConverterApi extends TestBase {
     public void testUnableToConvertPackage() throws Exception {
         Part part = Mockito.mock(Part.class);
         when(part.getInputStream()).thenReturn(new ByteArrayInputStream(TestUtil.loadFile("unittests/packageconverter/cbam.package.zip")));
-        when(httpRequest.getParts()).thenReturn(Lists.newArrayList(part));
+        when(httpRequest.getPart("fileToUpload")).thenReturn(part);
         try {
             converterApi.convert(httpResponse, httpRequest);
             fail();
index c627bfc..29dc616 100644 (file)
@@ -120,9 +120,9 @@ public class TestSystemFunctions {
 
     /**
      * Test spring application wrapping
-      */
+     */
     @Test
-    public void testSpring(){
+    public void testSpring() {
         SpringApplication springApplication = SystemFunctions.systemFunctions().newSpringApplication(NokiaSvnfmApplication.class);
 
         assertEquals(1, springApplication.getAllSources().size());
index 7817edf..74c40a2 100644 (file)
@@ -42,7 +42,6 @@ import org.springframework.core.env.Environment;
 import static junit.framework.TestCase.assertEquals;
 import static junit.framework.TestCase.assertNotNull;
 import static org.mockito.Mockito.*;
-import static org.springframework.test.util.ReflectionTestUtils.setField;
 
 class ResultCaptor<T> implements Answer {
     private T result = null;
@@ -72,7 +71,7 @@ public class TestCbamRestApiProvider extends TestBase {
     private java.util.List<NodeInfo> nodes = new ArrayList<>();
 
     private CbamRestApiProvider cbamRestApiProvider;
-    private CbamSecurityProvider cbamSecurityProvider ;
+    private CbamSecurityProvider cbamSecurityProvider;
 
     @Before
     public void init() {
index 6a98e9e..1db7d97 100644 (file)
@@ -22,7 +22,7 @@ import static junit.framework.TestCase.assertEquals;
 import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor;
 
 
-public class TestDriverProperties extends TestBase{
+public class TestDriverProperties extends TestBase {
 
     /**
      * Test basic POJO behaviour
@@ -34,13 +34,13 @@ public class TestDriverProperties extends TestBase{
 
     /**
      * Test parameter initialization by Spring
-     *  - changes in this constants should be also altered in
-     *    - application*.properties
-     *    - in deployment configuration file
-     *    - documentation
+     * - changes in this constants should be also altered in
+     * - application*.properties
+     * - in deployment configuration file
+     * - documentation
      */
     @Test
-    public void testSpringParameterLoading(){
+    public void testSpringParameterLoading() {
         DriverProperties driverProperties = new DriverProperties();
         setFieldWithPropertyAnnotation(driverProperties, "${cbamCatalogUrl}", "cbamCatalogUrl");
         setFieldWithPropertyAnnotation(driverProperties, "${cbamLcnUrl}", "cbamLcnUrl");