c7864560b5db58522f7d604eaae49b3794de8599
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
28 import static org.junit.Assert.fail;
29
30 import java.io.File;
31 import java.io.IOException;
32
33 import org.json.JSONArray;
34 import org.json.JSONObject;
35 import org.junit.Test;
36 import org.onap.ccsdk.features.sdnr.wt.common.test.JSONAssert;
37 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentData;
38 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ComponentName;
39 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ConfigData;
40 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.ConfigName;
41 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DataContainer;
42 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.DataMigrationReport;
43 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.MavenDatabasePluginInitFile;
44 import org.onap.ccsdk.features.sdnr.wt.dataprovider.setup.data.Release;
45
46 /**
47  * @author Michael Dürre
48  *
49  */
50 public class TestData {
51     private static final JSONObject EVENTLOG_SEARCHHIT = new JSONObject("{\n" + "\"_index\": \"sdnevents_v1\",\n"
52             + "\"_type\": \"eventlog\",\n" + "\"_id\": \"AXB7cJHlZ_FApnwi29xq\",\n" + "\"_version\": 1,\n"
53             + "\"_score\": 1,\n" + "\"_source\": {\n" + "\"event\": {\n"
54             + "\"nodeName\": \"SDN-Controller-465e2ae306ca\",\n" + "\"counter\": \"1\",\n"
55             + "\"timeStamp\": \"2020-02-25T08:22:19.8Z\",\n" + "\"objectId\": \"sim2230\",\n"
56             + "\"attributeName\": \"ConnectionStatus\",\n" + "\"newValue\": \"connecting\",\n"
57             + "\"type\": \"AttributeValueChangedNotificationXml\"\n" + "}\n" + "}\n" + "}");
58     private static final JSONObject EVENTLOG_SEARCHHIT2 = new JSONObject("{\n" + "\"_index\": \"sdnevents_v1\",\n"
59             + "\"_type\": \"eventlog\",\n" + "\"_id\": \"AXB7cJHlZ_FApnwi29xq\",\n" + "\"_version\": 1,\n"
60             + "\"_score\": 1,\n" + "\"_source\": {\n" + "\"event\": {\n"
61             + "\"nodeName\": \"SDN-Controller-465e2ae306ca\",\n" + "\"counter\": \"3\",\n"
62             + "\"timeStamp\": \"2020-02-22T08:22:19.8Z\",\n" + "\"objectId\": \"sim2230\",\n"
63             + "\"attributeName\": \"ConnectionStatus\",\n" + "\"newValue\": \"connected\",\n"
64             + "\"type\": \"AttributeValueChangedNotificationXml\"\n" + "}\n" + "}\n" + "}");
65     private static final String CONFIG_CONTENT = "[dcae]\n" + "dcaeUserCredentials=admin:admin\n" + "dcaeUrl=off\n"
66             + "dcaeHeartbeatPeriodSeconds=120\n" + "dcaeTestCollector=no\n" + "\n" + "[es]\n"
67             + "esCluster=sendateodl5\n" + "#time limit to keep increasing data in database [in seconds]\n"
68             + "#60*60*24*30 (30days)\n" + "esArchiveLimit=2592000\n" + "#folder where removed data will be stored\n"
69             + "esArchiveFolder=./backup\n" + "#interval to archive database [in seconds]\n" + "#60*60*24 (1day)\n"
70             + "esArchiveInterval=86400\n" + "\n" + "[aai]\n" + "#keep comment\n"
71             + "aaiHeaders=[\"X-TransactionId: 9999\"]\n" + "aaiUrl=http://localhost:81\n"
72             + "aaiUserCredentials=AAI:AAI\n" + "aaiDeleteOnMountpointRemove=false\n" + "aaiTrustAllCerts=false\n"
73             + "aaiApiVersion=aai/v13\n" + "aaiPropertiesFile=aaiclient.properties\n" + "aaiApplicationId=SDNR\n"
74             + "aaiPcks12ClientCertFile=/opt/logs/externals/data/stores/keystore.client.p12\n"
75             + "aaiPcks12ClientCertPassphrase=adminadmin\n" + "aaiClientConnectionTimeout=30000\n" + "\n" + "[pm]\n"
76             + "pmCluster=sendateodl5\n" + "pmEnabled=true\n" + "";
77
78     @Test
79     public void testComponentData() {
80         JSONArray hits = new JSONArray();
81         hits.put(EVENTLOG_SEARCHHIT);
82         hits.put(EVENTLOG_SEARCHHIT2);
83         ComponentData data = new ComponentData(ComponentName.EVENTLOG, hits);
84         JSONArray out = data.toJsonArray();
85         assertEquals(ComponentName.EVENTLOG, data.getName());
86         JSONAssert.assertEquals(EVENTLOG_SEARCHHIT.toString(), out.getJSONObject(0).toString(), false);
87         JSONAssert.assertEquals(EVENTLOG_SEARCHHIT2.toString(), out.getJSONObject(1).toString(), false);
88
89     }
90
91     @Test
92     public void testConfigData() {
93         ConfigData data = new ConfigData(CONFIG_CONTENT);
94         assertTrue(data.getLines().length > 10);
95     }
96
97     @Test
98     public void testConfigName() {
99         ConfigName name = ConfigName.APIGATEWAY;
100         assertEquals("apigateway", name.getValue());
101         try {
102             assertEquals(ConfigName.APIGATEWAY, ConfigName.getValueOf("apigateway"));
103         } catch (Exception e) {
104             fail(e.getMessage());
105         }
106
107     }
108
109     @Test
110     public void testDataContainer() {
111         DataContainer container = new DataContainer();
112         assertEquals(Release.CURRENT_RELEASE, container.getRelease());
113         assertNotNull(container.getCreated());
114
115         try {
116             container = DataContainer.load(new File("src/test/resources/test.bak.json"));
117         } catch (Exception e) {
118             fail(e.getMessage());
119         }
120         assertNotNull(container);
121         assertEquals(Release.EL_ALTO, container.getRelease());
122         assertNotNull(container.getCreated());
123         assertTrue(container.getComponents().size() > 0);
124         assertTrue(container.getConfigs().size() == 0);
125     }
126
127     @Test
128     public void testReport() {
129         DataMigrationReport report = new DataMigrationReport();
130
131         assertFalse(report.completed());
132         long myvar = 42;
133         String myvar2 = "come";
134         report.log("%d was wrong", myvar);
135         report.error("%s to me", myvar2);
136         assertTrue(report.toString().contains("42 was wrong"));
137         assertTrue(report.toString().contains("come to me"));
138         report.setCompleted(true);
139         assertTrue(report.completed());
140
141     }
142
143     @Test
144     public void TestPluginFileCreation() {
145
146         final String TESTFILE = "asi324po.sa";
147         try {
148             MavenDatabasePluginInitFile.create(Release.FRANKFURT_R1, TESTFILE);
149         } catch (IOException e) {
150             fail(e.getMessage());
151         }
152         File f = new File(TESTFILE);
153         if (f.exists()) {
154             f.delete();
155         }
156     }
157
158 }