@Test
  public void testSendMessage() throws Exception {
    MockEndpoint finish = consumerContext.getEndpoint("mock:finish", MockEndpoint.class);
    finish.whenAnyExchangeReceived(
        new Processor() {
          @Override
          public void process(Exchange exchange) throws Exception {
            throw new RuntimeException("TestException!!!");
          }
        });
    finish.expectedMessageCount(4);

    MockEndpoint consumerException =
        consumerContext.getEndpoint("mock:exception", MockEndpoint.class);
    consumerException.expectedMessageCount(0);

    MockEndpoint producerException =
        producerContext.getEndpoint("mock:exception", MockEndpoint.class);
    producerException.expectedBodiesReceived("1234567890");

    ProducerTemplate producerTemplate = producerContext.createProducerTemplate();
    try {
      producerTemplate.sendBody("direct:start", "1234567890");
      fail("CamelExecutionException expected");
    } catch (CamelExecutionException e) {
      assertEquals("TestException!!!", e.getCause().getMessage());
    }

    MockEndpoint.assertIsSatisfied(consumerContext);
    MockEndpoint.assertIsSatisfied(producerContext);
  }
  @Test
  public void testBlueprintProperties() throws Exception {
    // start bundle
    getInstalledBundle(name).start();

    // must use the camel context from osgi
    CamelContext ctx =
        getOsgiService(CamelContext.class, "(camel.context.symbolicname=" + name + ")", 10000);

    ProducerTemplate myTemplate = ctx.createProducerTemplate();
    myTemplate.start();

    // do our testing
    MockEndpoint foo = ctx.getEndpoint("mock:foo", MockEndpoint.class);
    foo.expectedMessageCount(1);
    MockEndpoint result = ctx.getEndpoint("mock:result", MockEndpoint.class);
    result.expectedMessageCount(1);

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

    foo.assertIsSatisfied();
    result.assertIsSatisfied();

    myTemplate.stop();
  }
