1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
35
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
112
113
114
115
116
117
118
119
120