camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ra...@apache.org
Subject [1/3] camel git commit: CAMEL-9129. Add OptionsVerbDefinition. Extend Rest & VerbDefintion to include OPTIONS. Create unit test
Date Sun, 13 Sep 2015 17:06:21 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.15.x 1e2f7dc07 -> 55889c39c
  refs/heads/master 36fdb1e5a -> 9c5395b15


CAMEL-9129. Add OptionsVerbDefinition. Extend Rest & VerbDefintion to include OPTIONS.
Create unit test


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

Branch: refs/heads/camel-2.15.x
Commit: d307ff126ac3d4955c1eb804f3d3bce8deeefcff
Parents: 1e2f7dc
Author: Charles Moulliard <cmoulliard@apache.org>
Authored: Sun Sep 13 17:57:34 2015 +0200
Committer: Raul Kripalani <raulk@apache.org>
Committed: Sun Sep 13 17:59:37 2015 +0100

----------------------------------------------------------------------
 .../camel/model/rest/OptionsVerbDefinition.java | 33 +++++++++
 .../apache/camel/model/rest/RestDefinition.java | 10 +++
 .../apache/camel/model/rest/VerbDefinition.java |  2 +
 .../component/rest/FromRestOptionsTest.java     | 71 ++++++++++++++++++++
 4 files changed, 116 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d307ff12/camel-core/src/main/java/org/apache/camel/model/rest/OptionsVerbDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/OptionsVerbDefinition.java
b/camel-core/src/main/java/org/apache/camel/model/rest/OptionsVerbDefinition.java
new file mode 100644
index 0000000..11a121c
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/OptionsVerbDefinition.java
@@ -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.model.rest;
+
+import org.apache.camel.spi.Metadata;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Rest OPTIONS command
+ */
+@Metadata(label = "rest")
+@XmlRootElement(name = "options")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class OptionsVerbDefinition extends VerbDefinition {
+
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/d307ff12/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
index 82633ca..5fcaa21 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
@@ -208,6 +208,14 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition>
         return addVerb("head", uri);
     }
 
+    public RestDefinition options() {
+        return addVerb("options", null);
+    }
+
+    public RestDefinition options(String uri) {
+        return addVerb("options", uri);
+    }
+
     public RestDefinition verb(String verb) {
         return addVerb(verb, null);
     }
@@ -412,6 +420,8 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition>
             answer = new HeadVerbDefinition();
         } else if ("put".equals(verb)) {
             answer = new PutVerbDefinition();
+        } else if ("options".equals(verb)) {
+            answer = new OptionsVerbDefinition();
         } else {
             answer = new VerbDefinition();
             answer.setMethod(verb);

http://git-wip-us.apache.org/repos/asf/camel/blob/d307ff12/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java
index df053fd..965e43c 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/VerbDefinition.java
@@ -313,6 +313,8 @@ public class VerbDefinition extends OptionalIdentifiedDefinition<VerbDefinition>
             return "delete";
         } else if (this instanceof HeadVerbDefinition) {
             return "head";
+        } else if (this instanceof OptionsVerbDefinition) {
+            return "options";
         } else {
             return method;
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/d307ff12/camel-core/src/test/java/org/apache/camel/component/rest/FromRestOptionsTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/component/rest/FromRestOptionsTest.java
b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestOptionsTest.java
new file mode 100644
index 0000000..2bff7fc
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/component/rest/FromRestOptionsTest.java
@@ -0,0 +1,71 @@
+/**
+ * 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.component.rest;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.model.rest.OptionsVerbDefinition;
+import org.apache.camel.model.rest.RestDefinition;
+
+public class FromRestOptionsTest extends ContextTestSupport {
+    
+    final static String ALLOWS = "HEAD,GET,PUT,POST,DELETE,OPTIONS";
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        JndiRegistry jndi = super.createRegistry();
+        jndi.bind("dummy-rest", new DummyRestConsumerFactory());
+        return jndi;
+    }
+
+    public void testRestOptionsModel() throws Exception {
+        
+        RestDefinition rest = context.getRestDefinitions().get(0);
+        assertNotNull(rest);
+        assertEquals("/say/hello", rest.getPath());
+        assertEquals(1, rest.getVerbs().size());
+        assertIsInstanceOf(OptionsVerbDefinition.class, rest.getVerbs().get(0));
+
+        Exchange out = template.request("seda:options-say-hello", new Processor() {
+                    @Override
+                    public void process(Exchange exchange) throws Exception {
+                        exchange.getIn().setBody("Me");
+                    }
+                });
+        assertMockEndpointsSatisfied();
+        assertNotNull(out);
+        assertEquals(out.getOut().getHeader("Allow"), ALLOWS);
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                restConfiguration().host("localhost");
+                rest("/say/hello")
+                    .options()
+                    .route()
+                    .setHeader(Exchange.HTTP_RESPONSE_CODE, constant(200))
+                    .setHeader("Allow", constant(ALLOWS));
+            }
+        };
+    }
+}


Mime
View raw message