2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * ============LICENSE_END=========================================================
22 package org.onap.appc.services;
24 import org.onap.appc.services.dmaapService.PublishRequest;
26 import org.junit.Assert;
27 import org.junit.Test;
29 public class PublishRequestTest {
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()));
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()));
66 public void testParsePublishRequest_with_missing_value() {
67 //props, partition, topic, message
68 String props = "props.test";
69 String partition = "testPartition";
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()));