Exemplo n.º 3
0
  public void testSplitterWithException() throws Exception {
    MockEndpoint resultEndpoint = getMockEndpoint("mock:result");
    resultEndpoint.expectedMessageCount(4);
    resultEndpoint.expectedHeaderReceived("foo", "bar");

    MockEndpoint failedEndpoint = getMockEndpoint("mock:failed");
    failedEndpoint.expectedMessageCount(1);
    failedEndpoint.expectedHeaderReceived("foo", "bar");

    Exchange result =
        template.request(
            "direct:exception",
            new Processor() {
              public void process(Exchange exchange) {
                Message in = exchange.getIn();
                in.setBody("James,Guillaume,Hiram,Rob,Exception");
                in.setHeader("foo", "bar");
              }
            });

    assertTrue(
        "The result exchange should have a camel exception",
        result.getException() instanceof CamelException);

    assertMockEndpointsSatisfied();
  }
  @Test
  public void testScheduledStartRoutePolicyWithTwoRoutes() throws Exception {
    MockEndpoint success1 = context.getEndpoint("mock:success1", MockEndpoint.class);
    MockEndpoint success2 = context.getEndpoint("mock:success2", MockEndpoint.class);
    success1.expectedMessageCount(1);
    success2.expectedMessageCount(1);

    context
        .getComponent("quartz2", QuartzComponent.class)
        .setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");

    context.addRoutes(
        new RouteBuilder() {
          public void configure() {
            CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
            policy.setRouteStartTime("*/3 * * * * ?");

            from("direct:start1").routeId("test1").routePolicy(policy).to("mock:success1");

            from("direct:start2").routeId("test2").routePolicy(policy).to("mock:success2");
          }
        });
    context.start();
    context.stopRoute("test1", 1000, TimeUnit.MILLISECONDS);
    context.stopRoute("test2", 1000, TimeUnit.MILLISECONDS);

    Thread.sleep(5000);
    assertTrue(context.getRouteStatus("test1") == ServiceStatus.Started);
    assertTrue(context.getRouteStatus("test2") == ServiceStatus.Started);
    template.sendBody("direct:start1", "Ready or not, Here, I come");
    template.sendBody("direct:start2", "Ready or not, Here, I come");

    success1.assertIsSatisfied();
    success2.assertIsSatisfied();
  }
 @Test
 public void pipelineCompletes() {
   end.expectedMessageCount(1);
   after.expectedMessageCount(1);
   producer.sendBody(3);
   assertEquals(1, table.values().size());
   assertEquals(3, (int) table.iterator().next());
 }
  @Test
  public void testTransaction() throws InterruptedException {
    // Assertions
    deletedEndpoint.expectedMessageCount(8);
    deletedEndpoint.expectedHeaderReceived(Exchange.HTTP_RESPONSE_CODE, 204);

    transactedEndpoint.expectedMessageCount(1);

    verifiedEndpoint.expectedMessageCount(3);

    midtransactionEndpoint.expectedMessageCount(3);
    midtransactionEndpoint.expectedHeaderReceived(Exchange.HTTP_RESPONSE_CODE, 201);

    notfoundEndpoint.expectedMessageCount(6);
    notfoundEndpoint.expectedHeaderReceived(Exchange.HTTP_RESPONSE_CODE, 404);

    // Start the transaction
    final Map<String, Object> headers = new HashMap<>();
    headers.put(Exchange.HTTP_METHOD, "POST");
    headers.put(Exchange.CONTENT_TYPE, "text/turtle");

    // Create the object
    final String fullPath =
        template.requestBodyAndHeaders(
            "direct:create", FcrepoTestUtils.getTurtleDocument(), headers, String.class);

    assertNotNull(fullPath);

    final String identifier = fullPath.replaceAll(FcrepoTestUtils.getFcrepoBaseUrl(), "");

    // Test the creation of several objects
    template.sendBodyAndHeader("direct:transact", null, "TestIdentifierBase", identifier);

    // Test the object
    template.sendBodyAndHeader(
        "direct:verify", null, FcrepoHeaders.FCREPO_IDENTIFIER, identifier + "/one");
    template.sendBodyAndHeader(
        "direct:verify", null, FcrepoHeaders.FCREPO_IDENTIFIER, identifier + "/two");
    template.sendBodyAndHeader(
        "direct:verify", null, FcrepoHeaders.FCREPO_IDENTIFIER, identifier + "/three");

    // Teardown
    template.sendBodyAndHeader(
        "direct:teardown", null, FcrepoHeaders.FCREPO_IDENTIFIER, identifier + "/one");
    template.sendBodyAndHeader(
        "direct:teardown", null, FcrepoHeaders.FCREPO_IDENTIFIER, identifier + "/two");
    template.sendBodyAndHeader(
        "direct:teardown", null, FcrepoHeaders.FCREPO_IDENTIFIER, identifier + "/three");
    template.sendBodyAndHeader(
        "direct:teardown", null, FcrepoHeaders.FCREPO_IDENTIFIER, identifier);

    // Confirm assertions
    verifiedEndpoint.assertIsSatisfied();
    deletedEndpoint.assertIsSatisfied();
    transactedEndpoint.assertIsSatisfied();
    notfoundEndpoint.assertIsSatisfied();
    midtransactionEndpoint.assertIsSatisfied();
  }
Exemplo n.º 7
0
  @Test
  public void testFunctions() throws Exception {
    raleighEndpoint.expectedMessageCount(1);
    tampaEndpoint.expectedMessageCount(0);

    template.sendBody("direct:start", "<person name='Hadrian' city='Raleigh'/>");

    assertMockEndpointsSatisfied();
  }
Exemplo n.º 8
0
  public void testValidMessage() throws Exception {
    validEndpoint.expectedMessageCount(1);
    invalidEndpoint.expectedMessageCount(0);

    Object result = template.requestBodyAndHeader("direct:start", "<valid/>", "foo", "bar");
    assertEquals("validResult", result);

    assertMockEndpointsSatisfied();
  }
