d1b5cfcfd943c7aa369b5e26d93576cc1ff07ac7
[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 java.io.IOException;
25 import java.util.ArrayList;
26 import java.util.List;
27 import java.util.Set;
28 import java.util.concurrent.TimeUnit;
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertNotNull;
31 import static org.junit.Assert.fail;
32 import org.junit.BeforeClass;
33 import org.junit.Test;
34 import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit;
35 import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo;
36 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl.ElasticSearchDataProvider;
37 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DatabaseDataProvider;
38 import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest;
39 import org.onap.ccsdk.features.sdnr.wt.yang.mapper.YangToolsMapper;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Inventory;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryDeviceListInputBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.ReadInventoryDeviceListOutputBuilder;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.entity.input.PaginationBuilder;
45 import org.opendaylight.yangtools.yang.common.Uint32;
46 import org.opendaylight.yangtools.yang.common.Uint64;
47
48 public class TestInventoryConsistency {
49
50     private static final String TEST1NODEID = "sim1";
51     private static DatabaseDataProvider dbProvider;
52
53     @BeforeClass
54     public static void init() throws Exception {
55         HostInfo[] hosts = HostInfoForTest.get();
56         dbProvider = new ElasticSearchDataProvider(hosts);
57         dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS);
58     }
59
60     @Test
61     public void test1() {
62         YangToolsMapper mapper = new YangToolsMapper();
63         SearchHit[] hits = null;
64         try {
65             hits = TestTree.loadEntries("test1.json");
66             List<Inventory> inventoryList = new ArrayList<>();
67             for (SearchHit hit : hits) {
68                 inventoryList.add(mapper.readValue(hit.getSourceAsString(), Inventory.class));
69             }
70             dbProvider.getDataProvider().writeInventory(TEST1NODEID, inventoryList);
71         } catch (IOException e) {
72
73             e.printStackTrace();
74             fail(e.getMessage());
75         }
76         SearchHit sim2Hit = hits[hits.length-1];
77         dbProvider.getRawClient().doWriteRaw(Entity.Inventoryequipment.getName(),sim2Hit.getId(),sim2Hit.getSourceAsString(),true);
78         ReadInventoryDeviceListOutputBuilder deviceListWithInventory =
79                 dbProvider.readInventoryDeviceList(new ReadInventoryDeviceListInputBuilder().setPagination(
80                         new PaginationBuilder().setSize(Uint32.valueOf(20)).setPage(Uint64.valueOf(1))
81                                 .build()).build());
82         assertNotNull(deviceListWithInventory);
83         assertEquals(2, deviceListWithInventory.getPagination().getTotal().intValue());
84         assertEquals(Set.of("sim1", "sim2"), deviceListWithInventory.getData());
85     }
86 }