CAMEL-6981: Include customId attribute in route model XML so we can know if the 
id is auto assigned or custom id.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/08ef2a43
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/08ef2a43
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/08ef2a43

Branch: refs/heads/master
Commit: 08ef2a438ca1701ced51645b240ea6457f643a01
Parents: 673384e
Author: Claus Ibsen <davscl...@apache.org>
Authored: Tue Nov 19 14:28:24 2013 +0100
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Tue Nov 19 14:28:24 2013 +0100

----------------------------------------------------------------------
 .../model/OptionalIdentifiedDefinition.java     | 15 +++--
 .../model/GenerateXmFromCamelContextTest.java   | 65 ++++++++++++++++++++
 .../model/GenerateXmFromCamelContextlTest.java  | 65 --------------------
 .../util/DumpModelAsXmlTransformRouteTest.java  |  3 +-
 4 files changed, 78 insertions(+), 70 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/08ef2a43/camel-core/src/main/java/org/apache/camel/model/OptionalIdentifiedDefinition.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/OptionalIdentifiedDefinition.java
 
b/camel-core/src/main/java/org/apache/camel/model/OptionalIdentifiedDefinition.java
index 33b00b9..f48097b 100644
--- 
a/camel-core/src/main/java/org/apache/camel/model/OptionalIdentifiedDefinition.java
+++ 
b/camel-core/src/main/java/org/apache/camel/model/OptionalIdentifiedDefinition.java
@@ -20,7 +20,6 @@ import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlTransient;
 import javax.xml.bind.annotation.XmlType;
 
 import org.apache.camel.NamedNode;
@@ -35,8 +34,7 @@ import org.apache.camel.spi.NodeIdFactory;
 @XmlAccessorType(XmlAccessType.PROPERTY)
 public abstract class OptionalIdentifiedDefinition<T extends 
OptionalIdentifiedDefinition<T>> implements NamedNode {
     private String id;
-    @XmlTransient
-    private boolean customId;
+    private Boolean customId;
     private DescriptionDefinition description;
 
     /**
@@ -128,11 +126,20 @@ public abstract class OptionalIdentifiedDefinition<T 
extends OptionalIdentifiedD
         return getId();
     }
 
+    public Boolean isCustomId() {
+        return customId;
+    }
+
+    @XmlAttribute
+    public void setCustomId(Boolean customId) {
+        this.customId = customId;
+    }
+
     /**
      * Returns whether a custom id has been assigned
      */
     public boolean hasCustomIdAssigned() {
-        return customId;
+        return customId != null && customId;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/camel/blob/08ef2a43/camel-core/src/test/java/org/apache/camel/model/GenerateXmFromCamelContextTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/model/GenerateXmFromCamelContextTest.java
 
b/camel-core/src/test/java/org/apache/camel/model/GenerateXmFromCamelContextTest.java
new file mode 100644
index 0000000..b711b10
--- /dev/null
+++ 
b/camel-core/src/test/java/org/apache/camel/model/GenerateXmFromCamelContextTest.java
@@ -0,0 +1,65 @@
+/**
+ * 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.model;
+
+import java.io.StringWriter;
+import java.util.List;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version 
+ */
+public class GenerateXmFromCamelContextTest extends ContextTestSupport {
+
+    public void testCreateRouteFromCamelContext() throws Exception {
+        List<RouteDefinition> list = context.getRouteDefinitions();
+        assertEquals("Size of list " + list, 1, list.size());
+        RouteDefinition routeType = list.get(0);
+
+        log.info("Found route: " + routeType);
+
+        // now lets marshall it!
+        dump(routeType);
+    }
+
+    protected void dump(Object object) throws Exception {
+        JAXBContext jaxbContext = XmlTestSupport.createJaxbContext();
+        Marshaller marshaller = jaxbContext.createMarshaller();
+        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
+        StringWriter buffer = new StringWriter();
+        marshaller.marshal(object, buffer);
+        log.info("Created: " + buffer);
+        assertNotNull(buffer);
+        String out = buffer.toString();
+        assertTrue("Should contain the description", out.indexOf("<from 
uri=\"direct:start\"/>") > 0);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").filter().xpath("/foo/bar = 
'abc'").to("mock:result");
+            }
+        };
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/08ef2a43/camel-core/src/test/java/org/apache/camel/model/GenerateXmFromCamelContextlTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/model/GenerateXmFromCamelContextlTest.java
 
b/camel-core/src/test/java/org/apache/camel/model/GenerateXmFromCamelContextlTest.java
deleted file mode 100644
index bd9223b..0000000
--- 
a/camel-core/src/test/java/org/apache/camel/model/GenerateXmFromCamelContextlTest.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/**
- * 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.model;
-
-import java.io.StringWriter;
-import java.util.List;
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.Marshaller;
-
-import org.apache.camel.ContextTestSupport;
-import org.apache.camel.builder.RouteBuilder;
-
-/**
- * @version 
- */
-public class GenerateXmFromCamelContextlTest extends ContextTestSupport {
-
-    public void testCreateRouteFromCamelCOntext() throws Exception {
-        List<RouteDefinition> list = context.getRouteDefinitions();
-        assertEquals("Size of list " + list, 1, list.size());
-        RouteDefinition routeType = list.get(0);
-
-        log.info("Found route: " + routeType);
-
-        // now lets marshall it!
-        dump(routeType);
-    }
-
-    protected void dump(Object object) throws Exception {
-        JAXBContext jaxbContext = XmlTestSupport.createJaxbContext();
-        Marshaller marshaller = jaxbContext.createMarshaller();
-        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
-        StringWriter buffer = new StringWriter();
-        marshaller.marshal(object, buffer);
-        log.info("Created: " + buffer);
-        assertNotNull(buffer);
-        String out = buffer.toString();
-        assertTrue("Should contain the description", out.indexOf("<from 
uri=\"direct:start\"/>") > 0);
-    }
-
-    @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                from("direct:start").filter().xpath("/foo/bar = 
'abc'").to("mock:result");
-            }
-        };
-
-    }
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/08ef2a43/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlTransformRouteTest.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlTransformRouteTest.java
 
b/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlTransformRouteTest.java
index d324171..f63f7bb 100644
--- 
a/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlTransformRouteTest.java
+++ 
b/camel-core/src/test/java/org/apache/camel/util/DumpModelAsXmlTransformRouteTest.java
@@ -31,6 +31,7 @@ public class DumpModelAsXmlTransformRouteTest extends 
ContextTestSupport {
         log.info(xml);
 
         assertTrue(xml.contains("<simple>Hello ${body}</simple>"));
+        assertTrue(xml.contains("<to uri=\"mock:result\" customId=\"true\" 
id=\"myMock\"/>"));
     }
 
     @Override
@@ -40,7 +41,7 @@ public class DumpModelAsXmlTransformRouteTest extends 
ContextTestSupport {
             public void configure() throws Exception {
                 from("direct:start").routeId("myRoute")
                    .transform().simple("Hello ${body}")
-                   .to("mock:result");
+                   .to("mock:result").id("myMock");
             }
         };
     }

Reply via email to