Add unit test 25/37025/1
authoryangyan <yangyanyj@chinamobile.com>
Tue, 20 Mar 2018 09:24:16 +0000 (17:24 +0800)
committeryangyan <yangyanyj@chinamobile.com>
Tue, 20 Mar 2018 09:24:35 +0000 (17:24 +0800)
Issue-ID: VFC-836
Change-Id: Ie893da7ce8c6c85459644b4e5251460e6439b420
Signed-off-by: yangyan <yangyanyj@chinamobile.com>
ems/boco/data/aaa.txt [new file with mode: 0644]
ems/boco/data/bbb.txt
ems/boco/src/main/java/org/onap/vfc/nfvo/emsdriver/collector/CollectMsgReceiverThread.java
ems/boco/src/test/java/org/onap/vfc/nfvo/emsdriver/collector/alarm/MessageUtilTest.java

diff --git a/ems/boco/data/aaa.txt b/ems/boco/data/aaa.txt
new file mode 100644 (file)
index 0000000..e69de29
index e69de29..458aab0 100644 (file)
@@ -0,0 +1 @@
+test abc
\ No newline at end of file
index d3ced48..89cf34b 100644 (file)
@@ -35,7 +35,6 @@ public class CollectMsgReceiverThread extends DriverThread {
     @Override
     public void dispose() {
         collectChannel = MessageChannelFactory.getMessageChannel(Constant.COLLECT_CHANNEL_KEY);
-
         taskService = TaskThreadService.getInstance(threadMaxNum);
         taskService.start();
 
index 2f3d637..171c041 100644 (file)
  */
 package org.onap.vfc.nfvo.emsdriver.collector.alarm;
 
-import org.junit.Test;
-
 import static org.junit.Assert.assertNotNull;
 
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.junit.Test;
+
 public class MessageUtilTest {
 
     @Test
@@ -62,6 +69,52 @@ public class MessageUtilTest {
 
         assertNotNull(msg);
     }
+    
+    @Test
+    public void putloginMsg() {
+       String user = "test";
+       String passwd = "test";
+       Msg msg = MessageUtil.putLoginMsg(user, passwd);
+       assertNotNull(msg);     
+    }
 
-
+    @Test
+    public void putHeartBeatMsg() {
+       Msg msg = MessageUtil.putHeartBeatMsg(1);
+       assertNotNull(msg);     
+    }
+    
+    @Test
+    public void readOneMsg(){
+       try {
+       String fileName = System.getProperty("user.dir") + "/data/" + "bbb.txt";
+       FileInputStream fis = new FileInputStream(fileName);
+        BufferedInputStream bis=new BufferedInputStream(fis);
+       Msg msg = MessageUtil.readOneMsg(bis);
+       assertNotNull(msg);             
+               } catch (FileNotFoundException e) {
+                       // TODO Auto-generated catch block
+                  System.out.println("File is not found");
+       } catch (IOException e){
+          System.out.println("There is IOException");
+       }
+    }
+    
+    
+    
+    @Test
+    public void writeMsg(){
+        try {
+       String msgBody = "Heartbeat";
+       Msg msg = new Msg(msgBody,MsgType.ACK_HEARTBEAT);
+       String fileName = System.getProperty("user.dir") + "/data/" + "aaa.txt";
+       FileOutputStream fos=new FileOutputStream(fileName);
+        BufferedOutputStream bos=new BufferedOutputStream(fos);
+        MessageUtil.writeMsg(msg, bos);
+               } catch (IOException e) {
+                       // TODO Auto-generated catch block
+                       System.out.println("There is IOException");
+               }
+        
+    }
 }