2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2019 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.assertEquals;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.fail;
27 import java.io.IOException;
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.config.HostInfo;
33 import org.onap.ccsdk.features.sdnr.wt.common.database.queries.QueryBuilders;
34 import org.onap.ccsdk.features.sdnr.wt.common.database.requests.DeleteByQueryRequest;
35 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.DatabaseDataProvider;
36 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.impl.ElasticSearchDataProvider;
37 import org.onap.ccsdk.features.sdnr.wt.dataprovider.impl.MediatorServerDataProvider;
38 import org.onap.ccsdk.features.sdnr.wt.dataprovider.test.util.HostInfoForTest;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMediatorServerInputBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.CreateMediatorServerOutputBuilder;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Entity;
44 * @author Michael Dürre
46 public class TestMediatorServerService {
47 private static DatabaseDataProvider dbProvider;
48 private static HtDatabaseClient dbRawProvider;
49 private static MediatorServerDataProvider service = null;
53 public static void init() throws Exception {
54 HostInfo[] hosts = HostInfoForTest.get();
55 dbProvider = new ElasticSearchDataProvider(hosts);
56 dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS);
57 dbRawProvider = HtDatabaseClient.getClient(hosts);
58 service = new MediatorServerDataProvider(dbProvider.getHtDatabaseMediatorServer());
63 clearDbEntity(Entity.MediatorServer);
64 System.out.println(service.triggerReloadSync());
65 String dbServerId = "abc";
66 String host = service.getHostUrl(dbServerId);
68 final String NAME = "ms1";
69 final String HOST = "http://10.20.30.40:7070";
70 CreateMediatorServerOutputBuilder output = null;
73 .createMediatorServer(new CreateMediatorServerInputBuilder().setName(NAME).setUrl(HOST).build());
74 } catch (IOException e) {
76 fail("unable to create ms entry: " + e.getMessage());
78 System.out.println(service.triggerReloadSync());
79 host = service.getHostUrl(output.getId());
80 assertEquals(HOST, host);
84 private static void clearDbEntity(Entity entity) {
85 DeleteByQueryRequest query = new DeleteByQueryRequest(entity.getName());
86 query.setQuery(QueryBuilders.matchAllQuery().toJSON());
88 dbRawProvider.deleteByQuery(query);
89 } catch (IOException e) {
92 TestCRUDforDatabase.trySleep(1000);