Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.camel.component.mock.MockEndpoint;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class DavidSiefertTest extends ContextTestSupport {
protected static final Object expectedBody = "Some Output";
Expand All @@ -40,16 +40,15 @@ public void testWorks() throws Exception {
}

@Test
public void testHeaderPredicateFails() throws Exception {
public void testHeaderPredicateFails() {
MockEndpoint result = getMockEndpoint("mock:result");
result.message(0).header("sample.name").isEqualTo("shouldNotMatch");
template.sendBody("direct:start", "<sample><name>value</name></sample>");
try {
result.assertIsSatisfied();
fail("Should have failed this test!");
} catch (AssertionError e) {
log.info("Caught expected assertion failure: {}", e, e);
}

AssertionError e = assertThrows(AssertionError.class, result::assertIsSatisfied,
"Should have failed this test!");

log.info("Caught expected assertion failure: {}", e, e);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,21 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class MockExpectedHeaderNoMessageSentTest extends ContextTestSupport {

@Test
public void testHeaderExpectedNoMessageSent() throws Exception {
public void testHeaderExpectedNoMessageSent() {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.setResultWaitTime(100); // run test quick

mock.expectedHeaderReceived("foo", "bar");

try {
mock.assertIsSatisfied();
fail("Should fail");
} catch (AssertionError e) {
assertEquals("mock://result Received message count 0, expected at least 1", e.getMessage());
}
AssertionError e = assertThrows(AssertionError.class, mock::assertIsSatisfied,
"Should fail");

assertEquals("mock://result Received message count 0, expected at least 1", e.getMessage());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
*
Expand All @@ -37,13 +37,12 @@ public void testOnExceptionErrorHandlerRef() throws Exception {
getMockEndpoint("mock:handled").expectedMessageCount(1);
getMockEndpoint("mock:dead").expectedMessageCount(0);

try {
template.sendBody("direct:start", "Hello World");
fail("Should have thrown exception");
} catch (CamelExecutionException e) {
IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertEquals("Damn", cause.getMessage());
}
CamelExecutionException e = assertThrows(CamelExecutionException.class,
() -> template.sendBody("direct:start", "Hello World"),
"Should have thrown exception");

IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertEquals("Damn", cause.getMessage());

assertMockEndpointsSatisfied();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
*
Expand All @@ -37,13 +37,12 @@ public void testOnExceptionErrorHandlerRef() throws Exception {
getMockEndpoint("mock:handled").expectedMessageCount(1);
getMockEndpoint("mock:dead").expectedMessageCount(0);

try {
template.sendBody("direct:start", "Hello World");
fail("Should have thrown exception");
} catch (CamelExecutionException e) {
IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertEquals("Damn", cause.getMessage());
}
CamelExecutionException e = assertThrows(CamelExecutionException.class,
() -> template.sendBody("direct:start", "Hello World"),
"Should have thrown exception");

IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertEquals("Damn", cause.getMessage());

assertMockEndpointsSatisfied();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
*
Expand All @@ -37,13 +37,12 @@ public void testOnExceptionErrorHandlerRef() throws Exception {
getMockEndpoint("mock:handled").expectedMessageCount(1);
getMockEndpoint("mock:dead").expectedMessageCount(0);

try {
template.sendBody("direct:start", "Hello World");
fail("Should have thrown exception");
} catch (CamelExecutionException e) {
IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertEquals("Damn", cause.getMessage());
}
CamelExecutionException e = assertThrows(CamelExecutionException.class,
() -> template.sendBody("direct:start", "Hello World"),
"Should have thrown exception");

IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertEquals("Damn", cause.getMessage());

assertMockEndpointsSatisfied();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
*
Expand All @@ -37,13 +37,12 @@ public void testOnExceptionErrorHandlerRef() throws Exception {
getMockEndpoint("mock:handled").expectedMessageCount(1);
getMockEndpoint("mock:dead").expectedMessageCount(0);

try {
template.sendBody("direct:start", "Hello World");
fail("Should have thrown exception");
} catch (CamelExecutionException e) {
IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertEquals("Damn", cause.getMessage());
}
CamelExecutionException e = assertThrows(CamelExecutionException.class,
() -> template.sendBody("direct:start", "Hello World"),
"Should have thrown exception");

IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause());
assertEquals("Damn", cause.getMessage());

assertMockEndpointsSatisfied();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class RecipientListShareUnitOfWorkOnExceptionHandledFalseIssueTest extends ContextTestSupport {

Expand All @@ -32,13 +32,12 @@ public void testRecipientList() throws Exception {
getMockEndpoint("mock:c").expectedMessageCount(1);
getMockEndpoint("mock:result").expectedMessageCount(0);

try {
template.sendBodyAndHeader("direct:start", "Hello World", "foo", "direct:b,direct:c");
fail("Should throw exception");
} catch (Exception e) {
IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause());
assertEquals("Forced", cause.getMessage());
}
Exception e = assertThrows(Exception.class,
() -> template.sendBodyAndHeader("direct:start", "Hello World", "foo", "direct:b,direct:c"),
"Should throw exception");

IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause());
assertEquals("Forced", cause.getMessage());

assertMockEndpointsSatisfied();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,13 @@ protected void assertErrorHandlingWorks(String route) throws Exception {
resultEndpoint.expectedMessageCount(0);
exceptionEndpoint.expectedBodiesReceived("<exception/>");

try {
template.sendBodyAndHeader("direct:start", "<body/>", "route", route);
fail("Should have thrown exception");
} catch (RuntimeCamelException e) {
boolean b = e.getCause() instanceof IllegalArgumentException;
assertTrue(b);
assertEquals("Exception thrown intentionally.", e.getCause().getMessage());
}
RuntimeCamelException e = assertThrows(RuntimeCamelException.class,
() -> template.sendBodyAndHeader("direct:start", "<body/>", "route", route),
"Should have thrown exception");

boolean b = e.getCause() instanceof IllegalArgumentException;
assertTrue(b);
assertEquals("Exception thrown intentionally.", e.getCause().getMessage());

assertMockEndpointsSatisfied();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* Based on user forum issue
Expand All @@ -51,13 +51,12 @@ public void configure() {
// we fail all redeliveries so after that we send to mock:exhausted
getMockEndpoint("mock:exhausted").expectedMessageCount(1);

try {
template.sendBody("direct:start", "Hello World");
fail("Should thrown an exception");
} catch (CamelExecutionException e) {
ConnectException cause = assertIsInstanceOf(ConnectException.class, e.getCause());
assertEquals("Forced", cause.getMessage());
}
CamelExecutionException e = assertThrows(CamelExecutionException.class,
() -> template.sendBody("direct:start", "Hello World"),
"Should thrown an exception");

ConnectException cause = assertIsInstanceOf(ConnectException.class, e.getCause());
assertEquals("Forced", cause.getMessage());

assertMockEndpointsSatisfied();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;

/**
* Based on user forum issue
Expand All @@ -50,13 +50,12 @@ public void configure() {
// we fail all redeliveries so after that we send to mock:exhausted
getMockEndpoint("mock:exhausted").expectedMessageCount(1);

try {
template.sendBody("direct:start", "Hello World");
fail("Should thrown an exception");
} catch (CamelExecutionException e) {
ConnectException cause = assertIsInstanceOf(ConnectException.class, e.getCause());
assertEquals("Forced", cause.getMessage());
}
CamelExecutionException e = assertThrows(CamelExecutionException.class,
() -> template.sendBody("direct:start", "Hello World"),
"Should thrown an exception");

ConnectException cause = assertIsInstanceOf(ConnectException.class, e.getCause());
assertEquals("Forced", cause.getMessage());

assertMockEndpointsSatisfied();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,7 @@ public void configure() {
}
});

try {
context.start();
} catch (Exception e) {
// should fail
}
assertThrows(Exception.class, () -> context.start(), "Should fail");

assertTrue(context.getRouteController().getRouteStatus("foo").isStopped());
assertFalse(context.getRouteController().getRouteStatus("foo").isStarted());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;

public class SplitShareUnitOfWorkOnExceptionHandledFalseIssueTest extends ContextTestSupport {

Expand All @@ -31,13 +31,11 @@ public void testSplit() throws Exception {
getMockEndpoint("mock:b").expectedMessageCount(2);
getMockEndpoint("mock:result").expectedMessageCount(0);

try {
template.sendBody("direct:start", "Camel,Donkey");
fail("Should throw exception");
} catch (Exception e) {
IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause());
assertEquals("Forced", cause.getMessage());
}
Exception e = assertThrows(Exception.class, () -> template.sendBody("direct:start", "Camel,Donkey"),
"Should throw exception");

IllegalArgumentException cause = assertIsInstanceOf(IllegalArgumentException.class, e.getCause().getCause());
assertEquals("Forced", cause.getMessage());

assertMockEndpointsSatisfied();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.apache.camel.builder.RouteBuilder;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class SplitterParallelRuntimeExceptionInHasNextOrNextTest extends ContextTestSupport {
Expand All @@ -50,12 +51,12 @@ public void testSplitErrorInNext() throws Exception {

private void execute(String from) throws InterruptedException {
for (int i = 0; i < 10; i++) {
try {
template.sendBody(from, "some content");
} catch (Exception e) {
// expected due to runtime exception in hasNext method
assertTrue(e.getMessage().startsWith("Exception occurred"));
}

Exception e = assertThrows(Exception.class, () -> template.sendBody(from, "some content"),
"expected due to runtime exception in hasNext method");

assertTrue(e.getMessage().startsWith("Exception occurred"));

assertMockEndpointsSatisfied();
}
}
Expand Down
Loading