Repository: camel Updated Branches: refs/heads/master 1a4376925 -> b6ee9c91e
CAMEL-7265: Added api to get json of route static input and output endpoint uris. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b6ee9c91 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b6ee9c91 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b6ee9c91 Branch: refs/heads/master Commit: b6ee9c91ec32d76a5b8959f1495f3adacd9083f1 Parents: 1a43769 Author: Claus Ibsen <[email protected]> Authored: Tue Mar 4 11:00:20 2014 +0100 Committer: Claus Ibsen <[email protected]> Committed: Tue Mar 4 11:00:47 2014 +0100 ---------------------------------------------------------------------- .../java/org/apache/camel/CamelContext.java | 10 ++- .../mbean/ManagedCamelContextMBean.java | 3 + .../api/management/mbean/ManagedRouteMBean.java | 3 + .../apache/camel/impl/DefaultCamelContext.java | 59 +++++++++++++++++ .../management/mbean/ManagedCamelContext.java | 4 ++ .../camel/management/mbean/ManagedRoute.java | 4 ++ .../camel/model/EndpointRequiredDefinition.java | 29 +++++++++ .../apache/camel/model/EnrichDefinition.java | 11 +++- .../org/apache/camel/model/FromDefinition.java | 7 ++- .../camel/model/PollEnrichDefinition.java | 11 +++- .../camel/model/RouteDefinitionHelper.java | 37 ++++++++++- .../org/apache/camel/model/SendDefinition.java | 10 ++- .../apache/camel/model/WireTapDefinition.java | 14 ++++- .../org/apache/camel/util/StringHelper.java | 18 ++++++ .../management/ManagedCamelContextTest.java | 16 +++++ .../ManagedRouteDumpRouteAsXmlTest.java | 18 ++++++ .../model/GatherAllStaticEndpointUrisTest.java | 66 ++++++++++++++++++++ 17 files changed, 312 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/b6ee9c91/camel-core/src/main/java/org/apache/camel/CamelContext.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java b/camel-core/src/main/java/org/apache/camel/CamelContext.java index a9005bc..9232038 100644 --- a/camel-core/src/main/java/org/apache/camel/CamelContext.java +++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java @@ -251,7 +251,7 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration { /** * Gets a component from the context by name. * - * @param componentName the name of the component + * @param name the name of the component * @param autoCreateComponents whether or not the component should * be lazily created if it does not already exist * @return the component @@ -1251,6 +1251,14 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration { String getComponentDocumentation(String componentName) throws IOException; /** + * Creates a JSON representation of all the <b>static</b> configured endpoints defined in the given route(s). + * + * @param routeId for a particular route, or <tt>null</tt> for all routes + * @return a JSON string + */ + String createRouteStaticEndpointJson(String routeId); + + /** * Gets the {@link StreamCachingStrategy} to use. */ StreamCachingStrategy getStreamCachingStrategy(); http://git-wip-us.apache.org/repos/asf/camel/blob/b6ee9c91/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java index fb9cdc2..1befa4f 100644 --- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java +++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java @@ -258,4 +258,7 @@ public interface ManagedCamelContextMBean extends ManagedPerformanceCounterMBean @ManagedOperation(description = "Returns the HTML documentation for the given camel component") String getComponentDocumentation(String componentName) throws IOException; + @ManagedOperation(description = "Returns the JSON representation of all the static endpoints defined in all the routes") + String createRouteStaticEndpointJson(); + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/b6ee9c91/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRouteMBean.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRouteMBean.java b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRouteMBean.java index 0fb7ff0..2b45bd3 100644 --- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRouteMBean.java +++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedRouteMBean.java @@ -104,4 +104,7 @@ public interface ManagedRouteMBean extends ManagedPerformanceCounterMBean { @ManagedOperation(description = "Reset counters") void reset(boolean includeProcessors) throws Exception; + @ManagedOperation(description = "Returns the JSON representation of all the static endpoints defined in this route") + String createRouteStaticEndpointJson(); + } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/camel/blob/b6ee9c91/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java index e3f6ad2..c10563d 100644 --- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java +++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java @@ -132,6 +132,7 @@ import org.apache.camel.util.LoadPropertiesException; import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.ServiceHelper; import org.apache.camel.util.StopWatch; +import org.apache.camel.util.StringHelper; import org.apache.camel.util.TimeUtils; import org.apache.camel.util.URISupport; import org.slf4j.Logger; @@ -1056,6 +1057,64 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon return componentName.replaceAll("-", ""); } + public String createRouteStaticEndpointJson(String routeId) { + List<RouteDefinition> routes = new ArrayList<RouteDefinition>(); + if (routeId != null) { + RouteDefinition route = getRouteDefinition(routeId); + if (route == null) { + throw new IllegalArgumentException("Route with id " + routeId + " does not exist"); + } + routes.add(route); + } else { + routes.addAll(getRouteDefinitions()); + } + + StringBuilder buffer = new StringBuilder("{\n \"routes\": {"); + boolean firstRoute = true; + for (RouteDefinition route : routes) { + if (!firstRoute) { + buffer.append("\n },"); + } else { + firstRoute = false; + } + + String id = route.getId(); + buffer.append("\n \"" + id + "\": {"); + buffer.append("\n \"inputs\": ["); + Set<String> inputs = RouteDefinitionHelper.gatherAllStaticEndpointUris(route, true, false); + boolean first = true; + for (String input : inputs) { + if (!first) { + buffer.append(","); + } else { + first = false; + } + buffer.append("\n "); + buffer.append(StringHelper.toJson("uri", input, true)); + } + buffer.append("\n ]"); + + buffer.append(","); + buffer.append("\n \"outputs\": ["); + Set<String> outputs = RouteDefinitionHelper.gatherAllStaticEndpointUris(route, false, true); + first = true; + for (String output : outputs) { + if (!first) { + buffer.append(","); + } else { + first = false; + } + buffer.append("\n "); + buffer.append(StringHelper.toJson("uri", output, true)); + } + buffer.append("\n ]"); + } + buffer.append("\n }"); + buffer.append("\n }\n}\n"); + + return buffer.toString(); + } + // Helper methods // ----------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/b6ee9c91/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java index e12de9c..a20617d 100644 --- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java +++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java @@ -432,6 +432,10 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements Ti return context.getComponentDocumentation(componentName); } + public String createRouteStaticEndpointJson() { + return context.createRouteStaticEndpointJson(null); + } + public List<String> findComponentNames() throws Exception { Map<String, Properties> map = findComponents(); return new ArrayList<String>(map.keySet()); http://git-wip-us.apache.org/repos/asf/camel/blob/b6ee9c91/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java index 0b026a6..0f3fa57 100644 --- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java +++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java @@ -357,6 +357,10 @@ public class ManagedRoute extends ManagedPerformanceCounter implements TimerList } } + public String createRouteStaticEndpointJson() { + return getContext().createRouteStaticEndpointJson(getRouteId()); + } + @Override public boolean equals(Object o) { return this == o || (o != null && getClass() == o.getClass() && route.equals(((ManagedRoute)o).route)); http://git-wip-us.apache.org/repos/asf/camel/blob/b6ee9c91/camel-core/src/main/java/org/apache/camel/model/EndpointRequiredDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/EndpointRequiredDefinition.java b/camel-core/src/main/java/org/apache/camel/model/EndpointRequiredDefinition.java new file mode 100644 index 0000000..6144cfd --- /dev/null +++ b/camel-core/src/main/java/org/apache/camel/model/EndpointRequiredDefinition.java @@ -0,0 +1,29 @@ +/** + * 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; + +/** + * A {@link org.apache.camel.model.ProcessorDefinition} that requires to be configured with an {@link org.apache.camel.Endpoint} such + * as {@link org.apache.camel.model.SendDefinition}. + */ +public interface EndpointRequiredDefinition { + + /** + * Gets the uri of the endpoint used by this definition. + */ + String getEndpointUri(); +} http://git-wip-us.apache.org/repos/asf/camel/blob/b6ee9c91/camel-core/src/main/java/org/apache/camel/model/EnrichDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/EnrichDefinition.java b/camel-core/src/main/java/org/apache/camel/model/EnrichDefinition.java index 9cb88bf..64935bb 100644 --- a/camel-core/src/main/java/org/apache/camel/model/EnrichDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/EnrichDefinition.java @@ -38,7 +38,7 @@ import org.apache.camel.util.ObjectHelper; */ @XmlRootElement(name = "enrich") @XmlAccessorType(XmlAccessType.FIELD) -public class EnrichDefinition extends NoOutputDefinition<EnrichDefinition> { +public class EnrichDefinition extends NoOutputDefinition<EnrichDefinition> implements EndpointRequiredDefinition { @XmlAttribute(name = "uri") private String resourceUri; // TODO: For Camel 3.0 we should remove this ref attribute as you can do that in the uri, by prefixing with ref: @@ -86,6 +86,15 @@ public class EnrichDefinition extends NoOutputDefinition<EnrichDefinition> { } @Override + public String getEndpointUri() { + if (resourceUri != null) { + return resourceUri; + } else { + return null; + } + } + + @Override public Processor createProcessor(RouteContext routeContext) throws Exception { if (ObjectHelper.isEmpty(resourceUri) && ObjectHelper.isEmpty(resourceRef)) { throw new IllegalArgumentException("Either uri or ref must be provided for resource endpoint"); http://git-wip-us.apache.org/repos/asf/camel/blob/b6ee9c91/camel-core/src/main/java/org/apache/camel/model/FromDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/FromDefinition.java b/camel-core/src/main/java/org/apache/camel/model/FromDefinition.java index cfa0db6..f6fdf72 100644 --- a/camel-core/src/main/java/org/apache/camel/model/FromDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/FromDefinition.java @@ -34,7 +34,7 @@ import org.apache.camel.util.ObjectHelper; */ @XmlRootElement(name = "from") @XmlAccessorType(XmlAccessType.FIELD) -public class FromDefinition extends OptionalIdentifiedDefinition<FromDefinition> { +public class FromDefinition extends OptionalIdentifiedDefinition<FromDefinition> implements EndpointRequiredDefinition { @XmlAttribute private String uri; @XmlAttribute @@ -75,6 +75,11 @@ public class FromDefinition extends OptionalIdentifiedDefinition<FromDefinition> } } + @Override + public String getEndpointUri() { + return getUri(); + } + // Properties // ----------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/b6ee9c91/camel-core/src/main/java/org/apache/camel/model/PollEnrichDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/PollEnrichDefinition.java b/camel-core/src/main/java/org/apache/camel/model/PollEnrichDefinition.java index 1fc9042..3ddec0c 100644 --- a/camel-core/src/main/java/org/apache/camel/model/PollEnrichDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/PollEnrichDefinition.java @@ -38,7 +38,7 @@ import org.apache.camel.util.ObjectHelper; */ @XmlRootElement(name = "pollEnrich") @XmlAccessorType(XmlAccessType.FIELD) -public class PollEnrichDefinition extends NoOutputDefinition<PollEnrichDefinition> { +public class PollEnrichDefinition extends NoOutputDefinition<PollEnrichDefinition> implements EndpointRequiredDefinition { @XmlAttribute(name = "uri") private String resourceUri; // TODO: For Camel 3.0 we should remove this ref attribute as you can do that in the uri, by prefixing with ref: @@ -84,6 +84,15 @@ public class PollEnrichDefinition extends NoOutputDefinition<PollEnrichDefinitio } @Override + public String getEndpointUri() { + if (resourceUri != null) { + return resourceUri; + } else { + return null; + } + } + + @Override public Processor createProcessor(RouteContext routeContext) throws Exception { if (ObjectHelper.isEmpty(resourceUri) && ObjectHelper.isEmpty(resourceRef)) { throw new IllegalArgumentException("Either uri or ref must be provided for resource endpoint"); http://git-wip-us.apache.org/repos/asf/camel/blob/b6ee9c91/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java b/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java index e669911..e7f77e8 100644 --- a/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java +++ b/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java @@ -17,6 +17,7 @@ package org.apache.camel.model; import java.util.ArrayList; +import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -27,6 +28,8 @@ import org.apache.camel.util.CamelContextHelper; import org.apache.camel.util.EndpointHelper; import org.apache.camel.util.ObjectHelper; +import static org.apache.camel.model.ProcessorDefinitionHelper.filterTypeInOutputs; + /** * Helper for {@link RouteDefinition} * <p/> @@ -40,6 +43,37 @@ public final class RouteDefinitionHelper { } /** + * Gather all the endpoint uri's the route is using from the EIPs that has a static endpoint defined. + * + * @param route the route + * @param includeInputs whether to include inputs + * @param includeOutputs whether to include outputs + * @return the endpoints uris + */ + public static Set<String> gatherAllStaticEndpointUris(RouteDefinition route, boolean includeInputs, boolean includeOutputs) { + Set<String> answer = new LinkedHashSet<String>(); + + if (includeInputs) { + for (FromDefinition from : route.getInputs()) { + String uri = from.getEndpointUri(); + if (uri != null) { + answer.add(uri); + } + } + } + + if (includeOutputs) { + Iterator<EndpointRequiredDefinition> it = filterTypeInOutputs(route.getOutputs(), EndpointRequiredDefinition.class); + while (it.hasNext()) { + String uri = it.next().getEndpointUri(); + answer.add(uri); + } + } + + return answer; + } + + /** * Force assigning ids to the routes * * @param context the camel context @@ -260,7 +294,6 @@ public final class RouteDefinitionHelper { } - private static void initOnExceptions(List<ProcessorDefinition<?>> abstracts, List<ProcessorDefinition<?>> upper, List<OnExceptionDefinition> onExceptions) { // add global on exceptions if any @@ -456,7 +489,7 @@ public final class RouteDefinitionHelper { * This is needed when doing tracing or the likes, where each node should have its id assigned * so the tracing can pin point exactly. * - * @param context the camel context + * @param context the camel context * @param processor the node */ public static void forceAssignIds(CamelContext context, ProcessorDefinition processor) { http://git-wip-us.apache.org/repos/asf/camel/blob/b6ee9c91/camel-core/src/main/java/org/apache/camel/model/SendDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/SendDefinition.java b/camel-core/src/main/java/org/apache/camel/model/SendDefinition.java index 0e5bf4b..a85d88e 100644 --- a/camel-core/src/main/java/org/apache/camel/model/SendDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/SendDefinition.java @@ -35,7 +35,7 @@ import org.apache.camel.util.ObjectHelper; * @version */ @XmlAccessorType(XmlAccessType.FIELD) -public abstract class SendDefinition<Type extends ProcessorDefinition<Type>> extends NoOutputDefinition<Type> { +public abstract class SendDefinition<Type extends ProcessorDefinition<Type>> extends NoOutputDefinition<Type> implements EndpointRequiredDefinition { @XmlAttribute protected String uri; @XmlAttribute @@ -64,6 +64,14 @@ public abstract class SendDefinition<Type extends ProcessorDefinition<Type>> ext } } + @Override + public String getEndpointUri() { + if (uri != null) { + return uri; + } + return null; + } + // Properties // ----------------------------------------------------------------------- public String getRef() { http://git-wip-us.apache.org/repos/asf/camel/blob/b6ee9c91/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java b/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java index f66f54d..88feb1d 100644 --- a/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java +++ b/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java @@ -43,7 +43,8 @@ import org.apache.camel.util.CamelContextHelper; */ @XmlRootElement(name = "wireTap") @XmlAccessorType(XmlAccessType.FIELD) -public class WireTapDefinition<Type extends ProcessorDefinition<Type>> extends NoOutputDefinition<WireTapDefinition<Type>> implements ExecutorServiceAwareDefinition<WireTapDefinition<Type>> { +public class WireTapDefinition<Type extends ProcessorDefinition<Type>> extends NoOutputDefinition<WireTapDefinition<Type>> + implements ExecutorServiceAwareDefinition<WireTapDefinition<Type>>, EndpointRequiredDefinition { @XmlAttribute protected String uri; @XmlAttribute @@ -81,6 +82,17 @@ public class WireTapDefinition<Type extends ProcessorDefinition<Type>> extends N } @Override + public String getEndpointUri() { + if (uri != null) { + return uri; + } else if (endpoint != null) { + return endpoint.getEndpointUri(); + } else { + return null; + } + } + + @Override public Processor createProcessor(RouteContext routeContext) throws Exception { // executor service is mandatory for wire tap boolean shutdownThreadPool = ProcessorDefinitionHelper.willCreateNewThreadPool(routeContext, this, true); http://git-wip-us.apache.org/repos/asf/camel/blob/b6ee9c91/camel-core/src/main/java/org/apache/camel/util/StringHelper.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/util/StringHelper.java b/camel-core/src/main/java/org/apache/camel/util/StringHelper.java index 46bdf8c..6b81015 100644 --- a/camel-core/src/main/java/org/apache/camel/util/StringHelper.java +++ b/camel-core/src/main/java/org/apache/camel/util/StringHelper.java @@ -16,6 +16,8 @@ */ package org.apache.camel.util; +import static org.apache.camel.util.StringQuoteHelper.doubleQuote; + /** * Helper methods for working with Strings. */ @@ -216,4 +218,20 @@ public final class StringHelper { return sb.toString(); } + /** + * Creates a json tuple with the given name/value pair. + * + * @param name the name + * @param value the value + * @param isMap whether the tuple should be map + * @return the json + */ + public static String toJson(String name, String value, boolean isMap) { + if (isMap) { + return "{ " + doubleQuote(name) + ": " + doubleQuote(value) + " }"; + } else { + return doubleQuote(name) + ": " + doubleQuote(value); + } + } + } http://git-wip-us.apache.org/repos/asf/camel/blob/b6ee9c91/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java index 97c9863..66cc4f7 100644 --- a/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java +++ b/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextTest.java @@ -202,6 +202,22 @@ public class ManagedCamelContextTest extends ManagementTestSupport { assertEquals("camel-core", prop.get("artifactId")); } + public void testManagedCamelContextCreateRouteStaticEndpointJson() throws Exception { + // JMX tests dont work well on AIX CI servers (hangs them) + if (isPlatform("aix")) { + return; + } + + MBeanServer mbeanServer = getMBeanServer(); + ObjectName on = ObjectName.getInstance("org.apache.camel:context=19-camel-1,type=context,name=\"camel-1\""); + + // get the json + String json = (String) mbeanServer.invoke(on, "createRouteStaticEndpointJson", null, null); + assertNotNull(json); + assertTrue(json.contains("{ \"uri\": \"direct:start\" }")); + assertTrue(json.contains("{ \"uri\": \"direct:foo\" }")); + } + @Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { http://git-wip-us.apache.org/repos/asf/camel/blob/b6ee9c91/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpRouteAsXmlTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpRouteAsXmlTest.java b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpRouteAsXmlTest.java index 206c7f9..274cab8 100644 --- a/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpRouteAsXmlTest.java +++ b/camel-core/src/test/java/org/apache/camel/management/ManagedRouteDumpRouteAsXmlTest.java @@ -57,6 +57,24 @@ public class ManagedRouteDumpRouteAsXmlTest extends ManagementTestSupport { assertTrue(xml.contains("mock:result")); } + public void testCreateRouteStaticEndpointJson() throws Exception { + // JMX tests dont work well on AIX CI servers (hangs them) + if (isPlatform("aix")) { + return; + } + + MBeanServer mbeanServer = getMBeanServer(); + ObjectName on = getRouteObjectName(mbeanServer); + + // get the json + String json = (String) mbeanServer.invoke(on, "createRouteStaticEndpointJson", null, null); + assertNotNull(json); + assertTrue(json.contains("\"myRoute\"")); + assertTrue(json.contains("{ \"uri\": \"direct:start\" }")); + assertTrue(json.contains("{ \"uri\": \"mock:result\" }")); + } + + static ObjectName getRouteObjectName(MBeanServer mbeanServer) throws Exception { Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=routes,*"), null); assertEquals(1, set.size()); http://git-wip-us.apache.org/repos/asf/camel/blob/b6ee9c91/camel-core/src/test/java/org/apache/camel/model/GatherAllStaticEndpointUrisTest.java ---------------------------------------------------------------------- diff --git a/camel-core/src/test/java/org/apache/camel/model/GatherAllStaticEndpointUrisTest.java b/camel-core/src/test/java/org/apache/camel/model/GatherAllStaticEndpointUrisTest.java new file mode 100644 index 0000000..a3fbb7e --- /dev/null +++ b/camel-core/src/test/java/org/apache/camel/model/GatherAllStaticEndpointUrisTest.java @@ -0,0 +1,66 @@ +/** + * 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.util.Set; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.builder.RouteBuilder; + +public class GatherAllStaticEndpointUrisTest extends ContextTestSupport { + + public void testGatherAllStaticEndpointUris() throws Exception { + RouteDefinition route = context.getRouteDefinition("foo"); + Set<String> uris = RouteDefinitionHelper.gatherAllStaticEndpointUris(route, true, true); + assertNotNull(uris); + assertEquals(5, uris.size()); + + RouteDefinition route2 = context.getRouteDefinition("bar"); + Set<String> uris2 = RouteDefinitionHelper.gatherAllStaticEndpointUris(route2, true, true); + assertNotNull(uris2); + assertEquals(2, uris2.size()); + + Set<String> uris2out = RouteDefinitionHelper.gatherAllStaticEndpointUris(route2, false, true); + assertNotNull(uris2out); + assertEquals(1, uris2out.size()); + + String json = context.createRouteStaticEndpointJson(null); + assertNotNull(json); + assertTrue(json.contains("{ \"uri\": \"direct:foo\" }")); + assertTrue(json.contains("{ \"uri\": \"seda:bar\" }")); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + @Override + public void configure() throws Exception { + from("direct:foo").routeId("foo") + .to("seda:bar") + .log("Hello World") + .wireTap("mock:tap") + .to("mock:foo") + .enrich("seda:stuff"); + + from("seda:bar").routeId("bar") + .log("Bye World") + .to("mock:bar"); + } + }; + } + +}
