2 * ============LICENSE_START=======================================================
3 * ONAP : CCSDK.apps.sdnr.wt.apigateway
4 * ================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.ccsdk.features.sdnr.wt.apigateway.test;
23 import static org.junit.Assert.*;
25 import java.io.ByteArrayInputStream;
27 import java.util.HashMap;
30 import org.junit.Test;
31 import org.onap.ccsdk.features.sdnr.wt.apigateway.MyProperties;
33 public class TestProperties {
35 private static final boolean DEFAULT_CORSENABLED = false;
36 private static final boolean DEFAULT_AAIOFF = true;
37 private static final boolean DEFAULT_ESOFF = false;
38 private static final boolean DEFAULT_TRUSTINSECURE = false;
39 private static final String DEFAULT_AAIBASEURL = "off";
40 private static Map<String, String> DEFAULT_AAIHEADERS = new HashMap<String, String>();
41 private static final String DEFAULT_ESBASEURL = "http://localhost:9200";
43 private static final boolean CUSTOM_CORSENABLED = true;
44 private static final boolean CUSTOM_AAIOFF = false;
45 private static final boolean CUSTOM_ESOFF = false;
46 private static final boolean CUSTOM_TRUSTINSECURE = true;
47 private static final String CUSTOM_AAIBASEURL = "https://aai.tld:2214";
48 private static Map<String, String> CUSTOM_AAIHEADERS = new HashMap<String, String>();
49 private static final String CUSTOM_ESBASEURL = "http://localhost:9200";
51 private static final String LR = "\n";
55 final String tmpFilename = "tmp2.cfg";
56 DEFAULT_AAIHEADERS.put("X-FromAppId", "SDNR");
57 DEFAULT_AAIHEADERS.put("Authorization", "Basic QUFJOkFBSQ==");
58 CUSTOM_AAIHEADERS.put("X-FromAppId", "SDNC");
59 CUSTOM_AAIHEADERS.put("Authorization", "Basic 1234");
60 final String TESTPROPERTYFILECONTENT = "aai=" + CUSTOM_AAIBASEURL + LR + "aaiHeaders=[\"X-FromAppId:"
61 + CUSTOM_AAIHEADERS.get("X-FromAppId") + "\",\"Authorization:" + CUSTOM_AAIHEADERS.get("Authorization")
62 + "\"]" + LR + "database=" + CUSTOM_ESBASEURL + LR + "insecure=" + (CUSTOM_TRUSTINSECURE ? "1" : "0")
63 + LR + "cors=" + (CUSTOM_CORSENABLED ? "1" : "0");
64 File ftest = new File(tmpFilename);
65 // delete autogenerated testfile
68 MyProperties prop = null;
69 ftest = new File(tmpFilename);
71 prop = MyProperties.Instantiate(ftest, true);
72 } catch (Exception e) {
73 fail("error instantiating properties");
75 assertNotNull("problem without exception instantiating properties", prop);
77 assertEquals("default config file was not created", true, ftest.exists());
79 // test default values
80 assertEquals("default value is not correct", DEFAULT_CORSENABLED, prop.corsEnabled());
81 assertEquals("default value is not correct", DEFAULT_AAIOFF, prop.isAAIOff());
82 assertEquals("default value is not correct", DEFAULT_ESOFF, prop.isEsOff());
83 assertEquals("default value is not correct", DEFAULT_TRUSTINSECURE, prop.trustInsecure());
84 assertEquals("default value is not correct", DEFAULT_AAIBASEURL, prop.getAAIBaseUrl());
85 assertEquals("default value is not correct", DEFAULT_AAIHEADERS, prop.getAAIHeaders());
86 assertEquals("default value is not correct", DEFAULT_ESBASEURL, prop.getEsBaseUrl());
89 prop.load(new ByteArrayInputStream(TESTPROPERTYFILECONTENT.getBytes()));
90 } catch (Exception e) {
91 fail("error loading custom values into properties");
95 assertEquals("custom value is not correct", CUSTOM_CORSENABLED, prop.corsEnabled());
96 assertEquals("custom value is not correct", CUSTOM_AAIOFF, prop.isAAIOff());
97 assertEquals("custom value is not correct", CUSTOM_ESOFF, prop.isEsOff());
98 assertEquals("custom value is not correct", CUSTOM_TRUSTINSECURE, prop.trustInsecure());
99 assertEquals("custom value is not correct", CUSTOM_AAIBASEURL, prop.getAAIBaseUrl());
100 assertEquals("custom value is not correct", CUSTOM_AAIHEADERS, prop.getAAIHeaders());
101 assertEquals("custom value is not correct", CUSTOM_ESBASEURL, prop.getEsBaseUrl());
103 // delete autogenerated testfile