3fcbdb84cd45dddc359d7cb0d8df9fdf24f9e008
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2021 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.test;
23
24 import static org.junit.Assert.fail;
25 import java.io.IOException;
26 import org.apache.sshd.common.util.io.IoUtils;
27 import org.junit.BeforeClass;
28 import org.junit.Ignore;
29 import org.junit.Test;
30 import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
31 import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo;
32 import org.onap.ccsdk.features.sdnr.wt.common.test.JSONAssert;
33 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl.HtUserdataManagerImpl;
34 import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest;
35
36 public class TestUserdata {
37
38     private static final String USERNAME = "admin";
39     private static HtDatabaseClient dbRawProvider;
40     private static HtUserdataManagerImpl userDbProvider;
41
42     @BeforeClass
43     public static void init() throws Exception {
44
45         HostInfo[] hosts = HostInfoForTest.get();
46         dbRawProvider = HtDatabaseClient.getClient(hosts);
47         userDbProvider = new HtUserdataManagerImpl(dbRawProvider);
48     }
49
50     public static void trySleep(long ms) {
51         try {
52             Thread.sleep(ms);
53         } catch (Exception e) {
54             Thread.currentThread().interrupt();
55         }
56     }
57
58     @Ignore
59     @Test
60     public void test1() {
61         String fullContent = "";
62         try {
63             fullContent = getFileContent("/userdata/full.json");
64             userDbProvider.setUserdata(USERNAME, fullContent);
65         } catch (IOException e) {
66             e.printStackTrace();
67             fail(e.getMessage());
68         }
69
70         trySleep(2000);
71
72         String userdata = userDbProvider.getUserdata(USERNAME);
73         JSONAssert.assertEquals(fullContent, userdata, false);
74         String networkMapContent = "";
75         String mergedContent = "";
76         try {
77             networkMapContent = getFileContent("/userdata/networkmap.json");
78             mergedContent = getFileContent("/userdata/merged.json");
79             userDbProvider.setUserdata(USERNAME, "networkMap", networkMapContent);
80         } catch (IOException e) {
81             e.printStackTrace();
82             fail(e.getMessage());
83         }
84
85         trySleep(2000);
86
87         userdata = userDbProvider.getUserdata(USERNAME);
88         JSONAssert.assertEquals(mergedContent, userdata, false);
89     }
90
91     private static String getFileContent(String filename) throws IOException {
92         return String.join("\n", IoUtils.readAllLines(TestTree.class.getResourceAsStream(filename)));
93     }
94 }