03629edaac74bd937760f24a8f3820317eabaff8
[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" + 
66                         "dcaeUserCredentials=admin:admin\n" + 
67                         "dcaeUrl=off\n" + 
68                         "dcaeHeartbeatPeriodSeconds=120\n" + 
69                         "dcaeTestCollector=no\n" + 
70                         "\n" + 
71                         "[es]\n" + 
72                         "esCluster=sendateodl5\n" + 
73                         "#time limit to keep increasing data in database [in seconds]\n" + 
74                         "#60*60*24*30 (30days)\n" + 
75                         "esArchiveLimit=2592000\n" + 
76                         "#folder where removed data will be stored\n" + 
77                         "esArchiveFolder=./backup\n" + 
78                         "#interval to archive database [in seconds]\n" + 
79                         "#60*60*24 (1day)\n" + 
80                         "esArchiveInterval=86400\n" + 
81                         "\n" + 
82                         "[aai]\n" + 
83                         "#keep comment\n" + 
84                         "aaiHeaders=[\"X-TransactionId: 9999\"]\n" + 
85                         "aaiUrl=http://localhost:81\n" + 
86                         "aaiUserCredentials=AAI:AAI\n" + 
87                         "aaiDeleteOnMountpointRemove=false\n" + 
88                         "aaiTrustAllCerts=false\n" + 
89                         "aaiApiVersion=aai/v13\n" + 
90                         "aaiPropertiesFile=aaiclient.properties\n" + 
91                         "aaiApplicationId=SDNR\n" + 
92                         "aaiPcks12ClientCertFile=/opt/logs/externals/data/stores/keystore.client.p12\n" + 
93                         "aaiPcks12ClientCertPassphrase=adminadmin\n" + 
94                         "aaiClientConnectionTimeout=30000\n" + 
95                         "\n" + 
96                         "[pm]\n" + 
97                         "pmCluster=sendateodl5\n" + 
98                         "pmEnabled=true\n" + 
99                         "";
100         @Test
101         public void testComponentData() {
102                 JSONArray hits = new JSONArray();
103                 hits.put(EVENTLOG_SEARCHHIT);
104                 hits.put(EVENTLOG_SEARCHHIT2);
105                 ComponentData data = new ComponentData(ComponentName.EVENTLOG,hits);
106                 JSONArray out = data.toJsonArray();
107                 assertEquals(ComponentName.EVENTLOG, data.getName());
108                 JSONAssert.assertEquals(EVENTLOG_SEARCHHIT.toString(),out.getJSONObject(0).toString(),false);
109                 JSONAssert.assertEquals(EVENTLOG_SEARCHHIT2.toString(),out.getJSONObject(1).toString(),false);
110                 
111         }
112         @Test
113         public void testConfigData() {
114                 ConfigData data = new ConfigData(CONFIG_CONTENT);
115                 assertTrue(data.getLines().length>10);
116         }
117         @Test
118         public void testConfigName() {
119                 ConfigName name = ConfigName.APIGATEWAY;
120                 assertEquals("apigateway", name.getValue());
121                 try {
122                         assertEquals(ConfigName.APIGATEWAY,ConfigName.getValueOf("apigateway"));
123                 } catch (Exception e) {
124                         fail(e.getMessage());
125                 }
126                 
127         }
128         @Test
129         public void testDataContainer() {
130                 DataContainer container  = new DataContainer();
131                 assertEquals(Release.CURRENT_RELEASE,container.getRelease());
132                 assertNotNull(container.getCreated());
133                 
134                 try {
135                         container = DataContainer.load(new File("src/test/resources/test.bak.json"));
136                 } catch (Exception e) {
137                         fail(e.getMessage());
138                 }
139                 assertNotNull(container);
140                 assertEquals(Release.EL_ALTO,container.getRelease());
141                 assertNotNull(container.getCreated());
142                 assertTrue(container.getComponents().size()>0);
143                 assertTrue(container.getConfigs().size()==0);
144         }
145         @Test
146         public void testReport() {
147                 DataMigrationReport report = new DataMigrationReport();
148                 
149                 assertFalse(report.completed());
150                 long myvar = 42;
151                 String myvar2 = "come";
152                 report.log("%d was wrong",myvar);
153                 report.error("%s to me",myvar2);
154                 assertTrue(report.toString().contains("42 was wrong"));
155                 assertTrue(report.toString().contains("come to me"));
156                 report.setCompleted(true);
157                 assertTrue(report.completed());
158                 
159         }
160         @Test
161         public void TestPluginFileCreation() {
162                 
163                 final String TESTFILE = "asi324po.sa";
164                 try {
165                         MavenDatabasePluginInitFile.create(Release.FRANKFURT_R1, TESTFILE);
166                 } catch (IOException e) {
167                         fail(e.getMessage());
168                 }
169                 File f = new File(TESTFILE);
170                 if(f.exists()) {
171                         f.delete();
172                 }
173         }
174         
175 }