Remove dmaap from models
[policy/models.git] / models-interactions / model-simulators / src / test / java / org / onap / policy / simulators / AppcLcmTopicServerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
4  * ================================================================================
5  * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2024 Nordix Foundation.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.simulators;
23
24 import static org.assertj.core.api.Assertions.assertThat;
25 import static org.junit.Assert.assertNotNull;
26 import static org.mockito.ArgumentMatchers.any;
27 import static org.mockito.Mockito.never;
28 import static org.mockito.Mockito.verify;
29
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.mockito.ArgumentCaptor;
34 import org.mockito.Mock;
35 import org.mockito.junit.MockitoJUnitRunner;
36 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
37 import org.onap.policy.common.endpoints.event.comm.TopicSink;
38 import org.onap.policy.common.endpoints.event.comm.TopicSource;
39 import org.onap.policy.common.utils.resources.ResourceUtils;
40
41 @RunWith(MockitoJUnitRunner.class)
42 public class AppcLcmTopicServerTest {
43     private static final String MY_TOPIC = "my-topic";
44
45     @Mock
46     private TopicSink sink;
47     @Mock
48     private TopicSource source;
49
50     private AppcLcmTopicServer server;
51
52     /**
53      * Sets up.
54      */
55     @Before
56     public void setUp() {
57         server = new AppcLcmTopicServer(sink, source);
58     }
59
60     @Test
61     public void testProcessAppcLcmMessageWrapper() {
62         String request = ResourceUtils.getResourceAsString("org/onap/policy/simulators/appclcm/appc.lcm.request.json");
63         assertNotNull(request);
64
65         server.onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, request);
66
67         ArgumentCaptor<String> respCaptor = ArgumentCaptor.forClass(String.class);
68         verify(sink).send(respCaptor.capture());
69
70         assertThat(respCaptor.getValue()).contains("111be3d2").doesNotContain("replaceMe");
71     }
72
73     /**
74      * Tests process() when the message is a response.
75      */
76     @Test
77     public void testProcessNoResponse() {
78         // NOTE: this json file is a RESPONSE, not a request
79         String request = ResourceUtils.getResourceAsString("org/onap/policy/simulators/appclcm/appc.lcm.success.json");
80         assertNotNull(request);
81
82         server.onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, request);
83
84         verify(sink, never()).send(any());
85     }
86 }