Drools support for kafka topics
[policy/drools-pdp.git] / feature-pooling-dmaap / src / test / java / org / onap / policy / drools / pooling / message / MessageTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2018 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  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.drools.pooling.message;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNull;
25
26 import org.junit.Test;
27
28 public class MessageTest extends SupportBasicMessageTester<Message> {
29
30     public MessageTest() {
31         super(Message.class);
32     }
33
34     @Test
35     public void testGetSource_testSetSource() {
36         Message msg = new Message();
37
38         msg.setSource("hello");
39         assertEquals("hello", msg.getSource());
40         assertNull(msg.getChannel());
41
42         msg.setSource("world");
43         assertEquals("world", msg.getSource());
44         assertNull(msg.getChannel());
45     }
46
47     @Test
48     public void testGetChannel_testSetChannel() {
49         Message msg = new Message();
50
51         msg.setChannel("hello");
52         assertEquals("hello", msg.getChannel());
53         assertNull(msg.getSource());
54
55         msg.setChannel("world");
56         assertEquals("world", msg.getChannel());
57         assertNull(msg.getSource());
58     }
59
60     @Test
61     public void testCheckValidity_InvalidFields() {
62         // null or empty source
63         expectCheckValidityFailure_NullOrEmpty((msg, value) -> msg.setSource(value));
64
65         // null or empty channel
66         expectCheckValidityFailure_NullOrEmpty((msg, value) -> msg.setChannel(value));
67     }
68
69     /**
70      * Makes a message that will pass the validity check.
71      * 
72      * @return a valid Message
73      */
74     public Message makeValidMessage() {
75         Message msg = new Message(VALID_HOST);
76         msg.setChannel(VALID_CHANNEL);
77
78         return msg;
79     }
80
81 }