Exemplo n.º 9
0
  @Test
  public void testIdempotent() throws Exception {
    String uri = "file:target/test-classes/idempotent?idempotent=true&delay=10";
    context
        .getRouteDefinitions()
        .get(1)
        .adviceWith(
            context,
            new AdviceWithRouteBuilder() {
              @Override
              public void configure() throws Exception {
                replaceFromWith(uri);
                weaveByType(ToDefinition.class).selectFirst().replace().to("mock:endpoint");
              }
            });
    MockEndpoint end = context.getEndpoint("mock:endpoint", MockEndpoint.class);
    end.expectedMessageCount(1);

    producer.sendBodyAndHeader(
        "file://target/test-classes/idempotent", Exchange.FILE_NAME, "FCOO1.nc");

    end.assertIsSatisfied();

    String fileName =
        (String) end.getReceivedExchanges().get(0).getIn().getHeader(Exchange.FILE_NAME_ONLY);
    assertEquals(fileName, "FCOO1.nc");

    // reset the mock
    end.reset();
    end.expectedMessageCount(0);

    // move file back
    File file = new File("target/test-classes/idempotent/.camel/FCOO1.nc");
    File renamed = new File("target/test-classes/idempotent/FCOO1.nc");
    file.renameTo(renamed);

    producer.sendBodyAndHeader(
        "file://target/test-classes/idempotent", Exchange.FILE_NAME, "FCOO1.nc");

    // let some time pass to let the consumer try to consume even though it cannot
    Thread.sleep(100);
    end.assertIsSatisfied();

    FileEndpoint fe = context.getEndpoint(uri, FileEndpoint.class);
    assertNotNull(fe);

    // Make sure that there are no incoming messages
    MemoryIdempotentRepository repo = (MemoryIdempotentRepository) fe.getInProgressRepository();
    assertEquals("Should be no in-progress files", 0, repo.getCacheSize());
  }
  @Test
  public void testSqlIdempotentConsumer() throws Exception {
    Assert.assertNotNull("DataSource not null", dataSource);

    final JdbcMessageIdRepository jdbcMessageIdRepository =
        new JdbcMessageIdRepository(dataSource, "myProcessorName");

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(
        new RouteBuilder() {
          @Override
          public void configure() throws Exception {
            from("direct:start")
                .idempotentConsumer(simple("${header.messageId}"), jdbcMessageIdRepository)
                .to("mock:result");
          }
        });

    camelctx.start();
    try {
      MockEndpoint mockEndpoint = camelctx.getEndpoint("mock:result", MockEndpoint.class);
      mockEndpoint.expectedMessageCount(1);

      // Send 5 messages with the same messageId header. Only 1 should be forwarded to the
      // mock:result endpoint
      ProducerTemplate template = camelctx.createProducerTemplate();
      for (int i = 0; i < 5; i++) {
        template.requestBodyAndHeader("direct:start", null, "messageId", "12345");
      }

      mockEndpoint.assertIsSatisfied();
    } finally {
      camelctx.stop();
    }
  }
  @Test
  public void sendLongSubmitSM() throws Exception {
    result.expectedMessageCount(2);

    Exchange exchange = start.createExchange(ExchangePattern.InOnly);
    exchange
        .getIn()
        .setBody(
            "Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! "
                + "Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! "
                + "Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! Hello SMPP World! "); // 270 chars

    template.send(start, exchange);

    assertMockEndpointsSatisfied();
    assertEquals(
        SmppMessageType.DeliveryReceipt.toString(),
        result.getExchanges().get(0).getIn().getHeader(SmppConstants.MESSAGE_TYPE));
    assertEquals(
        SmppMessageType.DeliveryReceipt.toString(),
        result.getExchanges().get(1).getIn().getHeader(SmppConstants.MESSAGE_TYPE));

    assertNotNull(exchange.getIn().getHeader(SmppConstants.ID));
    assertEquals(2, exchange.getIn().getHeader(SmppConstants.SENT_MESSAGE_COUNT));
  }
