Test coverage for CommonMessage 58/78758/2
authorJoss Armstrong <joss.armstrong@ericsson.com>
Tue, 19 Feb 2019 13:34:05 +0000 (13:34 +0000)
committerJoss Armstrong <joss.armstrong@ericsson.com>
Tue, 19 Feb 2019 13:38:04 +0000 (13:38 +0000)
Increased coverage from 41% to 95%

Issue-ID: APPC-1462
Change-Id: I602a0178617f29ab34f7a4ab4400d6e5c442bd9d
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/demo/model/CommonMessage.java
appc-event-listener/appc-event-listener-bundle/src/test/java/org/onap/appc/listener/demo/model/TestMessages.java

index ae32828..45b99a9 100644 (file)
@@ -5,6 +5,8 @@
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -265,7 +267,7 @@ public class CommonMessage implements Serializable {
         public void setGenericVnfId(String genericVnfId) {
             this.genericVnfId = genericVnfId;
         }
-        
+
         @JsonProperty("pg-streams")
         private pgStreams pgStreams;
 
@@ -303,38 +305,35 @@ public class CommonMessage implements Serializable {
     };
     @JsonIgnoreProperties(ignoreUnknown = true)
     public static class pgStreams {
-       @JsonProperty("pg-stream")
+        @JsonProperty("pg-stream")
         private Collection<pgStream> streams;
-       
-        public Collection<pgStream> getStreams() {
-                       return streams;
-               }
-
-               public void setStreams(Collection<pgStream> streams) {
-                       this.streams = streams;
-               }
 
+        public Collection<pgStream> getStreams() {
+            return streams;
+        }
 
+        public void setStreams(Collection<pgStream> streams) {
+            this.streams = streams;
+        }
     };
-       @JsonIgnoreProperties(ignoreUnknown = true)
-       public static class pgStream{
-       public String getId() {
-                       return id;
-               }
-               public void setId(String id) {
-                       this.id = id;
-               }
-               public String getIsEnabled() {
-                       return isEnabled;
-               }
-               public void setIsEnabled(String isEnabled) {
-                       this.isEnabled = isEnabled;
-               }
-               @JsonProperty("id")
+
+    @JsonIgnoreProperties(ignoreUnknown = true)
+    public static class pgStream{
+        public String getId() {
+            return id;
+        }
+        public void setId(String id) {
+            this.id = id;
+        }
+        public String getIsEnabled() {
+            return isEnabled;
+        }
+        public void setIsEnabled(String isEnabled) {
+            this.isEnabled = isEnabled;
+        }
+        @JsonProperty("id")
         private String id;
         @JsonProperty("is-enabled")
         private String isEnabled;
-       };
-
-
+     };
 }
index 2462e51..62ea83a 100644 (file)
@@ -7,6 +7,8 @@
  * Copyright (C) 2017 Amdocs
  * =============================================================================
  * Modification Copyright (C) 2018 IBM.
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -27,16 +29,17 @@ package org.onap.appc.listener.demo.model;
 
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
-
+import java.util.ArrayList;
+import java.util.Collection;
 import org.apache.commons.io.IOUtils;
 import org.json.JSONObject;
 import org.junit.Before;
 import org.junit.Ignore;
 import org.junit.Test;
+import org.onap.appc.listener.demo.model.CommonMessage.pgStream;
 import org.onap.appc.listener.demo.model.IncomingMessage;
 import org.onap.appc.listener.demo.model.OutgoingMessage;
 import org.onap.appc.listener.demo.model.Status;
@@ -64,7 +67,6 @@ public class TestMessages {
             assertNotNull(in);
             assertNotNull(out);
         } catch (Exception e) {
-            e.printStackTrace();
             fail(e.getMessage());
         }
     }
@@ -79,7 +81,7 @@ public class TestMessages {
         assertNotNull(in.getHeader().getRequestID());
         assertNotNull(in.getHeader().getSubRequestId());
         assertNotNull(in.getHeader().getTimeStamp());
-        
+
         assertNotNull(out);
         assertNotNull(out.getHeader().getApiVer());
         assertNotNull(out.getHeader().getOriginatorId());
@@ -90,7 +92,7 @@ public class TestMessages {
         assertNotNull(out.getStatus().getValue());
 
     }
-    
+
     @Test
     public void testGetRequest()
     {
@@ -98,13 +100,37 @@ public class TestMessages {
         in.setRequest(request);
         assertEquals(request, in.getRequest());
     }
-    
+
     @Test
     public void testIsValid()
     {
         assertEquals(true, in.isValid());
     }
 
+    @Test
+    public void testTime() {
+        in.setStartTime(0);
+        assertEquals(0, in.getStartTime());
+    }
+
+    @Test
+    public void testPayload() {
+        CommonMessage.Payload payload = new CommonMessage.Payload();
+        payload.setGenericVnfId("VNF_ID");
+        CommonMessage.pgStream pgStream = new CommonMessage.pgStream();
+        pgStream.setId("ID");
+        pgStream.setIsEnabled("true");
+        CommonMessage.pgStreams pgStreams = new CommonMessage.pgStreams();
+        Collection<pgStream> collectionPgStreams = new ArrayList<pgStream>();
+        collectionPgStreams.add(pgStream);
+        pgStreams.setStreams(collectionPgStreams);
+        payload.setPgStreams(pgStreams);
+        in.setPayload(payload);
+        assertEquals("VNF_ID", in.getPayload().getGenericVnfId());
+        assertEquals("{\\\"pg-streams\\\": {\\\"pg-stream\\\":[{\\\"id\\\":\\\"ID\\\", \\\"is-enabled\\\":\\\"true\\\"}]}}",
+                in.getPayload().getPgStreams());
+    }
+
     @Test
     @Ignore
     public void testIncommingToOutgoing(){
@@ -119,7 +145,7 @@ public class TestMessages {
         assertNotNull(newOut.getStatus().getCode());
         assertNotNull(newOut.getStatus().getValue());
     }
-    
+
     @Test
     @Ignore
     public void testToString() {
@@ -131,7 +157,6 @@ public class TestMessages {
         assertTrue(in.toString().contains(id));
     }
 
-    
     @Test
     @Ignore
     public void testOutgoingUpdateTime() {