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