2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2020 highstreet technologies GmbH Intellectual Property.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup;
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;
31 import java.io.IOException;
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;
47 * @author Michael Dürre
50 public class TestData {
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"
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"
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"
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"
88 private static final String CONFIG_CONTENT = "[dcae]\n"
89 + "dcaeUserCredentials=admin:admin\n"
91 + "dcaeHeartbeatPeriodSeconds=120\n"
92 + "dcaeTestCollector=no\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"
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"
120 + "pmCluster=sendateodl5\n"
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);
139 public void testConfigData() {
140 ConfigData data = new ConfigData(CONFIG_CONTENT);
141 assertTrue(data.getLines().length > 10);
145 public void testConfigName() {
146 ConfigName name = ConfigName.APIGATEWAY;
147 assertEquals("apigateway", name.getValue());
149 assertEquals(ConfigName.APIGATEWAY, ConfigName.getValueOf("apigateway"));
150 } catch (Exception e) {
151 fail(e.getMessage());
157 public void testDataContainer() {
158 DataContainer container = new DataContainer();
159 assertEquals(Release.CURRENT_RELEASE, container.getRelease());
160 assertNotNull(container.getCreated());
163 container = DataContainer.load(new File("src/test/resources/test.bak.json"));
164 } catch (Exception e) {
165 fail(e.getMessage());
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);
175 public void testReport() {
176 DataMigrationReport report = new DataMigrationReport();
178 assertFalse(report.completed());
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());
191 public void TestPluginFileCreation() {
193 final String TESTFILE = "asi324po.sa";
195 MavenDatabasePluginInitFile.create(Release.FRANKFURT_R1, TESTFILE);
196 } catch (IOException e) {
197 fail(e.getMessage());
199 File f = new File(TESTFILE);