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.dwrp;
17:
18: import org.directwebremoting.convert.BeanConverter;
19: import org.directwebremoting.convert.StringConverter;
20: import org.directwebremoting.extend.Converter;
21: import org.directwebremoting.extend.InboundContext;
22: import org.directwebremoting.extend.InboundVariable;
23: import org.junit.Assert;
24: import org.junit.Test;
25:
26: /**
27: * @author Bram Smeets
28: * @author Joe Walker [joe at getahead dot ltd dot uk]
29: */
30: public class DefaultConverterManagerTest {
31: private DefaultConverterManager manager = new DefaultConverterManager();
32:
33: @Test
34: public void addConverterTypeFail() {
35: int before = manager.converterTypes.size();
36:
37: manager.addConverterType(null, null);
38: manager.addConverterType(null, Converter.class.getName());
39: manager.addConverterType(null, BeanConverter.class.getName());
40:
41: int after = manager.converterTypes.size();
42: Assert.assertEquals(before, after);
43: }
44:
45: @Test(expected=NullPointerException.class)
46: public void convertInboundFail() throws Exception {
47: manager.convertInbound(null, null, null, null);
48: }
49:
50: @Test(expected=NullPointerException.class)
51: public void convertInboundFail2() throws Exception {
52: manager.convertInbound(null, null, new InboundContext(), null);
53: }
54:
55: @Test(expected=NullPointerException.class)
56: public void convertInboundFail3() throws Exception {
57: manager.convertInbound(String.class, null,
58: new InboundContext(), null);
59: }
60:
61: @Test(expected=NullPointerException.class)
62: public void convertInboundFail4() throws Exception {
63: manager.convertInbound(String.class, null,
64: new InboundContext(), null);
65: }
66:
67: @Test
68: public void convertInbound5() throws Exception {
69: manager.addConverter("java.lang.String", new StringConverter());
70:
71: InboundContext ctx = new InboundContext();
72: InboundVariable var = new InboundVariable(ctx, "e_1", "string",
73: "bla");
74: manager.convertInbound(String.class, var, ctx, null);
75: }
76:
77: @Test
78: public void convertOutbound() throws Exception {
79: manager.convertOutbound(null, null);
80: }
81: }
|