@Test
  public void aggregatesTwoMessagesIntoOne() throws Exception {
    mockAggregated.expectedHeaderReceived("invoiceItemTotal", BigDecimal.valueOf(5));
    mockAggregated.expectedMessageCount(1);

    start.sendBodyAndHeaders(
        null, toHeadersMap("invoiceId", "invoiceOne", "invoiceItemTotal", BigDecimal.valueOf(2)));
    start.sendBodyAndHeaders(
        null, toHeadersMap("invoiceId", "invoiceOne", "invoiceItemTotal", BigDecimal.valueOf(3)));
    assertMockEndpointsSatisfied();
  }
  @Test
  public void aggregatesMessagesByCorrelationKey() throws Exception {
    mockAggregated.expectedHeaderValuesReceivedInAnyOrder(
        "invoiceItemTotal", BigDecimal.valueOf(5), BigDecimal.valueOf(4));
    mockAggregated.expectedMessageCount(2);

    start.sendBodyAndHeaders(
        null, toHeadersMap("invoiceId", "invoiceOne", "invoiceItemTotal", BigDecimal.valueOf(2)));
    start.sendBodyAndHeaders(
        null, toHeadersMap("invoiceId", "invoiceTwo", "invoiceItemTotal", BigDecimal.valueOf(4)));
    start.sendBodyAndHeaders(
        null, toHeadersMap("invoiceId", "invoiceOne", "invoiceItemTotal", BigDecimal.valueOf(3)));
    assertMockEndpointsSatisfied();
  }
  @Test
  public void testInsert() throws IOException, InterruptedException {
    final String base = "http://localhost/rest";
    final String path = "/path/a/b/c";
    final String document = getN3Document();

    // Assertions
    resultEndpoint.allMessages().body().contains("update=INSERT DATA { ");
    resultEndpoint.allMessages().body().contains(" }");
    for (final String s : document.split("\n")) {
      resultEndpoint.expectedBodyReceived().body().contains(s);
    }
    resultEndpoint
        .expectedBodyReceived()
        .body()
        .contains("<" + base + path + "> dc:title \"some title\" .");
    resultEndpoint.expectedHeaderReceived("Content-Type", "application/x-www-form-urlencoded");
    resultEndpoint.expectedHeaderReceived(Exchange.HTTP_METHOD, "POST");

    // Test
    final Map<String, Object> headers = new HashMap<>();
    headers.put(FcrepoHeaders.FCREPO_BASE_URL, base);
    headers.put(FcrepoHeaders.FCREPO_IDENTIFIER, path);
    headers.put(Exchange.CONTENT_TYPE, "application/n-triples");
    template.sendBodyAndHeaders(document, headers);

    headers.clear();
    headers.put(JmsHeaders.BASE_URL, base);
    headers.put(JmsHeaders.IDENTIFIER, path);
    headers.put(Exchange.CONTENT_TYPE, "application/n-triples");
    template.sendBodyAndHeaders(document, headers);

    headers.clear();
    headers.put(JmsHeaders.BASE_URL, base);
    headers.put(FcrepoHeaders.FCREPO_IDENTIFIER, path);
    headers.put(Exchange.CONTENT_TYPE, "text/turtle");
    template.sendBodyAndHeaders(getTurtleDocument(), headers);

    headers.clear();
    headers.put(FcrepoHeaders.FCREPO_BASE_URL, base);
    headers.put(JmsHeaders.IDENTIFIER, path);
    headers.put(Exchange.CONTENT_TYPE, "application/n-triples");
    template.sendBodyAndHeaders(document, headers);

    // Confirm that assertions passed
    resultEndpoint.expectedMessageCount(4);
    resultEndpoint.assertIsSatisfied();
  }
