001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.jaxws.handler;
019:
020: import java.util.HashMap;
021: import java.util.Map;
022:
023: import org.junit.Assert;
024: import org.junit.Before;
025: import org.junit.Test;
026:
027: public class InitParamResourceResolverTest extends Assert {
028:
029: public static final String STRING_PARAM = "stringParam";
030: public static final String STRING_VALUE = "a string";
031: public static final String INT_PARAM = "intParam";
032: public static final String INT_VALUE = "42";
033: public static final String FLOAT_PARAM = "floatParam";
034: public static final String FLOAT_VALUE = Float
035: .toString(Float.MAX_VALUE);
036: public static final String CHAR_PARAM = "charParam";
037: public static final String CHAR_VALUE = "a";
038: public static final String BYTE_PARAM = "byteParam";
039: public static final String BYTE_VALUE = Byte
040: .toString(Byte.MAX_VALUE);
041: public static final String SHORT_PARAM = "shortParam";
042: public static final String SHORT_VALUE = "12";
043: public static final String LONG_PARAM = "longParam";
044: public static final String LONG_VALUE = Long
045: .toString(Long.MAX_VALUE);
046: public static final String DOUBLE_PARAM = "doubleParam";
047: public static final String DOUBLE_VALUE = Double
048: .toString(Double.MAX_VALUE);
049: public static final String BOOLEAN_PARAM = "booleanParam";
050: public static final String BOOLEAN_VALUE = "true";
051:
052: private Map<String, String> params = new HashMap<String, String>();
053:
054: private InitParamResourceResolver resolver;
055:
056: @Before
057: public void setUp() {
058: params.put(STRING_PARAM, STRING_VALUE);
059: params.put(INT_PARAM, INT_VALUE);
060: params.put(FLOAT_PARAM, FLOAT_VALUE);
061: params.put(CHAR_PARAM, CHAR_VALUE);
062: params.put(BYTE_PARAM, BYTE_VALUE);
063: params.put(SHORT_PARAM, SHORT_VALUE);
064: params.put(LONG_PARAM, LONG_VALUE);
065: params.put(DOUBLE_PARAM, DOUBLE_VALUE);
066: params.put(BOOLEAN_PARAM, BOOLEAN_VALUE);
067: resolver = new InitParamResourceResolver(params);
068: }
069:
070: /*
071: char, byte, short, int, long, float, double, boolean
072: */
073:
074: @Test
075: public void testResolveChar() {
076: doResolveTypeTest(CHAR_PARAM, Character.class, CHAR_VALUE
077: .charAt(0));
078: }
079:
080: @Test
081: public void testResolveByte() {
082: doResolveTypeTest(BYTE_PARAM, Byte.class, Byte
083: .valueOf(BYTE_VALUE));
084: }
085:
086: @Test
087: public void testResolveShort() {
088: doResolveTypeTest(SHORT_PARAM, Short.class, Short
089: .valueOf(SHORT_VALUE));
090: }
091:
092: @Test
093: public void testResolveLong() {
094: doResolveTypeTest(LONG_PARAM, Long.class, Long
095: .valueOf(LONG_VALUE));
096: }
097:
098: @Test
099: public void testResolveFloat() {
100: doResolveTypeTest(FLOAT_PARAM, Float.class, Float
101: .valueOf(FLOAT_VALUE));
102: }
103:
104: @Test
105: public void testResolveDouble() {
106: doResolveTypeTest(DOUBLE_PARAM, Double.class, Double
107: .valueOf(DOUBLE_VALUE));
108: }
109:
110: @Test
111: public void tesResolveBoolean() {
112: doResolveTypeTest(BOOLEAN_PARAM, Boolean.class, Boolean
113: .valueOf(BOOLEAN_VALUE));
114: }
115:
116: @Test
117: public void testResolveInt() {
118: doResolveTypeTest(INT_PARAM, Integer.class, Integer
119: .valueOf(INT_VALUE));
120: }
121:
122: @Test
123: public void testResolveString() {
124: String ret = resolver.resolve(STRING_PARAM, String.class);
125: assertEquals("incorrect string value returned", STRING_VALUE,
126: ret);
127: }
128:
129: private <T> void doResolveTypeTest(String param, Class<T> type,
130: T expectedValue) {
131: T ret = resolver.resolve(param, type);
132: assertEquals("incorrect string value returned", expectedValue,
133: ret);
134: }
135:
136: }
|