Package org.switchyard

Examples of org.switchyard.MockHandler


    @Test
    public void testNoNPEOnInOnlyFault() throws Exception {

        QName serviceName = new QName("testNoNPEOnNoConsumer");
        MockHandler provider = new MockHandler() {
            @Override
            public void handleMessage(Exchange exchange) throws HandlerException {
                throw new HandlerException("explode");
            }
        };
View Full Code Here


    @Test
    public void testFaultWithNoHandler() throws Exception {

        final QName serviceName = new QName("testFaultWithNoHandler");
        // Provide the service
        MockHandler provider = new MockHandler() {
            @Override
            public void handleMessage(Exchange exchange) throws HandlerException {
                throw new HandlerException("Fault With No Handler!");
            }
        };
View Full Code Here

   
    @Test
    public void testFaultTransformSequence() throws Exception {
        final QName serviceName = new QName("testFaultTransformSequence");
        // Provide the service
        MockHandler provider = new MockHandler() {
            @Override
            public void handleMessage(Exchange exchange) throws HandlerException {
                Message fault = exchange.createMessage();
                fault.setContent(new Exception("testFaultTransformSequence"));
                exchange.sendFault(fault);
            }
        };
        InOutOperation providerContract = new InOutOperation("faultOp",
                JavaTypes.toMessageType(String.class),   // input
                JavaTypes.toMessageType(String.class),   // output
                JavaTypes.toMessageType(Exception.class))// fault
        InOutOperation consumerContract = new InOutOperation("faultOp",
                JavaTypes.toMessageType(String.class),   // input
                JavaTypes.toMessageType(String.class),   // output
                JavaTypes.toMessageType(String.class))// fault
        _domain.registerService(serviceName, new InOutService(providerContract), provider);
        _domain.getTransformerRegistry().addTransformer(new ExceptionToStringTransformer());
        ServiceReference service = _domain.registerServiceReference(serviceName, new InOutService(consumerContract));

        // Consume the service
        Exchange exchange = service.createExchange(new MockHandler());
        exchange.send(exchange.createMessage());

        // Make sure the exchange is in fault status
        Assert.assertEquals(String.class, exchange.getMessage().getContent().getClass());
        Assert.assertEquals(exchange.getMessage().getContent(), "testFaultTransformSequence");
View Full Code Here

            public void handleFault(Exchange exchange) {
                throw new RuntimeException("oops!");
            }
        };
        // This goes second and should still be called despite the bad handler
        MockHandler goodHandler = new MockHandler();
       
        _chain.addFirst("first", badHandler);
        _chain.addLast("second", goodHandler);

        MockDomain domain = new MockDomain();
        ServiceReference reference = domain.createInOnlyService(new QName("bar"));
        Dispatcher dispatch = domain.getBus().createDispatcher(reference);
        Exchange ex = new ExchangeImpl(domain, dispatch).consumer(reference, new InOnlyOperation("foo"));
        _chain.handleFault(ex);
        Assert.assertNotNull(goodHandler.waitForFaultMessage());
    }
View Full Code Here

        Assert.assertNotNull(goodHandler.waitForFaultMessage());
    }
   
    @Test
    public void testReplace() {
        MockHandler m1 = new MockHandler();
        MockHandler m2 = new MockHandler();
        MockHandler m3 = new MockHandler();
        MockHandler m4 = new MockHandler();
       
        _chain.addFirst("1", m1);

        Assert.assertFalse(_chain.replace("5", m2));
        Assert.assertTrue(_chain.replace("1", m2));
View Full Code Here

    }
   
    @Test
    public void testUnregister() {
        Service service = _domain.registerService(new QName("TestService"),
                new InOnlyService(), new MockHandler());
        // test that it was added to the registry
        Assert.assertEquals(1, _domain.getServiceRegistry().getServices().size());
        service.unregister();
        // confirm that it was removed
        Assert.assertEquals(0, _domain.getServiceRegistry().getServices().size());
View Full Code Here

    private DomainImpl _domain;
   
    @Before
    public void setUp() throws Exception {
        _domain = new DomainImpl(new QName("test"));
        _domain.registerService(IN_ONLY_SERVICE, new InOnlyService(), new MockHandler());
        _domain.registerService(IN_OUT_SERVICE, new InOutService(), new MockHandler());
        _inOnlyReference = _domain.registerServiceReference(IN_ONLY_SERVICE, new InOnlyService());
        _inOutReference = _domain.registerServiceReference(IN_OUT_SERVICE, new InOutService());
    }
View Full Code Here

    @Test
    public void testCreateExchange() {
        Exchange inOnly = _inOnlyReference.createExchange();
        inOnly.consumer(null, new InOnlyOperation("foo"));
        Assert.assertEquals(ExchangePattern.IN_ONLY, inOnly.getContract().getConsumerOperation().getExchangePattern());
        Exchange inOut = _inOutReference.createExchange(new MockHandler());
        inOut.consumer(null, new InOutOperation("foo"));
        Assert.assertEquals(ExchangePattern.IN_OUT, inOut.getContract().getConsumerOperation().getExchangePattern());
    }
View Full Code Here

    }
   
    @Test
    public void testRegisterServiceWithoutInterface() {
        Service service = _domain.registerService(
                new QName("no-interface"), null, new MockHandler());
        // default interface should be used, which has one operation - process()
        Assert.assertNotNull(service.getInterface());
        Assert.assertTrue(service.getInterface().getOperations().size() == 1);
        Assert.assertNotNull(service.getInterface().getOperation(
                ServiceInterface.DEFAULT_OPERATION));
View Full Code Here

    }
   
    @Test
    public void testRegisterServiceWithInterface() {
        Service service = _domain.registerService(new QName("my-interface"),
                JavaService.fromClass(MyInterface.class), new MockHandler());
        // default interface should be used, which has one operation - process()
        Assert.assertNotNull(service.getInterface());
        Assert.assertTrue(service.getInterface().getOperations().size() == 1);
        Assert.assertNotNull(service.getInterface().getOperation("myOperation"));
    }
View Full Code Here

TOP

Related Classes of org.switchyard.MockHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.