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.js.rhino;
019:
020: import org.easymock.classextension.EasyMock;
021:
022: import org.junit.Assert;
023: import org.junit.Before;
024: import org.junit.Test;
025: import org.mozilla.javascript.Scriptable;
026:
027: public class AbstractDOMProviderTest extends Assert {
028:
029: private String epAddr = "http://cxf.apache.org/";
030:
031: private Scriptable scriptMock;
032:
033: @Before
034: public void setUp() throws Exception {
035: scriptMock = EasyMock.createMock(Scriptable.class);
036: }
037:
038: @Test
039: public void testNoWsdlLocation() throws Exception {
040: EasyMock.expect(scriptMock.get("wsdlLocation", scriptMock))
041: .andReturn(Scriptable.NOT_FOUND);
042: EasyMock.replay(scriptMock);
043: AbstractDOMProvider adp = new DOMMessageProvider(scriptMock,
044: scriptMock, null, false, false);
045: try {
046: adp.publish();
047: fail("expected exception did not occur");
048: } catch (AbstractDOMProvider.JSDOMProviderException ex) {
049: assertEquals("wrong exception message",
050: AbstractDOMProvider.NO_WSDL_LOCATION, ex
051: .getMessage());
052: }
053: EasyMock.verify(scriptMock);
054: }
055:
056: @Test
057: public void testNoSvcName() throws Exception {
058: EasyMock.expect(scriptMock.get("wsdlLocation", scriptMock))
059: .andReturn("found");
060: EasyMock.expect(scriptMock.get("serviceName", scriptMock))
061: .andReturn(Scriptable.NOT_FOUND);
062: EasyMock.replay(scriptMock);
063: AbstractDOMProvider adp = new DOMPayloadProvider(scriptMock,
064: scriptMock, null, false, false);
065: try {
066: adp.publish();
067: fail("expected exception did not occur");
068: } catch (AbstractDOMProvider.JSDOMProviderException ex) {
069: assertEquals("wrong exception message",
070: AbstractDOMProvider.NO_SERVICE_NAME, ex
071: .getMessage());
072: }
073: EasyMock.verify(scriptMock);
074: }
075:
076: @Test
077: public void testNoPortName() throws Exception {
078: EasyMock.expect(scriptMock.get("wsdlLocation", scriptMock))
079: .andReturn("found");
080: EasyMock.expect(scriptMock.get("serviceName", scriptMock))
081: .andReturn("found");
082: EasyMock.expect(scriptMock.get("portName", scriptMock))
083: .andReturn(Scriptable.NOT_FOUND);
084: EasyMock.replay(scriptMock);
085: AbstractDOMProvider adp = new DOMMessageProvider(scriptMock,
086: scriptMock, null, false, false);
087: try {
088: adp.publish();
089: fail("expected exception did not occur");
090: } catch (AbstractDOMProvider.JSDOMProviderException ex) {
091: assertEquals("wrong exception message",
092: AbstractDOMProvider.NO_PORT_NAME, ex.getMessage());
093: }
094: EasyMock.verify(scriptMock);
095: }
096:
097: @Test
098: public void testNoTgtNamespace() throws Exception {
099: EasyMock.expect(scriptMock.get("wsdlLocation", scriptMock))
100: .andReturn("found");
101: EasyMock.expect(scriptMock.get("serviceName", scriptMock))
102: .andReturn("found");
103: EasyMock.expect(scriptMock.get("portName", scriptMock))
104: .andReturn("found");
105: EasyMock.expect(scriptMock.get("targetNamespace", scriptMock))
106: .andReturn(Scriptable.NOT_FOUND);
107: EasyMock.replay(scriptMock);
108: AbstractDOMProvider adp = new DOMMessageProvider(scriptMock,
109: scriptMock, null, false, false);
110: try {
111: adp.publish();
112: fail("expected exception did not occur");
113: } catch (AbstractDOMProvider.JSDOMProviderException ex) {
114: assertEquals("wrong exception message",
115: AbstractDOMProvider.NO_TGT_NAMESPACE, ex
116: .getMessage());
117: }
118: EasyMock.verify(scriptMock);
119: }
120:
121: @Test
122: public void testNoAddr() throws Exception {
123: EasyMock.expect(scriptMock.get("wsdlLocation", scriptMock))
124: .andReturn("found");
125: EasyMock.expect(scriptMock.get("serviceName", scriptMock))
126: .andReturn("found");
127: EasyMock.expect(scriptMock.get("portName", scriptMock))
128: .andReturn("found");
129: EasyMock.expect(scriptMock.get("targetNamespace", scriptMock))
130: .andReturn("found");
131: EasyMock.expect(scriptMock.get("EndpointAddress", scriptMock))
132: .andReturn(Scriptable.NOT_FOUND);
133: EasyMock.replay(scriptMock);
134: AbstractDOMProvider adp = new DOMPayloadProvider(scriptMock,
135: scriptMock, null, false, false);
136: try {
137: adp.publish();
138: fail("expected exception did not occur");
139: } catch (AbstractDOMProvider.JSDOMProviderException ex) {
140: assertEquals("wrong exception message",
141: AbstractDOMProvider.NO_EP_ADDR, ex.getMessage());
142: }
143: EasyMock.verify(scriptMock);
144: }
145:
146: @Test
147: public void testNoInvoke() throws Exception {
148: EasyMock.expect(scriptMock.get("wsdlLocation", scriptMock))
149: .andReturn("found");
150: EasyMock.expect(scriptMock.get("serviceName", scriptMock))
151: .andReturn("found");
152: EasyMock.expect(scriptMock.get("portName", scriptMock))
153: .andReturn("found");
154: EasyMock.expect(scriptMock.get("targetNamespace", scriptMock))
155: .andReturn("found");
156: EasyMock.expect(scriptMock.get("EndpointAddress", scriptMock))
157: .andReturn(epAddr);
158: EasyMock.expect(scriptMock.get("BindingType", scriptMock))
159: .andReturn(Scriptable.NOT_FOUND);
160: EasyMock.expect(scriptMock.get("invoke", scriptMock))
161: .andReturn(Scriptable.NOT_FOUND);
162: EasyMock.replay(scriptMock);
163: AbstractDOMProvider adp = new DOMPayloadProvider(scriptMock,
164: scriptMock, null, false, false);
165: try {
166: adp.publish();
167: fail("expected exception did not occur");
168: } catch (AbstractDOMProvider.JSDOMProviderException ex) {
169: assertEquals("wrong exception message",
170: AbstractDOMProvider.NO_INVOKE, ex.getMessage());
171: }
172: EasyMock.verify(scriptMock);
173: }
174:
175: @Test
176: public void testIllegalInvoke() throws Exception {
177: EasyMock.expect(scriptMock.get("wsdlLocation", scriptMock))
178: .andReturn("found");
179: EasyMock.expect(scriptMock.get("serviceName", scriptMock))
180: .andReturn("found");
181: EasyMock.expect(scriptMock.get("portName", scriptMock))
182: .andReturn("found");
183: EasyMock.expect(scriptMock.get("targetNamespace", scriptMock))
184: .andReturn("found");
185: EasyMock.expect(scriptMock.get("BindingType", scriptMock))
186: .andReturn(Scriptable.NOT_FOUND);
187: EasyMock.expect(scriptMock.get("invoke", scriptMock))
188: .andReturn("string");
189: EasyMock.replay(scriptMock);
190: AbstractDOMProvider adp = new DOMMessageProvider(scriptMock,
191: scriptMock, epAddr, true, true);
192: try {
193: adp.publish();
194: fail("expected exception did not occur");
195: } catch (AbstractDOMProvider.JSDOMProviderException ex) {
196: assertEquals("wrong exception message",
197: AbstractDOMProvider.ILLEGAL_INVOKE_TYPE, ex
198: .getMessage());
199: }
200: EasyMock.verify(scriptMock);
201: }
202: }
|