1d97eb85bffe318c831b19a2840650c9ca5b95de
[ccsdk/features.git] /
1 /*******************************************************************************
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk feature sdnr wt
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 package org.onap.ccsdk.features.sdnr.wt.devicemanager.test;
22
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26 import java.time.ZonedDateTime;
27 import org.junit.Test;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.database.types.EsMaintenanceFilter;
29
30 public class TestMaintenanceTimeFilter {
31
32     private static String DEFAULT1 = "EsMaintenanceFilter [start=1970-01-01T00:00Z[UTC], end=1970-01-01T00:00Z[UTC], definition=EsMaintenanceFilterDefinition [objectIdRef=, problem=], description=]";
33     private static String DEFAULT2 = "EsMaintenanceFilter [start=1970-01-01T00:00Z[UTC], end=2018-01-01T10:00+05:00, definition=EsMaintenanceFilterDefinition [objectIdRef=, problem=], description=]";
34
35     @Test
36     public void test1() {
37         EsMaintenanceFilter fi = new EsMaintenanceFilter();
38         String fiAsString;
39
40         fiAsString = fi.toString();
41         System.out.println("Default 1: " + fiAsString);
42         if (! fiAsString.equals(DEFAULT1)) {
43             fail("Time conversion not OK");
44         }
45     }
46     @Test
47     public void test2() {
48         EsMaintenanceFilter fi = new EsMaintenanceFilter();
49         String fiAsString;
50
51         fi.setEndAsString("2018-01-01T10:00:00+05:00");
52         fiAsString = fi.toString();
53         System.out.println("Default 2: " + fi);
54         System.out.println("As String: " + fi.getEndAsString());
55         if (! fiAsString.equals(DEFAULT2)) {
56             fail("Time conversion not OK");
57         }
58     }
59     @Test
60     public void test3() {
61
62         boolean res;
63
64         ZonedDateTime start = ZonedDateTime.parse("2018-01-01T10:00:00+05:00");
65         ZonedDateTime end = ZonedDateTime.parse("2019-01-01T10:00:00+05:00");
66         ZonedDateTime now;
67
68         now = ZonedDateTime.parse("2017-05-01T10:00:00+05:00");
69         res = EsMaintenanceFilter.isInPeriod(start, end, now);
70         System.out.println("Before: " + res);
71         assertFalse("before period", res);
72
73         now = ZonedDateTime.parse("2018-05-01T10:00:00+05:00");
74         res = EsMaintenanceFilter.isInPeriod(start, end, now);
75         System.out.println("Within: " + res);
76         assertTrue("within period",res);
77
78         now = ZonedDateTime.parse("2019-05-01T10:00:00+05:00");
79         res = EsMaintenanceFilter.isInPeriod(start, end, now);
80         System.out.println("After: " + res);
81         assertFalse("after period", res);
82
83     }
84
85 }