ed8eac949c1d21c22118b7044a60afee3a45fead
[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.test;
23
24 import static org.junit.Assert.fail;
25 import java.io.IOException;
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.concurrent.TimeUnit;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
32 import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit;
33 import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo;
34 import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider;
35 import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest;
36 import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
38
39 public class TestInventoryConsistency {
40
41     private static final String TEST1NODEID = "sim1";
42     private static String resourceDirectoryPath = "/" + TestTree.class.getSimpleName() + "/";
43     private static ElasticSearchDataProvider dbProvider;
44     private static HtDatabaseClient dbRawProvider;
45
46     @BeforeClass
47     public static void init() throws Exception {
48         HostInfo[] hosts = HostInfoForTest.get();
49         dbProvider = new ElasticSearchDataProvider(hosts);
50         dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS);
51         dbRawProvider = HtDatabaseClient.getClient(hosts);
52     }
53
54     @Test
55     public void test1() {
56         YangToolsMapper mapper = new YangToolsMapper();
57         try {
58             SearchHit[] hits = TestTree.loadEntries("test1.json");
59             List<Inventory> inventoryList = new ArrayList<>();
60             for(SearchHit hit:hits) {
61                 inventoryList.add(mapper.readValue(hit.getSourceAsString(), Inventory.class));
62             }
63             dbProvider.getDataProvider().writeInventory(TEST1NODEID, inventoryList);
64         } catch (IOException e) {
65
66             e.printStackTrace();
67             fail(e.getMessage());
68         }
69     }
70 }