summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwangguirong <wangguirong@boco.com.cn>2017-10-08 11:55:38 +0800
committerwangguirong <wangguirong@boco.com.cn>2017-10-08 11:55:56 +0800
commit069b429457cfba4247e1942f094350c2feb923a7 (patch)
treed514f7122ec49a19ae04c2d09b01b38768e3ba49
parent94193cce5cc963c16625a5d7cc80d2a3efc6457f (diff)
Add Test Case
Issue-Id:VFC-461 Change-Id: I727dc45314c6cfd23212502d9141d8ebfe2207be Signed-off-by: wangguirong <wangguirong@boco.com.cn>
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/EMSDriverApp.java8
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/EmsDriverApplication.java13
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/CollectMsgReceiverThread.java11
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java8
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThread.java18
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/AFtpRemoteFile.java5
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/ExtendsDefaultFTPFileEntryParserFactory.java224
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPSrv.java1
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/SFTPSrv.java58
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/XmlUtil.java5
-rw-r--r--ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/serviceregister/MsbRestServiceProxy.java2
-rw-r--r--ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/CollectMsgReceiverThreadTest.java51
-rw-r--r--ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThreadServiceTest.java17
-rw-r--r--ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThreadTest.java22
-rw-r--r--ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmSocketServer.java105
-rw-r--r--ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThreadTest.java41
-rw-r--r--ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/MessageUtilTest.java71
-rw-r--r--ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/AFtpRemoteFileTest.java46
-rw-r--r--ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPSrvTest.java20
-rw-r--r--ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/northbound/service/CommandResourceTest.java28
-rw-r--r--ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/serviceregister/MsbRestServiceProxyTest.java14
21 files changed, 458 insertions, 310 deletions
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/EMSDriverApp.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/EMSDriverApp.java
index 943ab95..72d10cf 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/EMSDriverApp.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/EMSDriverApp.java
@@ -28,7 +28,7 @@ import org.springframework.context.support.FileSystemXmlApplicationContext;
public class EMSDriverApp {
private static Log log = LogFactory.getLog(DriverThread.class);
- public static ApplicationContext context = null;
+ private static ApplicationContext context = null;
static {
try {
/** spring bean applicationContext **/
@@ -57,9 +57,11 @@ public class EMSDriverApp {
if (thread == null) {
log.error(threadName + "Thread start error,system exit");
System.exit(1);
+ }else{
+ thread.setName(threadName);
+ thread.start();
}
- thread.setName(threadName);
- thread.start();
+
}
try {
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/EmsDriverApplication.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/EmsDriverApplication.java
index 6ae160f..b850f9f 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/EmsDriverApplication.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/EmsDriverApplication.java
@@ -18,7 +18,6 @@ package org.onap.vfc.nfvo.emsdriver;
import io.dropwizard.Application;
import io.dropwizard.assets.AssetsBundle;
import io.dropwizard.jetty.HttpConnectorFactory;
-import io.dropwizard.server.DefaultServerFactory;
import io.dropwizard.server.SimpleServerFactory;
import io.dropwizard.setup.Bootstrap;
import io.dropwizard.setup.Environment;
@@ -47,7 +46,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
public class EmsDriverApplication extends Application<EmsDriverConfiguration> {
protected static Log log = LogFactory.getLog(EmsDriverApplication.class);
- public static ApplicationContext context = null;
+ private ApplicationContext context = null;
public static void main(String[] args) throws Exception {
new EmsDriverApplication().run(args);
@@ -72,7 +71,7 @@ public class EmsDriverApplication extends Application<EmsDriverConfiguration> {
MsbConfiguration.setMsbAddress(configuration.getMsbAddress());
//MSB register
String registerFlag = configuration.getAutoServiceRegister();
- if(registerFlag.equalsIgnoreCase("false")){
+ if("false".equalsIgnoreCase(registerFlag)){
this.msbRegisteEmsDriverService(configuration);
}
//Start workThread
@@ -88,9 +87,11 @@ public class EmsDriverApplication extends Application<EmsDriverConfiguration> {
if (thread == null) {
log.error(threadName + "Thread start error,system exit");
System.exit(1);
+ }else{
+ thread.setName(threadName);
+ thread.start();
}
- thread.setName(threadName);
- thread.start();
+
}
}
// init swagger
@@ -122,7 +123,7 @@ public class EmsDriverApplication extends Application<EmsDriverConfiguration> {
try {
ip = InetAddress.getLocalHost().getHostAddress();
} catch (UnknownHostException e) {
- log.error("Unable to get host ip: " + e.getMessage());
+ log.error("Unable to get host ip: ",e);
}
if(ip.equals("")){
ip = connector.getBindHost();
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/CollectMsgReceiverThread.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/CollectMsgReceiverThread.java
index ae15248..5c84a72 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/CollectMsgReceiverThread.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/CollectMsgReceiverThread.java
@@ -88,5 +88,16 @@ public class CollectMsgReceiverThread extends DriverThread{
this.thread_max_num = thread_max_num;
}
+
+
+ /**
+ * @return the taskService
+ */
+ public TaskThreadService getTaskService() {
+ return taskService;
+ }
+
+
+
}
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java
index e77db8b..1d0b6bb 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThread.java
@@ -66,7 +66,7 @@ public class TaskThread implements Runnable{
public Log log = LogFactory.getLog(TaskThread.class);
private MessageChannel cmResultChannel;
- private MessageChannel pmResultChannel;
+ public MessageChannel pmResultChannel;
private CollectMsg data;
@@ -115,7 +115,7 @@ public class TaskThread implements Runnable{
}
}
- private void parseFtpAndSendMessage(String fileName, CollectVo collectVo) {
+ public void parseFtpAndSendMessage(String fileName, CollectVo collectVo) {
//
List<File> filelist = decompressed(fileName);
@@ -178,7 +178,7 @@ public class TaskThread implements Runnable{
String valueLine = "";
List<String> valuelist = new ArrayList<String>();
- while (br.readLine() != null) {
+ while ((valueLine = br.readLine()) != null) {
if (valueLine.trim().equals("")) {
continue;
}
@@ -404,7 +404,7 @@ public class TaskThread implements Runnable{
}
}
- private String createMessage(String zipName,String user,String pwd,String ip, String port,int countNum, String nename) {
+ public String createMessage(String zipName,String user,String pwd,String ip, String port,int countNum, String nename) {
StringBuffer strBuffer = new StringBuffer();
strBuffer
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThread.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThread.java
index 3d74045..ffc1822 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThread.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThread.java
@@ -74,6 +74,7 @@ public class AlarmTaskThread extends Thread{
log.error(StringUtil.getStackTrace(e));
}
} catch (Exception e) {
+ e.printStackTrace();
reinit();
}
}
@@ -275,4 +276,21 @@ public class AlarmTaskThread extends Thread{
}
}
}
+
+ /**
+ * @param isStop the isStop to set
+ */
+ public void setStop(boolean isStop) {
+ this.isStop = isStop;
+ }
+
+ /**
+ * @return the heartBeat
+ */
+ public HeartBeat getHeartBeat() {
+ return heartBeat;
+ }
+
+
+
}
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/AFtpRemoteFile.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/AFtpRemoteFile.java
index 5f7569d..3d3a27d 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/AFtpRemoteFile.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/AFtpRemoteFile.java
@@ -15,8 +15,6 @@
*/
package org.onap.vfc.nfvo.emsdriver.commons.ftp;
-import java.io.IOException;
-
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
@@ -25,8 +23,7 @@ public class AFtpRemoteFile implements RemoteFile{
protected FTPFile ftpFile = null;
protected String currDir = null;
- public AFtpRemoteFile(FTPFile rfile, FTPClient ftpClient, String currDir)
- throws IOException {
+ public AFtpRemoteFile(FTPFile rfile, FTPClient ftpClient, String currDir){
this.ftpClient = ftpClient;
this.ftpFile = rfile;
this.currDir = currDir;
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/ExtendsDefaultFTPFileEntryParserFactory.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/ExtendsDefaultFTPFileEntryParserFactory.java
deleted file mode 100644
index 81e269b..0000000
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/ExtendsDefaultFTPFileEntryParserFactory.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/**
- * Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onap.vfc.nfvo.emsdriver.commons.ftp;
-
-import org.apache.commons.net.ftp.Configurable;
-import org.apache.commons.net.ftp.FTPClientConfig;
-import org.apache.commons.net.ftp.FTPFileEntryParser;
-import org.apache.commons.net.ftp.parser.CompositeFileEntryParser;
-import org.apache.commons.net.ftp.parser.DefaultFTPFileEntryParserFactory;
-import org.apache.commons.net.ftp.parser.MVSFTPEntryParser;
-import org.apache.commons.net.ftp.parser.NTFTPEntryParser;
-import org.apache.commons.net.ftp.parser.OS2FTPEntryParser;
-import org.apache.commons.net.ftp.parser.OS400FTPEntryParser;
-import org.apache.commons.net.ftp.parser.ParserInitializationException;
-import org.apache.commons.net.ftp.parser.UnixFTPEntryParser;
-import org.apache.commons.net.ftp.parser.VMSVersioningFTPEntryParser;
- /**
- * This is the default implementation of the
- * FTPFileEntryParserFactory interface. This is the
- * implementation that will be used by
- * org.apache.commons.net.ftp.FTPClient.listFiles()
- * if no other implementation has been specified.
- *
- * @see org.apache.commons.net.ftp.FTPClient#listFiles
- * @see org.apache.commons.net.ftp.FTPClient#setParserFactory
- */
-public class ExtendsDefaultFTPFileEntryParserFactory extends
- DefaultFTPFileEntryParserFactory {
-
- private FTPClientConfig config = null;
-
- /**
- * This default implementation of the FTPFileEntryParserFactory
- * interface works according to the following logic:
- * First it attempts to interpret the supplied key as a fully
- * qualified classname of a class implementing the
- * FTPFileEntryParser interface. If that succeeds, a parser
- * object of this class is instantiated and is returned;
- * otherwise it attempts to interpret the key as an identirier
- * commonly used by the FTP SYST command to identify systems.
- * <p/>
- * If <code>key</code> is not recognized as a fully qualified
- * classname known to the system, this method will then attempt
- * to see whether it <b>contains</b> a string identifying one of
- * the known parsers. This comparison is <b>case-insensitive</b>.
- * The intent here is where possible, to select as keys strings
- * which are returned by the SYST command on the systems which
- * the corresponding parser successfully parses. This enables
- * this factory to be used in the auto-detection system.
- * <p/>
- *
- * @param key should be a fully qualified classname corresponding to
- * a class implementing the FTPFileEntryParser interface<br/>
- * OR<br/>
- * a string containing (case-insensitively) one of the
- * following keywords:
- * <ul>
- * <li>{@link FTPClientConfig#SYST_UNIX UNIX}</li>
- * <li>{@link FTPClientConfig#SYST_NT WINDOWS}</li>
- * <li>{@link FTPClientConfig#SYST_OS2 OS/2}</li>
- * <li>{@link FTPClientConfig#SYST_OS400 OS/400}</li>
- * <li>{@link FTPClientConfig#SYST_VMS VMS}</li>
- * <li>{@link FTPClientConfig#SYST_MVS MVS}</li>
- * </ul>
- * @return the FTPFileEntryParser corresponding to the supplied key.
- * @throws ParserInitializationException thrown if for any reason the factory cannot resolve
- * the supplied key into an FTPFileEntryParser.
- * @see FTPFileEntryParser
- */
- public FTPFileEntryParser createFileEntryParser(String key)
- {
- @SuppressWarnings("rawtypes")
- Class parserClass = null;
- FTPFileEntryParser parser = null;
- try
- {
- parserClass = Class.forName(key);
- parser = (FTPFileEntryParser) parserClass.newInstance();
- }
- catch (ClassNotFoundException e)
- {
- String ukey = null;
- if (null != key)
- {
- ukey = key.toUpperCase();
- }
- if (ukey.indexOf(FTPClientConfig.SYST_UNIX) >= 0)
- {
- parser = createUnixFTPEntryParser();
- }
- else if (ukey.indexOf(FTPClientConfig.SYST_VMS) >= 0)
- {
- parser = createVMSVersioningFTPEntryParser();
- }
- else if (ukey.indexOf(FTPClientConfig.SYST_NT) >= 0 || ukey.indexOf("DOPRA") >= 0 || ukey.indexOf("MSDOS") >= 0)
- {
- parser = createNTFTPEntryParser();
- }
- else if (ukey.indexOf(FTPClientConfig.SYST_OS2) >= 0)
- {
- parser = createOS2FTPEntryParser();
- }
- else if (ukey.indexOf(FTPClientConfig.SYST_OS400) >= 0)
- {
- parser = createOS400FTPEntryParser();
- }
- else if (ukey.indexOf(FTPClientConfig.SYST_MVS) >= 0)
- {
- parser = createMVSEntryParser();
- }
- else
- {
- throw new ParserInitializationException("Unknown parser type: " + key);
- }
- }
- catch (ClassCastException e)
- {
- throw new ParserInitializationException(parserClass.getName()
- + " does not implement the interface "
- + "org.apache.commons.net.ftp.FTPFileEntryParser.", e);
- }
- catch (Throwable e)
- {
- throw new ParserInitializationException("Error initializing parser", e);
- }
-
- if (parser instanceof Configurable) {
- ((Configurable)parser).configure(this.config);
- }
- return parser;
- }
-
- /**
- * <p>Implementation extracts a key from the supplied
- * {@link FTPClientConfig FTPClientConfig}
- * parameter and creates an object implementing the
- * interface FTPFileEntryParser and uses the supplied configuration
- * to configure it.
- * </p><p>
- * Note that this method will generally not be called in scenarios
- * that call for autodetection of parser type but rather, for situations
- * where the user knows that the server uses a non-default configuration
- * and knows what that configuration is.
- * </p>
- * @param config A {@link FTPClientConfig FTPClientConfig}
- * used to configure the parser created
- *
- * @return the @link FTPFileEntryParser FTPFileEntryParser} so created.
- * @exception ParserInitializationException
- * Thrown on any exception in instantiation
- * @since 1.4
- */
- public FTPFileEntryParser createFileEntryParser(FTPClientConfig config)
- throws ParserInitializationException
- {
- this.config = config;
- String key = config.getServerSystemKey();
- return createFileEntryParser(key);
- }
-
-
- public FTPFileEntryParser createUnixFTPEntryParser()
- {
- return (FTPFileEntryParser) new UnixFTPEntryParser();
- }
-
- public FTPFileEntryParser createVMSVersioningFTPEntryParser()
- {
- return (FTPFileEntryParser) new VMSVersioningFTPEntryParser();
- }
-
- public FTPFileEntryParser createNTFTPEntryParser()
- {
- if (config != null && FTPClientConfig.SYST_NT.equals(
- config.getServerSystemKey()))
- {
- return new NTFTPEntryParser();
- } else {
- return new CompositeFileEntryParser(new FTPFileEntryParser[]
- {
- new NTFTPEntryParser(),
- new UnixFTPEntryParser()
- });
- }
- }
-
- public FTPFileEntryParser createOS2FTPEntryParser()
- {
- return (FTPFileEntryParser) new OS2FTPEntryParser();
- }
-
- public FTPFileEntryParser createOS400FTPEntryParser()
- {
- if (config != null &&
- FTPClientConfig.SYST_OS400.equals(config.getServerSystemKey()))
- {
- return new OS400FTPEntryParser();
- } else {
- return new CompositeFileEntryParser(new FTPFileEntryParser[]
- {
- new OS400FTPEntryParser(),
- new UnixFTPEntryParser()
- });
- }
- }
-
- public FTPFileEntryParser createMVSEntryParser()
- {
- return new MVSFTPEntryParser();
- }
-}
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPSrv.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPSrv.java
index d008a43..fdb838f 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPSrv.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPSrv.java
@@ -16,7 +16,6 @@
package org.onap.vfc.nfvo.emsdriver.commons.ftp;
import java.io.BufferedOutputStream;
-import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.TimeZone;
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/SFTPSrv.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/SFTPSrv.java
deleted file mode 100644
index 1e0867e..0000000
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/SFTPSrv.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.onap.vfc.nfvo.emsdriver.commons.ftp;
-
-public class SFTPSrv implements FTPInterface{
-
- public boolean chdir(String dir) {
- // TODO Auto-generated method stub
- return false;
- }
-
- public boolean downloadFile(String remoteFile, String localFile) {
- // TODO Auto-generated method stub
- return false;
- }
-
- public RemoteFile[] list() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public RemoteFile[] list(String dir) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public void login(String host, int port, String user, String pwd,
- String encode, boolean isPassiveMode, int timeout) throws Exception {
- // TODO Auto-generated method stub
-
- }
-
- public void logout() {
- // TODO Auto-generated method stub
-
- }
-
- public boolean store(String localFile, String remoteFile) {
- // TODO Auto-generated method stub
- return false;
- }
-
-
-}
-
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/XmlUtil.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/XmlUtil.java
index 67f4688..e5a7839 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/XmlUtil.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/commons/utils/XmlUtil.java
@@ -34,9 +34,4 @@ public class XmlUtil {
Document doc = builder.build(is);
return doc;
}
- public static Document getDocument(Reader reader) throws XMLStreamException, JDOMException, IOException{
- SAXBuilder builder = new SAXBuilder();
- Document doc = builder.build(reader);
- return doc;
- }
}
diff --git a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/serviceregister/MsbRestServiceProxy.java b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/serviceregister/MsbRestServiceProxy.java
index 129511b..1e0693c 100644
--- a/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/serviceregister/MsbRestServiceProxy.java
+++ b/ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/serviceregister/MsbRestServiceProxy.java
@@ -45,7 +45,7 @@ public class MsbRestServiceProxy {
List<String> ipList = new ArrayList<String>();
String url = MsbConfiguration.getMsbAddress()+Constant.MSBAPIROOTDOMAIN+"/"+serviceName+"/version/"+version;
String response = HttpClientUtil.doGet(url, Constant.ENCODING_UTF8);
- if(!response.equals("")){
+ if(response !=null && !"".equals(response)){
MsbRegisterVo msbRegisterVo = JSON.parseObject(response,MsbRegisterVo.class);
List<ServiceNodeVo> nodeList = msbRegisterVo.getNodes();
diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/CollectMsgReceiverThreadTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/CollectMsgReceiverThreadTest.java
new file mode 100644
index 0000000..a57f0f3
--- /dev/null
+++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/CollectMsgReceiverThreadTest.java
@@ -0,0 +1,51 @@
+/**
+ * Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.vfc.nfvo.emsdriver.collector;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.vfc.nfvo.emsdriver.commons.model.CollectMsg;
+
+public class CollectMsgReceiverThreadTest {
+
+ CollectMsgReceiverThread col = null;
+ @Before
+ public void setUp() {
+ col = new CollectMsgReceiverThread();
+ }
+
+
+ @Test
+ public void dispose() {
+ new Thread(){
+ public void run() {
+ try {
+ Thread.sleep(10);
+ col.setRun(false);
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }.start();
+ col.setRun(true);
+ col.dispose();
+ col.getTaskService().stopTask();
+ col.getThread_max_num();
+ col.setThread_max_num(1);
+
+ }
+}
diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThreadServiceTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThreadServiceTest.java
index 76569ff..b22b260 100644
--- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThreadServiceTest.java
+++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThreadServiceTest.java
@@ -36,13 +36,30 @@ public class TaskThreadServiceTest {
@Test
public void add() {
taskThreadService.add(collectMsg);
+ taskThreadService.size();
+ new Thread(){
+ public void run() {
+ try {
+ Thread.sleep(10);
+ taskThreadService.stopTask();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }.start();
+ taskThreadService.run();
+
}
@Test
public void receive() {
taskThreadService.add(collectMsg);
CollectMsg collectMsg = taskThreadService.receive();
+
assertNotNull(collectMsg);
}
+
+
}
diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThreadTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThreadTest.java
index 13d7052..4f4cbd2 100644
--- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThreadTest.java
+++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/TaskThreadTest.java
@@ -25,7 +25,10 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onap.vfc.nfvo.emsdriver.collector.TaskThread;
+import org.onap.vfc.nfvo.emsdriver.commons.constant.Constant;
+import org.onap.vfc.nfvo.emsdriver.commons.model.CollectVo;
import org.onap.vfc.nfvo.emsdriver.commons.utils.Gzip;
+import org.onap.vfc.nfvo.emsdriver.messagemgr.MessageChannelFactory;
public class TaskThreadTest {
private String csvPath = System.getProperty("user.dir")+"/data/" +"PM-ENB-EUTRANCELLNB-test.csv";
@@ -35,6 +38,7 @@ public class TaskThreadTest {
@Before
public void setUp() throws IOException {
taskThread = new TaskThread();
+ taskThread.pmResultChannel = MessageChannelFactory.getMessageChannel(Constant.COLLECT_CHANNEL_KEY);
Gzip gzip = new Gzip();
gzip.compress(csvPath, gzPath);
}
@@ -55,6 +59,24 @@ public class TaskThreadTest {
}
}
+ @Test
+ public void parseFtpAndSendMessage(){
+ CollectVo collectVo = new CollectVo();
+ collectVo.setType("ems-p");
+ taskThread.parseFtpAndSendMessage(gzPath,collectVo);
+ }
+
+ @Test
+ public void createMessage(){
+ CollectVo collectVo = new CollectVo();
+ collectVo.setType("ems-p");
+ taskThread.createMessage("zipName", "user", "pwd", "ip", "port", 122, "nename");
+ }
+
+
+
+
+
@After
public void setDown() throws IOException {
new File(gzPath).delete();
diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmSocketServer.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmSocketServer.java
new file mode 100644
index 0000000..ada1fd3
--- /dev/null
+++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmSocketServer.java
@@ -0,0 +1,105 @@
+/**
+ * Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.vfc.nfvo.emsdriver.collector.alarm;
+
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketTimeoutException;
+
+public class AlarmSocketServer {
+
+ boolean stop = false;
+ InputStreamReader isr = null;
+ BufferedOutputStream dos = null;
+ Socket socket = null;
+ ServerSocket server = null;
+ public void socketServer(){
+
+ try {
+ server = new ServerSocket(12345);
+ socket = server.accept();
+
+ socket.setSoTimeout(3*1000);
+ socket.setTcpNoDelay(true);
+ socket.setKeepAlive(true);
+ InputStream in = socket.getInputStream();
+ isr = new InputStreamReader(in);
+ dos = new BufferedOutputStream(socket.getOutputStream());
+ while(!stop){
+ int len = 0;
+ char b[] = new char[1024 * 8];
+ try{
+ len = isr.read(b, 0, b.length);
+ }catch(SocketTimeoutException e){
+ e.printStackTrace();
+ break;
+ }
+ if (len > 0) {
+ String restlu = new String(b, 0, len);
+ if(restlu.contains("reqLoginAlarm")){
+ Msg msg = new Msg("ackLoginAlarm;result=succ;resDesc= ",MsgType.ackLoginAlarm);
+
+ MessageUtil.writeMsg(msg,dos);
+ }
+ if(restlu.contains("reqHeartBeat")){
+ Msg msg = new Msg("ackHeartBeat;result=succ;resDesc= ",MsgType.ackHeartBeat);
+
+ MessageUtil.writeMsg(msg,dos);
+ }
+ Msg msg = new Msg("realTimeAlarm;result=succ;resDesc= ",MsgType.realTimeAlarm);
+
+ MessageUtil.writeMsg(msg,dos);
+
+
+
+ }else{
+ System.out.println("len:" +len);
+ Thread.sleep(10);
+ }
+
+ }
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ public void stop(){
+ try {
+ stop = true;
+ if(isr != null){
+ isr.close();
+ }
+ if(dos != null){
+ dos.close();
+ }
+ if(socket != null){
+ socket.close();
+ }
+ if(server != null){
+ server.close();
+ }
+
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThreadTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThreadTest.java
index c657c19..4fd7bcd 100644
--- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThreadTest.java
+++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/AlarmTaskThreadTest.java
@@ -22,20 +22,57 @@ import java.io.IOException;
import org.junit.Before;
import org.junit.Test;
import org.onap.vfc.nfvo.emsdriver.collector.alarm.AlarmTaskThread;
+import org.onap.vfc.nfvo.emsdriver.commons.model.CollectVo;
public class AlarmTaskThreadTest {
private AlarmTaskThread taskThread;
+ private AlarmSocketServer server;
@Before
public void setUp() throws IOException {
- taskThread = new AlarmTaskThread();
+ new Thread(){
+ public void run(){
+ server = new AlarmSocketServer();
+ server.socketServer();
+ }
+ }.start();
+
+ CollectVo collectVo = new CollectVo();
+ collectVo.setIP("127.0.0.1");
+ collectVo.setPort("12345");
+ collectVo.setUser("user");
+ collectVo.setPassword("12345");
+ taskThread = new AlarmTaskThread(collectVo);
}
@Test
public void build120Alarm(){
String alarm = "{\"alarmSeq\":495,\"alarmTitle\":\"LTE cell outage\",\"alarmStatus\":1,\"alarmType\":\"processingErrorAlarm\"}";
-// String al = taskThread.build120Alarm(alarm);
+ try {
+ new Thread(){
+ public void run(){
+ try {
+ Thread.sleep(3000);
+
+ server.stop();
+ taskThread.setStop(true);
+ taskThread.close();
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }.start();
+
+ taskThread.init();
+ taskThread.receive();
+
+
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
assertNotNull(alarm);
}
diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/MessageUtilTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/MessageUtilTest.java
new file mode 100644
index 0000000..a4f264c
--- /dev/null
+++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/MessageUtilTest.java
@@ -0,0 +1,71 @@
+/**
+ * Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.vfc.nfvo.emsdriver.collector.alarm;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+public class MessageUtilTest {
+
+ @Test
+ public void putLoginFtp(){
+ Msg msg = MessageUtil.putLoginFtp("user", "passwd");
+
+ assertNotNull(msg);
+ }
+ @Test
+ public void putSyncMsg(){
+ Msg msg = MessageUtil.putSyncMsg(1, 10);
+
+ assertNotNull(msg);
+ }
+
+ @Test
+ public void reqSyncAlarmFile(){
+ Msg msg = MessageUtil.reqSyncAlarmFile(1, "2017-10-7","2017-10-7");
+
+ assertNotNull(msg);
+ }
+ @Test
+ public void reqSyncAlarmFileByAlarmSeq(){
+ Msg msg = MessageUtil.reqSyncAlarmFileByAlarmSeq(1, 12);
+
+ assertNotNull(msg);
+ }
+ @Test
+ public void reqSyncAlarmFileByTime(){
+ Msg msg = MessageUtil.reqSyncAlarmFileByTime(1, "2017-10-7","2017-10-7");
+
+ assertNotNull(msg);
+ }
+
+ @Test
+ public void closeConnAlarmMsg(){
+ Msg msg = MessageUtil.closeConnAlarmMsg();
+
+ assertNotNull(msg);
+ }
+
+
+
+
+
+
+
+
+
+}
diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/AFtpRemoteFileTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/AFtpRemoteFileTest.java
new file mode 100644
index 0000000..e17290d
--- /dev/null
+++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/AFtpRemoteFileTest.java
@@ -0,0 +1,46 @@
+/**
+ * Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.vfc.nfvo.emsdriver.commons.ftp;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.commons.net.ftp.FTPClient;
+import org.apache.commons.net.ftp.FTPFile;
+import org.junit.Before;
+import org.junit.Test;
+
+public class AFtpRemoteFileTest {
+
+ AFtpRemoteFile aFtpRemoteFile = null;
+ @Before
+ public void setUp() {
+ FTPFile f = new FTPFile();
+ f.setName("aaa/bb.txt");
+ aFtpRemoteFile = new AFtpRemoteFile(f , new FTPClient(), "aaa/");
+ }
+
+ @Test
+ public void getFileName() {
+ String fileName = aFtpRemoteFile.getFileName();
+ assertNotNull(fileName);
+ }
+ @Test
+ public void getAbsFileName() {
+ String absFileName = aFtpRemoteFile.getAbsFileName();
+ assertNotNull(absFileName);
+ }
+
+}
diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPSrvTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPSrvTest.java
new file mode 100644
index 0000000..0765cac
--- /dev/null
+++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/commons/ftp/FTPSrvTest.java
@@ -0,0 +1,20 @@
+/**
+ * Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.vfc.nfvo.emsdriver.commons.ftp;
+
+public class FTPSrvTest {
+
+}
diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/northbound/service/CommandResourceTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/northbound/service/CommandResourceTest.java
new file mode 100644
index 0000000..cb6c087
--- /dev/null
+++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/northbound/service/CommandResourceTest.java
@@ -0,0 +1,28 @@
+/**
+ * Copyright 2017 BOCO Corporation. CMCC Technologies Co., Ltd
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.vfc.nfvo.emsdriver.northbound.service;
+
+import org.junit.Test;
+
+public class CommandResourceTest {
+
+ @Test
+ public void testExecuteCommand(){
+ CommandResource commandResource = new CommandResource();
+ commandResource.executeCommand("aaa");
+ }
+}
+
diff --git a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/serviceregister/MsbRestServiceProxyTest.java b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/serviceregister/MsbRestServiceProxyTest.java
index 672c95d..25c599e 100644
--- a/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/serviceregister/MsbRestServiceProxyTest.java
+++ b/ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/serviceregister/MsbRestServiceProxyTest.java
@@ -15,6 +15,8 @@
*/
package org.onap.vfc.nfvo.emsdriver.serviceregister;
+import java.util.List;
+
import org.junit.Before;
import org.junit.Test;
import org.onap.vfc.nfvo.emsdriver.serviceregister.model.MsbRegisterVo;
@@ -30,7 +32,15 @@ public class MsbRestServiceProxyTest {
MsbRegisterVo registerInfo = new MsbRegisterVo();
registerInfo.setServiceName("ems-driver");
registerInfo.setUrl("/api/emsdriver/v1");
- String registerResponse = MsbRestServiceProxy.registerService(registerInfo);
- System.out.println(registerResponse);
+ MsbRestServiceProxy.registerService(registerInfo);
+ }
+ @Test
+ public void testunRegiserService(){
+ MsbRestServiceProxy.unRegiserService("emsdriver","v1","172.0.0.1","9999");
+ }
+
+ @Test
+ public void testqueryService(){
+ List<String> queryService = MsbRestServiceProxy.queryService("emsdriver","v1");
}
}