Removing deprecated DMAAP library
[policy/drools-pdp.git] / policy-management / src / test / java / org / onap / policy / drools / protocol / coders / EventProtocolCoderTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15
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=========================================================
21  */
22
23 package org.onap.policy.drools.protocol.coders;
24
25 import static org.junit.jupiter.api.Assertions.assertTrue;
26
27 import java.util.Properties;
28 import lombok.AllArgsConstructor;
29 import lombok.Getter;
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;
34
35 /**
36  * Tests Coders.
37  */
38 class EventProtocolCoderTest {
39
40     /**
41      * Coder Group.
42      */
43     private static final String ENCODER_GROUP = "foo";
44
45     /**
46      * Coder Artifact.
47      */
48     private static final String ENCODER_ARTIFACT = "bar";
49
50     /**
51      * Coder Version.
52      */
53     private static final String ENCODER_VERSION = null;
54
55     /**
56      * noop topic.
57      */
58     private static final String NOOP_TOPIC = "JUNIT";
59
60     /**
61      * Event Test Class.
62      */
63     @Getter
64     @AllArgsConstructor
65     public static class EventTest {
66         private String field;
67     }
68
69     @Test
70     void test() {
71
72         final Properties noopSinkProperties = new Properties();
73         noopSinkProperties.put(PolicyEndPointProperties.PROPERTY_NOOP_SINK_TOPICS, NOOP_TOPIC);
74
75         TopicEndpointManager.getManager().addTopicSinks(noopSinkProperties);
76
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());
82
83         final String json = EventProtocolCoderConstants.getManager().encode(NOOP_TOPIC,
84                 new DroolsConfiguration(ENCODER_ARTIFACT, ENCODER_GROUP, ENCODER_VERSION));
85
86         assertTrue(json.contains(ENCODER_GROUP));
87         assertTrue(json.contains(ENCODER_ARTIFACT));
88
89         EventProtocolCoderConstants.getManager().removeEncoders(ENCODER_GROUP, ENCODER_ARTIFACT, NOOP_TOPIC);
90     }
91 }