Java 类org.apache.camel.spi.BrowsableEndpoint 实例源码

项目:camelinaction2    文件:OrderTest.java   
@Test
public void testOrderClientInvalid() throws Exception {
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();

    Calendar cal = Calendar.getInstance(Locale.US);
    cal.set(Calendar.YEAR, 2017);
    cal.set(Calendar.MONTH, Calendar.APRIL);
    cal.set(Calendar.DAY_OF_MONTH, 20);
    cal.set(Calendar.HOUR_OF_DAY, 7);
    cal.set(Calendar.MINUTE, 47);
    cal.set(Calendar.SECOND, 58);
    Date date = cal.getTime();

    OrderClient client = new OrderClient("tcp://localhost:61616");
    // when using customer id 999 we force an invalid order
    client.sendOrder(999, date, "5555", "2222");

    boolean matches = notify.matches(5, TimeUnit.SECONDS);
    assertTrue(matches);

    // should be one message in confirm queue
    BrowsableEndpoint be = context.getEndpoint("activemq:queue:invalid", BrowsableEndpoint.class);
    List<Exchange> list = be.getExchanges();
    assertEquals(1, list.size());
    assertEquals("999,2017-04-20T07:47:58,5555,2222", list.get(0).getIn().getBody(String.class));
}
项目:camelinaction    文件:OrderTest.java   
@Test
public void testOrderClientInvalid() throws Exception {
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();

    Calendar cal = Calendar.getInstance(Locale.US);
    cal.set(Calendar.YEAR, 2010);
    cal.set(Calendar.MONTH, Calendar.APRIL);
    cal.set(Calendar.DAY_OF_MONTH, 20);
    cal.set(Calendar.HOUR_OF_DAY, 7);
    cal.set(Calendar.MINUTE, 47);
    cal.set(Calendar.SECOND, 58);
    Date date = cal.getTime();

    OrderClient client = new OrderClient("tcp://localhost:61616");
    // when using customer id 999 we force an invalid order
    client.sendOrder(999, date, "5555", "2222");

    boolean matches = notify.matches(5, TimeUnit.SECONDS);
    assertTrue(matches);

    // should be one message in confirm queue
    BrowsableEndpoint be = context.getEndpoint("activemq:queue:invalid", BrowsableEndpoint.class);
    List<Exchange> list = be.getExchanges();
    assertEquals(1, list.size());
    assertEquals("999,2010-04-20T07:47:58,5555,2222", list.get(0).getIn().getBody(String.class));
}
项目:Camel    文件:EndpointHelper.java   
/**
 * Browses the {@link BrowsableEndpoint} within the given range, and returns the messages as a XML payload.
 *
 * @param endpoint    the browsable endpoint
 * @param fromIndex   from range
 * @param toIndex     to range
 * @param includeBody whether to include the message body in the XML payload
 * @return XML payload with the messages
 * @throws IllegalArgumentException if the from and to range is invalid
 * @see MessageHelper#dumpAsXml(org.apache.camel.Message)
 */
