当前位置: 首页>>代码示例>>Java>>正文


Java MockEndpoint类代码示例

本文整理汇总了Java中org.apache.camel.component.mock.MockEndpoint的典型用法代码示例。如果您正苦于以下问题:Java MockEndpoint类的具体用法?Java MockEndpoint怎么用?Java MockEndpoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MockEndpoint类属于org.apache.camel.component.mock包,在下文中一共展示了MockEndpoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testMocksAreValid

import org.apache.camel.component.mock.MockEndpoint; //导入依赖的package包/类
@Test
@DirtiesContext
public void testMocksAreValid() throws Exception {
    result.setExpectedCount(1);

    ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
    producerTemplate.sendBody("direct:start", Util.generateMockTwitterStatus());

    MockEndpoint.assertIsSatisfied(camelContext);
    Object body = result.getExchanges().get(0).getIn().getBody();
    assertEquals(String.class, body.getClass());
    ObjectMapper mapper = new ObjectMapper();
    JsonNode outJson = mapper.readTree((String)body);
    assertEquals("Bob", outJson.get("FirstName").asText());
    assertEquals("Vila", outJson.get("LastName").asText());
    assertEquals("bobvila1982", outJson.get("Title").asText());
    assertEquals("Let's build a house!", outJson.get("Description").asText());
}
 
开发者ID:atlasmap,项目名称:camel-atlasmap,代码行数:19,代码来源:AtlasMapComponentTest.java

示例2: testMocksAreValid

import org.apache.camel.component.mock.MockEndpoint; //导入依赖的package包/类
@Test
@DirtiesContext
public void testMocksAreValid() throws Exception {
    result.setExpectedCount(1);

    ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
    producerTemplate.sendBody("direct:start", Util.generateMockTwitterStatus());

    MockEndpoint.assertIsSatisfied(camelContext);
    Object body = result.getExchanges().get(0).getIn().getBody();
    assertEquals(String.class, body.getClass());
    ObjectMapper mapper = new ObjectMapper();
    JsonNode sfJson = mapper.readTree((String)body);
    assertNotNull(sfJson.get("TwitterScreenName__c"));
    assertEquals("bobvila1982", sfJson.get("TwitterScreenName__c").asText());
}
 
开发者ID:atlasmap,项目名称:camel-atlasmap,代码行数:17,代码来源:AtlasMapComponentJavaToJsonTest.java

示例3: testSeparateNotSucceed

import org.apache.camel.component.mock.MockEndpoint; //导入依赖的package包/类
@Test
@DirtiesContext
public void testSeparateNotSucceed() throws Exception {
    result.setExpectedCount(1);

    ProducerTemplate producerTemplate = camelContext.createProducerTemplate();
    Status s = Util.generateMockTwitterStatus();
    when(s.getUser().getName()).thenReturn("BobVila");
    producerTemplate.sendBody("direct:start", s);

    MockEndpoint.assertIsSatisfied(camelContext);
    Object body = result.getExchanges().get(0).getIn().getBody();
    assertEquals(String.class, body.getClass());
    ObjectMapper mapper = new ObjectMapper();
    JsonNode outJson = mapper.readTree((String)body);
    assertEquals("BobVila", outJson.get("FirstName").asText());
    assertNull(outJson.get("LastName"));
    assertEquals("bobvila1982", outJson.get("Title").asText());
    assertEquals("Let's build a house!", outJson.get("Description").asText());
}
 
开发者ID:atlasmap,项目名称:camel-atlasmap,代码行数:21,代码来源:AtlasMapComponentTest.java

示例4: testStep

