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;
private ExecutorService executorService = newCachedThreadPool();
@Autowired
- SelfRegistrationTrigger(SelfRegistrationManager selfRegistrationManager, JobManager jobManager){
+ SelfRegistrationTrigger(SelfRegistrationManager selfRegistrationManager, JobManager jobManager) {
this.jobManager = jobManager;
this.selfRegistrationManager = selfRegistrationManager;
}
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);
private final JobManager jobManager;
@Autowired
- SelfDeRegistrationTrigger(SelfRegistrationManager selfRegistrationManager, JobManager jobManager){
+ SelfDeRegistrationTrigger(SelfRegistrationManager selfRegistrationManager, JobManager jobManager) {
this.jobManager = jobManager;
this.selfRegistrationManager = selfRegistrationManager;
}
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();
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);
* @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
/**
* @return is the component preparing for shutdown
*/
- public boolean isPreparingForShutDown(){
+ public boolean isPreparingForShutDown() {
return preparingForShutDown;
}
TOSCA-Meta-Version: 1.0
CSAR-Version: 1.0
Created-By: Kuku
-Entry-Definitions: Definitions/MainServiceTemplate.yaml
+Entry-Definitions: MainServiceTemplate.yaml
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;
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);
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;
//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());
*/
@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);
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;
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);
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());
*/
@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()));
}
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;
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
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());
@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();
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();
/**
* Test spring application wrapping
- */
+ */
@Test
- public void testSpring(){
+ public void testSpring() {
SpringApplication springApplication = SystemFunctions.systemFunctions().newSpringApplication(NokiaSvnfmApplication.class);
assertEquals(1, springApplication.getAllSources().size());
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;
private java.util.List<NodeInfo> nodes = new ArrayList<>();
private CbamRestApiProvider cbamRestApiProvider;
- private CbamSecurityProvider cbamSecurityProvider ;
+ private CbamSecurityProvider cbamSecurityProvider;
@Before
public void init() {
import static pl.pojo.tester.api.assertion.Assertions.assertPojoMethodsFor;
-public class TestDriverProperties extends TestBase{
+public class TestDriverProperties extends TestBase {
/**
* Test basic POJO behaviour
/**
* 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");