@Test
  public void testHandleException() throws Exception {
    for (int i = 0; i < DELIVERY_COUNT; i++) {
      MockEndpoint finish = consumerContext.getEndpoint("mock:finish" + i, MockEndpoint.class);
      finish.whenAnyExchangeReceived(
          new Processor() {
            @Override
            public void process(Exchange exchange) throws Exception {
              throw new RuntimeException("TestException!!!");
            }
          });
      finish.expectedBodiesReceived("1234567890");
    }
    MockEndpoint finish4 = consumerContext.getEndpoint("mock:finish4", MockEndpoint.class);
    finish4.expectedBodiesReceived("1234567890-1");

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

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

    MockEndpoint.assertIsSatisfied(consumerContext);
    MockEndpoint.assertIsSatisfied(producerContext);
  }
示例#2
0
  /**
   * Adds a trust bundle to the system.
   *
   * @param uriInfo Injected URI context used for building the location URI.
   * @param bundle The bundle to add to the system.
   * @return Status of 201 if the bundle was added or a status of 409 if a bundle with the same name
   *     already exists.
   */
  @PUT
  @Consumes(MediaType.APPLICATION_JSON)
  public Response addTrustBundle(@Context UriInfo uriInfo, TrustBundle bundle) {
    // make sure it doesn't exist
    try {
      if (bundleDao.getTrustBundleByName(bundle.getBundleName()) != null)
        return Response.status(Status.CONFLICT).cacheControl(noCache).build();
    } catch (Exception e) {
      log.error("Error looking up bundle.", e);
      return Response.serverError().cacheControl(noCache).build();
    }

    try {
      final org.nhindirect.config.store.TrustBundle entityBundle =
          EntityModelConversion.toEntityTrustBundle(bundle);

      bundleDao.addTrustBundle(entityBundle);

      final UriBuilder newLocBuilder = uriInfo.getBaseUriBuilder();
      final URI newLoc = newLocBuilder.path("trustbundle/" + bundle.getBundleName()).build();

      // the trust bundle does not contain any of the anchors
      // they must be fetched from the URL... use the
      // refresh route to force downloading the anchors
      template.sendBody(entityBundle);

      return Response.created(newLoc).cacheControl(noCache).build();
    } catch (Exception e) {
      log.error("Error adding trust bundle.", e);
      return Response.serverError().cacheControl(noCache).build();
    }
  }
  @Before
  public void setUp() throws Exception {

    for (String message : inputMessages) {
      template.sendBody("seda:inputQueue", message);
    }
  }
  @Test
  public void transform() throws Exception {
    String body = readFile("src/data/privateCustomers.xml");

    // This test is simply to inspect the data mapping behaviour closer
    startEndpoint.sendBody(body);
  }
示例#5
0
 @DirtiesContext
 @Test
 public void testSendInvalidData() throws Exception {
   resultEndpoint.expectedMessageCount(0);
   template.sendBody("CSV\nNullpointerException():100");
   resultEndpoint.assertIsSatisfied();
 }
示例#6
0
 @DirtiesContext
 @Test
 public void testSendCsvDataOneLine() throws Exception {
   resultEndpoint.expectedBodiesReceived(new MyCsvBean(1, "message", "db"));
   template.sendBody("CSV\n1,message,db");
   resultEndpoint.assertIsSatisfied();
 }
示例#7
0
 @DirtiesContext
 @Test
 public void testSendCsvDataZeroLines() throws Exception {
   resultEndpoint.expectedMessageCount(0);
   template.sendBody("only one line");
   resultEndpoint.assertIsSatisfied();
 }
 /**
  * Publish upload events to the queue
  *
  * @param username
  * @param siteName
  * @param eventType
  * @param numOfDays
  */
 public static void createHistoricEvents(
     String testName,
     ProducerTemplate template,
     String username,
     String siteName,
     String eventType,
     int numberOfUploadEvents,
     int numOfDays) {
   for (int i = 0; i < numberOfUploadEvents; i++) {
     String fileName = getFileName(testName + "_" + i + "." + "txt");
     Event event =
         new ActivityEvent(
             eventType,
             "a52fbbf9-a297-4fb5-aeea-8f5fe8087c7b",
             "alfresco.com",
             getEventDate(numOfDays),
             username,
             "e346bfa0-3177-4d64-b86d-05b433307d3b",
             siteName.toLowerCase(),
             "{http://www.alfresco.org/model/content/1.0}content",
             null,
             "{\"nodeRef\": \"workspace:\\/\\/SpacesStore\\/e346bfa0-3177-4d64-b86d-05b433307d3b\", \"title\": \"Filemiojkli-SiteContentReadsReportTest_0.txt\", \"page\": \"document-details?nodeRef=workspace:\\/\\/SpacesStore\\/e346bfa0-3177-4d64-b86d-05b433307d3b\"}",
             fileName,
             "text/plain",
             600L,
             "UTF-8");
     template.sendBody("activemq:alfresco.events.raw?requestTimeout=5000", event);
   }
 }
  @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();
  }
