4d6d03b24713edf53e335546790b7b02beebd93e
[appc.git] / appc-event-listener / appc-event-listener-bundle / src / test / java / org / onap / appc / listener / LCM / model / DmaapMessageTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2018 Nokia Solutions and Networks
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24 package org.onap.appc.listener.LCM.model;
25
26 import static org.junit.Assert.assertEquals;
27
28 import com.fasterxml.jackson.databind.JsonNode;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.onap.appc.listener.util.Mapper;
32
33 public class DmaapMessageTest {
34
35     private static final String jsonInputBodyStr =
36         "{\"input\":{ \"common-header\": { \"timestamp\": \"2016-08-03T08:50:18.97Z\", "
37             + "\"api-ver\": \"1\", \"originator-id\": \"1\", \"request-id\": \"123\", \"sub-request-id\": \"1\", "
38             + "\"flags\": { \"force\":\"TRUE\", \"ttl\":\"9900\" } }, \"action\": \"Stop\", "
39             + "\"action-identifiers\": { \"vnf-id\": \"TEST\" } }}";
40
41     private DmaapMessage dmaapMessage;
42
43     @Before
44     public void setup() {
45         dmaapMessage = new DmaapMessage();
46     }
47
48     @Test
49     public void should_set_properties() {
50
51         JsonNode jsonNode = Mapper.toJsonNodeFromJsonString(jsonInputBodyStr);
52
53         dmaapMessage.setVersion("test-version");
54         dmaapMessage.setType("test-type");
55         dmaapMessage.setCorrelationID("test-correlation-id");
56         dmaapMessage.setCambriaPartition("test-cambria-partition");
57         dmaapMessage.setRpcName("test-rpc-name");
58         dmaapMessage.setBody(jsonNode);
59
60         assertEquals("test-version", dmaapMessage.getVersion());
61         assertEquals("test-type", dmaapMessage.getType());
62         assertEquals("test-correlation-id", dmaapMessage.getCorrelationID());
63         assertEquals("test-cambria-partition", dmaapMessage.getCambriaPartition());
64         assertEquals("test-rpc-name", dmaapMessage.getRpcName());
65         assertEquals(jsonNode, dmaapMessage.getBody());
66     }
67
68     @Test
69     public void toString_should_return_valid_string_representation() {
70         JsonNode jsonNode = Mapper.toJsonNodeFromJsonString(jsonInputBodyStr);
71
72         dmaapMessage.setVersion("test-version");
73         dmaapMessage.setType("test-type");
74         dmaapMessage.setCorrelationID("test-correlation-id");
75         dmaapMessage.setCambriaPartition("test-cambria-partition");
76         dmaapMessage.setRpcName("test-rpc-name");
77         dmaapMessage.setBody(jsonNode);
78
79         assertEquals("DmaapMessage{" +
80             "version='" + dmaapMessage.getVersion() + '\'' +
81             ", type='" + dmaapMessage.getType() + '\'' +
82             ", correlationId='" + dmaapMessage.getCorrelationID() + '\'' +
83             ", cambriaPartition='" + dmaapMessage.getCambriaPartition() + '\'' +
84             ", rpcName='" + dmaapMessage.getRpcName() + '\'' +
85             ", body=" + dmaapMessage.getBody() +
86             '}', dmaapMessage.toString());
87     }
88 }
89