c17ef8b2db2a37c47fbff6f2c237790febb739f0
[ccsdk/features.git] /
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.dataprovider.setup;
19
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;
25
26 import java.io.File;
27 import java.io.IOException;
28
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;
41
42 /**
43  * @author Michael Dürre
44  *
45  */
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" + 
63                         "dcaeUrl=off\n" + 
64                         "dcaeHeartbeatPeriodSeconds=120\n" + 
65                         "dcaeTestCollector=no\n" + 
66                         "\n" + 
67                         "[es]\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" + 
77                         "\n" + 
78                         "[aai]\n" + 
79                         "#keep comment\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" + 
91                         "\n" + 
92                         "[pm]\n" + 
93                         "pmCluster=sendateodl5\n" + 
94                         "pmEnabled=true\n" + 
95                         "";
96         @Test
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);
106                 
107         }
108         @Test
109         public void testConfigData() {
110                 ConfigData data = new ConfigData(CONFIG_CONTENT);
111                 assertTrue(data.getLines().length>10);
112         }
113         @Test
114         public void testConfigName() {
115                 ConfigName name = ConfigName.APIGATEWAY;
116                 assertEquals("apigateway", name.getValue());
117                 try {
118                         assertEquals(ConfigName.APIGATEWAY,ConfigName.getValueOf("apigateway"));
119                 } catch (Exception e) {
120                         fail(e.getMessage());
121                 }
122                 
123         }
124         @Test
125         public void testDataContainer() {
126                 DataContainer container  = new DataContainer();
127                 assertEquals(Release.CURRENT_RELEASE,container.getRelease());
128                 assertNotNull(container.getCreated());
129                 
130                 try {
131                         container = DataContainer.load(new File("src/test/resources/test.bak.json"));
132                 } catch (Exception e) {
133                         fail(e.getMessage());
134                 }
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);
140         }
141         @Test
142         public void testReport() {
143                 DataMigrationReport report = new DataMigrationReport();
144                 
145                 assertFalse(report.completed());
146                 long myvar = 42;
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());
154                 
155         }
156         @Test
157         public void TestPluginFileCreation() {
158                 
159                 final String TESTFILE = "asi324po.sa";
160                 try {
161                         MavenDatabasePluginInitFile.create(Release.FRANKFURT_R1, TESTFILE);
162                 } catch (IOException e) {
163                         fail(e.getMessage());
164                 }
165                 File f = new File(TESTFILE);
166                 if(f.exists()) {
167                         f.delete();
168                 }
169         }
170         
171 }