Permalink
Browse files

Merge pull request #475 from nykolaslima/master

Support for PATCH http verb. Fixes #474
  • Loading branch information...
2 parents ad1e326 + 942fea9 commit b5ad8754d8c711f4bfc83089b319c5c42823b1a2 @lucascs lucascs committed Oct 31, 2012
@@ -0,0 +1,42 @@
+/***
+ * Copyright (c) 2009 Caelum - www.caelum.com.br/opensource
+ * All rights reserved.
+ *
+ * Licensed 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 br.com.caelum.vraptor;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Supports the PATCH http method.
+ *
+ * @author Nykolas Lima
+ */
+@Target({ElementType.TYPE, ElementType.METHOD})
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+public @interface Patch {
+
+ /**
+ * All paths that will be mapped to an annotated Resource method.
+ * @return
+ */
+ String[] value() default {};
+
+}
@@ -25,12 +25,13 @@
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Head;
import br.com.caelum.vraptor.Options;
+import br.com.caelum.vraptor.Patch;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Put;
import br.com.caelum.vraptor.Trace;
public enum HttpMethod {
- GET(Get.class), POST(Post.class), PUT(Put.class), DELETE(Delete.class), TRACE(Trace.class), HEAD(Head.class), OPTIONS(Options.class);
+ GET(Get.class), POST(Post.class), PUT(Put.class), DELETE(Delete.class), TRACE(Trace.class), HEAD(Head.class), OPTIONS(Options.class), PATCH(Patch.class);
private static final String METHOD_PARAMETER = "_method";
private final Class<? extends Annotation> type;
@@ -45,6 +45,7 @@
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Head;
import br.com.caelum.vraptor.Options;
+import br.com.caelum.vraptor.Patch;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.core.Converters;
@@ -334,6 +335,10 @@ public void head() {
public void options() {
}
+ @Patch("/clients/update")
+ public void update() {
+ }
+
public void add() {
}
@@ -425,6 +430,14 @@ public void shouldAcceptAResultWithOptionsWebMethod() throws SecurityException,
assertThat(route.allowedMethods(), is(EnumSet.of(HttpMethod.OPTIONS)));
}
+ @Test
+ public void shouldAcceptAResultWithPatchWebMethod() throws SecurityException, NoSuchMethodException {
+ List<Route> routes = parser.rulesFor(new DefaultResourceClass(ClientsController.class));
+ Route route = getRouteMatching(routes, "/clients/update");
+
+ assertThat(route.allowedMethods(), is(EnumSet.of(HttpMethod.PATCH)));
+ }
+
static class NiceClients extends ClientsController {
@Override

0 comments on commit b5ad875

Please sign in to comment.