Package org.switchyard.test

Examples of org.switchyard.test.MockHandler


    @Test
    public void shouldRetrieveGreetings() throws Exception {

        _testKit.removeService("PrintService");
        final MockHandler printService = _testKit.registerInOnlyService("PrintService");
        Thread.sleep(10001);
       
        final LinkedBlockingQueue<Exchange> receivedMessages = printService.getMessages();
        for (Exchange e : receivedMessages) {
            FOMEntry entry = (FOMEntry) e.getMessage().getContent();
            Assert.assertNotNull(entry);   
            Assert.assertTrue(entry.getTitle().equals(TITLE));
            Assert.assertTrue(entry.getId().toString().equals(ID));
View Full Code Here


    @Test
    public void receiveFile() throws Exception {
        final String payload = "dummy payload";
        // replace existing implementation for testing purposes
        _testKit.removeService("GreetingService");
        final MockHandler greetingService = _testKit.registerInOnlyService("GreetingService");

        createFile(payload, FILE_NAME);
        // Allow for the JMS Message to be processed.
        Thread.sleep(3000);

        final LinkedBlockingQueue<Exchange> recievedMessages = greetingService.getMessages();
        assertThat(recievedMessages, is(notNullValue()));
        final Exchange recievedExchange = recievedMessages.iterator().next();
        assertThat(recievedExchange.getMessage().getContent(String.class), is(equalTo(payload)));
    }
View Full Code Here

    @Test
    public void shouldExecuteService() throws Exception {
        // replace existing implementation for testing purposes
        _testKit.removeService("GreetingService");
        final MockHandler greetingService = _testKit.registerInOnlyService("GreetingService");

        // Number of executions can vary, depends on moment when sleep will be executed
        // eg. 10:50:999, 10:51:003, 10:52:000 - we'll get three executions
        // or  10:50:000, 10:51:001 - we'll get two executions
        // however we never should get more than three triggers and less than two
        Thread.sleep(1001);

        final LinkedBlockingQueue<Exchange> recievedMessages = greetingService.getMessages();
        assertThat(recievedMessages, is(notNullValue()));
        assertThat(recievedMessages.size(), is(greaterThanOrEqualTo(1)));
    }
View Full Code Here

        offer.setCar(car);
        offer.setApplication(app);
        offer.setAmount(450.00);

        // configure our proxy for the service reference
        MockHandler creditService = testKit.replaceService("CreditCheck");
        Application reply = new Application();
        reply.setApproved(true);
        creditService.replyWithOut(reply);

        // Invoke the service
        Deal deal = service.operation("offer").sendInOut(offer)
            .getContent(Deal.class);
View Full Code Here

    private SwitchYardTestKit _testKit;

    @Test
    public void shouldRetrieveGreetings() throws Exception {
        _testKit.removeService("GreetingService");
        MockHandler handler = new MockHandler();

        ServiceInterface metadata = JavaService.fromClass(GreetingService.class);
        _testKit.getServiceDomain().registerService(_testKit.createQName("GreetingService"), metadata, handler);
        PreparedStatement statement = connection.prepareStatement("INSERT INTO greetings (receiver, sender) VALUES (?,?)");
        statement.setString(1, RECEIVER);
View Full Code Here

    @Test
    public void sendTextMessageThroughTcp() throws Exception {
        // replace existing implementation for testing purposes
        _testKit.removeService("SecuredGreetingService");
        final MockHandler greetingService = _testKit.registerInOnlyService("SecuredGreetingService");
        greetingService.forwardInToOut();

        KeyStore keystore = KeyStore.getInstance("JKS");
        keystore.load(new FileInputStream("users.jks"), "changeit".toCharArray());

        TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
        tmf.init(keystore);

        SSLContext context = SSLContext.getInstance("TLS");
        KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        keyManagerFactory.init(keystore, "changeit".toCharArray());

        context.init(keyManagerFactory.getKeyManagers(), tmf.getTrustManagers(), null);

        SSLSocketFactory sf = context.getSocketFactory();

        Socket clientSocket = sf.createSocket("localhost", 3939);
        DataOutputStream outputStream = new DataOutputStream(clientSocket.getOutputStream());
        // lets write payload directly as bytes to avoid encoding mismatches
        outputStream.write(PAYLOAD.getBytes());
        outputStream.flush();

        // sleep a bit to receive message on camel side
        Thread.sleep(50);
        clientSocket.close();

        greetingService.waitForOKMessage();
        final LinkedBlockingQueue<Exchange> recievedMessages = greetingService.getMessages();
        assertThat(recievedMessages, is(notNullValue()));
        final Exchange recievedExchange = recievedMessages.iterator().next();
        assertThat(PAYLOAD, is(equalTo(recievedExchange.getMessage().getContent(String.class))));
    }
View Full Code Here

    @Test
    public void sendTextMessageThroughUdp() throws Exception {
        // replace existing implementation for testing purposes
        _testKit.removeService("DefaultGreetingService");
        final MockHandler greetingService = _testKit.registerInOnlyService("DefaultGreetingService");

        MulticastSocket clientSocket = new MulticastSocket();
        InetAddress group = InetAddress.getByName("localhost");
        byte[] datagramBody = PAYLOAD.getBytes(Charset.defaultCharset());
        DatagramPacket packet = new DatagramPacket(datagramBody, 0, datagramBody.length, group, 3940);
        clientSocket.send(packet);

        // sleep a bit to receive message on camel side
        clientSocket.close();

        greetingService.waitForOKMessage();
        final LinkedBlockingQueue<Exchange> recievedMessages = greetingService.getMessages();
        assertThat(recievedMessages, is(notNullValue()));
        final Exchange recievedExchange = recievedMessages.iterator().next();
        String content = recievedExchange.getMessage().getContent(String.class);
        // the receive content is trimmed because extra bytes appended to frame by receiver
        assertThat(PAYLOAD, is(equalTo(content.trim())));
View Full Code Here

    @Test
    public void sendTextMessageToJMSQueue() throws Exception {
        final String payload = "dummy payload";
        // replace existing implementation for testing purposes
        _testKit.removeService("GreetingService");
        final MockHandler greetingService = _testKit.registerInOnlyService("GreetingService");

        sendTextToQueue(payload, QUEUE_NAME);
        // Allow for the JMS Message to be processed.
        Thread.sleep(3000);

        final LinkedBlockingQueue<Exchange> recievedMessages = greetingService.getMessages();
        assertThat(recievedMessages, is(notNullValue()));
        final Exchange recievedExchange = recievedMessages.iterator().next();
        assertThat(recievedExchange.getMessage().getContent(String.class), is(equalTo(payload)));
    }
View Full Code Here

    @Test
    public void sendTextMessageToAmqpQueue() throws Exception {
        //replace existing implementation for testing purposes
        _testKit.removeService("GreetingService");
        final MockHandler greetingService = _testKit.registerInOnlyService("GreetingService");

        sentTextToQueue(PAYLOAD);
        greetingService.waitForOKMessage();

        final LinkedBlockingQueue<Exchange> receivedMessages = greetingService.getMessages();
        assertThat(receivedMessages, is(notNullValue()));
        final Exchange receivedExchange = receivedMessages.iterator().next();
        assertThat(receivedExchange.getMessage().getContent(String.class), is(equalTo(PAYLOAD)));
    }
View Full Code Here

    @Test
    public void shouldRetrieveGreetings() throws Exception {

        _testKit.removeService("PrintService");
        final MockHandler printService = _testKit.registerInOnlyService("PrintService");
        Thread.sleep(10001);
       
        final LinkedBlockingQueue<Exchange> receivedMessages = printService.getMessages();
        for (Exchange e : receivedMessages) {
            SyndFeed feed = (SyndFeed) e.getMessage().getContent();
            @SuppressWarnings("unchecked")
            List<SyndEntry> entries = feed.getEntries();
            Assert.assertEquals(feed.getEntries().size(), 1);
View Full Code Here

TOP

Related Classes of org.switchyard.test.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.