Search code examples
citrus-framework

Customize function by using JavaDSL


I would like to know how can I create a customize function in java code instead of XML? I know how to add my function in the XML function library. But is there another way to add to the library in code?


Solution

  • You can add function libraries as Spring Beans to the application context. This is all you have to do in order to use your custom functions in Citrus:

    @Bean
    public FunctionLibrary customFunctionLib() {
        FunctionLibrary functionLibrary = new FunctionLibrary();
    
        functionLibrary.setPrefix("foolib:");
        functionLibrary.setName("fooFunctionLibrary");
    
        functionLibrary.getMembers().put("fooFunction", new FooFunction());
        return functionLibrary;
    }
    

    After that you should be able to call the function with foolib:fooFunction().