1102e91c1dac892df8195b5de20d667d27334a8d
[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 java.time.ZonedDateTime;
26 import org.junit.Test;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.maintenance.impl.MaintenanceCalculator;
28 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.MaintenanceBuilder;
30
31 public class TestMaintenanceTimeFilter {
32
33     private static String DEFAULT1 =
34             "EsMaintenanceFilter [start=1970-01-01T00:00Z[UTC], end=1970-01-01T00:00Z[UTC], definition=EsMaintenanceFilterDefinition [objectIdRef=, problem=], description=]";
35     private static String DEFAULT2 =
36             "EsMaintenanceFilter [start=1970-01-01T00:00Z[UTC], end=2018-01-01T10:00+05:00, definition=EsMaintenanceFilterDefinition [objectIdRef=, problem=], description=]";
37
38     @Test
39     public void testBasic() {
40
41         boolean res;
42
43         DateAndTime start = new DateAndTime("2018-01-01T10:00:00+05:00");
44         DateAndTime end = new DateAndTime("2019-01-01T10:00:00+05:00");
45         ZonedDateTime now;
46
47         now = ZonedDateTime.parse("2017-05-01T10:00:00+05:00");
48         res = MaintenanceCalculator.isInPeriod(start, end, now);
49         System.out.println("Before: " + res);
50         assertFalse("before period", res);
51
52         now = ZonedDateTime.parse("2018-05-01T10:00:00+05:00");
53         res = MaintenanceCalculator.isInPeriod(start, end, now);
54         System.out.println("Within: " + res);
55         assertTrue("within period", res);
56
57         now = ZonedDateTime.parse("2019-05-01T10:00:00+05:00");
58         res = MaintenanceCalculator.isInPeriod(start, end, now);
59         System.out.println("After: " + res);
60         assertFalse("after period", res);
61
62     }
63
64     @Test
65     public void testBasic2() {
66
67         MaintenanceBuilder mb = new MaintenanceBuilder();
68
69         mb.setActive(true);
70         mb.setStart(new DateAndTime("1999-01-01T00:00:00Z"));
71         mb.setEnd(new DateAndTime("2001-01-01T00:00:00Z"));
72         mb.setId("id1");
73         mb.setObjectIdRef("Interface1");
74         mb.setProblem("Problem1");
75
76         boolean res;
77         ZonedDateTime now;
78
79         now = MaintenanceCalculator.valueOf("2000-01-01T00:00Z");
80         res = MaintenanceCalculator.isONFObjectInMaintenance(mb.build(), "Interface1", "Problem1", now);
81         assertTrue("within period", res);
82
83         now = MaintenanceCalculator.valueOf("2002-01-01T00:00Z");
84         res = MaintenanceCalculator.isONFObjectInMaintenance(mb.build(), "", "", now);
85         assertFalse("outside period", res);
86
87     }
88
89 }