public static String browseRangeMessagesAsXml(BrowsableEndpoint endpoint, Integer fromIndex, Integer toIndex, Boolean includeBody) {
    if (fromIndex == null) {
        fromIndex = 0;
    }
    if (toIndex == null) {
        toIndex = Integer.MAX_VALUE;
    }
    if (fromIndex > toIndex) {
        throw new IllegalArgumentException("From index cannot be larger than to index, was: " + fromIndex + " > " + toIndex);
    }

    List<Exchange> exchanges = endpoint.getExchanges();
    if (exchanges.size() == 0) {
        return null;
    }

    StringBuilder sb = new StringBuilder();
    sb.append("<messages>");
    for (int i = fromIndex; i < exchanges.size() && i <= toIndex; i++) {
        Exchange exchange = exchanges.get(i);
        Message msg = exchange.hasOut() ? exchange.getOut() : exchange.getIn();
        String xml = MessageHelper.dumpAsXml(msg, includeBody);
        sb.append("\n").append(xml);
    }
    sb.append("\n</messages>");
    return sb.toString();
}
项目:Camel    文件:FileBrowsableEndpointTest.java   
public void testBrowsableNoFiles() throws Exception {
    BrowsableEndpoint browse = context.getEndpoint("file:target/browse", BrowsableEndpoint.class);
    assertNotNull(browse);

    List<Exchange> list = browse.getExchanges();
    assertNotNull(list);
    assertEquals(0, list.size());
}
项目:Camel    文件:BrowseRouteTest.java   
public void testBrowseRoute() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World", "Bye World");

    template.sendBody("direct:start", "Hello World");
    template.sendBody("direct:start", "Bye World");

    assertMockEndpointsSatisfied();

    BrowsableEndpoint list = context.getEndpoint("browse:foo", BrowsableEndpoint.class);

    mock.getExchanges().get(0).equals(list.getExchanges().get(0));
    mock.getExchanges().get(1).equals(list.getExchanges().get(1));
}
项目:Camel    文件:FtpBrowsableEndpointTest.java   
@Test
public void testBrowsableNoFiles() throws Exception {
    // make sure starting directory exists
    createDirectory(FTP_ROOT_DIR + "/browse");

    BrowsableEndpoint browse = context.getEndpoint(getFtpUrl(), BrowsableEndpoint.class);
    assertNotNull(browse);

    List<Exchange> list = browse.getExchanges();
    assertNotNull(list);
    assertEquals(0, list.size());
}
项目:camelinaction2    文件:OrderTest.java   
@Test
public void testOrderClientValid() throws Exception {
    // notify when one message is done
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();

    // setup order information
    Calendar cal = Calendar.getInstance(Locale.US);
    cal.set(Calendar.YEAR, 2017);
    cal.set(Calendar.MONTH, Calendar.APRIL);
    cal.set(Calendar.DAY_OF_MONTH, 20);
    cal.set(Calendar.HOUR_OF_DAY, 7);
    cal.set(Calendar.MINUTE, 47);
    cal.set(Calendar.SECOND, 58);
    Date date = cal.getTime();

    // send an order using the client
    OrderClient client = new OrderClient("tcp://localhost:61616");
    client.sendOrder(123, date, "4444", "5555");

    // use the notifier to wait for Camel to process the message
    // wait at most 5 seconds to avoid blocking forever if something goes wrong
    boolean matches = notify.matches(5, TimeUnit.SECONDS);
    // true means the notifier condition matched (= 1 message is done)
    assertTrue(matches);

    // should be one message in confirm queue
    BrowsableEndpoint be = context.getEndpoint("activemq:queue:confirm", BrowsableEndpoint.class);
    List<Exchange> list = be.getExchanges();
    assertEquals(1, list.size());
    assertEquals("OK,123,2017-04-20T07:47:58,4444,5555", list.get(0).getIn().getBody(String.class));
}
项目:camelinaction    文件:OrderTest.java   
@Test
public void testOrderClientValid() throws Exception {
    // notify when one message is done
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(1).create();

    // setup order information
    Calendar cal = Calendar.getInstance(Locale.US);
    cal.set(Calendar.YEAR, 2010);
    cal.set(Calendar.MONTH, Calendar.APRIL);
    cal.set(Calendar.DAY_OF_MONTH, 20);
    cal.set(Calendar.HOUR_OF_DAY, 7);
    cal.set(Calendar.MINUTE, 47);
    cal.set(Calendar.SECOND, 58);
    Date date = cal.getTime();

    // send an order using the client
    OrderClient client = new OrderClient("tcp://localhost:61616");
    client.sendOrder(123, date, "4444", "5555");

    // use the notifier to wait for Camel to process the message
    // wait at most 5 seconds to avoid blocking forever if something goes wrong
    boolean matches = notify.matches(5, TimeUnit.SECONDS);
    // true means the notifier condition matched (= 1 message is done)
    assertTrue(matches);

    // should be one message in confirm queue
    BrowsableEndpoint be = context.getEndpoint("activemq:queue:confirm", BrowsableEndpoint.class);
    List<Exchange> list = be.getExchanges();
    assertEquals(1, list.size());
    assertEquals("OK,123,2010-04-20T07:47:58,4444,5555", list.get(0).getIn().getBody(String.class));
}
项目:Camel    文件:ManagedBrowsableEndpoint.java   
public ManagedBrowsableEndpoint(BrowsableEndpoint endpoint) {
    super(endpoint);
}
项目:Camel    文件:ManagedBrowsableEndpoint.java   
@Override
public BrowsableEndpoint getEndpoint() {
    return (BrowsableEndpoint) super.getEndpoint();
}
项目:Camel    文件:ManagedBrowsableEndpoint.java   
@Override
public BrowsableEndpoint getInstance() {
    return getEndpoint();
}
项目:metasfresh    文件:AbstractEDIRouteTest.java   
/**
 *
 * @param ediDataEndPoint the EDI-receiving endpoint to verify. Verification is only done if this endpoint is <code>instanceof</code> {@link MockEndpoint}.
 * @param xmlInoutResourceName name of the XML resource that is supposed to be transformed to EDI.
 * @param ediExpectedOutputResourceName
 * @param feedbackResourceName
 * @throws Exception
 */
protected void executeXMLToEDIExportRouteExchange(
        final BrowsableEndpoint ediDataEndPoint,
        final String xmlInoutResourceName,
        final String ediExpectedOutputResourceName,
        final String feedbackResourceName) throws Exception
{
    outJMSADEP.setExpectedMessageCount(1);

    // Send XML message
    // Note: we send a string, because sending a ressource stream failed
    // with an InOutException (stream closed) while trying to unmarshal the XML.
    final String xmlInput = AbstractEDITest.getResourceAsString(xmlInoutResourceName);
    final Exchange ex = new DefaultExchange(context);
    ex.getIn().setBody(xmlInput);
    inputXMLInvoice.send(ex);

    //
    // Test Feedback response
    final Exchange exchangeReceived = outJMSADEP.assertExchangeReceived(0);
    outJMSADEP.assertIsSatisfied();

    final String feedbackExpected = AbstractEDITest.getResourceAsString(feedbackResourceName);
    final String feedbackActual = exchangeReceived.getIn().getBody(String.class);
    Assert.assertEquals("Invalid XML feedback", Util.fixLineEnding(feedbackExpected), Util.fixLineEnding(feedbackActual));

    //
    // Test EDI Result
    final String expectedEDIOutput = AbstractEDITest.getResourceAsString(ediExpectedOutputResourceName);

    if (ediDataEndPoint instanceof MockEndpoint)
    {
        // we have this if to make it easier for a dev to experiment with endpoint types other than MockEndPoint
        final MockEndpoint mockedFILE = (MockEndpoint)ediDataEndPoint;

        Assert.assertEquals("EP " + mockedFILE + " did not receive an exchange!", 1, mockedFILE.getReceivedExchanges().size());
        final String actualResult = mockedFILE.getReceivedExchanges().get(0).getIn().getBody(String.class);
        Assert.assertNotNull(actualResult);
        Assert.assertEquals("Invalid EDI result", Util.fixLineEnding(expectedEDIOutput), Util.fixLineEnding(actualResult));
    }
}