Author: cmueller
Date: Thu Aug  5 15:27:23 2010
New Revision: 982663

URL: http://svn.apache.org/viewvc?rev=982663&view=rev
Log:
CAMEL-2752: Pluggable UUID generator

Added:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ActiveMQUuidGenerator.java
   (with props)
    
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultUuidGenerator.java
   (with props)
    
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SimpleUuidGenerator.java
   (with props)
    
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/UuidGenerator.java   
(with props)
    
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ActiveMQUuidGeneratorTest.java
   (with props)
    
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultUnitOfWorkTest.java
   (with props)
    
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultUuidGeneratorTest.java
   (with props)
    
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/SimpleUuidGeneratorTest.java
   (with props)
Removed:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/util/UuidGenerator.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/util/UuidGeneratorTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultUnitOfWork.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MessageSupportTest.java

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?rev=982663&r1=982662&r2=982663&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java 
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Thu 
Aug  5 15:27:23 2010
@@ -45,6 +45,7 @@ import org.apache.camel.spi.Registry;
 import org.apache.camel.spi.ServicePool;
 import org.apache.camel.spi.ShutdownStrategy;
 import org.apache.camel.spi.TypeConverterRegistry;
+import org.apache.camel.spi.UuidGenerator;
 
 /**
  * Interface used to represent the context used to configure routes and the
@@ -881,4 +882,17 @@ public interface CamelContext extends Su
      */
     void setDebugger(Debugger debugger);
 
-}
+    /**
+     * Gets the current {...@link UuidGenerator}
+     *
+     * @return the uuidGenerator
+     */
+    UuidGenerator getUuidGenerator();
+    
+    /**
+     * Sets a custom {...@link UuidGenerator} (should only be set once) 
+     *
+     * @param uuidGenerator the UUID Generator
+     */
+    void setUuidGenerator(UuidGenerator uuidGenerator);
+}
\ No newline at end of file

Added: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ActiveMQUuidGenerator.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ActiveMQUuidGenerator.java?rev=982663&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ActiveMQUuidGenerator.java
 (added)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ActiveMQUuidGenerator.java
 Thu Aug  5 15:27:23 2010
@@ -0,0 +1,109 @@
+/**
+ * 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.impl;
+
+import java.net.InetAddress;
+import java.net.ServerSocket;
+
+import org.apache.camel.spi.UuidGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class ActiveMQUuidGenerator implements UuidGenerator {
+
+    private static final transient Log LOG = 
LogFactory.getLog(ActiveMQUuidGenerator.class); 
+    private static final String UNIQUE_STUB;
+    private static int instanceCount;
+    private static String hostName;
+    private String seed;
+    private long sequence;
+
+    static {
+        String stub = "";
+        boolean canAccessSystemProps = true;
+        try {
+            SecurityManager sm = System.getSecurityManager();
+            if (sm != null) {
+                sm.checkPropertiesAccess();
+            }
+        } catch (SecurityException se) {
+            canAccessSystemProps = false;
+        }
+
+        if (canAccessSystemProps) {
+            try {
+                hostName = InetAddress.getLocalHost().getHostName();
+                ServerSocket ss = new ServerSocket(0);
+                stub = "/" + ss.getLocalPort() + "-" + 
System.currentTimeMillis() + "/";
+                Thread.sleep(100);
+                ss.close();
+            } catch (Exception ioe) {
+                LOG.warn("Could not generate unique stub", ioe);
+            }
+        } else {
+            hostName = "localhost";
+            stub = "-1-" + System.currentTimeMillis() + "-";
+        }
+        UNIQUE_STUB = stub;
+    }
+
+    public ActiveMQUuidGenerator(String prefix) {
+        synchronized (UNIQUE_STUB) {
+            this.seed = prefix + UNIQUE_STUB + (instanceCount++) + "-";
+        }
+    }
+
+    public ActiveMQUuidGenerator() {
+        this("ID-" + hostName);
+    }
+
+    /**
+     * As we have to find the hostname as a side-affect of generating a unique
+     * stub, we allow it's easy retrevial here
+     * 
+     * @return the local host name
+     */
+    public static String getHostName() {
+        return hostName;
+    }
+
+    public String generateUuid() {
+        return this.seed + (this.sequence++);
+    }
+
+    /**
+     * Generate a unique ID - that is friendly for a URL or file system
+     * 
+     * @return a unique id
+     */
+    public String generateSanitizedId() {
+        return generateSanitizedId(generateUuid());
+    }
+
+    /**
+     * Ensures that the id is friendly for a URL or file system
+     *
+     * @param id the unique id
+     * @return the id as file friendly id
+     */
+    public static String generateSanitizedId(String id) {
+        id = id.replace(':', '-');
+        id = id.replace('_', '-');
+        id = id.replace('.', '-');
+        return id;
+    }
+}
\ No newline at end of file

