742fe34ec835c2ae50763080c951fd5efd6015ed
[appc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Amdocs
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  */
22
23 package org.openecomp.appc.listener.demo.model;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertFalse;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29 import static org.junit.Assert.fail;
30
31 import org.apache.commons.io.IOUtils;
32 import org.json.JSONObject;
33 import org.junit.Before;
34 import org.junit.Ignore;
35 import org.junit.Test;
36 import org.openecomp.appc.listener.demo.model.IncomingMessage;
37 import org.openecomp.appc.listener.demo.model.OutgoingMessage;
38 import org.openecomp.appc.listener.demo.model.Status;
39 import org.openecomp.appc.listener.util.Mapper;
40
41 public class TestMessages {
42     private IncomingMessage in;
43     private OutgoingMessage out;
44
45     private String incomingStr;
46     private String outgoingStr;
47
48     @Before
49     public void setup() {
50         try {
51             incomingStr = IOUtils.toString(getClass().getResourceAsStream("/IncomingMessagedemo.txt"), "UTF-8");
52             outgoingStr = IOUtils.toString(getClass().getResourceAsStream("/OutgoingMessagedemo.txt"), "UTF-8");
53             assertNotNull(incomingStr);
54             assertNotNull(outgoingStr);
55
56             in = Mapper.mapOne(incomingStr, IncomingMessage.class);
57
58             out = Mapper.mapOne(outgoingStr, OutgoingMessage.class);
59
60             assertNotNull(in);
61             assertNotNull(out);
62         } catch (Exception e) {
63             e.printStackTrace();
64             fail(e.getMessage());
65         }
66     }
67
68     // NOTE Test Mapper will be used to test an event from dmaap.
69     @Test
70     public void testGetterSetter() {
71         assertNotNull(in);
72         assertNotNull(in.getAction());
73         assertNotNull(in.getHeader().getApiVer());
74         assertNotNull(in.getHeader().getOriginatorId());
75         assertNotNull(in.getHeader().getRequestID());
76         assertNotNull(in.getHeader().getSubRequestId());
77         assertNotNull(in.getHeader().getTimeStamp());
78         
79         assertNotNull(out);
80         assertNotNull(out.getHeader().getApiVer());
81         assertNotNull(out.getHeader().getOriginatorId());
82         assertNotNull(out.getHeader().getRequestID());
83         assertNotNull(out.getHeader().getSubRequestId());
84         assertNotNull(out.getHeader().getTimeStamp());
85         assertNotNull(out.getStatus().getCode());
86         assertNotNull(out.getStatus().getValue());
87
88     }
89
90     @Test
91     @Ignore
92     public void testIncommingToOutgoing(){
93         OutgoingMessage newOut;
94         newOut = Mapper.mapOne(in.toOutgoing(Status.ACCEPTED), OutgoingMessage.class);
95         assertNotNull(newOut);
96         assertNotNull(newOut.getHeader().getApiVer());
97         assertNotNull(newOut.getHeader().getOriginatorId());
98         assertNotNull(newOut.getHeader().getRequestID());
99         assertNotNull(newOut.getHeader().getSubRequestId());
100         assertNotNull(newOut.getHeader().getTimeStamp());
101         assertNotNull(newOut.getStatus().getCode());
102         assertNotNull(newOut.getStatus().getValue());
103     }
104     
105     @Test
106     @Ignore
107     public void testToString() {
108         in = new IncomingMessage();
109         assertNotNull(in.toString());
110         String id = "test";
111         //in.setId(id);
112         assertNotNull(in.toString());
113         assertTrue(in.toString().contains(id));
114     }
115
116     
117     @Test
118     @Ignore
119     public void testOutgoingUpdateTime() {
120         //String old = out.getResponseTime();
121         out.updateResponseTime();
122         //assertFalse(old.equals(out.getResponseTime()));
123     }
124
125     // Testing for 1510
126     @Test
127     @Ignore
128     public void testOutgoingToJson() {
129         // Message Set
130         String message = "MSG";
131         //out.setMessage(message);
132         JSONObject json = out.toResponse();
133         assertNotNull(json);
134         String respStr = json.getString("response");
135         //assertTrue(respStr.contains(out.getResponse().getValue()));
136
137         String msgStr = json.getString("message");
138         assertNotNull(msgStr);
139         //assertFalse(msgStr.contains(out.getOriginalRequest())); // False for 1602
140         //assertTrue(msgStr.contains(out.getMessage()));
141
142         // Null Message
143         //out.setMessage(null);
144         json = out.toResponse();
145         assertNotNull(json);
146         msgStr = json.getString("message");
147         assertNotNull(msgStr);
148         //assertFalse(msgStr.contains(out.getOriginalRequest())); // False for 1602
149         //assertTrue(msgStr.contains(out.getResponse().getValue()));
150
151         // Echoing request
152         //assertNotNull(out.getOriginalRequest());
153     }
154
155     @Test
156     @Ignore
157     public void testOutgoingToString() {
158         String s = out.toString();
159         //assertTrue(s.contains(out.getId()));
160     }
161 }