Exemplo n.º 4
0
  @Test
  public void testRecipientList() throws Exception {
    final String id = "/foo";

    context
        .getRouteDefinition("FcrepoReindexingTraverse")
        .adviceWith(
            context,
            new AdviceWithRouteBuilder() {
              @Override
              public void configure() throws Exception {
                replaceFromWith("direct:traverse");
                mockEndpointsAndSkip("activemq:*");
                mockEndpointsAndSkip("fcrepo:*");
              }
            });
    context.start();

    getMockEndpoint("mock:foo").expectedMessageCount(1);
    getMockEndpoint("mock:foo").expectedHeaderReceived(FCREPO_IDENTIFIER, id);
    getMockEndpoint("mock:bar").expectedMessageCount(1);
    getMockEndpoint("mock:bar").expectedHeaderReceived(FCREPO_IDENTIFIER, id);

    final Map<String, Object> headers = new HashMap<>();
    headers.put(FCREPO_IDENTIFIER, id);
    headers.put(ReindexingHeaders.RECIPIENTS, "mock:foo,mock:bar");

    template.sendBodyAndHeaders("direct:recipients", null, headers);

    assertMockEndpointsSatisfied();
  }
  @Override
  protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket packet) throws Exception {
    String request = packet.content().toString(CharsetUtil.UTF_8);
    if (logger.isDebugEnabled())
      logger.debug("Sender " + packet.sender() + " sent request:" + request);

    if (!sessionList.inverse().containsKey(packet.sender())) {
      String session = UUID.randomUUID().toString();
      String localAddress = ctx.channel().localAddress().toString();
      String remoteAddress = ctx.channel().remoteAddress().toString();
      SubscriptionManagerFactory.getInstance()
          .add(session, session, outputType, localAddress, remoteAddress);
      sessionList.put(session, packet.sender());
      if (logger.isDebugEnabled())
        logger.debug("Added Sender " + packet.sender() + ", session:" + session);
      ctx.channel()
          .writeAndFlush(
              new DatagramPacket(
                  Unpooled.copiedBuffer(
                      Util.getWelcomeMsg().toString() + "\r\n", CharsetUtil.UTF_8),
                  packet.sender()));
    }

    Map<String, Object> headers = getHeaders(sessionList.inverse().get(packet.sender()));
    producer.sendBodyAndHeaders(request, headers);
  }
Exemplo n.º 6
0
 public void sendBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers)
     throws Exception {
   ProducerTemplate template = context.createProducerTemplate();
   try {
     template.sendBodyAndHeaders(endpointUri, body, headers);
   } finally {
     template.stop();
   }
 }
 @DirtiesContext
 @Test
 public void helloRouteMustHaveBeenCalled() throws InterruptedException {
   JsonObject model = Json.createObjectBuilder().add("helloMessage", "toto").build();
   Map headers = new HashMap();
   headers.put("httpRequestType", Builder.constant("POST"));
   helloEntryPoint.sendBodyAndHeaders(model.toString(), headers);
   verify(helloService).persistHello((HelloEntity) anyObject());
   helloRouteMock.expectedMessageCount(1);
   helloRouteMock.assertIsSatisfied();
 }
  public void sendMessage(Object message, Map<String, Object> headers) {

    try {
      rwl.readLock().lock();
      producer.sendBodyAndHeaders(message, headers);
    } catch (Exception e) {
      LOG.error("Exception Sending Message: " + message, e);
    } finally {
      rwl.readLock().unlock();
    }
  }
 @Test
 public void testDNSWithNameHeader() throws Exception {
   resultEndpoint.expectedMessageCount(1);
   resultEndpoint.expectedMessagesMatches(
       new Predicate() {
         public boolean matches(Exchange exchange) {
           Record[] record = (Record[]) exchange.getIn().getBody();
           return record[0].getName().toString().equals("www.example.com.");
         }
       });
   Map<String, Object> headers = new HashMap<String, Object>();
   headers.put("dns.name", "www.example.com");
   template.sendBodyAndHeaders("hello", headers);
   resultEndpoint.assertIsSatisfied();
 }
Exemplo n.º 10
0
  @Test
  public void testReindexWithEndpointsRoute() throws Exception {
    final String id = "/foo";

    context
        .getRouteDefinition("FcrepoReindexingReindex")
        .adviceWith(
            context,
            new AdviceWithRouteBuilder() {
              @Override
              public void configure() throws Exception {
                mockEndpointsAndSkip(reindexingStream + "?disableTimeToLive=true");
                weaveByType(TransformDefinition.class).after().to("mock:result");
              }
            });
    context
        .getRouteDefinition("FcrepoReindexingTraverse")
        .adviceWith(
            context,
            new AdviceWithRouteBuilder() {
              @Override
              public void configure() throws Exception {
                replaceFromWith("direct:traverse");
                mockEndpointsAndSkip("activemq:*");
                mockEndpointsAndSkip("fcrepo:*");
              }
            });
    context.start();

    getMockEndpoint("mock:" + reindexingStream).expectedMessageCount(1);
    getMockEndpoint("mock:result").expectedMessageCount(1);
    getMockEndpoint("mock:result").expectedHeaderReceived(FCREPO_IDENTIFIER, id);
    getMockEndpoint("mock:result").expectedBodiesReceived("Indexing started at " + id);

    final Map<String, Object> headers = new HashMap<>();
    headers.put(Exchange.HTTP_URI, "http://localhost" + restPrefix + id);
    headers.put(ReindexingHeaders.RECIPIENTS, "mock:endpoint");

    template.sendBodyAndHeaders("direct:reindex", null, headers);

    assertMockEndpointsSatisfied();
  }