Propchange: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ActiveMQUuidGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/ActiveMQUuidGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=982663&r1=982662&r2=982663&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
 Thu Aug  5 15:27:23 2010
@@ -99,6 +99,7 @@ import org.apache.camel.spi.RouteStartup
 import org.apache.camel.spi.ServicePool;
 import org.apache.camel.spi.ShutdownStrategy;
 import org.apache.camel.spi.TypeConverterRegistry;
+import org.apache.camel.spi.UuidGenerator;
 import org.apache.camel.util.CamelContextHelper;
 import org.apache.camel.util.CastUtils;
 import org.apache.camel.util.EndpointHelper;
@@ -182,6 +183,7 @@ public class DefaultCamelContext extends
     private ShutdownRunningTask shutdownRunningTask = 
ShutdownRunningTask.CompleteCurrentTaskOnly;
     private ExecutorServiceStrategy executorServiceStrategy = new 
DefaultExecutorServiceStrategy(this);
     private Debugger debugger;
+    private UuidGenerator uuidGenerator = new DefaultUuidGenerator();
     private final StopWatch stopWatch = new StopWatch(false);
     private Date startDate;
 
@@ -2075,6 +2077,14 @@ public class DefaultCamelContext extends
     public void setDebugger(Debugger debugger) {
         this.debugger = debugger;
     }
