2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
20 package org.onap.policy.gui.editors.apex.rest.handling;
22 import static org.assertj.core.api.Assertions.assertThat;
23 import static org.junit.Assert.assertEquals;
25 import javax.ws.rs.core.Application;
26 import javax.ws.rs.core.Response;
27 import javax.ws.rs.core.Response.Status;
28 import org.glassfish.jersey.server.ResourceConfig;
29 import org.glassfish.jersey.test.JerseyTest;
30 import org.junit.Test;
31 import org.onap.policy.apex.model.modelapi.ApexApiResult;
32 import org.onap.policy.apex.model.modelapi.ApexApiResult.Result;
33 import org.onap.policy.common.parameters.ParameterService;
34 import org.onap.policy.gui.editors.apex.rest.UploadPluginConfigParameters;
35 import org.onap.policy.gui.editors.apex.rest.handling.config.PolicyUploadPluginConfigKey;
37 public class ConfigurationRestResourceTest extends JerseyTest {
40 private Boolean isEnabled;
43 protected Application configure() {
46 System.setProperty(PolicyUploadPluginConfigKey.URL.getKey(), anUrl);
47 System.setProperty(PolicyUploadPluginConfigKey.ENABLE.getKey(), String.valueOf(isEnabled));
48 final UploadPluginConfigParameters uploadPluginConfigParameters = new UploadPluginConfigParameters();
49 ParameterService.clear();
50 ParameterService.register(uploadPluginConfigParameters);
51 return new ResourceConfig(ConfigurationRestResource.class);
55 public void testShowSuccess() {
56 final Response response = target("/editor/config").request().get();
57 assertEquals(Status.OK.getStatusCode(), response.getStatus());
58 final ApexApiResult apexApiResult = response.readEntity(ApexApiResult.class);
59 assertEquals(Result.SUCCESS, apexApiResult.getResult());
60 final String message = apexApiResult.getMessage();
61 assertThat(message).contains(String.format("\"%s\":\"%s\"", PolicyUploadPluginConfigKey.URL.getKey(), anUrl))
62 .contains(String.format("\"%s\":%s", PolicyUploadPluginConfigKey.ENABLE.getKey(), isEnabled));