aboutsummaryrefslogtreecommitdiffstats
path: root/app-c/appc/appc-event-listener/appc-event-listener-bundle/src/test/java/org/openecomp/appc/listener/CL1607/model/TestMessages.java
blob: c7bc8630087b4cb929e073947a5bf32d401360ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*-
 * ============LICENSE_START=======================================================
 * openECOMP : APP-C
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights
 * 						reserved.
 * ================================================================================
 * 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.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.appc.listener.CL1607.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 org.apache.commons.io.IOUtils;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.openecomp.appc.listener.CL1607.model.IncomingMessage;
import org.openecomp.appc.listener.CL1607.model.OutgoingMessage;
import org.openecomp.appc.listener.CL1607.model.Status;
import org.openecomp.appc.listener.util.Mapper;

public class TestMessages {
    private IncomingMessage in;
    private OutgoingMessage out;

    private String incomingStr;
    private String outgoingStr;

    @Before
    public void setup() {
        try {
            incomingStr = IOUtils.toString(getClass().getResourceAsStream("/IncomingMessage1607.txt"), "UTF-8");
            outgoingStr = IOUtils.toString(getClass().getResourceAsStream("/OutgoingMessage1607.txt"), "UTF-8");
            assertNotNull(incomingStr);
            assertNotNull(outgoingStr);

            in = Mapper.mapOne(incomingStr, IncomingMessage.class);

            out = Mapper.mapOne(outgoingStr, OutgoingMessage.class);

            assertNotNull(in);
            assertNotNull(out);
        } catch (Exception e) {
            e.printStackTrace();
            fail(e.getMessage());
        }
    }

    // NOTE Test Mapper will be used to test an event from dmaap.
    @Test
    public void testGetterSetter() {
        assertNotNull(in);
        assertNotNull(in.getAction());
        assertNotNull(in.getHeader().getApiVer());
        assertNotNull(in.getHeader().getOriginatorId());
        assertNotNull(in.getHeader().getRequestID());
        assertNotNull(in.getHeader().getSubRequestId());
        assertNotNull(in.getHeader().getTimeStamp());
        
        assertNotNull(out);
        assertNotNull(out.getHeader().getApiVer());
        assertNotNull(out.getHeader().getOriginatorId());
        assertNotNull(out.getHeader().getRequestID());
        assertNotNull(out.getHeader().getSubRequestId());
        assertNotNull(out.getHeader().getTimeStamp());
        assertNotNull(out.getStatus().getCode());
        assertNotNull(out.getStatus().getValue());

    }

    @Test
    @Ignore
    public void testIncommingToOutgoing(){
    	OutgoingMessage newOut;
    	newOut = Mapper.mapOne(in.toOutgoing(Status.ACCEPTED), OutgoingMessage.class);
        assertNotNull(newOut);
        assertNotNull(newOut.getHeader().getApiVer());
        assertNotNull(newOut.getHeader().getOriginatorId());
        assertNotNull(newOut.getHeader().getRequestID());
        assertNotNull(newOut.getHeader().getSubRequestId());
        assertNotNull(newOut.getHeader().getTimeStamp());
        assertNotNull(newOut.getStatus().getCode());
        assertNotNull(newOut.getStatus().getValue());
    }
    
    @Test
    @Ignore
    public void testToString() {
        in = new IncomingMessage();
        assertNotNull(in.toString());
        String id = "test";
        //in.setId(id);
        assertNotNull(in.toString());
        assertTrue(in.toString().contains(id));
    }

    
    @Test
    @Ignore
    public void testOutgoingUpdateTime() {
        //String old = out.getResponseTime();
        out.updateResponseTime();
        //assertFalse(old.equals(out.getResponseTime()));
    }

    // Testing for 1510
    @Test
    @Ignore
    public void testOutgoingToJson() {
        // Message Set
        String message = "MSG";
        //out.setMessage(message);
        JSONObject json = out.toResponse();
        assertNotNull(json);
        String respStr = json.getString("response");
        //assertTrue(respStr.contains(out.getResponse().getValue()));

        String msgStr = json.getString("message");
        assertNotNull(msgStr);
        //assertFalse(msgStr.contains(out.getOriginalRequest())); // False for 1602
        //assertTrue(msgStr.contains(out.getMessage()));

        // Null Message
        //out.setMessage(null);
        json = out.toResponse();
        assertNotNull(json);
        msgStr = json.getString("message");
        assertNotNull(msgStr);
        //assertFalse(msgStr.contains(out.getOriginalRequest())); // False for 1602
        //assertTrue(msgStr.contains(out.getResponse().getValue()));

        // Echoing request
        //assertNotNull(out.getOriginalRequest());
    }

    @Test
    @Ignore
    public void testOutgoingToString() {
        String s = out.toString();
        //assertTrue(s.contains(out.getId()));
    }
}