Search in sources :

Example 1 with CustomResolver

use of org.apache.camel.dsl.yaml.deserializers.CustomResolver in project camel-k-runtime by apache.

the class CronTest method testCronTimerActivation.

@ParameterizedTest
@MethodSource("parameters")
public void testCronTimerActivation(String code, String cronOverride) throws Exception {
    final Runtime runtime = Runtime.on(new DefaultCamelContext());
    runtime.getRegistry().bind("__camel_k_resolver", new CustomResolver());
    final YamlRoutesBuilderLoader loader = new YamlRoutesBuilderLoader();
    loader.setCamelContext(runtime.getCamelContext());
    loader.start();
    final CronSourceLoaderInterceptor interceptor = new CronSourceLoaderInterceptor();
    interceptor.setRuntime(runtime);
    interceptor.setOverridableComponents(cronOverride);
    final RouteBuilder builder = (RouteBuilder) loader.loadRoutesBuilder(ResourceHelper.fromBytes("my-cron.yaml", code.getBytes(StandardCharsets.UTF_8)));
    builder.addLifecycleInterceptor(interceptor);
    runtime.getCamelContext().addRoutes(builder);
    CountDownLatch termination = new CountDownLatch(1);
    runtime.getCamelContext().addLifecycleStrategy(new LifecycleStrategySupport() {

        @Override
        public void onContextStopped(CamelContext context) {
            termination.countDown();
        }
    });
    MockEndpoint mock = runtime.getCamelContext().getEndpoint("mock:result", MockEndpoint.class);
    mock.expectedMessageCount(1);
    mock.setResultWaitTime(10000);
    runtime.getCamelContext().start();
    mock.assertIsSatisfied();
    termination.await(10, TimeUnit.SECONDS);
    assertThat(termination.getCount()).isZero();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Runtime(org.apache.camel.k.Runtime) RouteBuilder(org.apache.camel.builder.RouteBuilder) LifecycleStrategySupport(org.apache.camel.support.LifecycleStrategySupport) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) YamlRoutesBuilderLoader(org.apache.camel.dsl.yaml.YamlRoutesBuilderLoader) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) CustomResolver(org.apache.camel.dsl.yaml.deserializers.CustomResolver) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 CamelContext (org.apache.camel.CamelContext)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)1 YamlRoutesBuilderLoader (org.apache.camel.dsl.yaml.YamlRoutesBuilderLoader)1 CustomResolver (org.apache.camel.dsl.yaml.deserializers.CustomResolver)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 Runtime (org.apache.camel.k.Runtime)1 LifecycleStrategySupport (org.apache.camel.support.LifecycleStrategySupport)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1