import org.apache.camel.component.mock.MockEndpoint; //导入依赖的package包/类
@Test
public void testStep() throws Exception {
    List<String> allMessages = new ArrayList<>(matchedJames);
    allMessages.addAll(matchedJimmi);
    allMessages.addAll(otherwiseMessages);

    matchedEndpoint.expectedBodiesReceived(matchedJames);
    matchedJimmiEndpoint.expectedBodiesReceived(matchedJimmi);
    otherwiseEndpoint.expectedBodiesReceived(otherwiseMessages);
    allMessagesEndpoint.expectedBodiesReceived(allMessages);

    for (Object body : allMessages) {
        template.sendBody(START_URI, body);
    }

    MockEndpoint[] mockEndpoints = {
            matchedEndpoint, matchedJimmiEndpoint, otherwiseEndpoint, allMessagesEndpoint
    };
    MockEndpoint.assertIsSatisfied(mockEndpoints);
    logMessagesReceived(mockEndpoints);
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:22,代码来源:ChoiceTest.java

示例5: testStep

import org.apache.camel.component.mock.MockEndpoint; //导入依赖的package包/类
@Test
public void testStep() throws Exception {
    List<String> allMessages = new ArrayList<>(matchingMessages);
    allMessages.addAll(notMatchingMessages);

    matchedEndpoint.expectedBodiesReceived(matchingMessages);
    allMessagesEndpoint.expectedBodiesReceived(allMessages);

    for (Object body : allMessages) {
        template.sendBody(START_URI, body);
    }

    MockEndpoint[] mockEndpoints = {
            matchedEndpoint, allMessagesEndpoint
    };
    MockEndpoint.assertIsSatisfied(mockEndpoints);
    logMessagesReceived(mockEndpoints);
}
 
开发者ID:syndesisio,项目名称:syndesis-integration-runtime,代码行数:19,代码来源:FilterTest.java

示例6: testGrabbingListOfEntries

import org.apache.camel.component.mock.MockEndpoint; //导入依赖的package包/类
@Test
public void testGrabbingListOfEntries() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    // as the default delay option is one hour long, we expect exactly one message exchange
    mock.expectedMessageCount(1);

    // give the route a bit time to start and fetch the weather info
    assertMockEndpointsSatisfied(20, TimeUnit.SECONDS);

    Exchange exchange = mock.getExchanges().get(0);
    assertNotNull(exchange);
    Message in = exchange.getIn();
    assertNotNull(in);
    String weather = assertIsInstanceOf(String.class, in.getBody());

    checkWeatherContent(weather);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:BaseWeatherConsumerTest.java

示例7: testSimpleBody

import org.apache.camel.component.mock.MockEndpoint; //导入依赖的package包/类
@Test
public void testSimpleBody() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);

    Project pojo = new Project();
    pojo.setLicense("XXX");

    template.sendBody("direct:simple", pojo);

    mock.assertIsSatisfied();

    // the result is a List
    List<?> received = assertIsInstanceOf(List.class, mock.getReceivedExchanges().get(0).getIn().getBody());

    // and each row in the list is a Map
    Map<?, ?> row = assertIsInstanceOf(Map.class, received.get(0));

    // and we should be able the get the project from the map that should be Linux
    assertEquals("Linux", row.get("PROJECT"));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:ElSqlProducerBodySimpleTest.java

示例8: testNonJmsDeliveryModePreserveQos