Exemplo n.º 12
0
  @Test
  public void testScheduledResumeRoutePolicy() throws Exception {
    MockEndpoint success = context.getEndpoint("mock:success", MockEndpoint.class);
    success.expectedMessageCount(1);

    context
        .getComponent("quartz2", QuartzComponent.class)
        .setPropertiesFile("org/apache/camel/routepolicy/quartz2/myquartz.properties");
    context.addRoutes(
        new RouteBuilder() {
          public void configure() {
            CronScheduledRoutePolicy policy = new CronScheduledRoutePolicy();
            policy.setRouteResumeTime("*/3 * * * * ?");

            from("direct:start").routeId("test").routePolicy(policy).to("mock:success");
          }
        });
    context.start();

    ServiceHelper.suspendService(context.getRoute("test").getConsumer());

    Thread.sleep(5000);
    assertTrue(context.getRouteStatus("test") == ServiceStatus.Started);

    template.sendBody("direct:start", "Ready or not, Here, I come");

    success.assertIsSatisfied();
  }
  public void testSimpleSplitWriteRead() throws Exception {
    context.addRoutes(
        new RouteBuilder() {
          @Override
          public void configure() {
            from("direct:start")
                .to(
                    "hdfs://localhost:9000/tmp/test/test-camel-simple-write-file?fileSystemType=HDFS&splitStrategy=BYTES:5,IDLE:1000");
            from("hdfs://localhost:9000/tmp/test/test-camel-simple-write-file?pattern=seg*&initialDelay=2000&fileSystemType=HDFS&chunkSize=5")
                .to("mock:result");
          }
        });
    context.start();

    for (int i = 0; i < 10; ++i) {
      template.sendBody("direct:start", "CIAO" + i);
    }

    MockEndpoint resultEndpoint = (MockEndpoint) context.getEndpoint("mock:result");

    resultEndpoint.expectedMessageCount(10);
    resultEndpoint.assertIsSatisfied();

    int i = 0;
    List<Exchange> exchanges = resultEndpoint.getExchanges();
    for (Exchange exchange : exchanges) {
      Assert.assertEquals("CIAO" + i++, exchange.getIn().getBody(String.class));
    }
  }
Exemplo n.º 14
0
  @Test
  public void testHeaderAndTrailer() throws Exception {
    results.expectedMessageCount(1);
    results.message(0).body().isInstanceOf(List.class);
    results.message(0).header("camelFlatpackCounter").isEqualTo(6);

    results.assertIsSatisfied();

    List<Map<String, String>> data =
        CastUtils.cast(results.getExchanges().get(0).getIn().getBody(List.class));

    // assert header
    Map<String, String> header = data.get(0);
    assertEquals("HBT", header.get("INDICATOR"));
    assertEquals("20080817", header.get("DATE"));

    // assert body
    int counter = 0;
    for (Map<String, String> row : data.subList(1, 5)) {
      assertEquals("FIRSTNAME", expectedFirstName[counter], row.get("FIRSTNAME"));
      LOG.info("Result: " + counter + " = " + row);
      counter++;
    }

    // assert trailer
    Map<String, String> trailer = data.get(5);
    assertEquals("FBT", trailer.get("INDICATOR"));
    assertEquals("SUCCESS", trailer.get("STATUS"));
  }
  public void testCustomProducerServicePoolInRoute() throws Exception {
    context.addEndpoint("my", new MyEndpoint("my", context));

    MyPool pool = new MyPool();
    pool.start();
    context.setProducerServicePool(pool);

    context.addRoutes(
        new RouteBuilder() {
          @Override
          public void configure() throws Exception {
            from("direct:start").to("my", "mock:result");
          }
        });
    context.start();

    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(2);

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

    assertMockEndpointsSatisfied();

    assertEquals(2, counter);
    assertEquals(1, pool.size());
  }
Exemplo n.º 16
0
 @DirtiesContext
 @Test
 public void testSendInvalidData() throws Exception {
   resultEndpoint.expectedMessageCount(0);
   template.sendBody("CSV\nNullpointerException():100");
   resultEndpoint.assertIsSatisfied();
 }
Exemplo n.º 17
0
 @DirtiesContext
 @Test
 public void testSendCsvDataZeroLines() throws Exception {
   resultEndpoint.expectedMessageCount(0);
   template.sendBody("only one line");
   resultEndpoint.assertIsSatisfied();
 }
