Search in sources :

Example 36 with IMocksControl

use of org.easymock.IMocksControl in project cxf by apache.

the class CXFBusImplTest method testConstructionWithExtensions.

@Test
public void testConstructionWithExtensions() throws BusException {
    IMocksControl control;
    BindingFactoryManager bindingFactoryManager;
    InstrumentationManager instrumentationManager;
    PhaseManager phaseManager;
    control = EasyMock.createNiceControl();
    Map<Class<?>, Object> extensions = new HashMap<>();
    bindingFactoryManager = control.createMock(BindingFactoryManager.class);
    instrumentationManager = control.createMock(InstrumentationManager.class);
    phaseManager = control.createMock(PhaseManager.class);
    extensions.put(BindingFactoryManager.class, bindingFactoryManager);
    extensions.put(InstrumentationManager.class, instrumentationManager);
    extensions.put(PhaseManager.class, phaseManager);
    Bus bus = new ExtensionManagerBus(extensions);
    assertSame(bindingFactoryManager, bus.getExtension(BindingFactoryManager.class));
    assertSame(instrumentationManager, bus.getExtension(InstrumentationManager.class));
    assertSame(phaseManager, bus.getExtension(PhaseManager.class));
}
Also used : IMocksControl(org.easymock.IMocksControl) Bus(org.apache.cxf.Bus) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) PhaseManager(org.apache.cxf.phase.PhaseManager) HashMap(java.util.HashMap) BindingFactoryManager(org.apache.cxf.binding.BindingFactoryManager) InstrumentationManager(org.apache.cxf.management.InstrumentationManager) ExtensionManagerBus(org.apache.cxf.bus.extension.ExtensionManagerBus) Test(org.junit.Test)

Example 37 with IMocksControl

use of org.easymock.IMocksControl in project cxf by apache.

the class CXFBusLifeCycleManagerTest method testDeregistration.

@Test
public void testDeregistration() {
    IMocksControl ctrl = EasyMock.createStrictControl();
    BusLifeCycleListener listener1 = ctrl.createMock(BusLifeCycleListener.class);
    BusLifeCycleListener listener2 = ctrl.createMock(BusLifeCycleListener.class);
    CXFBusLifeCycleManager mgr = new CXFBusLifeCycleManager();
    mgr.registerLifeCycleListener(listener2);
    mgr.registerLifeCycleListener(listener1);
    mgr.unregisterLifeCycleListener(listener2);
    ctrl.reset();
    listener1.initComplete();
    ctrl.replay();
    mgr.initComplete();
    ctrl.verify();
    ctrl.reset();
    listener1.preShutdown();
    ctrl.replay();
    mgr.preShutdown();
    ctrl.verify();
    ctrl.reset();
    listener1.postShutdown();
    ctrl.replay();
    mgr.postShutdown();
    ctrl.verify();
}
Also used : IMocksControl(org.easymock.IMocksControl) CXFBusLifeCycleManager(org.apache.cxf.bus.managers.CXFBusLifeCycleManager) Test(org.junit.Test)

Example 38 with IMocksControl

use of org.easymock.IMocksControl in project cxf by apache.

the class ManagedConnectionImplTest method testHandleEqualsMethod.

/**
 * Verify the connection handle's equals() method
 */
@Test
public void testHandleEqualsMethod() throws Exception {
    BusFactory.setDefaultBus(null);
    IMocksControl control = EasyMock.createNiceControl();
    ManagedConnectionFactoryImpl mcf = control.createMock(ManagedConnectionFactoryImpl.class);
    CXFConnectionSpec cxRequestInfo = new CXFConnectionSpec();
    cxRequestInfo.setWsdlURL(getClass().getResource("/wsdl/hello_world.wsdl"));
    cxRequestInfo.setServiceClass(Greeter.class);
    cxRequestInfo.setEndpointName(new QName("http://apache.org/hello_world_soap_http", "SoapPort"));
    cxRequestInfo.setServiceName(new QName("http://apache.org/hello_world_soap_http", "SOAPService"));
    control.replay();
    Subject subject = new Subject();
    ManagedConnectionImpl conn = new ManagedConnectionImpl(mcf, cxRequestInfo, subject);
    Object handle1 = conn.getConnection(subject, cxRequestInfo);
    Object handle2 = conn.getConnection(subject, cxRequestInfo);
    assertEquals(handle1, handle1);
    assertEquals(handle2, handle2);
    assertFalse(handle1.equals(handle2));
}
Also used : IMocksControl(org.easymock.IMocksControl) QName(javax.xml.namespace.QName) Subject(javax.security.auth.Subject) Test(org.junit.Test)

Example 39 with IMocksControl

use of org.easymock.IMocksControl in project cxf by apache.

the class LogicalHandlerInterceptorTest method xtestReturnFalseClientSide.

