6436f1ef1089056f61485a348de9584c48068fa6
[ccsdk/sli.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : CCSDK
4  * ================================================================================
5  * Copyright (C) 2022 Samsung Electronics
6  * =============================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.ccsdk.sli.adaptors.resource.sql;
24
25 import static org.junit.Assert.assertNotNull;
26 import java.lang.reflect.Field;
27 import java.util.Map;
28 import java.util.Properties;
29
30 import org.junit.Test;
31
32 public class SqlResourceProviderTest {
33
34     private static SqlResourcePropertiesProvider provider;
35     private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
36
37     @Test
38     public void testSqlResourceProvider() {
39         try{
40             Map<String, String> env = System.getenv();
41             Class<?> cl = env.getClass();
42             Field field = cl.getDeclaredField("m");
43             field.setAccessible(true);
44             Map<String, String> writableEnv = (Map<String, String>) field.get(env);
45             writableEnv.put(SDNC_CONFIG_DIR, "./src/test/resources");
46         } catch (Exception e) {
47             throw new IllegalStateException("Failed to set environment variable", e);
48         }
49
50         provider = new SqlResourcePropertiesProviderImpl();
51         assertNotNull(provider);
52     }
53
54     @Test
55     public void testGetProperties() {
56         Properties properties = provider.getProperties();
57         assertNotNull(properties);
58     }
59
60     @Test
61     public void testReportSuccess() {
62         try{
63             Map<String, String> env = System.getenv();
64             Class<?> cl = env.getClass();
65             Field field = cl.getDeclaredField("m");
66             field.setAccessible(true);
67             Map<String, String> writableEnv = (Map<String, String>) field.get(env);
68             writableEnv.put(SDNC_CONFIG_DIR, "./src/test/resources");
69         } catch (Exception e) {
70             throw new IllegalStateException("Failed to set environment variable", e);
71         }
72
73         provider = new SqlResourcePropertiesProviderImpl();
74         Properties properties = provider.getProperties();
75         assertNotNull(properties);
76     }
77
78 }