ActivitySpec - Correcting logger messages
[sdc.git] / common / onap-common-configuration-management / onap-configuration-management-test / src / test / java / org / onap / config / test / ValidateNodeConfigTest.java
1 package org.onap.config.test;
2
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;
9 import org.junit.Test;
10 import org.junit.Assert;
11
12 import java.io.File;
13 import java.io.FileOutputStream;
14 import java.io.IOException;
15 import java.io.OutputStream;
16 import java.util.Properties;
17
18 /**
19  * Scenario 13
20  * Validate node specific configuration
21  * Pre-requisite - set -Dnode.config.location=${"user.home"}/TestResources/ while running test
22  *
23  * Created by sheetalm on 10/14/2016.
24  */
25 public class ValidateNodeConfigTest {
26
27     public final static String NAMESPACE = "ValidateNodeConfig";
28
29     @Before
30     public void setUp() throws IOException {
31         String data = "{name:\"SCM\"}";
32         TestUtil.writeFile(data);
33     }
34
35     @Test
36     public void testValidateNodeConfig() throws IOException, InterruptedException {
37         Configuration config = ConfigurationManager.lookup();
38
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");
45         }
46
47         System.out.println(System.getProperty("node.config.location"));
48
49         Thread.sleep(35000);
50
51         //Verify property from node specific configuration
52         Assert.assertEquals("56", config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH));
53
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));
56
57         //Verify if property is not in node specific and namespace then fetch from global
58         Assert.assertEquals("1024", config.getAsString(NAMESPACE, "maxCachedBufferSize"));
59
60         //Deleting node configurations to test property is fetched from namespace configuration when node configuration is not present
61         if(f.exists()) {
62             boolean isDeleted = f.delete();
63             System.out.println(isDeleted);
64         }
65
66         Thread.sleep(35000);
67
68         Assert.assertEquals(config.getAsString(NAMESPACE, ConfigTestConstant.ARTIFACT_NAME_MAXLENGTH), "14");
69     }
70
71     @After
72     public void tearDown() throws Exception {
73         TestUtil.cleanUp();
74         File f = new File(TestUtil.jsonSchemaLoc+"config.properties");
75         if(f.exists()) {
76             f.delete();
77         }
78     }
79
80 }