// JAX-WS spec: If handler returns false, for a request-response MEP, if the message
// direction is reversed during processing of a request message then the message
// becomes a response message.
// NOTE: commented out as this has been covered by other tests.
@Test
@org.junit.Ignore
public void xtestReturnFalseClientSide() throws Exception {
    @SuppressWarnings("rawtypes") List<Handler> list = new ArrayList<>();
    list.add(new LogicalHandler<LogicalMessageContext>() {

        public void close(MessageContext arg0) {
        }

        public boolean handleFault(LogicalMessageContext messageContext) {
            return true;
        }

        public boolean handleMessage(LogicalMessageContext messageContext) {
            LogicalMessage msg = messageContext.getMessage();
            AddNumbersResponse resp = new AddNumbersResponse();
            resp.setReturn(11);
            msg.setPayload(resp, null);
            return false;
        }
    });
    HandlerChainInvoker invoker1 = new HandlerChainInvoker(list);
    IMocksControl control1 = createNiceControl();
    Binding binding1 = control1.createMock(Binding.class);
    @SuppressWarnings("rawtypes") List<Handler> hList = CastUtils.cast(list);
    expect(binding1.getHandlerChain()).andReturn(hList).anyTimes();
    Exchange exchange1 = control1.createMock(Exchange.class);
    expect(exchange1.get(HandlerChainInvoker.class)).andReturn(invoker1).anyTimes();
    Message outMessage = new MessageImpl();
    outMessage.setExchange(exchange1);
    InterceptorChain chain = control1.createMock(InterceptorChain.class);
    outMessage.setInterceptorChain(chain);
    chain.abort();
    EasyMock.expectLastCall();
    MessageObserver observer = control1.createMock(MessageObserver.class);
    expect(exchange1.get(MessageObserver.class)).andReturn(observer).anyTimes();
    observer.onMessage(isA(Message.class));
    EasyMock.expectLastCall();
    control1.replay();
    LogicalHandlerInInterceptor li = new LogicalHandlerInInterceptor(binding1);
    li.handleMessage(outMessage);
    control1.verify();
}
Also used : Binding(javax.xml.ws.Binding) LogicalMessageContext(javax.xml.ws.handler.LogicalMessageContext) MessageObserver(org.apache.cxf.transport.MessageObserver) LogicalMessage(javax.xml.ws.LogicalMessage) Message(org.apache.cxf.message.Message) ArrayList(java.util.ArrayList) LogicalHandler(javax.xml.ws.handler.LogicalHandler) Handler(javax.xml.ws.handler.Handler) AddNumbersResponse(org.apache.handlers.types.AddNumbersResponse) IMocksControl(org.easymock.IMocksControl) Exchange(org.apache.cxf.message.Exchange) InterceptorChain(org.apache.cxf.interceptor.InterceptorChain) LogicalHandlerInInterceptor(org.apache.cxf.jaxws.handler.logical.LogicalHandlerInInterceptor) LogicalMessageContext(javax.xml.ws.handler.LogicalMessageContext) MessageContext(javax.xml.ws.handler.MessageContext) LogicalMessage(javax.xml.ws.LogicalMessage) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Example 40 with IMocksControl

use of org.easymock.IMocksControl in project cxf by apache.

the class SOAPHandlerInterceptorTest method testChangeSOAPHeaderInBound.

