2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018-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
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.drools.protocol.coders;
25 import static org.junit.jupiter.api.Assertions.assertTrue;
27 import java.util.Properties;
28 import lombok.AllArgsConstructor;
30 import org.junit.jupiter.api.Test;
31 import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
32 import org.onap.policy.common.endpoints.properties.PolicyEndPointProperties;
33 import org.onap.policy.drools.protocol.configuration.DroolsConfiguration;
38 class EventProtocolCoderTest {
43 private static final String ENCODER_GROUP = "foo";
48 private static final String ENCODER_ARTIFACT = "bar";
53 private static final String ENCODER_VERSION = null;
58 private static final String NOOP_TOPIC = "JUNIT";
65 public static class EventTest {
72 final Properties noopSinkProperties = new Properties();
73 noopSinkProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS, NOOP_TOPIC);
75 TopicEndpointManager.getManager().addTopicSinks(noopSinkProperties);
77 EventProtocolCoderConstants.getManager().addEncoder(
78 EventProtocolParams.builder().groupId(ENCODER_GROUP).artifactId(ENCODER_ARTIFACT)
79 .topic(NOOP_TOPIC).eventClass(DroolsConfiguration.class.getName())
80 .protocolFilter(new JsonProtocolFilter()).customGsonCoder(null)
81 .modelClassLoaderHash(DroolsConfiguration.class.getName().hashCode()).build());
83 final String json = EventProtocolCoderConstants.getManager().encode(NOOP_TOPIC,
84 new DroolsConfiguration(ENCODER_ARTIFACT, ENCODER_GROUP, ENCODER_VERSION));
86 assertTrue(json.contains(ENCODER_GROUP));
87 assertTrue(json.contains(ENCODER_ARTIFACT));
89 EventProtocolCoderConstants.getManager().removeEncoders(ENCODER_GROUP, ENCODER_ARTIFACT, NOOP_TOPIC);