Search in sources :

Example 1 with MllpJUnitResourceException

use of org.apache.camel.test.junit.rule.mllp.MllpJUnitResourceException in project camel by apache.

the class MllpTcpServerConsumerConnectionTest method testIdleConnection.

/**
     * Simulate an Idle Client
     *
     * @throws Exception
     */
@Test
public void testIdleConnection() throws Exception {
    final int maxReceiveTimeouts = 3;
    String testMessage = "MSH|^~\\&|ADT|EPIC|JCAPS|CC|20160902123950|RISTECH|ADT^A08|00001|D|2.3|||||||" + '\r' + '\n';
    result.setExpectedCount(1);
    result.setAssertPeriod(1000);
    addTestRoute(maxReceiveTimeouts);
    mllpClient.connect();
    mllpClient.sendMessageAndWaitForAcknowledgement(testMessage);
    Thread.sleep(RECEIVE_TIMEOUT * (maxReceiveTimeouts + 1));
    try {
        mllpClient.sendMessageAndWaitForAcknowledgement(testMessage);
        fail("The MllpClientResource should have thrown an exception when writing to the reset socket");
    } catch (MllpJUnitResourceException ex) {
        Throwable cause = ex.getCause();
        assertIsInstanceOf(SocketException.class, cause);
    }
    assertMockEndpointsSatisfied(15, TimeUnit.SECONDS);
}
Also used : SocketException(java.net.SocketException) MllpJUnitResourceException(org.apache.camel.test.junit.rule.mllp.MllpJUnitResourceException) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) Test(org.junit.Test)

Example 2 with MllpJUnitResourceException

use of org.apache.camel.test.junit.rule.mllp.MllpJUnitResourceException in project camel by apache.

the class MllpTcpServerConsumerTest method testOpenMllpEnvelopeWithReset.

@Test
public void testOpenMllpEnvelopeWithReset() throws Exception {
    result.expectedMessageCount(4);
    timeout.expectedMessageCount(1);
    NotifyBuilder notify1 = new NotifyBuilder(context).whenDone(2).create();
    NotifyBuilder notify2 = new NotifyBuilder(context).whenDone(5).create();
    mllpClient.connect();
    mllpClient.setSoTimeout(10000);
    log.info("Sending TEST_MESSAGE_1");
    String acknowledgement1 = mllpClient.sendMessageAndWaitForAcknowledgement(generateMessage(1));
    log.info("Sending TEST_MESSAGE_2");
    String acknowledgement2 = mllpClient.sendMessageAndWaitForAcknowledgement(generateMessage(2));
    assertTrue("First two normal exchanges did not complete", notify1.matches(10, TimeUnit.SECONDS));
    log.info("Sending TEST_MESSAGE_3");
    mllpClient.setSendEndOfBlock(false);
    mllpClient.setSendEndOfData(false);
    // Acknowledgement won't come here
    try {
        mllpClient.sendMessageAndWaitForAcknowledgement(generateMessage(3));
    } catch (MllpJUnitResourceException resourceEx) {
        log.info("Expected exception reading response");
    }
    mllpClient.disconnect();
    Thread.sleep(1000);
    mllpClient.connect();
    log.info("Sending TEST_MESSAGE_4");
    mllpClient.setSendEndOfBlock(true);
    mllpClient.setSendEndOfData(true);
    String acknowledgement4 = mllpClient.sendMessageAndWaitForAcknowledgement(generateMessage(4));
    log.info("Sending TEST_MESSAGE_5");
    String acknowledgement5 = mllpClient.sendMessageAndWaitForAcknowledgement(generateMessage(5));
    assertTrue("Remaining exchanges did not complete", notify2.matches(10, TimeUnit.SECONDS));
    assertMockEndpointsSatisfied(10, TimeUnit.SECONDS);
    assertTrue("Should be acknowledgment for message 1", acknowledgement1.contains("MSA|AA|00001"));
    assertTrue("Should be acknowledgment for message 2", acknowledgement2.contains("MSA|AA|00002"));
    // assertTrue("Should be acknowledgment for message 3", acknowledgement3.contains("MSA|AA|00003"));
    assertTrue("Should be acknowledgment for message 4", acknowledgement4.contains("MSA|AA|00004"));
    assertTrue("Should be acknowledgment for message 5", acknowledgement5.contains("MSA|AA|00005"));
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) MllpJUnitResourceException(org.apache.camel.test.junit.rule.mllp.MllpJUnitResourceException) Test(org.junit.Test)

