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