summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/dcae/vestest/TestFetchConfig.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/onap/dcae/vestest/TestFetchConfig.java')
-rw-r--r--src/test/java/org/onap/dcae/vestest/TestFetchConfig.java234
1 files changed, 144 insertions, 90 deletions
diff --git a/src/test/java/org/onap/dcae/vestest/TestFetchConfig.java b/src/test/java/org/onap/dcae/vestest/TestFetchConfig.java
index ed3e1086..2f18e820 100644
--- a/src/test/java/org/onap/dcae/vestest/TestFetchConfig.java
+++ b/src/test/java/org/onap/dcae/vestest/TestFetchConfig.java
@@ -1,90 +1,144 @@
-/*-
- * ============LICENSE_START=======================================================
- * PROJECT
- * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-package org.onap.dcae.vestest;
-
-import static org.junit.Assert.*;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.FileReader;
-import java.io.IOException;
-import org.json.JSONObject;
-import com.google.gson.JsonParser;
-import com.google.gson.JsonObject;
-
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.dcae.commonFunction.CommonStartup;
-import org.onap.dcae.commonFunction.DmaapPropertyReader;
-import org.onap.dcae.commonFunction.EventProcessor;
-import org.onap.dcae.commonFunction.EventPublisherHash;
-import org.onap.dcae.controller.FetchDynamicConfig;
-
-
-public class TestFetchConfig {
-
- JSONObject jsonObject;
-
- @Before
- public void setUp() throws Exception {
-
-
- }
-
- @After
- public void tearDown() throws Exception {
- }
-
-
-
- @Test
- public void testwritefile() {
- Boolean flag = false;
-
- FetchDynamicConfig fc = new FetchDynamicConfig();
- FetchDynamicConfig.configFile = "src/test/resources/controller-config_formatted_op.json";
-
-
-
- try{
- JsonParser parser = new JsonParser();
- FileReader fr = new FileReader ("src/test/resources/controller-config_singleline_ip.json" );
- final JsonObject jo = (JsonObject) parser.parse (fr);
- final String jsonText = jo.toString ();
- jsonObject = new JSONObject ( jsonText );
- fc.writefile(jsonObject.toString());
- }
- catch(Exception e){
- System.out.println("Exception while opening the file");
- e.printStackTrace();
- }
- if(jsonObject.has("streams_publishes"))
- {
- flag = true;
- }
-
- assertEquals(true, flag);
-
- }
-
-
-}
-
+/*-
+ * ============LICENSE_START=======================================================
+ * PROJECT
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+package org.onap.dcae.vestest;
+
+import static org.junit.Assert.*;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Map;
+import java.util.Properties;
+
+import org.json.JSONObject;
+import com.google.gson.JsonParser;
+import com.google.gson.JsonObject;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.dcae.commonFunction.CommonStartup;
+import org.onap.dcae.commonFunction.DmaapPropertyReader;
+import org.onap.dcae.commonFunction.EventProcessor;
+import org.onap.dcae.commonFunction.EventPublisherHash;
+import org.onap.dcae.controller.FetchDynamicConfig;
+
+
+public class TestFetchConfig {
+
+ JSONObject jsonObject;
+
+ @Before
+ public void setUp() throws Exception {
+
+
+ System.setProperty("CONSUL_HOST", "localhost");
+ System.setProperty("CONFIG_BINDING_SERVICE", "localhost");
+ System.setProperty("HOSTNAME", "localhost");
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+
+
+ @Test
+ public void testwritefile() {
+ Boolean flag = false;
+
+ FetchDynamicConfig fc = new FetchDynamicConfig();
+ //Used for writing the configuration output
+ FetchDynamicConfig.configFile = "src/test/resources/controller-config_formatted_op.json";
+
+
+
+ try{
+ JsonParser parser = new JsonParser();
+ FileReader fr = new FileReader ("src/test/resources/controller-config_singleline_ip.json" );
+ final JsonObject jo = (JsonObject) parser.parse (fr);
+ final String jsonText = jo.toString ();
+ jsonObject = new JSONObject ( jsonText );
+
+ fc.writefile(jsonObject.toString());
+ }
+ catch(Exception e){
+ System.out.println("Exception while opening the file");
+ e.printStackTrace();
+ }
+ if(jsonObject.has("streams_publishes"))
+ {
+ flag = true;
+ }
+
+ assertEquals(true, flag);
+
+ }
+
+ @Test
+ public void testgetConsul() {
+ Boolean flag = false;
+
+
+ try{
+
+ FetchDynamicConfig.getconsul();
+ flag = true;
+ }
+ catch(Exception e){
+ System.out.println("Exception while getting to consul");
+ e.printStackTrace();
+ }
+ assertEquals(true, flag);
+
+ }
+
+ @Test
+ public void testgetCBS() {
+ Boolean flag = false;
+
+ try{
+
+
+ JsonParser parser = new JsonParser();
+ FileReader fr = new FileReader ("src/test/resources/controller-config_singleline_ip.json" );
+ final JsonObject jo = (JsonObject) parser.parse (fr);
+ final String jsonText = jo.toString ();
+ jsonObject = new JSONObject ( jsonText );
+
+ //retstring from Consul is parsed
+ FetchDynamicConfig.retString = "[{\"ID\":\"81bc2a17-8cfa-3f6f-30a9-a545a9b6ac2f\",\"Node\":\"zldcrdm5bdcc2dokr00\",\"Address\":\"135.25.108.161\",\"Datacenter\":\"zldcrdm5bdcc2\",\"TaggedAddresses\":{\"lan\":\"135.25.108.161\",\"wan\":\"135.25.108.161\"},\"NodeMeta\":{\"fqdn\":\"zldcrdm5bdcc2dokr00.2f3fb3.rdm5b.tci.att.com\"},\"ServiceID\":\"20299a144716:config_binding_service:10000\",\"ServiceName\":\"config_binding_service\",\"ServiceTags\":[],\"ServiceAddress\":\"135.25.108.161\",\"ServicePort\":10000,\"ServiceEnableTagOverride\":false,\"CreateIndex\":9153156,\"ModifyIndex\":9153156}]";
+
+ //Mock the return CBS output
+ FetchDynamicConfig.retCBSString = jsonObject.toString();
+ FetchDynamicConfig.getCBS();
+ flag = true;
+ }
+ catch(Exception e){
+ System.out.println("Exception while fetching cbs configuration");
+ e.printStackTrace();
+ }
+ assertEquals(true, flag);
+
+ }
+
+}
+