import org.apache.camel.component.mock.MockEndpoint; //导入依赖的package包/类
@Test
public void testNonJmsDeliveryModePreserveQos() throws InterruptedException {
    MockEndpoint mock = getMockEndpoint("mock:bar");
    mock.expectedBodiesReceived("Beer is good...");

    // in this test, we can only pass if we are "preserving" existing deliveryMode.
    // this means camel expects to have an existing QoS set as a header, or it will pick
    // from the JMS message created by the message creator
    // otherwise, "preserveMessageQos==true" does not allow us to explicity set the deliveryMode
    // on the message
    mock.message(0).header("JMSDeliveryMode").isEqualTo(1);

    template.sendBodyAndHeader("direct:preserveQosNonJmsDeliveryMode", "Beer is good...", JmsConstants.JMS_DELIVERY_MODE, 3);

    assertMockEndpointsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:JmsRouteDeliveryModePreserveQoSTest.java

示例9: testBurstySampling

import org.apache.camel.component.mock.MockEndpoint; //导入依赖的package包/类
public void testBurstySampling() throws Exception {
    NotifyBuilder notify = new NotifyBuilder(context).whenDone(5).create();

    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(2);
    mock.setResultWaitTime(3000);

    List<Exchange> sentExchanges = new ArrayList<Exchange>();

    // send a burst of 5 exchanges, expecting only one to get through
    sendExchangesThroughDroppingThrottler(sentExchanges, 5);
    // sleep through a complete period
    Thread.sleep(1100);
    // send another 5 now
    sendExchangesThroughDroppingThrottler(sentExchanges, 5);

    notify.matchesMockWaitTime();
    mock.assertIsSatisfied();

    validateDroppedExchanges(sentExchanges, mock.getReceivedCounter());
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:SamplingThrottlerTest.java

示例10: doSendMessages

import org.apache.camel.component.mock.MockEndpoint; //导入依赖的package包/类
private void doSendMessages(int files, int poolSize) throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:aggregated");
    mock.expectedMessageCount(2);
    mock.setResultWaitTime(30 * 1000L);

    ExecutorService executor = Executors.newFixedThreadPool(poolSize);
    for (int i = 0; i < files; i++) {
        final int index = i;
        executor.submit(new Callable<Object>() {
            public Object call() throws Exception {
                String id = index % 2 == 0 ? "A" : "B";
                template.sendBodyAndHeader("direct:start", index, "id", id);
                // simulate a little delay
                Thread.sleep(3);
                return null;
            }
        });
    }

    assertMockEndpointsSatisfied();
    executor.shutdownNow();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:LevelDBAggregateConcurrentDifferentGroupsTest.java

示例11: testJmsPollingConsumerLowTimeout

import org.apache.camel.component.mock.MockEndpoint; //导入依赖的package包/类
@Test
public void testJmsPollingConsumerLowTimeout() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello Claus");

    // use another thread for polling consumer to demonstrate that we can wait before
    // the message is sent to the queue
    Executors.newSingleThreadExecutor().execute(new Runnable() {
        public void run() {
            String body = consumer.receiveBody("activemq:queue.start", 100, String.class);
            assertNull("Should be null", body);

            template.sendBody("activemq:queue.foo", "Hello Claus");
        }
    });

    // wait a little to demonstrate we can start poll before we have a msg on the queue
    Thread.sleep(500);

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

    assertMockEndpointsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:JmsPollingConsumerTest.java

示例12: testCached

import org.apache.camel.component.mock.MockEndpoint; //导入依赖的package包/类
@Test
public void testCached() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello London");

    template.sendBodyAndHeader("direct:b", "Body", "name", "London");
    mock.assertIsSatisfied();

    // now change content in the file in the classpath and try again
    template.sendBodyAndHeader("file://target/test-classes/org/apache/camel/component/freemarker?fileExist=Override", "Bye ${headers.name}", Exchange.FILE_NAME, "hello.ftl");

    mock.reset();
    // we must expected the original filecontent as the cache is enabled, so its Hello and not Bye
    mock.expectedBodiesReceived("Hello Paris");

    template.sendBodyAndHeader("direct:b", "Body", "name", "Paris");
    mock.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:19,代码来源:FreemarkerContentCacheTest.java

示例13: testRequestReplyCorrelationByMessageId

import org.apache.camel.component.mock.MockEndpoint; //导入依赖的package包/类
/**
 * When the setting useMessageIdAsCorrelationid is true and
 * a correlation id is set on the message then we expect the reply
 * to contain the messageId of the sent message. Here we test only that
 * it is not the correlation id given as the messageId is not know
 * beforehand.
 */
@Test
public void testRequestReplyCorrelationByMessageId() throws Exception {
    MockEndpoint result = getMockEndpoint("mock:result");
    result.expectedMessageCount(1);

    Exchange out = template.send("jms2:queue:hello2", ExchangePattern.InOut, new Processor() {
        public void process(Exchange exchange) throws Exception {
            Message in = exchange.getIn();
            in.setBody("Hello World");
            in.setHeader("JMSCorrelationID", "a");
        }
    });

    result.assertIsSatisfied();

    assertNotNull(out);

    assertEquals(REPLY_BODY, out.getOut().getBody(String.class));
    assertEquals("a", out.getOut().getHeader("JMSCorrelationID"));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:28,代码来源:JmsRequestReplyCorrelationTest.java

示例14: testPreMoveSameFileTwice

import org.apache.camel.component.mock.MockEndpoint; //导入依赖的package包/类
public void testPreMoveSameFileTwice() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");

    template.sendBodyAndHeader("file://target/premove", "Hello World", Exchange.FILE_NAME, "hello.txt");

    assertMockEndpointsSatisfied();
    oneExchangeDone.matchesMockWaitTime();

    // reset and drop the same file again
    mock.reset();
    mock.expectedBodiesReceived("Hello Again World");

    template.sendBodyAndHeader("file://target/premove", "Hello Again World", Exchange.FILE_NAME, "hello.txt");
    assertMockEndpointsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:FileConsumerPreMoveTest.java

示例15: testSendA01

import org.apache.camel.component.mock.MockEndpoint; //导入依赖的package包/类
@Test
public void testSendA01() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:a01");
    mock.expectedMessageCount(1);
    mock.message(0).body().isInstanceOf(Message.class);

    String line1 = "MSH|^~\\&|MYSENDER|MYSENDERAPP|MYCLIENT|MYCLIENTAPP|200612211200||ADT^A01|123|P|2.4";
    String line2 = "PID|||123456||Doe^John";

    StringBuilder in = new StringBuilder();
    in.append(line1);
    in.append("\r");
    in.append(line2);

    String out = template.requestBody("mina2:tcp://127.0.0.1:" + getPort() + "?sync=true&codec=#hl7codec", in.toString(), String.class);
    String[] lines = out.split("\r");
    assertEquals("MSH|^~\\&|MYSENDER||||200701011539||ADT^A01||||123", lines[0]);
    assertEquals("PID|||123||Doe^John", lines[1]);

    assertMockEndpointsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:HL7RouteTest.java


注:本文中的org.apache.camel.component.mock.MockEndpoint类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。