示例#10
0
  @Test
  public void testFilePollerB() throws Exception {
    String expected = "xxx";
    final MockEndpoint mockEndpoint = getMockEndpoint("mock:" + routeATo);
    cc.getRouteDefinitions()
        .get(0)
        .adviceWith(
            cc,
            new RouteBuilder() {
              @Override
              public void configure() throws Exception {
                // intercept sending to mock:foo and do something else
                interceptSendToEndpoint(routeATo).to(mockEndpoint);
              }
            });

    mockEndpoint.expectedBodiesReceived(expected);

    Endpoint ep = cc.getEndpoint(routeAFrom);
    Assert.assertNotNull(ep);
    ProducerTemplate pt = cc.createProducerTemplate();
    pt.start();
    pt.sendBody(ep, expected);

    assertMockEndpointsSatisfied();
  }
 @Listen("onClick = button#cfgSave")
 public void cfgSaveClick(MouseEvent event) {
   if (logger.isDebugEnabled()) logger.debug(" cfgSave button event = " + event);
   try {
     Properties config = Util.getConfig(null);
     if (isValidPort(portsToScan.getText())) {
       config.setProperty(Constants.SERIAL_PORTS, portsToScan.getValue());
     } else {
       Messagebox.show(
           "Device ports to scan is invalid. In Linux (pi) '/dev/ttyUSB0,/dev/ttyUSB1,etc', in MS Windows 'COM1,COM2,COM3,etc'");
     }
     if (isValidBaudRate(portBaudRate.getValue())) {
       config.setProperty(Constants.SERIAL_PORT_BAUD, portBaudRate.getValue());
       Util.saveConfig();
     } else {
       Messagebox.show("Device baud rate (speed) must be one of 4800,9600,19200,38400,57600");
     }
     if (NumberUtils.isNumber(cfgWindOffset.getValue())) {
       config.setProperty(Constants.WIND_ZERO_OFFSET, cfgWindOffset.getValue());
       Util.saveConfig();
       // notify others
       producer.sendBody(Constants.WIND_ZERO_ADJUST_CMD + ":" + cfgWindOffset.getValue() + ",");
     } else {
       Messagebox.show("Wind offset must be numeric");
     }
     config.setProperty(Constants.PREFER_RMC, (String) useRmcGroup.getSelectedItem().getValue());
     config.setProperty(
         Constants.DNS_USE_CHOICE, (String) useHomeGroup.getSelectedItem().getValue());
     Util.saveConfig();
   } catch (Exception e) {
     logger.error(e.getMessage(), e);
   }
 }
  @Test
  public void testMarshallMessage() throws Exception {
    resultEndpoint.expectedBodiesReceived(result);

    template.sendBody(generateModel());

    resultEndpoint.assertIsSatisfied();
  }
  @Test
  public void testMocksIsValid() throws Exception {
    mock.expectedMessageCount(1);

    producer.sendBody(null);

    mock.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());
 }
示例#15
0
 @DirtiesContext
 @Test
 public void testSendCsvDataTwoLines() throws Exception {
   resultEndpoint.expectedBodiesReceived(
       new MyCsvBean(1, "message", "db"), new MyCsvBean(2, "second", "never mind"));
   template.sendBody("CSV\n1,message,db\n2,second,never mind");
   resultEndpoint.assertIsSatisfied();
 }
示例#16
0
 public void sendBody(String endpointUri, Object body) throws Exception {
   ProducerTemplate template = context.createProducerTemplate();
   try {
     template.sendBody(endpointUri, body);
   } finally {
     template.stop();
   }
 }
  @DirtiesContext
  @Test
  public void testJobRegistry() throws InterruptedException {
    outputEndpoint.expectedBodiesReceived("Echo foo", "Echo bar", "Echo baz");

    template.sendBody("direct:start", "Start batch!");

    outputEndpoint.assertIsSatisfied();
  }
  @Test
  public void sendMessageToInbound() throws InterruptedException {
    outbound.expectedMessageCount(1);
    outbound.expectedBodiesReceived("test");

    inbound.sendBody("test");

    assertIsSatisfied(2L, TimeUnit.SECONDS, outbound);
  }
 @Test
 public void testDNSWithNoHeaders() throws Exception {
   resultEndpoint.expectedMessageCount(0);
   try {
     template.sendBody("hello");
   } catch (Throwable t) {
     assertTrue(t.getCause() instanceof IllegalArgumentException);
   }
   resultEndpoint.assertIsSatisfied();
 }
  @Test
  public void testUsingContextComponent() throws Exception {
    resultEndpoint.expectedHeaderReceived("received", "true");
    resultEndpoint.expectedMessageCount(2);

    template.sendBody("<purchaseOrder>one</purchaseOrder>");
    template.sendBody("<purchaseOrder>two</purchaseOrder>");

    assertMockEndpointsSatisfied();
  }
示例#21
0
  @Test
  public void testFromListAccountsToFindAccounts() throws Exception {
    String expectedBody = "<listAccounts><id>123</id></listAccounts>";

    resultEndpoint.expectedBodiesReceived(expectedBody);

    template.sendBody(expectedBody);

    resultEndpoint.assertIsSatisfied();
  }
  public void sendMessage(Object message) {

    try {
      rwl.readLock().lock();
      producer.sendBody(message);
    } catch (Exception e) {
      LOG.error("Exception Sending Message: " + message, e);
    } finally {
      rwl.readLock().unlock();
    }
  }
