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;
019:
020: import java.util.ArrayList;
021: import java.util.Arrays;
022: import java.util.List;
023:
024: import javax.xml.bind.annotation.XmlAccessType;
025: import javax.xml.bind.annotation.XmlAccessorType;
026: import javax.xml.bind.annotation.XmlElement;
027: import javax.xml.bind.annotation.XmlRootElement;
028: import javax.xml.bind.annotation.XmlType;
029:
030: import org.apache.cxf.jaxws.interceptors.WrapperHelper;
031: import org.junit.Assert;
032: import org.junit.Test;
033:
034: public class WrapperHelperTest extends Assert {
035:
036: @Test
037: public void getBooleanTypeWrappedPart() throws Exception {
038: SetIsOK ok = new SetIsOK();
039: ok.setParameter3(new boolean[] { true, false });
040: ok.setParameter4("hello");
041:
042: List<String> partNames = Arrays.asList(new String[] {
043: "Parameter1", "Parameter2", "Parameter3", "Parameter4",
044: "Parameter5", });
045: List<String> elTypeNames = Arrays.asList(new String[] {
046: "boolean", "int", "boolean", "string", "string", });
047: List<Class<?>> partClasses = Arrays.asList(new Class<?>[] {
048: Boolean.TYPE, Integer.TYPE, boolean[].class,
049: String.class, List.class, });
050:
051: WrapperHelper wh = WrapperHelper.createWrapperHelper(
052: SetIsOK.class, partNames, elTypeNames, partClasses);
053:
054: List<Object> lst = wh.getWrapperParts(ok);
055: assertEquals(5, lst.size());
056: assertTrue(lst.get(0) instanceof Boolean);
057: assertTrue(lst.get(1) instanceof Integer);
058: assertTrue(lst.get(2) instanceof boolean[]);
059: assertTrue(((boolean[]) lst.get(2))[0]);
060: assertFalse(((boolean[]) lst.get(2))[1]);
061: assertEquals("hello", (String) lst.get(3));
062:
063: lst.set(0, Boolean.TRUE);
064: Object o = wh.createWrapperObject(lst);
065: assertNotNull(0);
066: ok = (SetIsOK) o;
067: assertTrue(ok.isParameter1());
068: assertTrue(ok.getParameter3()[0]);
069: assertFalse(ok.getParameter3()[1]);
070: assertEquals("hello", ok.getParameter4());
071: }
072:
073: @XmlAccessorType(XmlAccessType.FIELD)
074: @XmlType(name="",propOrder={"parameter1","parameter2","parameter3","parameter4"})
075: @XmlRootElement(name="setIsOK")
076: public static class SetIsOK {
077:
078: @XmlElement(name="Parameter1")
079: protected boolean parameter1;
080: @XmlElement(name="Parameter2")
081: protected int parameter2;
082: @XmlElement(name="Parameter3")
083: protected boolean parameter3[];
084: @XmlElement(name="Parameter4")
085: protected String parameter4;
086: @XmlElement(name="Parameter5")
087: protected List<String> parameter5 = new ArrayList<String>();
088:
089: /**
090: * Gets the value of the parameter1 property.
091: *
092: */
093: public boolean isParameter1() {
094: return parameter1;
095: }
096:
097: /**
098: * Sets the value of the parameter1 property.
099: *
100: */
101: public void setParameter1(boolean value) {
102: this .parameter1 = value;
103: }
104:
105: /**
106: * Gets the value of the parameter2 property.
107: *
108: */
109: public int getParameter2() {
110: return parameter2;
111: }
112:
113: /**
114: * Sets the value of the parameter2 property.
115: *
116: */
117: public void setParameter2(int value) {
118: this .parameter2 = value;
119: }
120:
121: /**
122: * Gets the value of the parameter2 property.
123: *
124: */
125: public boolean[] getParameter3() {
126: return parameter3;
127: }
128:
129: /**
130: * Sets the value of the parameter2 property.
131: *
132: */
133: public void setParameter3(boolean value[]) {
134: this .parameter3 = value;
135: }
136:
137: public String getParameter4() {
138: return parameter4;
139: }
140:
141: public void setParameter4(String value) {
142: this .parameter4 = value;
143: }
144:
145: public List<String> getParameter5() {
146: return parameter5;
147: }
148: }
149: }
|