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.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import java.io.IOException;
28 import java.util.List;
29 import java.util.concurrent.TimeUnit;
30 import org.junit.BeforeClass;
31 import org.junit.Test;
32 import org.onap.ccsdk.features.sdnr.wt.common.database.HtDatabaseClient;
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.data.ElasticSearchDataProvider;
36 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.HtDatabaseMaintenance;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.Entity;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.MaintenanceBuilder;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.MaintenanceEntity;
42 * - Handling of inital values for Maintenance mode.
44 public class TestMaintenanceServiceData {
46 private static ElasticSearchDataProvider dbProvider;
47 private static HtDatabaseClient dbRawProvider;
48 private static HtDatabaseMaintenance service = null;
50 private static final String NODEID = "tmsnode1";
51 private static final String NODEID2 = "tmsnode2";
54 public static void init() throws Exception {
56 dbProvider = new ElasticSearchDataProvider(TestCRUDforDatabase.hosts);
57 dbProvider.waitForYellowDatabaseStatus(30, TimeUnit.SECONDS);
58 dbRawProvider = HtDatabaseClient.getClient(TestCRUDforDatabase.hosts);
59 service = dbProvider.getHtDatabaseMaintenance();
63 public void test() throws InterruptedException {
64 clearDbEntity(Entity.Maintenancemode);
65 MaintenanceEntity obj = service.createIfNotExists(NODEID);
66 assertNotNull("Create first id", obj);
67 obj = service.createIfNotExists(NODEID2);
68 assertNotNull("Create second id", obj);
69 obj = service.getMaintenance(NODEID);
71 List<MaintenanceEntity> list = service.getAll();
72 assertEquals("Verify for two ids", 2, list.size());
73 service.deleteIfNotRequired(NODEID);
74 obj = service.getMaintenance(NODEID);
75 assertNull("Check if first id was removed", obj);
77 obj = service.setMaintenance(createMaintenance(NODEID, true));
87 private static MaintenanceEntity createMaintenance(String nodeId, Boolean active) {
88 return new MaintenanceBuilder().setNodeId(nodeId).setActive(active).setProblem("problem")
89 .setObjectIdRef("idref").build();
97 private static void clearDbEntity(Entity entity) {
98 DeleteByQueryRequest query = new DeleteByQueryRequest(entity.getName());
99 query.setQuery(QueryBuilders.matchAllQuery().toJSON());
101 dbRawProvider.deleteByQuery(query);
102 } catch (IOException e) {
105 TestCRUDforDatabase.trySleep(1000);