/v3.2/nimbits-tds/test/TestTimespanInterpeter.java
http://nimbits-server.googlecode.com/ · Java · 211 lines · 156 code · 34 blank · 21 comment · 0 complexity · 01c1667a1070ae85c1721122b1c14f42 MD5 · raw file
- /*
- * Copyright (c) 2010 Tonic Solutions LLC.
- *
- * http://www.nimbits.com
- *
- *
- * 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
- *
- * http://www.gnu.org/licenses/gpl.html
- *
- * 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.
- */
- import com.google.gwt.junit.client.GWTTestCase;
- import com.nimbits.client.model.timespan.InvalidTimespanException;
- import com.nimbits.client.model.timespan.Timespan;
- import com.nimbits.server.timespan.TimespanServiceFactory;
- import org.junit.Assert;
- import org.junit.Test;
- /**
- * Created by bsautner
- * User: benjamin
- * Date: 4/25/11
- * Time: 7:48 PM
- */
- public class TestTimespanInterpeter extends GWTTestCase {
- @Test
- public void testAbsolute() {
- String s1 = "20100410000000";
- String s2 = "20110410000000";
- Timespan ts = null;
- try {
- ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2);
- } catch (InvalidTimespanException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- Assert.assertEquals(ts.getStart().getTime(), 1270872000000L);
- Assert.assertEquals(ts.getEnd().getTime(), 1302408000000L);
- Assert.assertNotNull(ts);
- }
- @Test
- public void testEpoch() {
- String s1 = "1270872000";
- String s2 = "1302408000";
- Timespan ts = null;
- try {
- ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2);
- } catch (InvalidTimespanException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- Assert.assertEquals(ts.getStart().getTime(), 1270872000000L);
- Assert.assertEquals(ts.getEnd().getTime(), 1302408000000L);
- Assert.assertNotNull(ts);
- }
- @Test
- public void testEpochMs() {
- String s1 = "1270872000000";
- String s2 = "1302408000000";
- Timespan ts = null;
- try {
- ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2);
- } catch (InvalidTimespanException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- Assert.assertEquals(ts.getStart().getTime(), 1270872000000L);
- Assert.assertEquals(ts.getEnd().getTime(), 1302408000000L);
- Assert.assertNotNull(ts);
- }
- @Test
- public void testTime5() {
- String s1 = "05/09/2011 07:01:44 PM";
- String s2 = "05/09/2011 08:40:44 PM";
- Timespan ts = null;
- try {
- ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2);
- } catch (InvalidTimespanException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- Assert.assertEquals(1304924504000L, ts.getStart().getTime());
- Assert.assertEquals(1304930444000L, ts.getEnd().getTime());
- Assert.assertNotNull(ts);
- }
- @Test
- public void testTime() {
- String s1 = "02/23/2010 11:29:08 AM";
- String s2 = "02/23/2011 11:29:08 AM";
- Timespan ts = null;
- try {
- ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2);
- } catch (InvalidTimespanException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- Assert.assertEquals(1304924504000L, ts.getStart().getTime());
- Assert.assertEquals(1298478548000L, ts.getEnd().getTime());
- Assert.assertNotNull(ts);
- }
- @Test
- public void testTime2() {
- String s1 = "02/23/2010 11:29:08 AM";
- String s2 = "2/23/2011 11:29:08 PM";
- Timespan ts = null;
- try {
- ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2);
- } catch (InvalidTimespanException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- Assert.assertEquals(1266942548000L, ts.getStart().getTime());
- Assert.assertEquals(1298478548000L, ts.getEnd().getTime());
- Assert.assertNotNull(ts);
- }
- @Test
- public void testTime3() {
- String s1 = "02/23/2010 11:29:08 AM";
- String s2 = "2/23/2011 01:29:08 PM";
- Timespan ts = null;
- try {
- ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2);
- } catch (InvalidTimespanException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- System.out.println(ts.getEnd());
- Assert.assertEquals(1266942548000L, ts.getStart().getTime());
- Assert.assertEquals(1298442548000L, ts.getEnd().getTime());
- Assert.assertNotNull(ts);
- }
- @Test
- public void testSQLTime5() {
- String s1 = "04/09/2011 09:10:44 AM";
- String s2 = "04/09/2011 09:10:45 AM";
- Timespan ts = null;
- try {
- ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2);
- } catch (InvalidTimespanException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- System.out.println(ts.getEnd());
- Assert.assertEquals(1302354644000L, ts.getStart().getTime());
- Assert.assertEquals(1302354645000L, ts.getEnd().getTime());
- Assert.assertNotNull(ts);
- }
- @Test
- public void testTime43() {
- String s1 = "23/2/2010 11:29:08";
- String s2 = "23/2/2011 01:29:08";
- Timespan ts = null;
- try {
- ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2);
- } catch (InvalidTimespanException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- System.out.println(ts.getEnd());
- Assert.assertEquals(1266942548000L, ts.getStart().getTime());
- Assert.assertEquals(1298442548000L, ts.getEnd().getTime());
- Assert.assertNotNull(ts);
- }
- @Test
- public void testSpecial() {
- String s1 = "-1s";
- String s2 = "*";
- Timespan ts = null;
- try {
- ts = TimespanServiceFactory.getInstance().createTimespan(s1, s2);
- } catch (InvalidTimespanException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- System.out.println(ts.getStart().getTime());
- System.out.println(ts.getEnd().getTime());
- long r = ts.getEnd().getTime() - ts.getStart().getTime();
- Assert.assertEquals(r, 1000);
- // Assert.assertEquals(ts.getStart().getTime(), 1270872000000L);
- // Assert.assertEquals(ts.getEnd().getTime(), 1302408000000L);
- // Assert.assertNotNull(ts);
- }
- @Override
- public String getModuleName() {
- return null; //auto generated
- }
- }