3820240b649bc18fdda52423e5a9a85be186455b
[policy/gui.git] /
1 /*
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
8  *
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.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.onap.policy.gui.editors.apex.rest.handling;
21
22 import static org.assertj.core.api.Assertions.assertThat;
23 import static org.junit.Assert.assertEquals;
24
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;
36
37 public class ConfigurationRestResourceTest extends JerseyTest {
38
39     private String anUrl;
40     private Boolean isEnabled;
41
42     @Override
43     protected Application configure() {
44         anUrl = "url";
45         isEnabled = true;
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);
52     }
53
54     @Test
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));
63     }
64 }