Rename packages from openecomp to onap.
[sdc.git] / common / onap-common-configuration-management / onap-configuration-management-test / src / test / java / org / onap / config / test / CLIFallbackAndLookupTest.java
1 package org.onap.config.test;
2
3 import org.onap.config.util.ConfigTestConstant;
4 import org.onap.config.Constants;
5 import org.onap.config.api.ConfigurationManager;
6 import org.onap.config.util.TestUtil;
7 import org.junit.Assert;
8 import org.junit.After;
9 import org.junit.Before;
10 import org.junit.Test;
11
12 import javax.management.JMX;
13 import javax.management.MBeanServerConnection;
14 import javax.management.ObjectName;
15 import java.io.IOException;
16 import java.lang.management.ManagementFactory;
17 import java.util.HashMap;
18 import java.util.Map;
19
20
21
22 /**
23  * Created by sheetalm on 10/18/2016.
24  * Scenario 21, Scenario 23
25  * 21 - Verify the CLI fetches only the current value unless the fallback option is specified
26  * 23 - Fetch value using CLI for a key with underlying resource
27  */
28 public class CLIFallbackAndLookupTest {
29
30     public final static String NAMESPACE = "CLIFallback";
31     public final static String TENANT = "OPENECOMP";
32
33     @Before
34     public void setUp() throws IOException {
35         String data = "{name:\"SCM\"}";
36         TestUtil.writeFile(data);
37     }
38
39     @Test
40     public void testCLIFallbackAndLookup() throws Exception{
41
42         //Verify without fallback
43         Map<String, Object> input = new HashMap<>();
44         input.put("ImplClass", "org.openecomp.config.type.ConfigurationQuery");
45         input.put("tenant", TENANT);
46         input.put("namespace", NAMESPACE);
47         input.put("key", ConfigTestConstant.ARTIFACT_MAXSIZE);
48
49         MBeanServerConnection mbsc = ManagementFactory.getPlatformMBeanServer();
50         ObjectName mbeanName = new ObjectName(Constants.MBEAN_NAME);
51         ConfigurationManager conf = JMX.newMBeanProxy(mbsc, mbeanName, ConfigurationManager.class, true);
52         String maxSizeWithNoFallback = conf.getConfigurationValue(input);
53         Assert.assertEquals("",maxSizeWithNoFallback);
54
55         //Verify underlying resource without lookup switch
56         input.put("key", ConfigTestConstant.ARTIFACT_JSON_SCHEMA);
57         String jsonSchema = conf.getConfigurationValue(input);
58         System.out.println("jsonSchema=="+jsonSchema);
59         Assert.assertEquals("@"+System.getProperty("user.home")+"/TestResources/GeneratorsList.json" , jsonSchema);
60
61         //Verify underlying resource with lookup switch
62         input.put("externalLookup", true);
63         jsonSchema = conf.getConfigurationValue(input);
64         System.out.println("jsonSchema=="+jsonSchema);
65         Assert.assertEquals("{name:\"SCM\"}" , jsonSchema);
66
67         //Verify with fallback
68         Map<String, Object> fallbackInput = new HashMap<>();
69         fallbackInput.put("ImplClass", "org.openecomp.config.type.ConfigurationQuery");
70         fallbackInput.put("fallback", true);
71         fallbackInput.put("tenant", TENANT);
72         fallbackInput.put("namespace", NAMESPACE);
73         fallbackInput.put("key", ConfigTestConstant.ARTIFACT_MAXSIZE);
74
75         String maxSizeWithFallback = conf.getConfigurationValue(fallbackInput);
76         Assert.assertEquals("1024",maxSizeWithFallback);
77     }
78
79     @After
80     public void tearDown() throws Exception {
81       TestUtil.cleanUp();
82     }
83 }