[CAMEL-9636] Fail fast in case of empty cm:property-placeholder + test (cherry picked from commit e15603a977b825a89fcad20b8da0a8ba59d982d3)
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/28bf2484 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/28bf2484 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/28bf2484 Branch: refs/heads/camel-2.15.x Commit: 28bf2484c88fcbd33774aad4c67745f7901f0a03 Parents: b5cfe4d Author: Grzegorz Grzybek <gr.grzy...@gmail.com> Authored: Wed Feb 24 14:27:25 2016 +0100 Committer: Grzegorz Grzybek <gr.grzy...@gmail.com> Committed: Wed Feb 24 18:21:08 2016 +0100 ---------------------------------------------------------------------- .../test/blueprint/CamelBlueprintHelper.java | 19 ++++++++++--- .../blueprint/CamelBlueprintTestSupport.java | 6 ++-- ...minNoDefaultValuesBlueprintCreationTest.java | 29 ++++++++------------ 3 files changed, 28 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/28bf2484/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java index 8cc8ef2..4466246 100644 --- a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java +++ b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintHelper.java @@ -314,13 +314,20 @@ public final class CamelBlueprintHelper { final String symbolicName, final int bpEvent, final Runnable runAndWait) throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); + final Throwable[] pThrowable = new Throwable[] {null}; ServiceRegistration<BlueprintListener> registration = context.registerService(BlueprintListener.class, new BlueprintListener() { @Override public void blueprintEvent(BlueprintEvent event) { - if (event.getType() == bpEvent && event.getBundle().getSymbolicName().equals(symbolicName)) { - // we skip events that we've already seen - // it works with BP container reloads if next CREATE state is at least 1ms after previous one - if (eventHistory == null || eventHistory.add(event.getTimestamp())) { + if (event.getBundle().getSymbolicName().equals(symbolicName)) { + if (event.getType() == bpEvent) { + // we skip events that we've already seen + // it works with BP container reloads if next CREATE state is at least 1ms after previous one + if (eventHistory == null || eventHistory.add(event.getTimestamp())) { + latch.countDown(); + } + } else if (event.getType() == BlueprintEvent.FAILURE) { + // we didn't wait for FAILURE, but we got it - fail fast then + pThrowable[0] = event.getCause(); latch.countDown(); } } @@ -331,6 +338,10 @@ public final class CamelBlueprintHelper { } latch.await(CamelBlueprintHelper.DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS); registration.unregister(); + + if (pThrowable[0] != null) { + throw new RuntimeException(pThrowable[0].getMessage(), pThrowable[0]); + } } protected static TinyBundle createTestBundle(String name, String version, String descriptors, String[] ... configAdminPidFiles) throws IOException { http://git-wip-us.apache.org/repos/asf/camel/blob/28bf2484/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java index 48bc05d..adda7bf 100644 --- a/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java +++ b/components/camel-test-blueprint/src/main/java/org/apache/camel/test/blueprint/CamelBlueprintTestSupport.java @@ -144,10 +144,8 @@ public abstract class CamelBlueprintTestSupport extends CamelTestSupport { // to the same state of BP container Set<Long> bpEvents = new HashSet<Long>(); - if (!expectReload) { - CamelBlueprintHelper.waitForBlueprintContainer(bpEvents, answer, symbolicName, BlueprintEvent.CREATED, null); - } - + CamelBlueprintHelper.waitForBlueprintContainer(bpEvents, answer, symbolicName, BlueprintEvent.CREATED, null); + // must reuse props as we can do both load from .cfg file and override afterwards final Dictionary props = new Properties(); http://git-wip-us.apache.org/repos/asf/camel/blob/28bf2484/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminNoDefaultValuesBlueprintCreationTest.java ---------------------------------------------------------------------- diff --git a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminNoDefaultValuesBlueprintCreationTest.java b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminNoDefaultValuesBlueprintCreationTest.java index 8ace8c9..260d2e1 100644 --- a/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminNoDefaultValuesBlueprintCreationTest.java +++ b/components/camel-test-blueprint/src/test/java/org/apache/camel/test/blueprint/ConfigAdminNoDefaultValuesBlueprintCreationTest.java @@ -16,18 +16,23 @@ */ package org.apache.camel.test.blueprint; -import java.util.Dictionary; - import org.junit.Test; +import static org.hamcrest.CoreMatchers.equalTo; + /** - * + * A test showing that if Blueprint XML contains property placeholders, some property source has to be defined. */ public class ConfigAdminNoDefaultValuesBlueprintCreationTest extends CamelBlueprintTestSupport { @Override - protected boolean expectBlueprintContainerReloadOnConfigAdminUpdate() { - return true; + public void setUp() throws Exception { + try { + super.setUp(); + fail("Should fail, because Blueprint XML uses property placeholders, but we didn't define any property sources"); + } catch (Exception e) { + assertThat(e.getCause().getCause().getMessage(), equalTo("Property placeholder key: destination not found")); + } } @Override @@ -35,20 +40,8 @@ public class ConfigAdminNoDefaultValuesBlueprintCreationTest extends CamelBluepr return "org/apache/camel/test/blueprint/configadmin-endpoint-no-defaults.xml"; } - @Override - protected String useOverridePropertiesWithConfigAdmin(Dictionary props) throws Exception { - props.put("greeting", "Bye"); - props.put("destination", "mock:result"); - return "my-placeholders"; - } - @Test - public void testConfigAdmin() throws Exception { - getMockEndpoint("mock:result").expectedBodiesReceived("Bye World"); - - template.sendBody("direct:start", "World"); - - assertMockEndpointsSatisfied(); + public void test() throws Exception { } }