Code formatting of configuration framework
[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 java.io.IOException;
20 import java.util.ArrayList;
21 import java.util.List;
22 import org.junit.After;
23 import org.junit.Assert;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.onap.config.api.Configuration;
27 import org.onap.config.api.ConfigurationManager;
28 import org.onap.config.util.ConfigTestConstant;
29 import org.onap.config.util.TestUtil;
30
31 /**
32  * Scenario 8 Validate configuration with mode specified as a configuration property.
33  */
34 public class ModeAsConfigPropTest {
35
36     private static final String NAMESPACE = "ModeAsConfigProp";
37
38     @Before
39     public void setUp() throws IOException {
40         String data = "{name:\"SCM\"}";
41         TestUtil.writeFile(data);
42     }
43
44     @Test
45     public void testMergeStrategyInConfig() {
46         Configuration config = ConfigurationManager.lookup();
47
48         Assert.assertEquals("14", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
49
50         Assert.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         Assert.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         Assert.assertEquals(expectedEncList, encList);
67
68         Assert.assertEquals("{name:\"SCM\"}", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_JSON_SCHEMA));
69
70         Assert.assertEquals("a-zA-Z_0-9", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_UPPER));
71
72         Assert.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         Assert.assertEquals(expectedLocList, locList);
79
80         Assert.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         Assert.assertEquals(config.getAsStringValues(NAMESPACE, ConfigTestConstant.ARTIFACT_CONSUMER_APPC),
85                 artifactConsumer);
86
87         Assert.assertEquals(config.getAsBooleanValue(NAMESPACE, ConfigTestConstant.ARTIFACT_MANDATORY_NAME), true);
88
89         Assert.assertEquals(config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MINLENGTH), "6");
90
91         Assert.assertEquals(config.getAsBooleanValue(NAMESPACE, ConfigTestConstant.ARTIFACT_ENCODED), true);
92     }
93
94     @After
95     public void tearDown() throws Exception {
96         TestUtil.cleanUp();
97     }
98
99 }