Exemplo n.º 1
0
  @Test
  public void testStreamCacheToFileShouldBeDeletedInCaseOfException() throws Exception {
    try {
      template.requestBody("direct:start", null, String.class);
      fail("Should have thrown an exception");
    } catch (CamelExecutionException e) {
      HttpOperationFailedException hofe =
          assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
      String s = context.getTypeConverter().convertTo(String.class, hofe.getResponseBody());
      assertEquals("Response body", body, s);
    }

    // the temporary files should have been deleted
    File file = new File("target/cachedir");
    String[] files = file.list();
    assertEquals("There should be no files", 0, files.length);
  }
  @Test
  public void testJettySuspend() throws Exception {
    context.getShutdownStrategy().setTimeout(50);

    String reply = template.requestBody(serverUri, "World", String.class);
    assertEquals("Bye World", reply);

    // now suspend jetty
    HttpConsumer consumer = (HttpConsumer) context.getRoute("route1").getConsumer();
    assertNotNull(consumer);

    // suspend
    consumer.suspend();

    try {
      template.requestBody(serverUri, "Moon", String.class);
      fail("Should throw exception");
    } catch (Exception e) {
      HttpOperationFailedException cause =
          assertIsInstanceOf(HttpOperationFailedException.class, e.getCause());
      assertEquals(503, cause.getStatusCode());
    }
  }