@Test
public void testChangeSOAPHeaderInBound() throws Exception {
    @SuppressWarnings("rawtypes") List<Handler> list = new ArrayList<>();
    list.add(new SOAPHandler<SOAPMessageContext>() {

        public boolean handleMessage(SOAPMessageContext smc) {
            try {
                Boolean outboundProperty = (Boolean) smc.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
                if (!outboundProperty.booleanValue()) {
                    // change mustUnderstand to false
                    SOAPMessage message = smc.getMessage();
                    SOAPHeader soapHeader = message.getSOAPHeader();
                    Element headerElementNew = (Element) soapHeader.getFirstChild();
                    SoapVersion soapVersion = Soap11.getInstance();
                    Attr attr = headerElementNew.getOwnerDocument().createAttributeNS(soapVersion.getNamespace(), "SOAP-ENV:mustUnderstand");
                    attr.setValue("false");
                    headerElementNew.setAttributeNodeNS(attr);
                }
            } catch (Exception e) {
                throw new Fault(e);
            }
            return true;
        }

        public boolean handleFault(SOAPMessageContext smc) {
            return true;
        }

        public Set<QName> getHeaders() {
            return null;
        }

        public void close(MessageContext messageContext) {
        }
    });
    HandlerChainInvoker invoker = new HandlerChainInvoker(list);
    IMocksControl control = createNiceControl();
    Binding binding = control.createMock(Binding.class);
    expect(binding.getHandlerChain()).andReturn(list).anyTimes();
    Exchange exchange = control.createMock(Exchange.class);
    expect(exchange.get(HandlerChainInvoker.class)).andReturn(invoker).anyTimes();
    // This is to set direction to inbound
    expect(exchange.getOutMessage()).andReturn(null);
    SoapMessage message = new SoapMessage(new MessageImpl());
    message.setExchange(exchange);
    XMLStreamReader reader = preparemXMLStreamReader("resources/greetMeRpcLitReq.xml");
    message.setContent(XMLStreamReader.class, reader);
    Object[] headerInfo = prepareSOAPHeader();
    message.setContent(Node.class, headerInfo[0]);
    Node node = ((Element) headerInfo[1]).getFirstChild();
    message.getHeaders().add(new Header(new QName(node.getNamespaceURI(), node.getLocalName()), node));
    control.replay();
    SOAPHandlerInterceptor li = new SOAPHandlerInterceptor(binding);
    li.handleMessage(message);
    control.verify();
    // Verify SOAPMessage header
    SOAPMessage soapMessageNew = message.getContent(SOAPMessage.class);
    Element headerElementNew = DOMUtils.getFirstElement(soapMessageNew.getSOAPHeader());
    SoapVersion soapVersion = Soap11.getInstance();
    assertEquals("false", headerElementNew.getAttributeNS(soapVersion.getNamespace(), "mustUnderstand"));
    // Verify XMLStreamReader
    XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);
    QName qn = xmlReader.getName();
    assertEquals("sendReceiveData", qn.getLocalPart());
    // Verify Header Element
    Iterator<Header> iter = message.getHeaders().iterator();
    Element requiredHeader = null;
    while (iter.hasNext()) {
        Header localHdr = iter.next();
        if (localHdr.getObject() instanceof Element) {
            Element elem = (Element) localHdr.getObject();
            if (elem.getNamespaceURI().equals("http://apache.org/hello_world_rpclit/types") && elem.getLocalName().equals("header1")) {
                requiredHeader = (Element) localHdr.getObject();
                break;
            }
        }
    }
    assertNotNull("Should have found header1", requiredHeader);
    assertEquals("false", requiredHeader.getAttributeNS(soapVersion.getNamespace(), "mustUnderstand"));
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) XMLStreamReader(javax.xml.stream.XMLStreamReader) PartialXMLStreamReader(org.apache.cxf.staxutils.PartialXMLStreamReader) SOAPHeaderElement(javax.xml.soap.SOAPHeaderElement) SOAPBodyElement(javax.xml.soap.SOAPBodyElement) SOAPElement(javax.xml.soap.SOAPElement) Element(org.w3c.dom.Element) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Fault(org.apache.cxf.interceptor.Fault) SOAPMessage(javax.xml.soap.SOAPMessage) Attr(org.w3c.dom.Attr) SoapMessage(org.apache.cxf.binding.soap.SoapMessage) IMocksControl(org.easymock.IMocksControl) MessageContext(javax.xml.ws.handler.MessageContext) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) SOAPHeader(javax.xml.soap.SOAPHeader) Binding(javax.xml.ws.Binding) QName(javax.xml.namespace.QName) SOAPHandler(javax.xml.ws.handler.soap.SOAPHandler) Handler(javax.xml.ws.handler.Handler) IOException(java.io.IOException) SoapVersion(org.apache.cxf.binding.soap.SoapVersion) Exchange(org.apache.cxf.message.Exchange) HandlerChainInvoker(org.apache.cxf.jaxws.handler.HandlerChainInvoker) SOAPHeader(javax.xml.soap.SOAPHeader) Header(org.apache.cxf.headers.Header) SOAPMessageContext(javax.xml.ws.handler.soap.SOAPMessageContext) MessageImpl(org.apache.cxf.message.MessageImpl) Test(org.junit.Test)

Aggregations

IMocksControl (org.easymock.IMocksControl)57 Test (org.junit.Test)34 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 Message (org.apache.cxf.message.Message)11 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 MessageImpl (org.apache.cxf.message.MessageImpl)9 QName (javax.xml.namespace.QName)7 BindingFactoryManager (org.apache.cxf.binding.BindingFactoryManager)7 Before (org.junit.Before)7 ArrayList (java.util.ArrayList)6 HashSet (java.util.HashSet)6 Set (java.util.Set)6 Exchange (org.apache.cxf.message.Exchange)6 FakeHttpServletRequest (com.google.gerrit.util.http.testutil.FakeHttpServletRequest)5 FakeHttpServletResponse (com.google.gerrit.util.http.testutil.FakeHttpServletResponse)5 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 Binding (javax.xml.ws.Binding)5 Handler (javax.xml.ws.handler.Handler)5 MessageContext (javax.xml.ws.handler.MessageContext)5