/v3.2/nimbits-tds/test/TestTimespanInterpeter.java
Java | 211 lines | 156 code | 34 blank | 21 comment | 0 complexity | 01c1667a1070ae85c1721122b1c14f42 MD5 | raw file
1/* 2 * Copyright (c) 2010 Tonic Solutions LLC. 3 * 4 * http://www.nimbits.com 5 * 6 * 7 * Licensed under the GNU GENERAL PUBLIC LICENSE, Version 3.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 8 * 9 * http://www.gnu.org/licenses/gpl.html 10 * 11 * Unless required by applicable law or agreed to in writing, software distributed under the license is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 12 */ 13 14import com.google.gwt.junit.client.GWTTestCase; 15import com.nimbits.client.model.timespan.InvalidTimespanException; 16import com.nimbits.client.model.timespan.Timespan; 17import com.nimbits.server.timespan.TimespanServiceFactory; 18import org.junit.Assert; 19import org.junit.Test; 20 21/** 22 * Created by bsautner 23 * User: benjamin 24 * Date: 4/25/11 25 * Time: 7:48 PM 26 */ 27public class TestTimespanInterpeter extends GWTTestCase { 28 29 @Test 30 public void testAbsolute() { 31 String s1 = "20100410000000"; 32 String s2 = "20110410000000"; 33 Timespan ts = null; 34 try { 35 ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2); 36 } catch (InvalidTimespanException e) { 37 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 38 } 39 40 Assert.assertEquals(ts.getStart().getTime(), 1270872000000L); 41 Assert.assertEquals(ts.getEnd().getTime(), 1302408000000L); 42 Assert.assertNotNull(ts); 43 44 } 45 46 @Test 47 public void testEpoch() { 48 String s1 = "1270872000"; 49 String s2 = "1302408000"; 50 Timespan ts = null; 51 try { 52 ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2); 53 } catch (InvalidTimespanException e) { 54 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 55 } 56 57 Assert.assertEquals(ts.getStart().getTime(), 1270872000000L); 58 Assert.assertEquals(ts.getEnd().getTime(), 1302408000000L); 59 Assert.assertNotNull(ts); 60 61 } 62 63 @Test 64 public void testEpochMs() { 65 String s1 = "1270872000000"; 66 String s2 = "1302408000000"; 67 Timespan ts = null; 68 try { 69 ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2); 70 } catch (InvalidTimespanException e) { 71 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 72 } 73 74 Assert.assertEquals(ts.getStart().getTime(), 1270872000000L); 75 Assert.assertEquals(ts.getEnd().getTime(), 1302408000000L); 76 Assert.assertNotNull(ts); 77 78 } 79 80 @Test 81 public void testTime5() { 82 String s1 = "05/09/2011 07:01:44 PM"; 83 String s2 = "05/09/2011 08:40:44 PM"; 84 Timespan ts = null; 85 try { 86 ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2); 87 } catch (InvalidTimespanException e) { 88 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 89 } 90 91 Assert.assertEquals(1304924504000L, ts.getStart().getTime()); 92 Assert.assertEquals(1304930444000L, ts.getEnd().getTime()); 93 Assert.assertNotNull(ts); 94 95 } 96 97 98 @Test 99 public void testTime() { 100 String s1 = "02/23/2010 11:29:08 AM"; 101 String s2 = "02/23/2011 11:29:08 AM"; 102 Timespan ts = null; 103 try { 104 ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2); 105 } catch (InvalidTimespanException e) { 106 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 107 } 108 109 Assert.assertEquals(1304924504000L, ts.getStart().getTime()); 110 Assert.assertEquals(1298478548000L, ts.getEnd().getTime()); 111 Assert.assertNotNull(ts); 112 113 } 114 115 @Test 116 public void testTime2() { 117 String s1 = "02/23/2010 11:29:08 AM"; 118 String s2 = "2/23/2011 11:29:08 PM"; 119 Timespan ts = null; 120 try { 121 ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2); 122 } catch (InvalidTimespanException e) { 123 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 124 } 125 126 Assert.assertEquals(1266942548000L, ts.getStart().getTime()); 127 Assert.assertEquals(1298478548000L, ts.getEnd().getTime()); 128 Assert.assertNotNull(ts); 129 130 } 131 132 @Test 133 public void testTime3() { 134 String s1 = "02/23/2010 11:29:08 AM"; 135 String s2 = "2/23/2011 01:29:08 PM"; 136 Timespan ts = null; 137 try { 138 ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2); 139 } catch (InvalidTimespanException e) { 140 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 141 } 142 System.out.println(ts.getEnd()); 143 144 Assert.assertEquals(1266942548000L, ts.getStart().getTime()); 145 Assert.assertEquals(1298442548000L, ts.getEnd().getTime()); 146 Assert.assertNotNull(ts); 147 148 } 149 150 @Test 151 public void testSQLTime5() { 152 String s1 = "04/09/2011 09:10:44 AM"; 153 String s2 = "04/09/2011 09:10:45 AM"; 154 Timespan ts = null; 155 try { 156 ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2); 157 } catch (InvalidTimespanException e) { 158 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 159 } 160 System.out.println(ts.getEnd()); 161 162 Assert.assertEquals(1302354644000L, ts.getStart().getTime()); 163 Assert.assertEquals(1302354645000L, ts.getEnd().getTime()); 164 Assert.assertNotNull(ts); 165 166 } 167 168 @Test 169 public void testTime43() { 170 String s1 = "23/2/2010 11:29:08"; 171 String s2 = "23/2/2011 01:29:08"; 172 Timespan ts = null; 173 try { 174 ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2); 175 } catch (InvalidTimespanException e) { 176 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 177 } 178 System.out.println(ts.getEnd()); 179 180 Assert.assertEquals(1266942548000L, ts.getStart().getTime()); 181 Assert.assertEquals(1298442548000L, ts.getEnd().getTime()); 182 Assert.assertNotNull(ts); 183 184 } 185 186 @Test 187 public void testSpecial() { 188 String s1 = "-1s"; 189 String s2 = "*"; 190 Timespan ts = null; 191 try { 192 ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2); 193 } catch (InvalidTimespanException e) { 194 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 195 } 196 System.out.println(ts.getStart().getTime()); 197 System.out.println(ts.getEnd().getTime()); 198 long r = ts.getEnd().getTime() - ts.getStart().getTime(); 199 Assert.assertEquals(r, 1000); 200 201// Assert.assertEquals(ts.getStart().getTime(), 1270872000000L); 202// Assert.assertEquals(ts.getEnd().getTime(), 1302408000000L); 203// Assert.assertNotNull(ts); 204 205 } 206 207 @Override 208 public String getModuleName() { 209 return null; //auto generated 210 } 211}