01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.binding.jbi.interceptor;
19:
20: import java.util.ResourceBundle;
21: import java.util.logging.Logger;
22:
23: import javax.jbi.messaging.MessageExchange;
24: import javax.xml.namespace.QName;
25:
26: import org.apache.cxf.binding.jbi.JBIBindingInfo;
27: import org.apache.cxf.binding.jbi.JBIConstants;
28: import org.apache.cxf.binding.jbi.JBIMessage;
29: import org.apache.cxf.common.i18n.Message;
30: import org.apache.cxf.common.logging.LogUtils;
31: import org.apache.cxf.endpoint.Endpoint;
32: import org.apache.cxf.endpoint.EndpointImpl;
33: import org.apache.cxf.interceptor.Fault;
34: import org.apache.cxf.message.ExchangeImpl;
35: import org.apache.cxf.message.MessageImpl;
36: import org.apache.cxf.phase.Phase;
37: import org.apache.cxf.phase.PhaseInterceptor;
38: import org.apache.cxf.service.model.EndpointInfo;
39: import org.easymock.classextension.EasyMock;
40: import org.junit.Assert;
41: import org.junit.Test;
42:
43: public class JBIOperationInInterceptorTest extends Assert {
44:
45: private static final Logger LOG = LogUtils
46: .getL7dLogger(JBIOperationInInterceptor.class);
47: private static final ResourceBundle BUNDLE = LOG
48: .getResourceBundle();
49:
50: @Test
51: public void testPhase() throws Exception {
52: PhaseInterceptor<JBIMessage> interceptor = new JBIOperationInInterceptor();
53: assertEquals(Phase.PRE_PROTOCOL, interceptor.getPhase());
54: }
55:
56: @Test
57: public void testUnknownOperation() throws Exception {
58: PhaseInterceptor<JBIMessage> interceptor = new JBIOperationInInterceptor();
59: JBIMessage msg = new JBIMessage(new MessageImpl());
60: MessageExchange me = EasyMock.createMock(MessageExchange.class);
61: EasyMock.expect(me.getOperation()).andReturn(
62: new QName("urn:test", "SayHi")).times(4);
63: EasyMock.replay(me);
64: msg.put(MessageExchange.class, me);
65: EndpointInfo endpointInfo = new EndpointInfo();
66: endpointInfo.setBinding(new JBIBindingInfo(null,
67: JBIConstants.NS_JBI_BINDING));
68: Endpoint ep = new EndpointImpl(null, null, endpointInfo);
69: msg.setExchange(new ExchangeImpl());
70: msg.getExchange().put(Endpoint.class, ep);
71: try {
72: interceptor.handleMessage(msg);
73: fail("shouldn't found SayHi operation");
74: } catch (Fault fault) {
75: assertEquals(fault.getMessage(), new Message(
76: "UNKNOWN_OPERATION", BUNDLE, msg.getJbiExchange()
77: .getOperation().toString()).toString());
78: }
79: }
80:
81: }
|