2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2021 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.test;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26 import java.io.IOException;
27 import org.apache.sshd.common.util.io.IoUtils;
28 import org.junit.BeforeClass;
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;
36 public class TestUserdata {
38 private static final String USERNAME = "admin132";
39 private static HtDatabaseClient dbRawProvider;
40 private static HtUserdataManagerImpl userDbProvider;
43 public static void init() throws Exception {
45 HostInfo[] hosts = HostInfoForTest.get();
46 dbRawProvider = HtDatabaseClient.getClient(hosts);
47 userDbProvider = new HtUserdataManagerImpl(dbRawProvider);
50 public static void trySleep(long ms) {
53 } catch (Exception e) {
54 Thread.currentThread().interrupt();
60 String fullContent = "";
61 boolean success = false;
63 fullContent = getFileContent("/userdata/full.json");
64 success = userDbProvider.setUserdata(USERNAME, fullContent);
65 } catch (IOException e) {
69 assertTrue("problem writing data into db",success);
73 String userdata = userDbProvider.getUserdata(USERNAME);
74 JSONAssert.assertEquals(fullContent, userdata, false);
75 String networkMapContent = "";
76 String mergedContent = "";
78 networkMapContent = getFileContent("/userdata/networkmap.json");
79 mergedContent = getFileContent("/userdata/merged.json");
80 userDbProvider.setUserdata(USERNAME, "networkMap", networkMapContent);
81 } catch (IOException e) {
88 userdata = userDbProvider.getUserdata(USERNAME);
89 JSONAssert.assertEquals(mergedContent, userdata, false);
92 private static String getFileContent(String filename) throws IOException {
93 return String.join("\n", IoUtils.readAllLines(TestUserdata.class.getResourceAsStream(filename)));