Removing deprecated DMAAP library
[policy/drools-pdp.git] / feature-legacy-config / src / test / java / org / onap / policy / drools / server / restful / RestLegacyConfigTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
4  * Modifications Copyright (C) 2024 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  * ============LICENSE_END=========================================================
18  */
19
20 package org.onap.policy.drools.server.restful;
21
22 import static org.junit.jupiter.api.Assertions.assertEquals;
23 import static org.junit.jupiter.api.Assertions.assertTrue;
24
25 import jakarta.ws.rs.core.Response;
26 import java.util.Properties;
27 import org.junit.jupiter.api.AfterAll;
28 import org.junit.jupiter.api.BeforeAll;
29 import org.junit.jupiter.api.Test;
30 import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
31 import org.onap.policy.common.endpoints.http.client.HttpClient;
32 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
33 import org.onap.policy.common.endpoints.http.server.HttpServletServer;
34 import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
35 import org.onap.policy.common.endpoints.http.server.YamlJacksonHandler;
36 import org.onap.policy.common.gson.JacksonHandler;
37 import org.onap.policy.common.utils.network.NetworkUtil;
38 import org.onap.policy.drools.legacy.config.LegacyConfigFeature;
39 import org.onap.policy.drools.persistence.SystemPersistenceConstants;
40 import org.onap.policy.drools.system.PolicyControllerConstants;
41
42 public class RestLegacyConfigTest {
43
44     private static HttpClient client;
45
46     /**
47      * Set up.
48      */
49     @BeforeAll
50     public static void setUp() throws Exception {
51         SystemPersistenceConstants.getManager().setConfigurationDir("target/test-classes");
52
53         HttpServletServerFactoryInstance.getServerFactory().destroy();
54         HttpClientFactoryInstance.getClientFactory().destroy();
55         PolicyControllerConstants.getFactory().destroy();
56
57         int port = NetworkUtil.allocPort();
58
59         HttpClientFactoryInstance.getClientFactory().build(
60                 BusTopicParams.builder()
61                         .clientName("legacy")
62                         .hostname("localhost")
63                         .port(port)
64                         .basePath("policy/pdp/engine/legacy/config")
65                         .managed(true)
66                         .build());
67
68         HttpServletServer server =
69                 HttpServletServerFactoryInstance.getServerFactory().build("legacy", "localhost", port, "/",
70                         true, true);
71         server.setSerializationProvider(
72                 String.join(",", JacksonHandler.class.getName(), YamlJacksonHandler.class.getName()));
73         server.addServletClass("/*", RestLegacyConfigManager.class.getName());
74         server.waitedStart(5000L);
75
76         assertTrue(NetworkUtil.isTcpPortOpen("localhost", port, 40, 250L));
77         client = HttpClientFactoryInstance.getClientFactory().get("legacy");
78     }
79
80     /**
81      * Tear down.
82      */
83     @AfterAll
84     public static void tearDown() {
85         LegacyConfigFeature.getLegacyConfig().shutdown();
86         HttpClientFactoryInstance.getClientFactory().destroy();
87         HttpServletServerFactoryInstance.getServerFactory().destroy();
88         SystemPersistenceConstants.getManager().setConfigurationDir(null);
89     }
90
91     @Test
92     void properties() {
93         Response response = client.get("properties");
94         assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
95         assertEquals(LegacyConfigFeature.getLegacyConfig().getProperties(),
96                 HttpClient.getBody(response, Properties.class));
97     }
98
99     @Test
100     void topic() {
101         Response response = client.get("source");
102         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());
103     }
104 }
105
106
107