[ 
https://issues.apache.org/jira/browse/CAMEL-21427?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Adriano Machado updated CAMEL-21427:
------------------------------------
    Description: Pull request contains test showing the issue  (was: Here's a 
unit test showing the problem:

 
{code:java}
package org.apache.camel.yaml.out;

import java.io.ByteArrayInputStream;
import java.io.StringWriter;
import java.nio.charset.Charset;
import java.util.Optional;

import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.model.RoutesDefinition;
import org.apache.camel.xml.in.ModelParser;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class XPathNamespacesTest {

    @Test
    void test() throws Exception {
        try (ByteArrayInputStream is = new 
ByteArrayInputStream(XML.getBytes(Charset.defaultCharset()))) {
            Optional<RoutesDefinition> routesDefinition = new ModelParser(is, 
XmlToYamlTest.NAMESPACE).parseRoutesDefinition();
            assertThat(routesDefinition).isPresent()
                    .get(InstanceOfAssertFactories.type(RoutesDefinition.class))
                    .extracting(RoutesDefinition::getRoutes, 
InstanceOfAssertFactories.list(RouteDefinition.class))
                    .singleElement()
                    .extracting(RouteDefinition::getOutputs, 
InstanceOfAssertFactories.list(ProcessorDefinition.class))
                    .hasSize(3);

            StringWriter sw = new StringWriter();
            new 
org.apache.camel.yaml.out.ModelWriter(sw).writeRoutesDefinition(routesDefinition.get());

            assertThat(sw).hasToString(EXPECTED_YAML);
        }
    }

    //language=XML
    private static final String XML = """
            <routes xmlns="http://camel.apache.org/schema/spring";
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
                    xmlns:routes-ns-def="http://www.example.com/schema";
                    xsi:schemaLocation="http://camel.apache.org/schema/spring 
https://camel.apache.org/schema/spring/camel-spring.xsd";>
            
                <route id="direct:route-with-xpath-expression-custom-namespace"
                       xmlns:route-ns-def="http://www.example.com/schema";>
            
                    <from 
uri="direct:route-with-xpath-expression-custom-namespace"/>
            
                    <setProperty name="child-expression-namespace-from-routes">
                        <xpath saxon="true" 
resultType="java.lang.String">/routes-ns-def:parent/routes-ns-def:child</xpath>
                    </setProperty>
            
                    <setProperty name="child-expression-namespace-from-route">
                        <xpath saxon="true" 
resultType="java.lang.String">/route-ns-def:parent/route-ns-def:child</xpath>
                    </setProperty>
            
                    <setProperty name="child-expression-namespace-from-xpath">
                        <xpath saxon="true" resultType="java.lang.String" 
xmlns:expression-ns-def="http://www.example.com/schema";>/expression-ns-def:parent/expression-ns-def:child</xpath>
                    </setProperty>
                </route>
            
            </routes>
            """;
    
    //language=yaml
    private static final String EXPECTED_YAML = """
            - route:
                id: direct:route-with-xpath-expression-custom-namespace
                from:
                  uri: direct:route-with-xpath-expression-custom-namespace
                  steps:
                    - setProperty:
                        name: child-expression-namespace-from-routes
                        xpath:
                          resultType: java.lang.String
                          saxon: "true"
                          namespace:
                            xsi: http://www.w3.org/2001/XMLSchema-instance
                            routes-ns-def: http://www.example.com/schema
                            route-ns-def: http://www.example.com/schema
                          expression: /routes-ns-def:parent/routes-ns-def:child
                    - setProperty:
                        name: child-expression-namespace-from-route
                        xpath:
                          resultType: java.lang.String
                          saxon: "true"
                          namespace:
                            xsi: http://www.w3.org/2001/XMLSchema-instance
                            routes-ns-def: http://www.example.com/schema
                            route-ns-def: http://www.example.com/schema
                          expression: /route-ns-def:parent/route-ns-def:child
                    - setProperty:
                        name: child-expression-namespace-from-xpath
                        xpath:
                          resultType: java.lang.String
                          saxon: "true"
                          namespace:
                            xsi: http://www.w3.org/2001/XMLSchema-instance
                            routes-ns-def: http://www.example.com/schema
                            route-ns-def: http://www.example.com/schema
                            expression-ns-def: http://www.example.com/schema
                          expression: 
/expression-ns-def:parent/expression-ns-def:child
            """;
}
 {code})

> XML model serializer is serializing default values
> --------------------------------------------------
>
>                 Key: CAMEL-21427
>                 URL: https://issues.apache.org/jira/browse/CAMEL-21427
>             Project: Camel
>          Issue Type: Bug
>          Components: camel-xml-io
>    Affects Versions: 4.8.1
>            Reporter: Adriano Machado
>            Assignee: Claus Ibsen
>            Priority: Major
>
> Pull request contains test showing the issue



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

Reply via email to