1 /*******************************************************************************
2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6 * =================================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8 * in compliance with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software distributed under the License
13 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14 * or implied. See the License for the specific language governing permissions and limitations under
16 * ============LICENSE_END==========================================================================
17 ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.common.test;
20 import static org.junit.Assert.*;
22 import org.junit.BeforeClass;
23 import org.junit.Test;
24 import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
25 import org.onap.ccsdk.features.sdnr.wt.common.database.SearchHit;
26 import org.onap.ccsdk.features.sdnr.wt.common.database.SearchResult;
27 import org.onap.ccsdk.features.sdnr.wt.common.database.config.HostInfo;
28 import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders;
30 public class TestDbClient {
32 private static HtDatabaseClient dbClient;
33 private static HostInfo[] hosts = new HostInfo[] { new HostInfo("localhost", Integer
34 .valueOf(System.getProperty("databaseport") != null ? System.getProperty("databaseport") : "49200")) };
37 public static void init() {
39 dbClient = new HtDatabaseClient(hosts);
40 dbClient.waitForYellowStatus(20000);
44 public void testCRUD() {
45 final String IDX = "test23-knmoinsd";
46 final String ID = "abcddd";
47 final String JSON = "{\"data\":{\"inner\":\"more\"}}";
48 final String JSON2 = "{\"data\":{\"inner\":\"more2\"}}";
50 String esId=dbClient.doWriteRaw(IDX, ID, JSON);
51 assertEquals("inserted id is wrong",ID,esId);
53 SearchResult<SearchHit> result = dbClient.doReadByQueryJsonData(IDX, QueryBuilders.matchQuery("_id", ID));
54 assertEquals("amount of results is wrong",1,result.getTotal());
55 assertEquals("data not valid", JSON,result.getHits().get(0).getSourceAsString());
57 esId= dbClient.doUpdateOrCreate(IDX, ID, JSON2);
58 assertEquals("update response not successfull",ID,esId);
60 result = dbClient.doReadByQueryJsonData( IDX, QueryBuilders.matchQuery("_id", ID));
61 assertEquals("amount of results is wrong",1,result.getTotal());
62 assertEquals("data not valid", JSON2,result.getHits().get(0).getSourceAsString());
64 boolean del=dbClient.doRemove(IDX, ID);
65 assertTrue("item not deleted",del);
67 result = dbClient.doReadByQueryJsonData(IDX, QueryBuilders.matchQuery("_id", ID));
68 assertEquals("amount of results is wrong",0,result.getTotal());