Removing blueprints-processor
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / test / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / test / util / DBCleanServiceHelper.java
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
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
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
15  * the License.
16  * ============LICENSE_END==========================================================================
17  ******************************************************************************/
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.test.util;
19
20 import java.util.Date;
21 import java.util.concurrent.TimeUnit;
22 import org.onap.ccsdk.features.sdnr.wt.base.netconf.util.NetconfTimeStamp;
23 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.DataProvider;
24 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.DeviceManagerImpl;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalDateAndTime;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalSeverity;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ObjectCreationNotificationXml;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml.ProblemNotificationXml;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.SourceType;
30
31 public class DBCleanServiceHelper {
32
33     private static final NetconfTimeStamp NETCONFTIME_CONVERTER = NetconfTimeStamp.getConverter();
34
35     private final DataProvider databaseEventService;
36
37     /**
38      * Helper to fill data into the database
39      * @param deviceManager devicemanger to get services
40      */
41     public DBCleanServiceHelper(DeviceManagerImpl deviceManager) {
42         this.databaseEventService = deviceManager.getDatabaseClientEvents();
43     }
44
45     /**
46      * Write data into database with specific date and content profile.
47      * @param number of data to be written for each log
48      * @param days starting day, relative to actual date
49      * @param hours starting hour ... increased by one hour for each write
50      * @return integer with the amount of written data
51      */
52     public int writeDataToLogs(int number, int days, int hours) {
53         int res = 0;
54         for (Integer t=0; t < number; t++) { //Test "sdnevents", "eventlog"
55             ObjectCreationNotificationXml notificationXml = new ObjectCreationNotificationXml(
56                     "Testpoint"+t, t, getInternalDateAndTime(days, hours+t), "ObjectId"+t);
57             databaseEventService.writeConnectionLog(notificationXml.getConnectionlogEntity());
58             res++;
59         }
60
61         for (Integer t=0; t < number; t++) { //Test "sdnevents", "faultlog"
62             ProblemNotificationXml fault = new ProblemNotificationXml(
63                     "ProblemNode"+t, "Problemuuid", "Problemname", InternalSeverity.Major, t, getInternalDateAndTime(days, hours+t));
64             databaseEventService.writeFaultLog(fault.getFaultlog(SourceType.Unknown));
65             res++;
66         }
67
68         return res;
69     }
70
71     /**************************************************************
72      * Private section
73      */
74
75     private InternalDateAndTime getInternalDateAndTime(int days, int hours) {
76         Date actual = new Date(new Date().getTime() - TimeUnit.MILLISECONDS.convert(days, TimeUnit.DAYS) - TimeUnit.MILLISECONDS.convert(hours, TimeUnit.HOURS));
77         InternalDateAndTime timeStamp = InternalDateAndTime.valueOf(NETCONFTIME_CONVERTER.getTimeStamp(actual));
78         return timeStamp;
79     }
80
81
82 }