+    
+    public UuidGenerator getUuidGenerator() {
+        return uuidGenerator;
+    }
+
+    public void setUuidGenerator(UuidGenerator uuidGenerator) {
+        this.uuidGenerator = uuidGenerator;
+    }
 
     protected String getEndpointKey(String uri, Endpoint endpoint) {
         if (endpoint.isSingleton()) {

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java?rev=982663&r1=982662&r2=982663&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java 
(original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java 
Thu Aug  5 15:27:23 2010
@@ -30,7 +30,6 @@ import org.apache.camel.spi.Synchronizat
 import org.apache.camel.spi.UnitOfWork;
 import org.apache.camel.util.ExchangeHelper;
 import org.apache.camel.util.ObjectHelper;
-import org.apache.camel.util.UuidGenerator;
 
 /**
  * A default implementation of {...@link Exchange}
@@ -373,7 +372,7 @@ public final class DefaultExchange imple
             answer = in.createExchangeId();
         }
         if (answer == null) {
-            answer = UuidGenerator.get().generateUuid();
+            answer = context.getUuidGenerator().generateUuid();
         }
         return answer;
     }

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultUnitOfWork.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultUnitOfWork.java?rev=982663&r1=982662&r2=982663&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultUnitOfWork.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultUnitOfWork.java
 Thu Aug  5 15:27:23 2010
@@ -24,6 +24,7 @@ import java.util.List;
 import java.util.Set;
 import java.util.Stack;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
 import org.apache.camel.Service;
@@ -34,7 +35,6 @@ import org.apache.camel.spi.TracedRouteN
 import org.apache.camel.spi.UnitOfWork;
 import org.apache.camel.util.EventHelper;
 import org.apache.camel.util.OrderedComparator;
-import org.apache.camel.util.UuidGenerator;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -47,6 +47,7 @@ public class DefaultUnitOfWork implement
     private static final transient Log LOG = 
LogFactory.getLog(DefaultUnitOfWork.class);
 
     private String id;
+    private CamelContext context;
     private List<Synchronization> synchronizations;
     private Message originalInMessage;
     private final TracedRouteNodes tracedRouteNodes;
@@ -58,6 +59,7 @@ public class DefaultUnitOfWork implement
             LOG.trace("UnitOfWork created for ExchangeId: " + 
exchange.getExchangeId() + " with " + exchange);
         }
         tracedRouteNodes = new DefaultTracedRouteNodes();
+        context = exchange.getContext();
 
         // TODO: the copy on facade strategy will help us here in the future
         // TODO: optimize to only copy original message if enabled to do so in 
the route
@@ -202,7 +204,7 @@ public class DefaultUnitOfWork implement
 
     public String getId() {
         if (id == null) {
-            id = UuidGenerator.get().generateUuid();
+            id = context.getUuidGenerator().generateUuid();
         }
         return id;
     }

Added: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultUuidGenerator.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultUuidGenerator.java?rev=982663&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultUuidGenerator.java
 (added)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultUuidGenerator.java
 Thu Aug  5 15:27:23 2010
@@ -0,0 +1,28 @@
+/**
+ * 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.impl;
+
+import java.util.UUID;
+
+import org.apache.camel.spi.UuidGenerator;
+
+public class DefaultUuidGenerator implements UuidGenerator {
+    
+    public String generateUuid() {
+        return UUID.randomUUID().toString();
+    }
+}
\ No newline at end of file

Propchange: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultUuidGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultUuidGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java?rev=982663&r1=982662&r2=982663&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java 
(original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java 
Thu Aug  5 15:27:23 2010
@@ -20,7 +20,6 @@ import org.apache.camel.Exchange;
 import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.Message;
 import org.apache.camel.TypeConverter;
-import org.apache.camel.util.UuidGenerator;
 
 /**
  * A base class for implementation inheritance providing the core
@@ -189,6 +188,14 @@ public abstract class MessageSupport imp
      * Lets allow implementations to auto-create a messageId
      */
     protected String createMessageId() {
-        return UuidGenerator.get().generateUuid();
+        String uuid = null;
+        if (exchange != null) {
+            uuid = exchange.getContext().getUuidGenerator().generateUuid();
+        }
+        // fall back to the default UUID generator
+        if (uuid == null) {
+            uuid = new DefaultUuidGenerator().generateUuid();
+        }
+        return uuid;
     }
 }

Added: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SimpleUuidGenerator.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SimpleUuidGenerator.java?rev=982663&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SimpleUuidGenerator.java
 (added)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SimpleUuidGenerator.java
 Thu Aug  5 15:27:23 2010
@@ -0,0 +1,30 @@
+/**
+ * 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.impl;
+
+import java.util.concurrent.atomic.AtomicLong;
+
+import org.apache.camel.spi.UuidGenerator;
+
+public class SimpleUuidGenerator implements UuidGenerator {
+    
+    private AtomicLong id = new AtomicLong(1);
+
+    public String generateUuid() {
+        return String.valueOf(id.getAndIncrement());
+    }
+}
\ No newline at end of file

Propchange: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SimpleUuidGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/SimpleUuidGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/UuidGenerator.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/UuidGenerator.java?rev=982663&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/UuidGenerator.java 
(added)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/UuidGenerator.java 
Thu Aug  5 15:27:23 2010
@@ -0,0 +1,27 @@
+/**
+ * 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.spi;
+
+public interface UuidGenerator {
+
+    /**
+     * Generates a UUID string representation.  
+     * 
+     * @return a UUID string.
+     */
+    String generateUuid();
+}

Propchange: 
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/UuidGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/UuidGenerator.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ActiveMQUuidGeneratorTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ActiveMQUuidGeneratorTest.java?rev=982663&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ActiveMQUuidGeneratorTest.java
 (added)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ActiveMQUuidGeneratorTest.java
 Thu Aug  5 15:27:23 2010
@@ -0,0 +1,37 @@
+/**
+ * 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.impl;
+
+import junit.framework.TestCase;
+
+public class ActiveMQUuidGeneratorTest extends TestCase {
+    
+    private ActiveMQUuidGenerator uuidGenerator;
+
+    public void setUp() throws Exception {
+        uuidGenerator = new ActiveMQUuidGenerator();
+    }
+
+    public void testGenerateUUID() {
+        String firstUUID = uuidGenerator.generateUuid();
+        String secondUUID = uuidGenerator.generateUuid();
+        
+        assertTrue(firstUUID.matches("^ID-.*/\\d{5}-\\d{13}/\\d{1}-\\d{1}$"));
+        assertTrue(secondUUID.matches("^ID-.*/\\d{5}-\\d{13}/\\d{1}-\\d{1}$"));
+        assertFalse(firstUUID.equals(secondUUID));
+    }
+}
\ No newline at end of file

Propchange: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ActiveMQUuidGeneratorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/ActiveMQUuidGeneratorTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java?rev=982663&r1=982662&r2=982663&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextTest.java
 Thu Aug  5 15:27:23 2010
