ab0510c9c367f48896879ea815d3970b1eee84f0
[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     // @formatter:off 
52     private static final JSONObject EVENTLOG_SEARCHHIT = new JSONObject("{\n"
53             + "\"_index\": \"sdnevents_v1\",\n"
54             + "\"_type\": \"eventlog\",\n"
55             + "\"_id\": \"AXB7cJHlZ_FApnwi29xq\",\n"
56             + "\"_version\": 1,\n"
57             + "\"_score\": 1,\n"
58             + "\"_source\": {\n"
59             + "\"event\": {\n"
60             + "\"nodeName\": \"SDN-Controller-465e2ae306ca\",\n"
61             + "\"counter\": \"1\",\n"
62             + "\"timeStamp\": \"2020-02-25T08:22:19.8Z\",\n"
63             + "\"objectId\": \"sim2230\",\n"
64             + "\"attributeName\": \"ConnectionStatus\",\n"
65             + "\"newValue\": \"connecting\",\n"
66             + "\"type\": \"AttributeValueChangedNotificationXml\"\n"
67             + "}\n"
68             + "}\n"
69             + "}");
70     private static final JSONObject EVENTLOG_SEARCHHIT2 = new JSONObject("{\n"
71             + "\"_index\": \"sdnevents_v1\",\n"
72             + "\"_type\": \"eventlog\",\n"
73             + "\"_id\": \"AXB7cJHlZ_FApnwi29xq\",\n"
74             + "\"_version\": 1,\n"
75             + "\"_score\": 1,\n"
76             + "\"_source\": {\n"
77             + "\"event\": {\n"
78             + "\"nodeName\": \"SDN-Controller-465e2ae306ca\",\n"
79             + "\"counter\": \"3\",\n"
80             + "\"timeStamp\": \"2020-02-22T08:22:19.8Z\",\n"
81             + "\"objectId\": \"sim2230\",\n"
82             + "\"attributeName\": \"ConnectionStatus\",\n"
83             + "\"newValue\": \"connected\",\n"
84             + "\"type\": \"AttributeValueChangedNotificationXml\"\n"
85             + "}\n"
86             + "}\n"
87             + "}");
88     private static final String CONFIG_CONTENT = "[dcae]\n"
89             + "dcaeUserCredentials=admin:admin\n"
90             + "dcaeUrl=off\n"
91             + "dcaeHeartbeatPeriodSeconds=120\n"
92             + "dcaeTestCollector=no\n"
93             + "\n"
94             + "[es]\n"
95             + "esCluster=sendateodl5\n"
96             + "#time limit to keep increasing data in database [in seconds]\n"
97             + "#60*60*24*30 (30days)\n"
98             + "esArchiveLimit=2592000\n"
99             + "#folder where removed data will be stored\n"
100             + "esArchiveFolder=./backup\n"
101             + "#interval to archive database [in seconds]\n"
102             + "#60*60*24 (1day)\n"
103             + "esArchiveInterval=86400\n"
104             + "\n"
105             + "[aai]\n"
106             + "#keep comment\n"
107             + "aaiHeaders=[\"X-TransactionId: 9999\"]\n"
108             + "aaiUrl=http://localhost:81\n"
109             + "aaiUserCredentials=AAI:AAI\n"
110             + "aaiDeleteOnMountpointRemove=false\n"
111             + "aaiTrustAllCerts=false\n"
112             + "aaiApiVersion=aai/v13\n"
113             + "aaiPropertiesFile=aaiclient.properties\n"
114             + "aaiApplicationId=SDNR\n"
115             + "aaiPcks12ClientCertFile=/opt/logs/externals/data/stores/keystore.client.p12\n"
116             + "aaiPcks12ClientCertPassphrase=adminadmin\n"
117             + "aaiClientConnectionTimeout=30000\n"
118             + "\n"
119             + "[pm]\n"
120             + "pmCluster=sendateodl5\n"
121             + "pmEnabled=true\n"
122             + "";
123     // @formatter:on 
124
125     @Test
126     public void testComponentData() {
127         JSONArray hits = new JSONArray();
128         hits.put(EVENTLOG_SEARCHHIT);
129         hits.put(EVENTLOG_SEARCHHIT2);
130         ComponentData data = new ComponentData(ComponentName.EVENTLOG, hits);
131         JSONArray out = data.toJsonArray();
132         assertEquals(ComponentName.EVENTLOG, data.getName());
133         JSONAssert.assertEquals(EVENTLOG_SEARCHHIT.toString(), out.getJSONObject(0).toString(), false);
134         JSONAssert.assertEquals(EVENTLOG_SEARCHHIT2.toString(), out.getJSONObject(1).toString(), false);
135
136     }
137
138     @Test
139     public void testConfigData() {
140         ConfigData data = new ConfigData(CONFIG_CONTENT);
141         assertTrue(data.getLines().length > 10);
142     }
143
144     @Test
145     public void testConfigName() {
146         ConfigName name = ConfigName.APIGATEWAY;
147         assertEquals("apigateway", name.getValue());
148         try {
149             assertEquals(ConfigName.APIGATEWAY, ConfigName.getValueOf("apigateway"));
150         } catch (Exception e) {
151             fail(e.getMessage());
152         }
153
154     }
155
156     @Test
157     public void testDataContainer() {
158         DataContainer container = new DataContainer();
159         assertEquals(Release.CURRENT_RELEASE, container.getRelease());
160         assertNotNull(container.getCreated());
161
162         try {
163             container = DataContainer.load(new File("src/test/resources/test.bak.json"));
164         } catch (Exception e) {
165             fail(e.getMessage());
166         }
167         assertNotNull(container);
168         assertEquals(Release.EL_ALTO, container.getRelease());
169         assertNotNull(container.getCreated());
170         assertTrue(container.getComponents().size() > 0);
171         assertTrue(container.getConfigs().size() == 0);
172     }
173
174     @Test
175     public void testReport() {
176         DataMigrationReport report = new DataMigrationReport();
177
178         assertFalse(report.completed());
179         long myvar = 42;
180         String myvar2 = "come";
181         report.log("%d was wrong", myvar);
182         report.error("%s to me", myvar2);
183         assertTrue(report.toString().contains("42 was wrong"));
184         assertTrue(report.toString().contains("come to me"));
185         report.setCompleted(true);
186         assertTrue(report.completed());
187
188     }
189
190     @Test
191     public void TestPluginFileCreation() {
192
193         final String TESTFILE = "asi324po.sa";
194         try {
195             MavenDatabasePluginInitFile.create(Release.FRANKFURT_R1, TESTFILE);
196         } catch (IOException e) {
197             fail(e.getMessage());
198         }
199         File f = new File(TESTFILE);
200         if (f.exists()) {
201             f.delete();
202         }
203     }
204
205 }