Exemplo n.º 18
0
  public void testSendLotsOfMessagesSimultaneouslyButOnly3GetThrough() throws Exception {
    MockEndpoint resultEndpoint = resolveMandatoryEndpoint("mock:result", MockEndpoint.class);
    resultEndpoint.expectedMessageCount(messageCount);

    ExecutorService executor = Executors.newFixedThreadPool(messageCount);

    long start = System.currentTimeMillis();
    for (int i = 0; i < messageCount; i++) {
      executor.execute(
          new Runnable() {
            public void run() {
              template.sendBody("direct:a", "<message>payload</message>");
            }
          });
    }

    // let's wait for the exchanges to arrive
    resultEndpoint.assertIsSatisfied();

    // now assert that they have actually been throttled
    long minimumTime = (messageCount - 1) * INTERVAL;
    // add a little slack
    long delta = System.currentTimeMillis() - start + 200;
    assertTrue("Should take at least " + minimumTime + "ms, was: " + delta, delta >= minimumTime);
  }
Exemplo n.º 19
0
  public void testConcurrentPipeline() throws Exception {
    int total = 200;
    final int group = total / 20;
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(total);

    ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
    executor.setCorePoolSize(20);
    executor.afterPropertiesSet();
    for (int i = 0; i < 20; i++) {
      final int threadCount = i;
      executor.execute(
          new Runnable() {
            public void run() {
              int start = threadCount * group;
              for (int i = 0; i < group; i++) {
                try {
                  // do some random sleep to simulate spread in user activity
                  Thread.sleep(new Random().nextInt(10));
                } catch (InterruptedException e) {
                  // ignore
                }
                template.sendBody(uri, "" + (start + i));
              }
            }
          });
    }

    mock.assertIsSatisfied();
    mock.expectsNoDuplicates(body());
    executor.shutdown();
  }
Exemplo n.º 20
0
  @Test
  public void testFileToFile() throws Exception {

    // Body contains two CDs, one DVD and one BOOK.
    String bodyOfMessage =
        "eminem / cd,harry potter and the deathly hollows / dvd,"
            + "Claus Ibsen - Camel in Action / book,"
            + "Xzibit / cd";

    // The TemplateProducer is part of CamelTestSupport. It is used to send messages to Camel
    // endpoints.
    template.sendBodyAndHeader(
        "file://orders/inbox", bodyOfMessage, Exchange.FILE_NAME, "order.csv");

    // Mock is included implicitly.
    MockEndpoint mock = context.getEndpoint("mock:others", MockEndpoint.class);
    // The Mock expects only one message, because it only receives the BOOK order:
    mock.expectedMessageCount(1);
    mock.setResultWaitTime(1000);

    Thread.sleep(3000);

    String dvdBody = " harry potter and the deathly hollows / dvd";

    File target = new File("orders/outbox/dvd/order.csv");
    String content = context.getTypeConverter().convertTo(String.class, target);

    // Assertions
    mock.assertIsSatisfied();
    assertEquals(dvdBody.toUpperCase(), content);
  }
Exemplo n.º 21
0
 @Test
 public void testTerserPredicateNull() throws Exception {
   MockEndpoint mock = getMockEndpoint("mock:test3");
   mock.expectedMessageCount(1);
   template.sendBody("direct:test3", createADT01Message());
   assertMockEndpointsSatisfied();
 }