Example 3 with MllpJUnitResourceException

use of org.apache.camel.test.junit.rule.mllp.MllpJUnitResourceException in project camel by apache.

the class MllpTcpServerConsumerMessageValidationTest method testOpenMllpEnvelopeWithReset.

@Test
public void testOpenMllpEnvelopeWithReset() throws Exception {
    result.expectedMessageCount(4);
    result.setAssertPeriod(1000);
    timeout.expectedMessageCount(1);
    invalid.expectedMessageCount(0);
    NotifyBuilder notify1 = new NotifyBuilder(context).whenDone(2).create();
    NotifyBuilder notify2 = new NotifyBuilder(context).whenDone(5).create();
    mllpClient.connect();
    mllpClient.setSoTimeout(10000);
    log.info("Sending TEST_MESSAGE_1");
    String acknowledgement1 = mllpClient.sendMessageAndWaitForAcknowledgement(generateMessage(1));
    log.info("Sending TEST_MESSAGE_2");
    String acknowledgement2 = mllpClient.sendMessageAndWaitForAcknowledgement(generateMessage(2));
    assertTrue("First two normal exchanges did not complete", notify1.matches(10, TimeUnit.SECONDS));
    log.info("Sending TEST_MESSAGE_3");
    mllpClient.setSendEndOfBlock(false);
    mllpClient.setSendEndOfData(false);
    // Acknowledgement won't come here
    try {
        mllpClient.sendMessageAndWaitForAcknowledgement(generateMessage(3));
    } catch (MllpJUnitResourceException resourceEx) {
        log.info("Expected exception reading response");
    }
    mllpClient.disconnect();
    Thread.sleep(1000);
    mllpClient.connect();
    log.info("Sending TEST_MESSAGE_4");
    mllpClient.setSendEndOfBlock(true);
    mllpClient.setSendEndOfData(true);
    String acknowledgement4 = mllpClient.sendMessageAndWaitForAcknowledgement(generateMessage(4));
    log.info("Sending TEST_MESSAGE_5");
    String acknowledgement5 = mllpClient.sendMessageAndWaitForAcknowledgement(generateMessage(5));
    assertTrue("Remaining exchanges did not complete", notify2.matches(10, TimeUnit.SECONDS));
    assertMockEndpointsSatisfied(10, TimeUnit.SECONDS);
    assertTrue("Should be acknowledgment for message 1", acknowledgement1.contains("MSA|AA|00001"));
    assertTrue("Should be acknowledgment for message 2", acknowledgement2.contains("MSA|AA|00002"));
    // assertTrue("Should be acknowledgment for message 3", acknowledgement3.contains("MSA|AA|00003"));
    assertTrue("Should be acknowledgment for message 4", acknowledgement4.contains("MSA|AA|00004"));
    assertTrue("Should be acknowledgment for message 5", acknowledgement5.contains("MSA|AA|00005"));
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) MllpJUnitResourceException(org.apache.camel.test.junit.rule.mllp.MllpJUnitResourceException) Test(org.junit.Test)

Aggregations

MllpJUnitResourceException (org.apache.camel.test.junit.rule.mllp.MllpJUnitResourceException)3 Test (org.junit.Test)3 NotifyBuilder (org.apache.camel.builder.NotifyBuilder)2 SocketException (java.net.SocketException)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1