1   /*
2   wsmo4j - a WSMO API and Reference Implementation
3   
4   Copyright (c) 2004-2005 , OntoText Lab. / SIRMA
5                             University of Innsbruck, Austria  
6   
7   This library is free software; you can redistribute it and/or modify it under
8   the terms of the GNU Lesser General Public License as published by the Free
9   Software Foundation; either version 2.1 of the License, or (at your option)
10  any later version.
11  This library is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
14  details.
15  You should have received a copy of the GNU Lesser General Public License along
16  with this library; if not, write to the Free Software Foundation, Inc.,
17  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19  
20  package test.wsmo4j.factory;
21  import static junit.framework.Assert.*;
22  
23  import java.math.BigDecimal;
24  import java.math.BigInteger;
25  import java.util.Calendar;
26  import java.util.GregorianCalendar;
27  
28  import org.omwg.ontology.ComplexDataValue;
29  
30  import test.wsmo4j.Wsmo4jTestCase;
31  
32  
33  /**
34   *@author Luchesar Cekov
35   *Test fix of https://sourceforge.net/tracker/?func=detail&atid=665346&aid=1723466&group_id=113501
36   */
37  public class DataFactoryDateTimeTest extends Wsmo4jTestCase {
38      public void testCreateDateTimeCalendar() throws Exception {
39          GregorianCalendar calendar = new GregorianCalendar();
40          calendar.set(Calendar.YEAR, 7890);
41          calendar.set(Calendar.MONTH, Calendar.MAY);
42          calendar.set(Calendar.DAY_OF_MONTH, 25);
43          calendar.set(Calendar.HOUR_OF_DAY, 17);
44          calendar.set(Calendar.MINUTE, 17);
45          calendar.set(Calendar.SECOND, 17);
46          calendar.set(Calendar.MILLISECOND, 234);
47         
48          ComplexDataValue value = dataFactory.createWsmlDateTime(calendar);
49          validate(value);
50      }
51      
52      
53      public void testCreateDateTimeFloat() throws Exception {        
54          ComplexDataValue value = dataFactory.createWsmlDateTime(7890, 5, 25, 17, 17, 17.234f, 0, 0);
55          validate(value);
56      }
57      
58      public void testCreateDateTimeString() throws Exception {        
59          ComplexDataValue value = dataFactory.createWsmlDateTime("7890", "5", "25", "17", "17", new BigDecimal("" + 17.234f).toString(), "0", "0");
60          validate(value);
61      }
62      
63      private void validate(ComplexDataValue dataValue) {
64          assertEquals(8, dataValue.getArity());        
65          assertEquals(dataFactory.createWsmlInteger(new BigInteger("" +7890)), dataValue.getArgumentValue((byte)0));
66          assertEquals(dataFactory.createWsmlInteger(new BigInteger("" +5)), dataValue.getArgumentValue((byte)1));
67          assertEquals(dataFactory.createWsmlInteger(new BigInteger("" +25)), dataValue.getArgumentValue((byte)2));
68          assertEquals(dataFactory.createWsmlInteger(new BigInteger("" +17)), dataValue.getArgumentValue((byte)3));
69          assertEquals(dataFactory.createWsmlInteger(new BigInteger("" +17)), dataValue.getArgumentValue((byte)4));
70          assertEquals(dataFactory.createWsmlDecimal(new BigDecimal("" + 17.234f)), dataValue.getArgumentValue((byte)5));
71      }
72      
73      public void testCreateTimeCalendar() throws Exception {
74          GregorianCalendar calendar = new GregorianCalendar();        
75          calendar.set(Calendar.HOUR_OF_DAY, 17);
76          calendar.set(Calendar.MINUTE, 17);
77          calendar.set(Calendar.SECOND, 17);
78          calendar.set(Calendar.MILLISECOND, 234);
79         
80          ComplexDataValue value = dataFactory.createWsmlTime(calendar);
81          validateTime(value);
82      }
83      
84      
85      public void testCreateTimeFloat() throws Exception {        
86          ComplexDataValue value = dataFactory.createWsmlTime(17, 17, 17.234f, 0, 0);
87          validateTime(value);
88      }
89      
90      public void testCreateTimeInt() throws Exception {        
91          ComplexDataValue value = dataFactory.createWsmlTime(17, 17, 17, 0, 0);
92          assertEquals(dataFactory.createWsmlInteger(new BigInteger("" +17)), value.getArgumentValue((byte)0));
93          assertEquals(dataFactory.createWsmlInteger(new BigInteger("" +17)), value.getArgumentValue((byte)1));
94          assertEquals(dataFactory.createWsmlDecimal(new BigDecimal(17f)), value.getArgumentValue((byte)2));
95      }
96      
97      public void testCreateTimeString() throws Exception {        
98          ComplexDataValue value = dataFactory.createWsmlTime("17", "17", new BigDecimal(17.234f).toString(), "0", "0");
99          validateTime(value);
100     }
101     
102     private void validateTime(ComplexDataValue dataValue) {
103         assertEquals(5, dataValue.getArity());        
104         assertEquals(dataFactory.createWsmlInteger(new BigInteger("" +17)), dataValue.getArgumentValue((byte)0));
105         assertEquals(dataFactory.createWsmlInteger(new BigInteger("" +17)), dataValue.getArgumentValue((byte)1));
106         assertEquals(dataFactory.createWsmlDecimal(new BigDecimal(17.234f)), dataValue.getArgumentValue((byte)2));
107     }
108 }
109 
110 
111 /*$Log$
112  *Revision 1.2  2007/09/04 08:17:59  lcekov
113  *DataTypeFactory.createWsmlTime must support milliseconds
114  *https://sourceforge.net/tracker/?func=detail&atid=665346&aid=1723466&group_id=113501
115  *
116 /*Revision 1.1  2007/06/22 13:25:17  lcekov
117 /*DataTypeFactory.createWsmlDateTime must support milliseconds
118 /*https://sourceforge.net/tracker/?func=detail&atid=665346&aid=1723466&group_id=113501
119 /*
120 */