示例#23
0
 public void directStartTask(DirectConfig directConfig) {
   try {
     ProducerTemplate template = context.createProducerTemplate();
     Router createRouter = directConfig.getRouter();
     template.sendBody(
         "direct:" + createRouter.getFrom().getName(), createRouter.getFrom().getParaText());
   } catch (Exception e) {
     e.printStackTrace();
     // this.updateTaskStatus(task, TaskStatus.ERROR_ON_STARTING);
   }
 }
示例#24
0
  /**
   * Updates multiple bundle attributes. If the URL of the bundle changes, then the bundle is
   * automatically refreshed.
   *
   * @param bundleName The name of the bundle to update.
   * @param bundleData The data of the trust bundle to update. Empty or null attributes indicate
   *     that the attribute should not be changed.
   * @return Status of 204 if the bundle attributes were updated, status of 400 if the signing
   *     certificate is invalid, or a status 404 if a trust bundle with the given name does not
   *     exist.
   */
  @POST
  @Path("{bundle}/bundleAttributes")
  @Consumes(MediaType.APPLICATION_JSON)
  public Response updateBundleAttributes(
      @PathParam("bundle") String bundleName, TrustBundle bundleData) {
    // make sure the bundle exists
    org.nhindirect.config.store.TrustBundle entityBundle;
    try {
      entityBundle = bundleDao.getTrustBundleByName(bundleName);
      if (entityBundle == null)
        return Response.status(Status.NOT_FOUND).cacheControl(noCache).build();
    } catch (Exception e) {
      log.error("Error looking up bundle.", e);
      return Response.serverError().cacheControl(noCache).build();
    }

    final String oldBundleURL = entityBundle.getBundleURL();

    // if there is a signing certificate in the request, make sure it's valid
    X509Certificate newSigningCert = null;
    if (bundleData.getSigningCertificateData() != null) {

      try {
        newSigningCert = CertUtils.toX509Certificate(bundleData.getSigningCertificateData());
      } catch (CertificateConversionException ex) {
        log.error("Signing certificate is not in a valid format " + bundleName, ex);
        return Response.status(Status.BAD_REQUEST).cacheControl(noCache).build();
      }
    }

    // update the bundle
    try {
      bundleDao.updateTrustBundleAttributes(
          entityBundle.getId(),
          bundleData.getBundleName(),
          bundleData.getBundleURL(),
          newSigningCert,
          bundleData.getRefreshInterval());

      // if the URL changed, the bundle needs to be refreshed
      if (bundleData.getBundleURL() != null
          && !bundleData.getBundleURL().isEmpty()
          && !oldBundleURL.equals(bundleData.getBundleURL())) {
        entityBundle = bundleDao.getTrustBundleById(entityBundle.getId());

        template.sendBody(entityBundle);
      }

      return Response.noContent().cacheControl(noCache).build();
    } catch (Exception e) {
      log.error("Error updating trust bundle attributes.", e);
      return Response.serverError().cacheControl(noCache).build();
    }
  }
  @Test
  public void testWithBean() throws InterruptedException {
    endpoint.expectedMessageCount(0);
    error.expectedBodiesReceived("foo");
    checkpoint1.expectedBodiesReceived("foo");
    checkpoint2.expectedBodiesReceived("oh no");

    broken.sendBody("foo");

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

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

    mockResult.expectedMinimumMessageCount(1);

    directStart.sendBody("start test");

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

    expected = "1,B2,Keira,Knightley,ISIN,XX23456789,BUY,Share,400.25,EUR,14-01-2009\r\n";

    result.expectedBodiesReceived(expected);

    template.sendBody(generateModel());

    result.assertIsSatisfied();
  }
  @Test
  @DirtiesContext
  public void testMarshallMessage() throws Exception {

    String result =
        "1=BE.CHM.0018=FIX 4.19=2010=22011=CHM0001-0122=434=148=BE000124567849=INVMGR54=156=BRKR58=this is a camel - bindy test\r\n";

    resultEndpoint.expectedBodiesReceived(result);
    template.sendBody(generateModel());

    resultEndpoint.assertIsSatisfied();
  }
  @Test
  public void testMessageLoadBalancedWithFailover() throws InterruptedException {
    String messageBody = "Client has bought something";
    first.setExpectedMessageCount(1);
    third.setExpectedMessageCount(1);
    out.setExpectedMessageCount(2);

    template.sendBody(messageBody);
    template.sendBody(messageBody);

    assertMockEndpointsSatisfied();
  }
  @Test
  public void testAsyncEndpointOK() throws InterruptedException {
    end.expectedBodiesReceived("Bye Camel");

    producer.sendBody(3);

    Collection<Integer> values = table.values();
    assertEquals(2, values.size());

    Iterator<Integer> it = values.iterator();
    assertEquals(Integer.valueOf(3), it.next());
    assertEquals(Integer.valueOf(4), it.next());

    end.assertIsSatisfied();
  }