@@ -32,6 +32,7 @@ import org.apache.camel.component.bean.B
 import org.apache.camel.component.direct.DirectComponent;
 import org.apache.camel.component.log.LogComponent;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.spi.UuidGenerator;
 import org.apache.camel.util.CamelContextHelper;
 
 /**
@@ -54,6 +55,14 @@ public class DefaultCamelContextTest ext
         Component component = ctx.getComponent("bean");
         assertNull(component);
     }
+    
+    public void testCreateDefaultUuidGenerator() {
+        DefaultCamelContext ctx = new DefaultCamelContext();
+        ctx.disableJMX();
+        UuidGenerator uuidGenerator = ctx.getUuidGenerator();
+        assertNotNull(uuidGenerator);
+        assertEquals(uuidGenerator.getClass(), DefaultUuidGenerator.class);
+    }
 
     public void testGetComponents() throws Exception {
         DefaultCamelContext ctx = new DefaultCamelContext();

Added: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultUnitOfWorkTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultUnitOfWorkTest.java?rev=982663&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultUnitOfWorkTest.java
 (added)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultUnitOfWorkTest.java
 Thu Aug  5 15:27:23 2010
@@ -0,0 +1,38 @@
+/**
+ * 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.impl;
+
+import junit.framework.TestCase;
+import org.apache.camel.CamelContext;
+
+public class DefaultUnitOfWorkTest extends TestCase {
+    
+    private DefaultUnitOfWork unitOfWork;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        
+        CamelContext context = new DefaultCamelContext();
+        context.setUuidGenerator(new SimpleUuidGenerator());
+        unitOfWork = new DefaultUnitOfWork(new DefaultExchange(context));
+    }
+
+    public void testGetId() {
+        assertEquals("2", unitOfWork.getId());
+        assertEquals("2", unitOfWork.getId());
+    }
+}
\ No newline at end of file

Propchange: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultUnitOfWorkTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultUnitOfWorkTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultUuidGeneratorTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultUuidGeneratorTest.java?rev=982663&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultUuidGeneratorTest.java
 (added)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultUuidGeneratorTest.java
 Thu Aug  5 15:27:23 2010
@@ -0,0 +1,37 @@
+/**
+ * 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.impl;
+
+import junit.framework.TestCase;
+
+public class DefaultUuidGeneratorTest extends TestCase {
+    
+    private DefaultUuidGenerator uuidGenerator;
+
+    public void setUp() throws Exception {
+        uuidGenerator = new DefaultUuidGenerator();
+    }
+
+    public void testGenerateUUID() {
+        String firstUUID = uuidGenerator.generateUuid();
+        String secondUUID = uuidGenerator.generateUuid();
+        
+        assertTrue(firstUUID.matches("^\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}$"));
+        
assertTrue(secondUUID.matches("^\\w{8}-\\w{4}-\\w{4}-\\w{4}-\\w{12}$"));
+        assertFalse(firstUUID.equals(secondUUID));
+    }
+}
\ No newline at end of file

Propchange: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultUuidGeneratorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DefaultUuidGeneratorTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MessageSupportTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MessageSupportTest.java?rev=982663&r1=982662&r2=982663&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MessageSupportTest.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/MessageSupportTest.java
 Thu Aug  5 15:27:23 2010
@@ -50,4 +50,17 @@ public class MessageSupportTest extends 
         assertEquals("Hello World", in.getMandatoryBody());
     }
 
-}
+    public void testGetMessageId() {
+        context.setUuidGenerator(new SimpleUuidGenerator());
+        Exchange exchange = new DefaultExchange(context);
+        Message in = exchange.getIn();
+        
+        assertEquals("1", in.getMessageId());
+    }
+    
+    public void testGetMessageIdWithoutAnExchange() {
+        Message in = new DefaultMessage();
+        
+        assertNotNull(in.getMessageId());
+    }
+}
\ No newline at end of file

Added: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/SimpleUuidGeneratorTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/SimpleUuidGeneratorTest.java?rev=982663&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/SimpleUuidGeneratorTest.java
 (added)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/SimpleUuidGeneratorTest.java
 Thu Aug  5 15:27:23 2010
@@ -0,0 +1,33 @@
+/**
+ * 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.impl;
+
+import junit.framework.TestCase;
+
+public class SimpleUuidGeneratorTest extends TestCase {
+    
+    private SimpleUuidGenerator uuidGenerator;
+
+    public void setUp() throws Exception {
+        uuidGenerator = new SimpleUuidGenerator();
+    }
+
+    public void testGenerateUUID() {
+        assertEquals("1", uuidGenerator.generateUuid());
+        assertEquals("2", uuidGenerator.generateUuid());
+    }
+}
\ No newline at end of file

Propchange: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/SimpleUuidGeneratorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/SimpleUuidGeneratorTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to