CAMEL-10321, Asterisk Component: test added

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

Branch: refs/heads/master
Commit: 7feb7e7844326077321f13f6efbedd74406ce355
Parents: 4e049a9
Author: Fabryprog <fabryp...@gmail.com>
Authored: Fri Sep 16 23:25:59 2016 +0200
Committer: Andrea Cosentino <anco...@gmail.com>
Committed: Wed Sep 21 13:44:14 2016 +0200

----------------------------------------------------------------------
 .../camel/component/asterisk/AsteriskEndpoint.java   |  8 ++++++++
 .../camel/component/asterisk/AsteriskProducer.java   | 15 ++++++++-------
 2 files changed, 16 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/7feb7e78/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskEndpoint.java
----------------------------------------------------------------------
diff --git 
a/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskEndpoint.java
 
b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskEndpoint.java
index 6c0679c..c261b32 100644
--- 
a/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskEndpoint.java
+++ 
b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskEndpoint.java
@@ -41,8 +41,13 @@ import org.slf4j.LoggerFactory;
  */
 @UriEndpoint(scheme = "asterisk", title = "Asterisk", syntax = 
"asterisk:name", consumerClass = AsteriskConsumer.class, label = "voip")
 public class AsteriskEndpoint extends DefaultEndpoint {
+    @SuppressWarnings("unused")
     private static final Logger LOG = 
LoggerFactory.getLogger(AsteriskProducer.class);
 
+    protected enum ActionsEnum {
+        QUEUE_STATUS, SIP_PEERS, EXTENSION_STATE;
+    }
+    
     @UriPath(description = "Name of component") @Metadata(required = "true")
     private String name;
     
@@ -82,6 +87,9 @@ public class AsteriskEndpoint extends DefaultEndpoint {
         if (action == null) {
             throw new IllegalArgumentException("Missing required action 
parameter");
         }
+        
+        // validate action value
+        ActionsEnum.valueOf(action);
 
         return new AsteriskProducer(this);
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/7feb7e78/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskProducer.java
----------------------------------------------------------------------
diff --git 
a/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskProducer.java
 
b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskProducer.java
index d09778b..50a6cd8 100644
--- 
a/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskProducer.java
+++ 
b/components/camel-asterisk/src/main/java/org/apache/camel/component/asterisk/AsteriskProducer.java
@@ -35,13 +35,14 @@ import org.slf4j.LoggerFactory;
  */
 public class AsteriskProducer extends DefaultProducer {
     private static final Logger LOG = 
LoggerFactory.getLogger(AsteriskProducer.class);
+
     private AsteriskEndpoint endpoint;
 
     public AsteriskProducer(AsteriskEndpoint endpoint) throws 
IllegalStateException, IOException, AuthenticationFailedException, 
TimeoutException, CamelAsteriskException {
         super(endpoint);
         this.endpoint = endpoint;
     }
-    
+
     @Override
     protected void doStart() throws Exception {
         endpoint.login();
@@ -51,17 +52,17 @@ public class AsteriskProducer extends DefaultProducer {
     protected void doStop() throws Exception {
         endpoint.logoff();
     }
-    
+
     public void process(Exchange exchange) throws Exception {
         ManagerAction action;
-        switch (endpoint.getAction()) {
-        case "QueueStatus":
+        switch (AsteriskEndpoint.ActionsEnum.valueOf(endpoint.getAction())) {
+        case QUEUE_STATUS:
             action = new QueueStatusAction();
             break;
-        case "SipPeers":
+        case SIP_PEERS:
             action = new SipPeersAction();
             break;
-        case "ExtensionState":
+        case EXTENSION_STATE:
             action = new 
ExtensionStateAction((String)exchange.getIn().getHeader(AsteriskConstants.EXTEN),
 (String)exchange.getIn().getHeader(AsteriskConstants.CONTEXT));
             break;
 
@@ -70,7 +71,7 @@ public class AsteriskProducer extends DefaultProducer {
         }
 
         LOG.debug("Asterisk, send action {} ", endpoint.getAction());
-        
+
         ManagerResponse response = endpoint.sendAction(action);
         exchange.getIn().setBody(response);
     }

Reply via email to