2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.policy.simulators;
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;
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;
41 @RunWith(MockitoJUnitRunner.class)
42 public class AppcLcmTopicServerTest {
43 private static final String MY_TOPIC = "my-topic";
46 private TopicSink sink;
48 private TopicSource source;
50 private AppcLcmTopicServer server;
57 server = new AppcLcmTopicServer(sink, source);
61 public void testProcessAppcLcmMessageWrapper() {
62 String request = ResourceUtils.getResourceAsString("org/onap/policy/simulators/appclcm/appc.lcm.request.json");
63 assertNotNull(request);
65 server.onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, request);
67 ArgumentCaptor<String> respCaptor = ArgumentCaptor.forClass(String.class);
68 verify(sink).send(respCaptor.capture());
70 assertThat(respCaptor.getValue()).contains("111be3d2").doesNotContain("replaceMe");
74 * Tests process() when the message is a response.
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);
82 server.onTopicEvent(CommInfrastructure.NOOP, MY_TOPIC, request);
84 verify(sink, never()).send(any());