6cbb561ee8933e5decddf8b01f5da628cfba5345
[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 = {
35             "2017-01-18T11:44:49.482-0500",
36             "2017-01-18T11:44:49.482-05:00",
37             "20170118114449.123Z",
38             "20170118114449.1Z",
39             "20170118114449.1-0500",
40             "2017-01-23T13:32:38-05:00",
41             "2017-01-23T13:32-05:00",
42             "2017-01-18T11:44:49Z"
43     };
44     private static String[] testPatterProblem = {
45             "2017-01-18T11:44:49"
46     };
47
48
49     private final static NetconfTimeStampOld netconfTimeConverterOld = NetconfTimeStampOld.getConverter();
50     private final static NetconfTimeStamp netconfTimeConverterNew = NetconfTimeStampImpl.getConverter();
51
52     @Test
53     public void test1() {
54
55         int t = 1;
56         String timeNew, timeOld;
57         for (String testTime : testPatterPostive) {
58             timeNew = netconfTimeConverterNew.getTimeStampFromNetconf(testTime);
59             timeOld = netconfTimeConverterOld.getTimeStampFromNetconf(testTime);
60
61             System.out.println("No "+t+++" Pattern: "+testTime);
62             System.out.println(" to old "+timeOld);
63             System.out.println(" to new "+timeNew);
64             System.out.println();
65
66             assertTrue("Old/New implementation not same "+timeOld+"/"+timeNew, timeOld.equals(timeNew));
67         }
68
69         for (String testTime : testPatterProblem) {
70             timeNew = netconfTimeConverterNew.getTimeStampFromNetconf(testTime);
71             timeOld = netconfTimeConverterOld.getTimeStampFromNetconf(testTime);
72
73             System.out.println("No "+t+++" Pattern: "+testTime);
74             System.out.println(" to old "+timeOld);
75             System.out.println(" to new "+timeNew);
76             System.out.println();
77
78             assertTrue("Old/New implementation not same "+timeOld+"/"+timeNew, timeOld.equals(timeNew));
79         }
80     }
81
82     @Test
83     public void test2() {
84
85         int t = 1;
86         Long timeNew, timeOld;
87         for (String testTime : testPatterPostive) {
88             timeNew = netconfTimeConverterNew.getTimeStampFromNetconfAsMilliseconds(testTime);
89             timeOld = netconfTimeConverterOld.getTimeStampFromNetconfAsMilliseconds(testTime);
90
91             System.out.println("No "+t+++" Pattern: "+testTime);
92             System.out.println(" to old "+timeOld);
93             System.out.println(" to new "+timeNew);
94             System.out.println();
95
96             assertTrue("Old/New implementation not same "+timeOld+"/"+timeNew, timeOld.equals(timeNew));
97         }
98
99     }
100
101
102     @Test
103     public void test3() {
104
105         Date now = new Date();
106         String timeNew = netconfTimeConverterNew.getTimeStampAsNetconfString(now);
107         String timeOld = netconfTimeConverterOld.getTimeStampAsNetconfString(now);
108
109         System.out.println("Old/New: "+timeOld+"/"+timeNew);
110
111         assertTrue("Old/New implementation not same "+timeOld+"/"+timeNew, timeOld.equals(timeNew));
112
113
114     }
115
116 }