1 /*******************************************************************************
2 * ============LICENSE_START========================================================================
3 * ONAP : ccsdk feature sdnr wt
4 * =================================================================================================
5 * Copyright (C) 2020 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.dataprovider.test;
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertNull;
22 import static org.junit.Assert.fail;
24 import java.io.IOException;
25 import java.util.concurrent.TimeUnit;
27 import org.junit.BeforeClass;
28 import org.junit.Test;
29 import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
30 import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders;
31 import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteByQueryRequest;
32 import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.ElasticSearchDataProvider;
33 import org.onap.ccsdk.features.sdnr.wt.dataprovider.data.MediatorServerDataProvider;
34 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateMediatorServerInputBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.CreateMediatorServerOutputBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity;
40 * @author Michael Dürre
43 public class TestMediatorServerService {
44 private static final String SERVERID = null;
45 private static ElasticSearchDataProvider dbProvider;
46 private static HtDatabaseClient dbRawProvider;
47 private static MediatorServerDataProvider service = null;
51 public static void init() throws Exception {
53 dbProvider = new ElasticSearchDataProvider(TestCRUDforDatabase.hosts);
54 dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS);
55 dbRawProvider = new HtDatabaseClient(TestCRUDforDatabase.hosts);
56 service = new MediatorServerDataProvider(TestCRUDforDatabase.hosts);
62 clearDbEntity(Entity.MediatorServer);
63 System.out.println(service.triggerReloadSync());
64 String dbServerId="abc";
65 String host = service.getHostUrl(dbServerId);
67 final String NAME="ms1";
68 final String HOST = "http://10.20.30.40:7070";
69 CreateMediatorServerOutputBuilder output = null;
71 output = dbProvider.createMediatorServer(new CreateMediatorServerInputBuilder().setName(NAME).setUrl(HOST).build());
72 } catch (IOException e) {
74 fail("unable to create ms entry: "+e.getMessage());
76 System.out.println(service.triggerReloadSync());
77 host = service.getHostUrl(output.getId());
78 assertEquals(HOST, host);
82 private static void clearDbEntity(Entity entity) {
83 DeleteByQueryRequest query = new DeleteByQueryRequest(entity.getName());
84 query.setQuery(QueryBuilders.matchAllQuery().toJSON());
86 dbRawProvider.deleteByQuery(query);
87 } catch (IOException e) {
90 TestCRUDforDatabase.trySleep(1000);