01: /*
02: * Copyright 2005 Joe Walker
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.directwebremoting.convert;
17:
18: import static org.junit.Assert.*;
19:
20: import java.sql.Time;
21: import java.sql.Timestamp;
22: import java.util.Date;
23:
24: import org.directwebremoting.extend.InboundContext;
25: import org.directwebremoting.extend.InboundVariable;
26: import org.directwebremoting.extend.MarshallException;
27: import org.directwebremoting.extend.OutboundContext;
28: import org.directwebremoting.extend.OutboundVariable;
29: import org.junit.Ignore;
30: import org.junit.Test;
31:
32: /**
33: * The tests for the <code>DateConverter</code> class.
34: * @see DateConverter
35: * @author Bram Smeets
36: * @author Joe Walker [joe at getahead dot ltd dot uk]
37: */
38: public class DateConverterTest {
39: private DateConverter converter = new DateConverter();
40:
41: @Test
42: public void convertOutbound() throws Exception {
43: OutboundVariable result = converter.convertOutbound(new Date(
44: 1104534000000L), new OutboundContext(false));
45:
46: assertNotNull(result);
47: assertEquals("new Date(1104534000000)", result.getAssignCode());
48: assertEquals("", result.getBuildCode());
49: }
50:
51: @Test(expected=MarshallException.class)
52: public void convertOutboundFail() throws Exception {
53: // try to convert a non-date object
54: converter.convertOutbound("01-01-2005", new OutboundContext(
55: false));
56: }
57:
58: @Test
59: public void testConvertInbound() throws Exception {
60: InboundContext ctx = new InboundContext();
61: InboundVariable iv = new InboundVariable(ctx, null, "type",
62: "null");
63:
64: Object result = converter.convertInbound(Date.class, iv, ctx);
65: assertNull(result);
66:
67: iv = new InboundVariable(ctx, null, "type", "1104534000000");
68: result = converter.convertInbound(Date.class, iv, ctx);
69:
70: assertNotNull(result);
71: assertTrue(result instanceof Date);
72: assertEquals(new Date(1104534000000L), result);
73:
74: result = converter.convertInbound(java.sql.Date.class, iv, ctx);
75: assertNotNull(result);
76: assertTrue(result instanceof java.sql.Date);
77:
78: result = converter.convertInbound(Time.class, iv, ctx);
79: assertNotNull(result);
80: assertTrue(result instanceof Time);
81:
82: result = converter.convertInbound(Timestamp.class, iv, ctx);
83: assertNotNull(result);
84: assertTrue(result instanceof Timestamp);
85: }
86:
87: @Ignore
88: @Test(expected=MarshallException.class)
89: public void testConvertInboundFail() throws Exception {
90: InboundContext ctx = new InboundContext();
91: InboundVariable iv = new InboundVariable(ctx, null, "type",
92: "null");
93:
94: // try to convert a non-supported type
95: converter.convertInbound(String.class, iv, ctx);
96: }
97: }
|