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.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;
36 public class TestUserdata {
38 private static final String USERNAME = "admin";
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();
61 String fullContent = "";
63 fullContent = getFileContent("/userdata/full.json");
64 userDbProvider.setUserdata(USERNAME, fullContent);
65 } catch (IOException e) {
72 String userdata = userDbProvider.getUserdata(USERNAME);
73 JSONAssert.assertEquals(fullContent, userdata, false);
74 String networkMapContent = "";
75 String mergedContent = "";
77 networkMapContent = getFileContent("/userdata/networkmap.json");
78 mergedContent = getFileContent("/userdata/merged.json");
79 userDbProvider.setUserdata(USERNAME, "networkMap", networkMapContent);
80 } catch (IOException e) {
87 userdata = userDbProvider.getUserdata(USERNAME);
88 JSONAssert.assertEquals(mergedContent, userdata, false);
91 private static String getFileContent(String filename) throws IOException {
92 return String.join("\n", IoUtils.readAllLines(TestTree.class.getResourceAsStream(filename)));