579f90069f7ccc5ff74bbfb33fb7017a8f43a07f
[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.assertTrue;
24
25 import java.util.Date;
26
27 import org.junit.Test;
28 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.NetconfTimeStamp;
29 import org.onap.ccsdk.features.sdnr.wt.dataprovider.model.types.NetconfTimeStampImpl;
30 import org.onap.ccsdk.features.sdnr.wt.devicemanager.test.util.NetconfTimeStampOld;
31
32 public class TestsNectconfDateTime {
33
34     private static String[] testPatterPostive = {"2017-01-18T11:44:49.482-0500", "2017-01-18T11:44:49.482-05:00",
35             "20170118114449.123Z", "20170118114449.1Z", "20170118114449.1-0500", "2017-01-23T13:32:38-05:00",
36             "2017-01-23T13:32-05:00", "2017-01-18T11:44:49Z"};
37     private static String[] testPatterProblem = {"2017-01-18T11:44:4"
38             //"2017-01-18T11:44:49" Excluded Test Ok in J8 and false in J11 .. impact low .. so excluded.
39     };
40
41
42     private final static NetconfTimeStampOld netconfTimeConverterOld = NetconfTimeStampOld.getConverter();
43     private final static NetconfTimeStamp netconfTimeConverterNew = NetconfTimeStampImpl.getConverter();
44
45     @Test
46     public void test1() {
47
48         int t = 1;
49         String timeNew, timeOld;
50         for (String testTime : testPatterPostive) {
51             timeNew = netconfTimeConverterNew.getTimeStampFromNetconf(testTime);
52             timeOld = netconfTimeConverterOld.getTimeStampFromNetconf(testTime);
53
54             System.out.println("No " + t++ + " Pattern: " + testTime);
55             System.out.println(" to old " + timeOld);
56             System.out.println(" to new " + timeNew);
57             System.out.println();
58
59             assertTrue("Old/New implementation not same " + timeOld + "/" + timeNew, timeOld.equals(timeNew));
60         }
61
62         for (String testTime : testPatterProblem) {
63             timeNew = netconfTimeConverterNew.getTimeStampFromNetconf(testTime);
64             timeOld = netconfTimeConverterOld.getTimeStampFromNetconf(testTime);
65
66             System.out.println("No " + t++ + " Pattern: " + testTime);
67             System.out.println(" to old " + timeOld);
68             System.out.println(" to new " + timeNew);
69             System.out.println();
70             assertTrue("Old/New implementation not same " + timeOld + "/" + timeNew, timeOld.equals(timeNew));
71         }
72     }
73
74     @Test
75     public void test2() {
76
77         int t = 1;
78         Long timeNew, timeOld;
79         for (String testTime : testPatterPostive) {
80             timeNew = netconfTimeConverterNew.getTimeStampFromNetconfAsMilliseconds(testTime);
81             timeOld = netconfTimeConverterOld.getTimeStampFromNetconfAsMilliseconds(testTime);
82
83             System.out.println("No " + t++ + " Pattern: " + testTime);
84             System.out.println(" to old " + timeOld);
85             System.out.println(" to new " + timeNew);
86             System.out.println();
87
88             assertTrue("Old/New implementation not same " + timeOld + "/" + timeNew, timeOld.equals(timeNew));
89         }
90
91     }
92
93
94     @Test
95     public void test3() {
96
97         Date now = new Date();
98         String timeNew = netconfTimeConverterNew.getTimeStampAsNetconfString(now);
99         String timeOld = netconfTimeConverterOld.getTimeStampAsNetconfString(now);
100
101         System.out.println("Old/New: " + timeOld + "/" + timeNew);
102
103         assertTrue("Old/New implementation not same " + timeOld + "/" + timeNew, timeOld.equals(timeNew));
104
105
106     }
107
108 }