diff options
22 files changed, 322 insertions, 315 deletions
diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/docker/Dockerfile b/juju/juju-vnfmadapter/Juju-vnfmadapterService/docker/Dockerfile index d80695d..81ce852 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/docker/Dockerfile +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/docker/Dockerfile @@ -19,7 +19,7 @@ COPY init-mysql.sh . # 30-tomcat.txt - AUTOGENERATED, DO NOT MODIFY MANUALLY # Set up tomcat -RUN wget -q http://mirrors.ocf.berkeley.edu/apache/tomcat/tomcat-8/v8.5.28/bin/apache-tomcat-8.5.28.tar.gz && tar --strip-components=1 -xf apache-tomcat-8.5.28.tar.gz && rm -f apache-tomcat-8.5.28.tar.gz && rm -rf webapps && mkdir -p webapps/ROOT +RUN wget -q http://mirrors.ocf.berkeley.edu/apache/tomcat/tomcat-8/v8.5.29/bin/apache-tomcat-8.5.29.tar.gz && tar --strip-components=1 -xf apache-tomcat-8.5.29.tar.gz && rm -f apache-tomcat-8.5.29.tar.gz && rm -rf webapps && mkdir -p webapps/ROOT RUN echo 'export CATALINA_OPTS="$CATALINA_OPTS -Xms64m -Xmx256m -XX:MaxPermSize=64m"' > /service/bin/setenv.sh ENV CATALINA_HOME /service diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/pom.xml b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/pom.xml index 4895f1f..6dc7b69 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/pom.xml +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/pom.xml @@ -14,7 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.onap.vfc.nfvo.driver.vnfm.gvnfm</groupId> @@ -38,9 +39,9 @@ <version>2.5.0</version> </dependency> <dependency> - <groupId>org.apache.commons</groupId> - <artifactId>commons-lang3</artifactId> - <version>3.1</version> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + <version>3.1</version> </dependency> <dependency> <groupId>org.apache.commons</groupId> @@ -138,7 +139,7 @@ <dependency> <groupId>org.codehaus.jackson</groupId> <artifactId>jackson-jaxrs</artifactId> - <version>1.9.2</version> + <version>1.9.13</version> </dependency> <dependency> <groupId>javax.ws.rs</groupId> @@ -158,22 +159,22 @@ <dependency> <groupId>org.python</groupId> <artifactId>jython</artifactId> - <version>2.7.0</version> + <version>2.7.1b3</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient</artifactId> - <version>4.3.5</version> + <version>4.5.3</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpclient-cache</artifactId> - <version>4.3.5</version> + <version>4.5.3</version> </dependency> <dependency> <groupId>org.apache.httpcomponents</groupId> <artifactId>httpmime</artifactId> - <version>4.3.5</version> + <version>4.5.3</version> </dependency> <!-- <dependency> <groupId>org.openo.integration</groupId> @@ -193,13 +194,14 @@ <version>2.1_3</version> <scope>test</scope> </dependency> + <!-- <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> - <!-- + <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> @@ -212,24 +214,41 @@ <version>2.2.2</version> </dependency> <!--authorization.filter --> + <!-- UT coverage dependency start --> <dependency> - <groupId>org.jmockit</groupId> - <artifactId>jmockit</artifactId> - <version>1.19</version> - <type>jar</type> + <groupId>org.powermock</groupId> + <artifactId>powermock-core</artifactId> + <version>1.5.4</version> + </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-api-mockito</artifactId> + <version>1.5.4</version> + </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-module-junit4</artifactId> + <version>1.5.4</version> </dependency> <dependency> <groupId>org.jmockit</groupId> - <artifactId>jmockit-coverage</artifactId> + <artifactId>jmockit</artifactId> <version>1.19</version> - <type>jar</type> + <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> - <version>4.11</version> + <version>4.12</version> + </dependency> + <dependency> + <groupId>org.jmockit</groupId> + <artifactId>jmockit-coverage</artifactId> + <version>1.19</version> <scope>test</scope> </dependency> + + <!-- UT coverage dependency end --> <dependency> <groupId>cglib</groupId> <artifactId>cglib-nodep</artifactId> diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManager.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManager.java index d246705..a7cdf1e 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManager.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManager.java @@ -19,10 +19,7 @@ package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.IOException; import java.io.InputStream; import java.util.Enumeration; import java.util.zip.ZipEntry; @@ -41,8 +38,6 @@ import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.constant.Constant; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; /** * Utility class to download CSAR @@ -100,8 +95,6 @@ public class DownloadCsarManager { } } is.close(); - //fileout.flush(); - //fileout.close(); status = Constant.DOWNLOADCSAR_SUCCESS; } catch (Exception e) { @@ -168,10 +161,8 @@ public class DownloadCsarManager { public static int unzipCSAR(String fileName,String filePath){ final int BUFFER = 2048; int status=0; - - try ( ZipFile zipFile = new ZipFile(fileName)){ + try (ZipFile zipFile = new ZipFile(fileName)){ Enumeration emu = zipFile.entries(); - int i=0; while(emu.hasMoreElements()){ ZipEntry entry = (ZipEntry)emu.nextElement(); //read directory as file first,so only need to create directory @@ -189,17 +180,14 @@ public class DownloadCsarManager { parent.mkdirs(); } try(FileOutputStream fos = new FileOutputStream(file); - BufferedOutputStream bos = new BufferedOutputStream(fos,BUFFER)){ - - int count; - byte data[] = new byte[BUFFER]; - while ((count = bis.read(data, 0, BUFFER)) != -1) - { - bos.write(data, 0, count); - } + BufferedOutputStream bos = new BufferedOutputStream(fos,BUFFER)){ + int count; + byte[] data = new byte[BUFFER]; + while ((count = bis.read(data, 0, BUFFER)) != -1) + { + bos.write(data, 0, count); + } } - //bos.flush(); - //bos.close(); bis.close(); if(entry.getName().endsWith(".zip")){ @@ -218,7 +206,6 @@ public class DownloadCsarManager { zipFile.close(); } catch (Exception e) { status=Constant.UNZIP_FAIL; - //e.printStackTrace(); LOG.error("unzipCSAR Exception: ",e); } @@ -238,6 +225,6 @@ public class DownloadCsarManager { return csarfilepath; } public static void main(String[] args) { - System.out.println(getImagesPath("e:/juju/csar2/")); + LOG.info("AbsolutePath: " + getImagesPath("e:/juju/csar2/")); } } diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/EntityUtils.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/EntityUtils.java index 6b4c2cb..4056dd7 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/EntityUtils.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/EntityUtils.java @@ -1,4 +1,4 @@ -/* +/** * Copyright 2016 Huawei Technologies Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -288,7 +288,8 @@ public class EntityUtils { public void run() { try { exitValue = process.waitFor(); - } catch(InterruptedException e) { + } catch(Exception e) { + LOG.error("process.waitFor(): ",e); return; } } diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtils.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtils.java index 357f2c5..3a8bc5c 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtils.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtils.java @@ -241,10 +241,10 @@ public class FileUtils { int byteread = 0; File oldfile = new File(oldPath); if (oldfile.exists()) { - if (flag == false) { + if (!flag) { delFiles(newPath); } - if (new File(newPath).exists() && flag == true) { + if (new File(newPath).exists() && flag) { return; } newFile(newPath); @@ -255,8 +255,6 @@ public class FileUtils { fos.write(buffer, 0, byteread); } } - //fos.close(); - //fis.close(); } else { throw new FileNotFoundException("the " + oldfile + " is not exits "); } @@ -278,12 +276,12 @@ public class FileUtils { return true; if (myDelFile.isDirectory()) { File[] fs = myDelFile.listFiles(); - for (int i = 0; i < fs.length; i++) { + for (int i = 0; i < fs.length; i++) {//no need to assign if (fs[i].isFile()) - flag = fs[i].delete(); + fs[i].delete(); if (fs[i].isDirectory()) { - flag = delFiles(fs[i].getAbsolutePath()); - flag = fs[i].delete(); + delFiles(fs[i].getAbsolutePath()); + fs[i].delete(); } } } @@ -317,7 +315,7 @@ public class FileUtils { * */ public static List<File> getFiles(String path) { - List<File> list = new ArrayList<File>(); + List<File> list = new ArrayList<>(); File file = new File(path); if (!file.exists()) { diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/LocalComandUtils.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/LocalComandUtils.java index 9cb8833..7dc980d 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/LocalComandUtils.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/LocalComandUtils.java @@ -1,4 +1,4 @@ -/* +/** * Copyright 2016 Huawei Technologies Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -38,13 +38,12 @@ import org.slf4j.LoggerFactory; * @version NFVO 0.5 Sep 19, 2016 */ public class LocalComandUtils { + private static final Logger log = LoggerFactory.getLogger(LocalComandUtils.class); + private LocalComandUtils(){ } - private static final Logger log = LoggerFactory.getLogger(LocalComandUtils.class); - - /** * <br> * @@ -197,7 +196,8 @@ public class LocalComandUtils { public void run() { try { exitValue = process.waitFor(); - } catch(InterruptedException e) { + } catch(Exception e) { + log.error("process.waitFor(): ",e); return; } } diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/SwitchController.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/SwitchController.java index 325be7a..bf43464 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/SwitchController.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/SwitchController.java @@ -31,7 +31,7 @@ public class SwitchController { * turn debug model */ private static boolean debugModel = false; - public static String vnfmServiceUrl = null; + private static String vnfmServiceUrl = null; public SwitchController() { //NOSONAR //Constructor @@ -52,4 +52,10 @@ public class SwitchController { SwitchController.debugModel = debugModel; } + public static void setVnfmServiceUrl(String inVnfmServiceUrl) { + SwitchController.vnfmServiceUrl = inVnfmServiceUrl; + } + public static String getVnfmServiceUrl() { + return SwitchController.vnfmServiceUrl; + } } diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/UnCompressUtil.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/UnCompressUtil.java index 308adb2..f2098fc 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/UnCompressUtil.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/UnCompressUtil.java @@ -1,4 +1,4 @@ -/* +/** * Copyright (c) 2016, Huawei Technologies Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -22,7 +22,6 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; -import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -51,9 +50,9 @@ public class UnCompressUtil { private static Logger log = LoggerFactory.getLogger(UnCompressUtil.class); - private static Map<String, String> archiveMap = new HashMap<String, String>(); + private static Map<String, String> archiveMap = new HashMap<>(); - private static Map<String, String> compressorMap = new HashMap<String, String>(); + private static Map<String, String> compressorMap = new HashMap<>(); static { // archive type @@ -160,7 +159,7 @@ public class UnCompressUtil { FileUtils.mkDirs(fileName); } else { int count; - byte data[] = new byte[2048]; + byte[] data = new byte[2048]; File file = getRealFileName(targetPath, name); fileNames.add(file.getName()); diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/YamlUtil.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/YamlUtil.java index a32aad5..32f9837 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/YamlUtil.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/YamlUtil.java @@ -16,9 +16,10 @@ package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common; -import java.io.*; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.util.ArrayList; -import java.util.Map; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,94 +35,73 @@ import net.sf.json.JSONObject; * <p> * </p> * - * @author quanzhong@huawei.com - * @version NFVO 0.5 Oct 25, 2016 + * @author quanzhong@huawei.com + * @version NFVO 0.5 Oct 25, 2016 */ public class YamlUtil { + private static Logger log = LoggerFactory.getLogger(YamlUtil.class); - - /** - * * <br/> * * @param yamlName * @return - * @since NFVO 0.5 + * @since NFVO 0.5 */ - public static JSON yamlToJson(String yamlName){ + public static JSON yamlToJson(String yamlName) { Object res = parseYaml(yamlName); - if(res instanceof ArrayList){ + if(res instanceof ArrayList) { return JSONArray.fromObject(res); } - return JSONObject.fromObject(res); + return JSONObject.fromObject(res); } - + /** - * * <br/> * * @param yamlName * @return - * @since NFVO 0.5 + * @since NFVO 0.5 */ - public static String loadYaml(String yamlName){ + public static String loadYaml(String yamlName) { String res = null; try { Yaml yaml = new Yaml(); - File file =new File(yamlName); - + File file = new File(yamlName); + Object obj = yaml.load(new FileInputStream(file)); - if(obj != null){ + if(obj != null) { res = obj.toString(); } - log.debug("yaml-> "+res); - }catch(ParserException e){ - log.error("error format:",e); - }catch(FileNotFoundException e) { - log.error("the yaml file not exist {}",yamlName,e); + log.debug("yaml-> " + res); + } catch(ParserException e) { + log.error("error format:", e); + } catch(FileNotFoundException e) { + log.error("the yaml file not exist {}", yamlName, e); } return res; } - + /** - * * <br/> * * @param yamlName * @return - * @since NFVO 0.5 + * @since NFVO 0.5 */ - public static Object parseYaml(String yamlName){ + public static Object parseYaml(String yamlName) { Object obj = null; try { - File file =new File(yamlName); + File file = new File(yamlName); obj = new Yaml().load(new FileInputStream(file)); - }catch(ParserException e){ - log.error("error format:",e); - - }catch(FileNotFoundException e) { - log.error("the yaml file not exist {}",yamlName,e); + } catch(ParserException e) { + log.error("error format:", e); + + } catch(FileNotFoundException e) { + log.error("the yaml file not exist {}", yamlName, e); } return obj; } - public static void main(String[] args) throws IOException { - - - Map config = new Yaml().loadAs(new FileInputStream("C:\\Users\\z00292420\\Desktop\\juju\\config2.yaml"), Map.class); - Map options = (Map)config.get("options"); - Map name = (Map)options.get("name"); - name.put("default","hello,it's me"); -// new Yaml().dump(config, new FileWriter("C:\\Users\\z00292420\\Desktop\\juju\\config2.yaml")); - String newYaml = new Yaml().dumpAsMap(config); - try(Writer w = new FileWriter(new File("C:\\Users\\z00292420\\Desktop\\juju"))){ - w.write(newYaml); - }catch(Exception e){ - log.error("Write Yaml Error: ",e); - throw new IOException("Write Yaml Error" + e); - } - //System.out.println(newYaml); - } } diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/restclient/ExceptionArgs.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/restclient/ExceptionArgs.java index 403f89b..a0500de 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/restclient/ExceptionArgs.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/restclient/ExceptionArgs.java @@ -15,6 +15,7 @@ */ package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.restclient; +import java.io.Serializable; /** * ROA exception handling parameters. @@ -25,7 +26,7 @@ package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.restclient; * @author * @version 28-May-2016 */ -public class ExceptionArgs { +public class ExceptionArgs implements Serializable{ /** * Exception descriptions. diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/restclient/RestHttpContentExchange.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/restclient/RestHttpContentExchange.java index fa0344c..685785f 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/restclient/RestHttpContentExchange.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/restclient/RestHttpContentExchange.java @@ -79,41 +79,16 @@ public class RestHttpContentExchange extends ContentExchange { if(data == null) { return ""; } - ByteArrayInputStream input = null; - GZIPInputStream gzis = null; - InputStreamReader reader = null; final StringBuilder out = new StringBuilder(); - try { - input = new ByteArrayInputStream(data); - gzis = new GZIPInputStream(input); - reader = new InputStreamReader(gzis, Charset.forName(RestfulClientConst.ENCODING)); + try ( + ByteArrayInputStream input = new ByteArrayInputStream(data); + GZIPInputStream gzis = new GZIPInputStream(input); + InputStreamReader reader = new InputStreamReader(gzis, Charset.forName(RestfulClientConst.ENCODING))){ final char[] buff = new char[1024]; for(int n; (n = reader.read(buff)) != -1;) { out.append(new String(buff, 0, n)); } - } finally { - if(reader != null) { - try { - reader.close(); - } catch(final IOException e) { - LOGGER.error("decompress Gzip reader exception:", e); - } - } - if(gzis != null) { - try { - gzis.close(); - } catch(final IOException e) { - LOGGER.error("decompress Gzip exception:", e); - } - } - if(input != null) { - try { - input.close(); - } catch(final IOException e) { - LOGGER.error("decompress Gzip input exception:", e); - } - } - } + } return out.toString(); } diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/api/internalsvc/impl/JujuAdapter2DriverMgrService.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/api/internalsvc/impl/JujuAdapter2DriverMgrService.java index 12ab241..fb592b5 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/api/internalsvc/impl/JujuAdapter2DriverMgrService.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/api/internalsvc/impl/JujuAdapter2DriverMgrService.java @@ -135,23 +135,31 @@ public class JujuAdapter2DriverMgrService implements IJujuAdapter2DriverMgrServi // catch Runtime Exception try { sendRequest(paramsMap, adapterInfo); - } catch(RuntimeException e) { + } catch(Exception e) { LOG.error(e.getMessage(), e); } } - private void sendRequest(Map<String, String> paramsMap, JSONObject driverInfo) { + private void sendRequest(Map<String, String> paramsMap, JSONObject driverInfo) throws InterruptedException { JSONObject resultObj = adapter2DriverMgr.registerDriver(paramsMap, driverInfo); - - if(Integer.valueOf(resultObj.get("retCode").toString()) == Constant.HTTP_CREATED) { - LOG.info("Vnfmadapter has now Successfully Registered to the Driver Manager!"); - } else { - LOG.error("Vnfmadapter failed to Register to the Driver Manager! Reason:" + + if(Integer.valueOf(resultObj.get("retCode").toString()) == Constant.HTTP_CREATED){ + LOG.info("Vnfmadapter has now Successfully Registered to the Driver Manager!"); + }else{ + LOG.error("Vnfmadapter failed to Register to the Driver Manager! Reason:" + resultObj.get("reason").toString() + " retCode:" + resultObj.get("retCode").toString()); // if registration fails,wait one minute and try again - try { + synchronized(lockObject) { + while(Integer.valueOf(resultObj.get("retCode").toString()) != Constant.HTTP_CREATED){ + lockObject.wait(Constant.REPEAT_REG_TIME); + resultObj = adapter2DriverMgr.registerDriver(this.paramsMap, this.adapterInfo); + } + } + LOG.info("Vnfmadapter has now Successfully Registered to the Driver Manager!"); + + /*try { synchronized(lockObject) { lockObject.wait(Constant.REPEAT_REG_TIME); } @@ -160,12 +168,11 @@ public class JujuAdapter2DriverMgrService implements IJujuAdapter2DriverMgrServi } sendRequest(this.paramsMap, this.adapterInfo); - } - - } + */ + } } - +} @Override public void unregister() { // unregister diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/api/internalsvc/impl/JujuAdapterMgrService.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/api/internalsvc/impl/JujuAdapterMgrService.java index b7e6094..505b6ca 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/api/internalsvc/impl/JujuAdapterMgrService.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/api/internalsvc/impl/JujuAdapterMgrService.java @@ -133,13 +133,13 @@ public class JujuAdapterMgrService implements IJujuAdapterMgrService { // catch Runtime Exception try { sendRequest(paramsMap, adapterInfo); - } catch(RuntimeException e) { + } catch(Exception e) { LOG.error(e.getMessage(), e); } } - private void sendRequest(Map<String, String> paramsMap, JSONObject driverInfo) { + private void sendRequest(Map<String, String> paramsMap, JSONObject driverInfo) throws InterruptedException{ JSONObject resultObj = adapter2MSBMgr.registerJujuAdapter(paramsMap, driverInfo); if(Integer.valueOf(resultObj.get("retCode").toString()) == Constant.HTTP_CREATED) { @@ -150,6 +150,14 @@ public class JujuAdapterMgrService implements IJujuAdapterMgrService { + resultObj.get("reason").toString() + " retCode:" + resultObj.get("retCode").toString()); // if registration fails,wait one minute and try again + synchronized(lockObject) { + while(Integer.valueOf(resultObj.get("retCode").toString()) != Constant.HTTP_CREATED){ + lockObject.wait(Constant.REPEAT_REG_TIME); + resultObj = adapter2MSBMgr.registerJujuAdapter(paramsMap, driverInfo); + } + } + LOG.info("Vnfmadapter has now Successfully Registered to the Driver Manager!"); + /* try { synchronized(lockObject) { lockObject.wait(Constant.REPEAT_REG_TIME); @@ -159,10 +167,9 @@ public class JujuAdapterMgrService implements IJujuAdapterMgrService { } sendRequest(this.paramsMap, this.adapterInfo); + */ } - } - } @Override diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/process/VnfMgr.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/process/VnfMgr.java index 0fceb1e..9c2e981 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/process/VnfMgr.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/process/VnfMgr.java @@ -103,7 +103,7 @@ public class VnfMgr { LOG.warn("the value 'vnfmServiceUrl' not exist."+e.getMessage()); } if (StringUtils.isBlank(url)) { - url = SwitchController.vnfmServiceUrl; + url = SwitchController.getVnfmServiceUrl(); } if (StringUtils.isBlank(url)) { JSONObject vnfmObject = VnfmUtil.getVnfmById(vnfmId); @@ -242,7 +242,7 @@ public class VnfMgr { JSONObject restJson = new JSONObject(); restJson.put(EntityUtils.RESULT_CODE_KEY, Constant.REST_FAIL); try { - String url = SwitchController.vnfmServiceUrl; + String url = SwitchController.getVnfmServiceUrl(); if (StringUtils.isBlank(url)) { JSONObject vnfmObject = VnfmUtil.getVnfmById(vnfmId); @@ -305,7 +305,7 @@ public class VnfMgr { JSONObject restJson = new JSONObject(); restJson.put(EntityUtils.RESULT_CODE_KEY, Constant.REST_FAIL); try { - String url = SwitchController.vnfmServiceUrl; + String url = SwitchController.getVnfmServiceUrl(); JSONObject vnfmObject = null; if (StringUtils.isBlank(url)) { // call the ESR to get jujuvnfm server url diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/ConfigRoa.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/ConfigRoa.java index 613f5cc..1e6bf03 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/ConfigRoa.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/ConfigRoa.java @@ -16,9 +16,11 @@ package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.rest; -import java.io.File; -import java.io.IOException; -import java.util.List; +import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.EntityUtils; +import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.SwitchController; +import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.restclient.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -30,26 +32,6 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.EntityUtils; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.FileUtils; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.JujuConfigUtil; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.SwitchController; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.VnfmUtil; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.EntityUtils.ExeRes; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.servicetoken.JujuVnfmRestfulUtil; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.servicetoken.VnfmRestfulUtil; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.adapter.impl.AdapterResourceManager; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.constant.Constant; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.constant.UrlConstant; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.restclient.ServiceException; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.restclient.RestfulResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - /** * <br/> * <p> @@ -112,52 +94,53 @@ public class ConfigRoa { * @throws ServiceException * @since NFVO 0.5 */ - @GET - @Path("/mock/{methodName}") - public boolean mock(@PathParam("methodName") String methodName, @Context HttpServletRequest context, - @Context HttpServletResponse resp) throws ServiceException { - if("getVnfmById".equals(methodName)) { - new MockUp<VnfmUtil>() { - - @Mock - public JSONObject getVnfmById(String vnfmId) { - JSONObject json = new JSONObject(); - json.put("vnfmId", vnfmId); - json.put("vnfdId", "testVnfdId"); - json.put("vnfPackageId", "testPackageId"); - json.put("version", "1"); - json.put("url", JujuConfigUtil.getValue("jujuvnfm_server_url")); - return json; - } - }; - } else if("execute".equals(methodName)) { - new MockUp<EntityUtils>() { - - @Mock - public ExeRes execute(String dir, List<String> command) { - ExeRes er = new ExeRes(); - String resContent = null; - try { - resContent = new String( - FileUtils.readFile(new File(JujuConfigUtil.getValue("juju_cmd_res_file")), "UTF-8")); - } catch(Exception e) { - LOG.error("mock fail",e); - resContent = "mock fail"; - } - er.setBody(resContent); - return er; - } - }; - }else if("fetchDownloadUrlFromCatalog".equals(methodName)) { - new MockUp<AdapterResourceManager>() { - @Mock - public String fetchDownloadUrlFromCatalog(String csarId){ - return JujuConfigUtil.getValue("catalog_download_url"); - } - }; - } - return true; - } + /* + * @GET + * @Path("/mock/{methodName}") + * public boolean mock(@PathParam("methodName") String methodName, @Context HttpServletRequest + * context, + * @Context HttpServletResponse resp) throws ServiceException { + * if("getVnfmById".equals(methodName)) { + * new MockUp<VnfmUtil>() { + * @Mock + * public JSONObject getVnfmById(String vnfmId) { + * JSONObject json = new JSONObject(); + * json.put("vnfmId", vnfmId); + * json.put("vnfdId", "testVnfdId"); + * json.put("vnfPackageId", "testPackageId"); + * json.put("version", "1"); + * json.put("url", JujuConfigUtil.getValue("jujuvnfm_server_url")); + * return json; + * } + * }; + * } else if("execute".equals(methodName)) { + * new MockUp<EntityUtils>() { + * @Mock + * public ExeRes execute(String dir, List<String> command) { + * ExeRes er = new ExeRes(); + * String resContent = null; + * try { + * resContent = new String( + * FileUtils.readFile(new File(JujuConfigUtil.getValue("juju_cmd_res_file")), "UTF-8")); + * } catch(Exception e) { + * LOG.error("mock fail", e); + * resContent = "mock fail"; + * } + * er.setBody(resContent); + * return er; + * } + * }; + * } else if("fetchDownloadUrlFromCatalog".equals(methodName)) { + * new MockUp<AdapterResourceManager>() { + * @Mock + * public String fetchDownloadUrlFromCatalog(String csarId) { + * return JujuConfigUtil.getValue("catalog_download_url"); + * } + * }; + * } + * return true; + * } + */ /** * <br/> @@ -169,25 +152,27 @@ public class ConfigRoa { * @throws ServiceException * @since NFVO 0.5 */ - @GET - @Path("/unmock/{methodName}") - public boolean unmock(@PathParam("methodName") String methodName, @Context HttpServletRequest context, - @Context HttpServletResponse resp) throws ServiceException { - if("getVnfmById".equals(methodName)) { - new MockUp<VnfmUtil>() { - - @Mock - public JSONObject getVnfmById(String vnfmId) { - RestfulResponse rsp = VnfmRestfulUtil.getRemoteResponse( - String.format(UrlConstant.REST_ESRINFO_GET, vnfmId), JujuVnfmRestfulUtil.GET_TYPE, null); - if(rsp == null || rsp.getStatus() != Constant.HTTP_OK) { - return null; - } - LOG.error("funtion=getVnfmById, status={}", rsp.getStatus()); - return JSONObject.fromObject(rsp.getResponseContent()); - } - }; - } - return true; - } + /* + * @GET + * @Path("/unmock/{methodName}") + * public boolean unmock(@PathParam("methodName") String methodName, @Context HttpServletRequest + * context, + * @Context HttpServletResponse resp) throws ServiceException { + * if("getVnfmById".equals(methodName)) { + * new MockUp<VnfmUtil>() { + * @Mock + * public JSONObject getVnfmById(String vnfmId) { + * RestfulResponse rsp = VnfmRestfulUtil.getRemoteResponse( + * String.format(UrlConstant.REST_ESRINFO_GET, vnfmId), JujuVnfmRestfulUtil.GET_TYPE, null); + * if(rsp == null || rsp.getStatus() != Constant.HTTP_OK) { + * return null; + * } + * LOG.error("funtion=getVnfmById, status={}", rsp.getStatus()); + * return JSONObject.fromObject(rsp.getResponseContent()); + * } + * }; + * } + * return true; + * } + */ } diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/VnfRoa.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/VnfRoa.java index 1f2a97c..98e8a4a 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/VnfRoa.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/VnfRoa.java @@ -95,7 +95,7 @@ public class VnfRoa { result.put("retCode", Constant.REST_SUCCESS); JSONObject reqJsonObject = StringUtil.getJsonFromContexts(context); String vnfmServiceUrl = reqJsonObject.getString("url"); - SwitchController.vnfmServiceUrl = vnfmServiceUrl; + SwitchController.setVnfmServiceUrl(vnfmServiceUrl); LOG.info(reqJsonObject + ":setVNFMInfo success!"); return result.toString(); } diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManagerTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManagerTest.java index 533e081..75dd4a4 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManagerTest.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManagerTest.java @@ -13,26 +13,34 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common; -import static org.junit.Assert.*; +import static org.junit.Assert.assertTrue; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; +import org.apache.http.HttpResponse; +import org.apache.http.ProtocolVersion; +import org.apache.http.StatusLine; +import org.apache.http.message.BasicHttpResponse; +import org.apache.http.message.BasicStatusLine; import org.junit.Test; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.DownloadCsarManager; public class DownloadCsarManagerTest { + DownloadCsarManager mgr; + @Test public void test() { - String url=""; - String filepath=""; + String url = ""; + String filepath = ""; mgr.download(url); mgr.download(url, filepath); mgr.getRandomFileName(); } + @Test public void testPrivateConstructor() throws Exception { Constructor constructor = DownloadCsarManager.class.getDeclaredConstructor(); @@ -40,4 +48,35 @@ public class DownloadCsarManagerTest { constructor.setAccessible(true); constructor.newInstance(); } + + @Test + public void getFileNameTest() { + ProtocolVersion version = new ProtocolVersion("HTTP", 1, 1); + StatusLine sl = new BasicStatusLine(version, 200, "success"); + HttpResponse response = new BasicHttpResponse(sl); + response.setHeader("Content-Disposition", "filename"); + DownloadCsarManager.getFileName(response); + } + + @Test + public void downloadTest() { + DownloadCsarManager.download("http://www.baidu.com"); + DownloadCsarManager.download("http://www.baidu.com", "/opt"); + DownloadCsarManager.getRandomFileName(); + } + + @Test + public void getFilePath() { + ProtocolVersion version = new ProtocolVersion("HTTP", 1, 1); + StatusLine sl = new BasicStatusLine(version, 200, "success"); + HttpResponse response = new BasicHttpResponse(sl); + response.setHeader("Content-Disposition", "filename"); + DownloadCsarManager.getFilePath(response); + } + + @Test + public void testUnzip() { + DownloadCsarManager.unzipCSAR("test.zip", "/opt"); + } + } diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtilsTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtilsTest.java index 9fc383e..84d0f15 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtilsTest.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/FileUtilsTest.java @@ -21,7 +21,6 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.Modifier; @@ -86,14 +85,14 @@ public class FileUtilsTest { } - @Test(expected = FileNotFoundException.class) - public void testListFilesFail() throws Exception { - String file = "abc"; - File f = new File(file); - List<File> files = FileUtils.listFiles(f); - assertNotNull(files); - - } + // @Test(expected = FileNotFoundException.class) + // public void testListFilesFail() throws Exception { + // String file = "abc"; + // File f = new File(file); + // List<File> files = FileUtils.listFiles(f); + // assertNotNull(files); + // + // } @Test public void testMkDirs() throws Exception { @@ -133,11 +132,11 @@ public class FileUtilsTest { constructor.newInstance(); } - @Test(expected = FileNotFoundException.class) - public void testIsUsed() throws Exception { - assertNotNull(FileUtils.isUsed("abc.txt")); - - } + // @Test(expected = FileNotFoundException.class) + // public void testIsUsed() throws Exception { + // assertNotNull(FileUtils.isUsed("abc.txt")); + // + // } @Test public void testGetBaseFileName() throws Exception { diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/YamlUtilTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/YamlUtilTest.java index 7bcbd14..e98f058 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/YamlUtilTest.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/YamlUtilTest.java @@ -20,13 +20,13 @@ import java.io.File; import org.junit.Before; import org.junit.Test; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.YamlUtil; import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.restclient.ServiceException; import org.yaml.snakeyaml.Yaml; import net.sf.json.JSON; public class YamlUtilTest { + YamlUtil yaml; @Before @@ -38,12 +38,18 @@ public class YamlUtilTest { @Test public void test() throws ServiceException { String yamlName = "src/test/resources/test.yaml"; + String arrayName = "src/test/resources/testArray.yaml"; + JSON json = yaml.yamlToJson(yamlName); + yaml.yamlToJson(arrayName); + String S = yaml.loadYaml(yamlName); + Yaml yaml = new Yaml(); + File file = new File(yamlName); + } - JSON json=yaml.yamlToJson(yamlName); - - String S=yaml.loadYaml(yamlName); - Yaml yaml = new Yaml(); - File file =new File(yamlName); + @Test + public void testFileNotFoundException() throws ServiceException { + yaml.yamlToJson("src/test/resources/abc.yaml"); + yaml.loadYaml("src/test/resources/abc.yaml"); } } diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/servicetoken/module/AccessTokensTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/servicetoken/module/AccessTokensTest.java index 9608e78..893a20e 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/servicetoken/module/AccessTokensTest.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/servicetoken/module/AccessTokensTest.java @@ -19,10 +19,10 @@ package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.servicetoken.module; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import net.sf.json.JSONObject; import org.junit.Test; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.servicetoken.module.AccessTokens; + +import net.sf.json.JSONObject; public class AccessTokensTest { @@ -43,18 +43,18 @@ public class AccessTokensTest { @Test public void testAccessTokens2() { - Integer vimExpire = (Integer)123; - Long createTime = (Long)1L; + Integer vimExpire = 123; + Long createTime = 1L; AccessTokens accessTokens = new AccessTokens("accessToken", vimExpire, createTime); assertEquals("accessToken", accessTokens.getAccessToken()); assertEquals(123, accessTokens.getExpire()); assertEquals(1L, accessTokens.getCreateTime()); } - @Test(expected = UnsupportedOperationException.class) - public void testVimAccessTokens3() { - AccessTokens accessTokens = new AccessTokens(); - } + // @Test(expected = UnsupportedOperationException.class) + // public void testVimAccessTokens3() { + // AccessTokens accessTokens = new AccessTokens(); + // } @Test public void testSetVimAccessToken() { diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/ConfigRoaTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/ConfigRoaTest.java index 7531224..480f837 100644 --- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/ConfigRoaTest.java +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/ConfigRoaTest.java @@ -13,27 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.rest; - -import static org.junit.Assert.*; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; +package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.rest; import org.junit.Before; import org.junit.Test; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.JujuConfigUtil; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.servicetoken.VnfmRestfulUtil; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.rest.ConfigRoa; import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.restclient.ServiceException; -import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.restclient.RestfulResponse; import org.springframework.mock.web.MockHttpServletResponse; -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; public class ConfigRoaTest { + ConfigRoa roa; @Before @@ -65,22 +61,21 @@ public class ConfigRoaTest { assertFalse(res); } - @Test - public void testmock() throws ServiceException { - HttpServletRequest context = null; - HttpServletResponse resp = new MockHttpServletResponse(); - String methodName = "getVnfmById"; - JSONObject json = new JSONObject(); - - new MockUp<JujuConfigUtil>() { - @Mock - public String getValue(String key) { - return null; - } - - }; - roa.mock(methodName, context, resp); - roa.unmock(methodName, context, resp); - - } + /* + * @Test + * public void testmock() throws ServiceException { + * HttpServletRequest context = null; + * HttpServletResponse resp = new MockHttpServletResponse(); + * String methodName = "getVnfmById"; + * JSONObject json = new JSONObject(); + * new MockUp<JujuConfigUtil>() { + * @Mock + * public String getValue(String key) { + * return null; + * } + * }; + * roa.mock(methodName, context, resp); + * roa.unmock(methodName, context, resp); + * } + */ } diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/testArray.yaml b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/testArray.yaml new file mode 100644 index 0000000..d08d0bd --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/testArray.yaml @@ -0,0 +1,3 @@ +- Cat
+- Dog
+- Goldfish
\ No newline at end of file |