1 package org.onap.config.test;
3 import org.onap.config.api.Configuration;
4 import org.onap.config.api.ConfigurationManager;
5 import org.onap.config.util.ConfigTestConstant;
6 import org.onap.config.util.TestUtil;
7 import org.junit.After;
8 import org.junit.Before;
10 import org.junit.Assert;
13 import java.io.FileOutputStream;
14 import java.io.IOException;
15 import java.io.OutputStream;
16 import java.util.Properties;
20 * Validate node specific configuration
21 * Pre-requisite - set -Dnode.config.location=${"user.home"}/TestResources/ while running test
23 * Created by sheetalm on 10/14/2016.
25 public class ValidateNodeConfigTest {
27 public final static String NAMESPACE = "ValidateNodeConfig";
30 public void setUp() throws IOException {
31 String data = "{name:\"SCM\"}";
32 TestUtil.writeFile(data);
36 public void testValidateNodeConfig() throws IOException, InterruptedException {
37 Configuration config = ConfigurationManager.lookup();
39 Properties props = new Properties();
40 props.setProperty(ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH, "56");
41 props.setProperty("_config.namespace","ValidateNodeConfig");
42 File f = new File(TestUtil.jsonSchemaLoc+"config.properties");
43 try (OutputStream out = new FileOutputStream(f)) {
44 props.store(out, "Node Config Property");
47 System.out.println(System.getProperty("node.config.location"));
51 //Verify property from node specific configuration
52 Assert.assertEquals("56", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
54 //Verify if property is not in node specific then fetch from namespace
55 //Assert.assertEquals("a-zA-Z",config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_UPPER));
57 //Verify if property is not in node specific and namespace then fetch from global
58 Assert.assertEquals("1024", config.getAsString(NAMESPACE, "maxCachedBufferSize"));
60 //Deleting node configurations to test property is fetched from namespace configuration when node configuration is not present
62 boolean isDeleted = f.delete();
63 System.out.println(isDeleted);
68 Assert.assertEquals(config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH), "14");
72 public void tearDown() throws Exception {
74 File f = new File(TestUtil.jsonSchemaLoc+"config.properties");