[ 
https://issues.apache.org/jira/browse/CAMEL-21962?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17944286#comment-17944286
 ] 

Aurélien Pupier commented on CAMEL-21962:
-----------------------------------------

current attempt by using ConfigurableContext interface and configureContext are 
failing:

{noformat}
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.camel.example;

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

import java.util.Properties;
import java.util.concurrent.TimeUnit;

import org.apache.camel.builder.NotifyBuilder;
import org.apache.camel.main.MainConfigurationProperties;
import org.apache.camel.test.junit5.CamelContextConfiguration;
import org.apache.camel.test.junit5.ConfigurableContext;
import org.apache.camel.test.main.junit5.CamelMainTestSupport;
import org.junit.jupiter.api.Test;

/**
 * A unit test checking that the compiled simple expressions are evaluated as 
expected.
 */
class CSimpleTest extends CamelMainTestSupport implements ConfigurableContext {

    @Override
    public void configureContext(CamelContextConfiguration 
camelContextConfiguration) {
        Properties properties = new Properties();
        properties.put("myPeriod", Integer.toString(500));
        
camelContextConfiguration.useOverridePropertiesWithPropertiesComponent();
                
camelContextConfiguration.withUseOverridePropertiesWithPropertiesComponent(properties);
    }

    @Test
    void should_be_evaluated() {
        NotifyBuilder notify = new 
NotifyBuilder(context).from("timer:*").whenCompleted(5).create();

        assertTrue(
            notify.matches(5, TimeUnit.SECONDS), "5 messages should be 
completed"
        );
    }

    @Override
    protected void configure(MainConfigurationProperties configuration) {
        configuration.addRoutesBuilder(MyRouteBuilder.class);
    }
}
{noformat}

{noformat}
java.lang.NullPointerException: Cannot invoke 
"org.apache.camel.test.junit5.CamelContextConfiguration$CamelContextSupplier.createCamelContext()"
 because the return value of 
"org.apache.camel.test.junit5.CamelContextConfiguration.camelContextSupplier()" 
is null
        at 
org.apache.camel.test.junit5.TransientCamelContextManager.initialize(TransientCamelContextManager.java:87)
        at 
org.apache.camel.test.junit5.TransientCamelContextManager.createCamelContext(TransientCamelContextManager.java:66)
        at 
org.apache.camel.test.junit5.CamelTestSupport.setUp(CamelTestSupport.java:150)
        at java.base/java.lang.reflect.Method.invoke(Unknown Source)
        at java.base/java.util.ArrayList.forEach(Unknown Source)
        at java.base/java.util.ArrayList.forEach(Unknown Source)
{noformat}



> CSimpleTest is failing in camel-examples repository
> ---------------------------------------------------
>
>                 Key: CAMEL-21962
>                 URL: https://issues.apache.org/jira/browse/CAMEL-21962
>             Project: Camel
>          Issue Type: Bug
>          Components: examples
>            Reporter: Aurélien Pupier
>            Priority: Major
>
> {noformat}
> org.apache.camel.PropertyBindingException: Error binding property 
> (camel.main.lightweight=true) with name: lightweight on bean: 
> org.apache.camel.main.MainConfigurationProperties@1deb2c43 with value: true
>       at 
> org.apache.camel.main.MainHelper.setPropertiesOnTarget(MainHelper.java:380)
>       at 
> org.apache.camel.main.BaseMainSupport.autoConfigurationMainConfiguration(BaseMainSupport.java:2388)
>       at 
> org.apache.camel.main.BaseMainSupport.autoconfigure(BaseMainSupport.java:566)
>       at org.apache.camel.main.MainSupport.autoconfigure(MainSupport.java:79)
>       at 
> org.apache.camel.main.BaseMainSupport.postProcessCamelContext(BaseMainSupport.java:919)
>       at 
> org.apache.camel.test.main.junit5.MainForTest.init(MainForTest.java:46)
>       at 
> org.apache.camel.test.main.junit5.CamelMainTestSupport.createCamelContext(CamelMainTestSupport.java:147)
>       at 
> org.apache.camel.test.junit5.TransientCamelContextManager.initialize(TransientCamelContextManager.java:87)
>       at 
> org.apache.camel.test.junit5.TransientCamelContextManager.createCamelContext(TransientCamelContextManager.java:66)
>       at 
> org.apache.camel.test.junit5.CamelTestSupport.setUp(CamelTestSupport.java:150)
>       at java.base/java.lang.reflect.Method.invoke(Unknown Source)
>       at java.base/java.util.ArrayList.forEach(Unknown Source)
>       at java.base/java.util.ArrayList.forEach(Unknown Source)
> {noformat}
> it seems to be related to the changes in 4.9 
> https://camel.apache.org/blog/2024/10/modernizing-test-code-how-to/
> the method useOverridePropertiesWithPropertiesComponent 
> https://github.com/apache/camel-examples/blob/09051c7c8d33f34ec933ecde67456cff67f6fc59/csimple/src/test/java/org/apache/camel/example/CSimpleTest.java#L36
>  is now deprecated (and dos't seem to work anymore)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to