Release version 1.13.7
[sdc.git] / common / onap-common-configuration-management / onap-configuration-management-core / src / test / java / org / onap / config / test / ModeAsConfigPropTest.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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
17 package org.onap.config.test;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20 import static org.junit.jupiter.api.Assertions.assertTrue;
21
22 import java.util.ArrayList;
23 import java.util.List;
24 import org.junit.jupiter.api.AfterEach;
25 import org.junit.jupiter.api.BeforeEach;
26 import org.junit.jupiter.api.Test;
27 import org.onap.config.api.Configuration;
28 import org.onap.config.api.ConfigurationManager;
29 import org.onap.config.util.ConfigTestConstant;
30 import org.onap.config.util.TestUtil;
31
32 /**
33  * Scenario 8 Validate configuration with mode specified as a configuration property.
34  */
35 class ModeAsConfigPropTest {
36
37     private static final String NAMESPACE = "ModeAsConfigProp";
38
39     @BeforeEach
40     public void setUp() throws Exception {
41         TestUtil.cleanUp();
42     }
43
44     @Test
45     void testMergeStrategyInConfig() {
46         Configuration config = ConfigurationManager.lookup();
47
48         assertEquals("14", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
49
50         assertEquals("1048", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_MAXSIZE));
51
52         List<String> expectedExtList = new ArrayList<>();
53         expectedExtList.add("pdf");
54         expectedExtList.add("zip");
55         expectedExtList.add("xml");
56         expectedExtList.add("pdf");
57         expectedExtList.add("tgz");
58         expectedExtList.add("xls");
59         List<String> extList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_EXT);
60         assertEquals(expectedExtList, extList);
61
62         List<String> expectedEncList = new ArrayList<>();
63         expectedEncList.add("Base64");
64         expectedEncList.add("MD5");
65         List<String> encList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_ENC);
66         assertEquals(expectedEncList, encList);
67
68         assertEquals("{name:\"SCM\"}", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_JSON_SCHEMA));
69
70         assertEquals("a-zA-Z_0-9", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_UPPER));
71
72         assertEquals("Deleted", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_STATUS));
73
74         List<String> expectedLocList = new ArrayList<>();
75         expectedLocList.add("/opt/spool");
76         expectedLocList.add(System.getProperty("user.home") + "/asdc");
77         List<String> locList = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_LOC);
78         assertEquals(expectedLocList, locList);
79
80         assertEquals("@" + TestUtil.getenv(ConfigTestConstant.PATH) + "/myschema.json",
81             config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_XML_SCHEMA));
82
83         List<String> artifactConsumer = config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_CONSUMER);
84         assertEquals(config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_CONSUMER_APPC),
85             artifactConsumer);
86
87         assertTrue(config.getAsBooleanValue(NAMESPACE, ConfigTestConstant.ARTIFACT_MANDATORY_NAME));
88
89         assertEquals("6", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MINLENGTH));
90
91         assertTrue(config.getAsBooleanValue(NAMESPACE, ConfigTestConstant.ARTIFACT_ENCODED));
92     }
93
94     @AfterEach
95     public void tearDown() throws Exception {
96         TestUtil.cleanUp();
97     }
98
99 }