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