7cc9bccfd5bef5ed140aea40b54bdacec935697b
[appc.git] / services / appc-dmaap-service / appc-dmaap-event-service / src / test / java / org / onap / appc / services / PublishRequestTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * 
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.appc.services;
23
24 import org.onap.appc.services.dmaapService.PublishRequest;
25
26 import org.junit.Assert;
27 import org.junit.Test;
28
29 public class PublishRequestTest {
30     
31     @Test
32     public void testParsePublishRequest() {
33         //props, partition, topic, message
34         String props = "props.test";
35         String partition = "testPartition";
36         String topic = "testTopic";
37         String message = "sameple message data";
38         String data = props.length() + "." + partition.length() + "." + topic.length()
39         + "." + message.length() + "." + props + partition + topic + message;
40         PublishRequest publishRequest = PublishRequest.parsePublishRequest(data);
41         Assert.assertTrue(props.equals(publishRequest.getProps()));
42         Assert.assertTrue(partition.equals(publishRequest.getPartition()));
43         Assert.assertTrue(topic.equals(publishRequest.getTopic()));
44         Assert.assertTrue(message.equals(publishRequest.getMessage()));
45         
46     }
47     
48     @Test
49     public void testParsePublishRequest_period_in_message() {
50         //props, partition, topic, message
51         String props = "props.test";
52         String partition = "testPartition";
53         String topic = "testTopic";
54         String message = "sameple. message. dat.a";
55         String data = props.length() + "." + partition.length() + "." + topic.length()
56         + "." + message.length() + "." + props + partition + topic + message;
57         PublishRequest publishRequest = PublishRequest.parsePublishRequest(data);
58         Assert.assertTrue(props.equals(publishRequest.getProps()));
59         Assert.assertTrue(partition.equals(publishRequest.getPartition()));
60         Assert.assertTrue(topic.equals(publishRequest.getTopic()));
61         Assert.assertTrue(message.equals(publishRequest.getMessage()));
62         
63     }
64     
65     @Test
66     public void testParsePublishRequest_with_missing_value() {
67         //props, partition, topic, message
68         String props = "props.test";
69         String partition = "testPartition";
70         String topic = "";
71         String message = "sameple message data";
72         String data = props.length() + "." + partition.length() + "." + topic.length()
73         + "." + message.length() + "." + props + partition + topic + message;
74         PublishRequest publishRequest = PublishRequest.parsePublishRequest(data);
75         Assert.assertTrue(props.equals(publishRequest.getProps()));
76         Assert.assertTrue(partition.equals(publishRequest.getPartition()));
77         Assert.assertTrue(null == publishRequest.getTopic());
78         Assert.assertTrue(message.equals(publishRequest.getMessage()));
79         
80     }
81
82 }