@Test
 @Ignore
 public void shouldNotThrowClassNotFoundException() throws InterruptedException {
   MockEndpoint mockEndpoint = camelContext.getEndpoint("mock:test", MockEndpoint.class);
   mockEndpoint.expectedMinimumMessageCount(5);
   mockEndpoint.assertIsSatisfied();
 }
Esempio n. 2
0
  @Test
  public void testSendAccountBean() throws Exception {
    MockEndpoint endpoint = getMockEndpoint("mock:results");
    endpoint.expectedMinimumMessageCount(1);

    Account account = new Account();
    account.setId(123);
    account.setFirstName("James");
    account.setLastName("Strachan");
    account.setEmailAddress("*****@*****.**");

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

    assertMockEndpointsSatisfied();

    // now lets poll that the account has been inserted
    List body =
        template.requestBody(
            "ibatis:selectAllAccounts?statementType=QueryForList", null, List.class);

    assertEquals("Wrong size: " + body, 1, body.size());
    Account actual = assertIsInstanceOf(Account.class, body.get(0));

    assertEquals("Account.getFirstName()", "James", actual.getFirstName());
    assertEquals("Account.getLastName()", "Strachan", actual.getLastName());

    log.info("Found: " + actual);
  }
  public void testFromWithNoOutputs() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(2);

    assertMockEndpointsSatisfied();

    assertTrue("Counter should be 2 or higher", counter >= 2);
  }
  public void testTimerUsingStopWatch() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(2);

    StopWatch watch = new StopWatch();
    assertMockEndpointsSatisfied();
    long interval = watch.stop();

    LOG.trace("Should take approx 2000 milliseconds, was: {}", interval);
    assertTrue("Should take approx 2000 milliseconds, was: " + interval, interval >= 1700);
  }
  public void testDropInNewFiles() throws Exception {
    // do not test on windows
    if (isPlatform("windows")) {
      return;
    }

    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(250);

    assertMockEndpointsSatisfied();
  }
  @Test
  public void testCreate() throws Exception {

    Assert.assertNotNull(directStart);
    Assert.assertNotNull(mockResult);

    mockResult.expectedMinimumMessageCount(1);

    directStart.sendBody("start test");

    assertMockEndpointsSatisfied();
  }
  @Test
  public void testShutdownCompleteCurrentTaskOnly() throws Exception {
    MockEndpoint bar = getMockEndpoint("mock:bar");
    bar.expectedMinimumMessageCount(1);
    bar.setResultWaitTime(3000);

    assertMockEndpointsSatisfied();

    // shutdown during processing
    context.stop();

    // should NOT route all 8
    assertTrue(
        "Should NOT complete all messages, was: " + bar.getReceivedCounter(),
        bar.getReceivedCounter() < 8);
  }
  @Test
  public void testDiscovery() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(1);
    mock.setResultWaitTime(5000);
    // force shutdown after 5 seconds as otherwise the bean will keep generating a new input
    context.getShutdownStrategy().setTimeout(5);

    assertMockEndpointsSatisfied();

    // sleep a little
    Thread.sleep(1000);

    Map<String, Map> map = new HashMap<String, Map>(registry.getServices());
    assertTrue("There should be 1 or more, was: " + map.size(), map.size() >= 1);
  }
 @Test
 public void testTranslatedEvent() throws Exception {
   out.expectedMinimumMessageCount(1);
   trap.send();
   out.assertIsSatisfied();
   List<Exchange> exchanges = out.getExchanges();
   Exchange exchange = exchanges.get(0);
   Message message = exchange.getIn();
   RawEvent event = message.getBody(RawEvent.class);
   assertNotNull("check for not null", event);
   assertEquals("check event title", "linkDown trap received from 127.0.0.1", event.getTitle());
   assertEquals("check event message", "Received linkDown trap", event.getMessage());
   Map<String, Object> properties = event.getProperties();
   assertEquals("check trap property", "Host has been restarted", properties.get("linkDown"));
   assertEquals("check uptime property", "7:12:00.00", properties.get("sysUpTimeInstance"));
   assertEquals("check description property", "Test Trap!", properties.get("sysDescr.0"));
 }
  public void testShutdownCompleteCurrentTaskOnly() throws Exception {
    // give it 20 seconds to shutdown
    context.getShutdownStrategy().setTimeout(20);

    MockEndpoint bar = getMockEndpoint("mock:bar");
    bar.expectedMinimumMessageCount(1);

    assertMockEndpointsSatisfied();

    // shutdown during processing
    context.stop();

    // should NOT route all 5
    assertTrue(
        "Should NOT complete all messages, was: " + bar.getReceivedCounter(),
        bar.getReceivedCounter() < 5);
  }
  @Test
  public void testCamelDropbox() throws Exception {
    template.send(
        "direct:start",
        new Processor() {
          @Override
          public void process(Exchange exchange) throws Exception {
            exchange.getIn().setHeader("test", "test");
          }
        });

    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(1);
    assertMockEndpointsSatisfied();

    List<Exchange> exchanges = mock.getReceivedExchanges();
    Exchange exchange = exchanges.get(0);
    Object header = exchange.getIn().getHeader(DropboxResultHeader.DOWNLOADED_FILE.name());
    Object body = exchange.getIn().getBody();
    assertNotNull(header);
    assertNotNull(body);
  }
  public void testTimerInvocation() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMinimumMessageCount(2);

    assertMockEndpointsSatisfied();
  }
  @Test
  public void testQuartzPersistentStoreClusteredApp() throws Exception {
    // boot up the database the two apps are going to share inside a clustered quartz setup
    AbstractXmlApplicationContext db =
        new ClassPathXmlApplicationContext(
            "org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppDatabase.xml");
    db.start();

    // now launch the first clustered app which will acquire the quartz database lock and become the
    // master
    AbstractXmlApplicationContext app =
        new ClassPathXmlApplicationContext(
            "org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppOne.xml");
    app.start();

    // as well as the second one which will run in slave mode as it will not be able to acquire the
    // same lock
    AbstractXmlApplicationContext app2 =
        new ClassPathXmlApplicationContext(
            "org/apache/camel/component/quartz2/SpringQuartzConsumerClusteredAppTwo.xml");
    app2.start();

    CamelContext camel = app.getBean("camelContext", CamelContext.class);

    MockEndpoint mock = camel.getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMinimumMessageCount(3);
    mock.expectedMessagesMatches(new ClusteringPredicate(true));

    // let the route run a bit...
    Thread.sleep(5000);

    mock.assertIsSatisfied();

    // now let's simulate a crash of the first app (the quartz instance 'app-one')
    log.warn("The first app is going to crash NOW!");
    IOHelper.close(app);

    log.warn("Crashed...");
    log.warn("Crashed...");
    log.warn("Crashed...");

    // wait long enough until the second app takes it over...
    Thread.sleep(20000);
    // inside the logs one can then clearly see how the route of the second app ('app-two') starts
    // consuming:
    // 2013-09-30 11:22:20,349 [main           ] WARN  erTwoAppsClusteredFailoverTest - Crashed...
    // 2013-09-30 11:22:20,349 [main           ] WARN  erTwoAppsClusteredFailoverTest - Crashed...
    // 2013-09-30 11:22:20,349 [main           ] WARN  erTwoAppsClusteredFailoverTest - Crashed...
    // 2013-09-30 11:22:35,340 [_ClusterManager] INFO  LocalDataSourceJobStore        -
    // ClusterManager: detected 1 failed or restarted instances.
    // 2013-09-30 11:22:35,340 [_ClusterManager] INFO  LocalDataSourceJobStore        -
    // ClusterManager: Scanning for instance "app-one"'s failed in-progress jobs.
    // 2013-09-30 11:22:35,369 [eduler_Worker-1] INFO  triggered                      -
    // Exchange[ExchangePattern: InOnly, BodyType: String, Body: clustering PONGS!]

    CamelContext camel2 = app2.getBean("camelContext2", CamelContext.class);

    MockEndpoint mock2 = camel2.getEndpoint("mock:result", MockEndpoint.class);
    mock2.expectedMinimumMessageCount(3);
    mock2.expectedMessagesMatches(new ClusteringPredicate(false));

    mock2.assertIsSatisfied();

    // and as the last step shutdown the second app as well as the database
    IOHelper.close(app2, db);
  }