Exemplo n.º 22
0
  public void testSendingAMessageUsingMulticastReceivesItsOwnExchangeParallel() throws Exception {
    MockEndpoint resultEndpoint = getMockEndpoint("mock:result");

    resultEndpoint.expectsNoDuplicates(body());
    resultEndpoint.expectedMessageCount(4);

    // InOnly
    template.send(
        "direct:parallel",
        new Processor() {
          public void process(Exchange exchange) {
            Message in = exchange.getIn();
            in.setBody("James,Guillaume,Hiram,Rob");
            in.setHeader("foo", "bar");
          }
        });

    assertMockEndpointsSatisfied();

    List<Exchange> list = resultEndpoint.getReceivedExchanges();
    Set<Integer> numbersFound = new TreeSet<Integer>();
    final String[] names = {"James", "Guillaume", "Hiram", "Rob"};

    for (int i = 0; i < 4; i++) {
      Exchange exchange = list.get(i);
      Message in = exchange.getIn();
      Integer splitCounter = exchange.getProperty(Exchange.SPLIT_INDEX, Integer.class);
      numbersFound.add(splitCounter);
      assertEquals(names[splitCounter], in.getBody());
      assertProperty(exchange, Exchange.SPLIT_SIZE, 4);
    }

    assertEquals(4, numbersFound.size());
  }
  @Test
  public void testMarshall()
      throws InterruptedException, ParserConfigurationException, IOException, SAXException {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);

    PurchaseOrder purchaseOrder = new PurchaseOrder();
    String name = "foo";
    purchaseOrder.setName(name);
    double price = 49;
    purchaseOrder.setPrice(price);
    double amount = 3;
    purchaseOrder.setAmount(amount);

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

    assertMockEndpointsSatisfied();

    String body = mock.getReceivedExchanges().get(0).getIn().getBody(String.class);
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    Element root = builder.parse(new InputSource(new StringReader(body))).getDocumentElement();

    assertEquals(name, root.getAttribute("name"));
    assertEquals(price + "", root.getAttribute("price"));
    assertEquals(amount + "", root.getAttribute("amount"));
  }
  @Test
  public void testScheduledStartRoutePolicy() throws Exception {
    MockEndpoint success = (MockEndpoint) context.getEndpoint("mock:success");

    success.expectedMessageCount(1);

    context
        .getComponent("quartz", QuartzComponent.class)
        .setPropertiesFile("org/apache/camel/routepolicy/quartz/myquartz.properties");
    context.getComponent("quartz", QuartzComponent.class).start();
    context.addRoutes(
        new RouteBuilder() {
          public void configure() {
            SimpleScheduledRoutePolicy policy = new SimpleScheduledRoutePolicy();
            long startTime = System.currentTimeMillis() + 3000L;
            policy.setRouteStartDate(new Date(startTime));
            policy.setRouteStartRepeatCount(1);
            policy.setRouteStartRepeatInterval(3000);

            from("direct:start").routeId("test").routePolicy(policy).to("mock:success");
          }
        });
    context.start();
    context.stopRoute("test", 0, TimeUnit.MILLISECONDS);

    Thread.sleep(5000);
    assertTrue(context.getRouteStatus("test") == ServiceStatus.Started);
    template.sendBody("direct:start", "Ready or not, Here, I come");

    context.getComponent("quartz", QuartzComponent.class).stop();
    success.assertIsSatisfied();
  }
  public void testXPathSplitStream() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:splitted");
    mock.expectedMessageCount(size);
    mock.expectsNoDuplicates().body();

    assertMockEndpointsSatisfied();
  }
  @Test
  /** Operation: CREATE Body contains: Metacard */
  public void testCreateWithIngestException() throws Exception {
    resetMocks();

    // Setup expectations to verify
    final MockEndpoint mockVerifierEndpoint = getMockEndpoint("mock:result");
    mockVerifierEndpoint.expectedMessageCount(1);

    final List<Metacard> metacards = new ArrayList<Metacard>();
    metacards.add(metacard1);

    // Mock catalog framework
    final CreateRequest createRequest = new CreateRequestImpl(metacards);
    final CreateResponse createResponse =
        new CreateResponseImpl(createRequest, new HashMap(), metacards);
    when(catalogFramework.create(any(CreateRequest.class))).thenThrow(new IngestException());

    // Exercise the route with a CREATE operation
    template.sendBodyAndHeader("direct:sampleInput", metacard1, "Operation", "CREATE");

    // Verify that the number of metacards in the exchange after the records
    // is identical to the input
    assertListSize(mockVerifierEndpoint.getExchanges(), 1);
    final Exchange exchange = mockVerifierEndpoint.getExchanges().get(0);
    final List<Metacard> cardsCreated = (List<Metacard>) exchange.getIn().getBody();
    assertListSize(cardsCreated, 0);

    mockVerifierEndpoint.assertIsSatisfied();
  }
 @Test
 public void testBlobStorePut() throws InterruptedException {
   MockEndpoint mockEndpoint = resolveMandatoryEndpoint("mock:results", MockEndpoint.class);
   mockEndpoint.expectedMessageCount(1);
   template.sendBody("direct:put", "Some message");
   mockEndpoint.assertIsSatisfied();
 }
  @Test
  /** Operation: DELETE Body contains: 12345678900987654321abcdeffedcba */
  public void testDeleteWithIngestException() throws Exception {
    resetMocks();

    // Setup expectations to verify
    final MockEndpoint mockVerifierEndpoint = getMockEndpoint("mock:result");
    mockVerifierEndpoint.expectedMessageCount(1);

    final List<Metacard> metacards = new ArrayList<Metacard>();
    metacards.add(metacard1);

    // setup mock catalog framework
    final String[] metacardIds = new String[metacards.size()];
    for (int i = 0; i < metacards.size(); i++) {
      metacardIds[i] = metacards.get(i).getId();
    }

    DeleteRequest deleteRequest = new DeleteRequestImpl(metacardIds);
    DeleteResponse deleteResponse = new DeleteResponseImpl(deleteRequest, new HashMap(), metacards);
    when(catalogFramework.delete(any(DeleteRequest.class))).thenThrow(new IngestException());

    // Exercise the route with a DELETE operation
    template.sendBodyAndHeader("direct:sampleInput", metacardIds, "Operation", "DELETE");

    // Verify that the number of metacards in the exchange after the records
    // is identical to the input
    assertListSize(mockVerifierEndpoint.getExchanges(), 1);
    final Exchange exchange = mockVerifierEndpoint.getExchanges().get(0);
    final List<Update> cardsDeleted = (List<Update>) exchange.getIn().getBody();
    assertListSize(cardsDeleted, 0);

    mockVerifierEndpoint.assertIsSatisfied();
  }
  @Test
  public void testInOnlyMultipleJMSHeadersAndExpiration() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    mock.message(0).header("JMSPriority").isEqualTo(3);
    mock.message(0).header("JMSDeliveryMode").isEqualTo(2);

    long ttl = System.currentTimeMillis() + 2000;
    Map<String, Object> headers = new HashMap<String, Object>();
    headers.put("JMSPriority", 3);
    headers.put("JMSDeliveryMode", 2);
    headers.put("JMSExpiration", ttl);
    template.sendBodyAndHeaders(
        "activemq:queue:bar?preserveMessageQos=true", "Hello World", headers);

    // sleep just a little
    Thread.sleep(50);

    Exchange bar = consumer.receive("activemq:queue:bar", 5000);
    assertNotNull("Should be a message on queue", bar);

    template.send("activemq:queue:foo?preserveMessageQos=true", bar);

    Thread.sleep(1000);

    assertMockEndpointsSatisfied();
  }
  @Test
  public void sendSubmitSMInOnly() throws Exception {
    result.expectedMessageCount(1);

    Exchange exchange = start.createExchange(ExchangePattern.InOnly);
    exchange.getIn().setBody("Hello SMPP World!");

    template.send(start, exchange);

    assertMockEndpointsSatisfied();
    Exchange resultExchange = result.getExchanges().get(0);
    assertEquals(
        SmppMessageType.DeliveryReceipt.toString(),
        resultExchange.getIn().getHeader(SmppConstants.MESSAGE_TYPE));
    assertEquals("Hello SMPP World!", resultExchange.getIn().getBody());
    assertNotNull(resultExchange.getIn().getHeader(SmppConstants.ID));
    assertEquals(1, resultExchange.getIn().getHeader(SmppConstants.SUBMITTED));
    assertEquals(1, resultExchange.getIn().getHeader(SmppConstants.DELIVERED));
    assertNotNull(resultExchange.getIn().getHeader(SmppConstants.DONE_DATE));
    assertNotNull(resultExchange.getIn().getHeader(SmppConstants.SUBMIT_DATE));
    assertNull(resultExchange.getIn().getHeader(SmppConstants.ERROR));

    assertNotNull(exchange.getIn().getHeader(SmppConstants.ID));
    assertEquals(1, exchange.getIn().getHeader(SmppConstants.SENT_MESSAGE_COUNT));
  }