1 package org.onap.config.test;
3 import org.junit.After;
4 import org.junit.Assert;
5 import org.junit.Before;
7 import org.onap.config.Constants;
8 import org.onap.config.api.ConfigurationManager;
9 import org.onap.config.util.ConfigTestConstant;
10 import org.onap.config.util.TestUtil;
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;
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
28 public class CLIFallbackAndLookupTest {
30 public final static String NAMESPACE = "CLIFallback";
31 public final static String TENANT = "OPENECOMP";
34 public void setUp() throws IOException {
35 String data = "{name:\"SCM\"}";
36 TestUtil.writeFile(data);
40 public void testCLIFallbackAndLookup() throws Exception{
42 //Verify without fallback
43 Map<String, Object> input = new HashMap<>();
44 input.put("ImplClass", "org.onap.config.type.ConfigurationQuery");
45 input.put("tenant", TENANT);
46 input.put("namespace", NAMESPACE);
47 input.put("key", ConfigTestConstant.ARTIFACT_MAXSIZE);
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);
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);
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);
67 //Verify with fallback
68 Map<String, Object> fallbackInput = new HashMap<>();
69 fallbackInput.put("ImplClass", "org.onap.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);
75 String maxSizeWithFallback = conf.getConfigurationValue(fallbackInput);
76 Assert.assertEquals("1024",maxSizeWithFallback);
80 public void tearDown() throws Exception {