davsclaus commented on code in PR #27629: URL: https://github.com/apache/camel/pull/27629#discussion_r4236603955
########## dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/java/org/apache/camel/dsl/yaml/RouteConfigurationYamlDumpTest.java: ########## @@ -0,0 +1,83 @@ +/* + * 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.dsl.yaml; + +import org.apache.camel.dsl.yaml.support.YamlTestSupport; +import org.apache.camel.model.Model; +import org.apache.camel.model.RouteConfigurationDefinition; +import org.apache.camel.model.RouteConfigurationsDefinition; +import org.apache.camel.yaml.LwModelToYAMLDumper; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +class RouteConfigurationYamlDumpTest extends YamlTestSupport { + + @Test + void routeConfigurationIsDumpedAsTheYamlDslLoadsIt() throws Exception { + loadRoutes(""" + - routeConfiguration: + id: myConfig + onException: + - onException: + exception: + - java.lang.Exception + handled: + constant: "true" + steps: + - to: mock:error + onCompletion: + - onCompletion: + steps: + - to: mock:completed + interceptSendToEndpoint: + - interceptSendToEndpoint: + uri: "mock:result*" + steps: + - to: mock:send + interceptFrom: + - interceptFrom: + uri: "direct*" + steps: + - to: mock:from + intercept: + - intercept: + steps: + - to: mock:intercept + """); + Model model = context.getCamelContextExtension().getContextPlugin(Model.class); + + // as the route configurations are dumped by camel.main.dumpRoutes, which camel validate normalize uses + RouteConfigurationsDefinition configs = new RouteConfigurationsDefinition(); + configs.getRouteConfigurations().addAll(model.getRouteConfigurationDefinitions()); + String yaml = new LwModelToYAMLDumper().dumpModelAsYaml(context, configs, false, true, false, false); + + // the dump is valid for the YAML DSL schema and loads with the same content + model.removeRouteConfiguration(model.getRouteConfigurationDefinition("myConfig")); + loadRoutes(yaml); + RouteConfigurationDefinition config = model.getRouteConfigurationDefinition("myConfig"); + assertThat(config).isNotNull(); + assertThat(config.getOnExceptions()).singleElement() + .satisfies(oe -> assertThat(oe.getExceptions()).containsExactly("java.lang.Exception")); + assertThat(config.getOnCompletions()).hasSize(1); + assertThat(config.getInterceptSendTos()).singleElement() + .satisfies(i -> assertThat(i.getUri()).isEqualTo("mock:result*")); + assertThat(config.getInterceptFroms()).singleElement() + .satisfies(i -> assertThat(i.getUri()).isEqualTo("direct*")); + assertThat(config.getIntercepts()).hasSize(1); Review Comment: Optional: `onCompletion` and `intercept` only get a size check, and `handled` and the steps are not checked. A stronger check, the one `YamlRoundTripTest` (camel-yaml-dsl-validator) uses, is to dump the route configuration with `LwModelToXMLDumper` before and after the reload and compare the two strings. That catches any field that gets lost on the way. A route-configuration variant of `YamlRoundTripTest` over `errorHandlerConfiguration*.xml` could be a follow-up too. ########## tooling/maven/camel-package-maven-plugin/src/main/resources/velocity/model-yaml-writer.vm: ########## @@ -17,6 +17,9 @@ #set( $default = "#[[##default]]#" ) ## the YAML DSL names some lists other than the XML DSL does (keyed by class.member) #set( $yamlKeys = { "VerbDefinition.params": "param", "VerbDefinition.responseMsgs": "responseMessage", "RouteTemplateDefinition.templateParameters": "parameters", "RouteTemplateDefinition.templateBeans": "beans" } ) +## the YAML DSL reads each item of some lists as a one-key map named after the list (wrapItem = true in the YAML DSL +## deserializer), such as - onException: ... in a route configuration (keyed by class.member) +#set( $wrapItems = [ "RouteConfigurationDefinition.intercepts", "RouteConfigurationDefinition.interceptFroms", "RouteConfigurationDefinition.interceptSendTos", "RouteConfigurationDefinition.onCompletions", "RouteConfigurationDefinition.onExceptions" ] ) Review Comment: Optional: this list repeats the `wrapItem = true` properties of `RouteConfigurationDefinitionDeserializer` by hand, as `$yamlKeys` does for the renamed lists, so the two can drift apart if another YAML property gets `wrapItem` later. A small guard test in camel-yaml-dsl (or a comment on the `@YamlProperty`s of the deserializer pointing back here) would catch that. Fine to leave for later. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
