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
10 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.policy.drools.server.restful;
22 import static org.junit.jupiter.api.Assertions.assertEquals;
23 import static org.junit.jupiter.api.Assertions.assertTrue;
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;
42 public class RestLegacyConfigTest {
44 private static HttpClient client;
50 public static void setUp() throws Exception {
51 SystemPersistenceConstants.getManager().setConfigurationDir("target/test-classes");
53 HttpServletServerFactoryInstance.getServerFactory().destroy();
54 HttpClientFactoryInstance.getClientFactory().destroy();
55 PolicyControllerConstants.getFactory().destroy();
57 int port = NetworkUtil.allocPort();
59 HttpClientFactoryInstance.getClientFactory().build(
60 BusTopicParams.builder()
62 .hostname("localhost")
64 .basePath("policy/pdp/engine/legacy/config")
68 HttpServletServer server =
69 HttpServletServerFactoryInstance.getServerFactory().build("legacy", "localhost", port, "/",
71 server.setSerializationProvider(
72 String.join(",", JacksonHandler.class.getName(), YamlJacksonHandler.class.getName()));
73 server.addServletClass("/*", RestLegacyConfigManager.class.getName());
74 server.waitedStart(5000L);
76 assertTrue(NetworkUtil.isTcpPortOpen("localhost", port, 40, 250L));
77 client = HttpClientFactoryInstance.getClientFactory().get("legacy");
84 public static void tearDown() {
85 LegacyConfigFeature.getLegacyConfig().shutdown();
86 HttpClientFactoryInstance.getClientFactory().destroy();
87 HttpServletServerFactoryInstance.getServerFactory().destroy();
88 SystemPersistenceConstants.getManager().setConfigurationDir(null);
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));
101 Response response = client.get("source");
102 assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());