Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #27. Validate path params with regex
If @PathParam defines a regex, the latter will be used to validate the given argument at substitution time.
- Loading branch information
Showing
15 changed files
with
303 additions
and
31 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...iguration-webapp/src/test/java/fr/vidal/oss/jax_rs_linker/it/BrandResourceLinkerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package fr.vidal.oss.jax_rs_linker.it; | ||
|
||
import fr.vidal.oss.jax_rs_linker.Linkers; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
public class BrandResourceLinkerTest { | ||
|
||
@Rule | ||
public ExpectedException thrown = ExpectedException.none(); | ||
|
||
@Test | ||
public void no_exception_is_thrown_when_argument_matches_regex() { | ||
Linkers.brandResourceLinker() | ||
.relatedBrandResourceByZipCode() | ||
.replace(BrandResourcePathParameters.CODE, "aBc"); | ||
} | ||
|
||
@Test | ||
public void illegal_argument_exception_is_thrown_when_regex_is_not_matched() { | ||
thrown.expect(IllegalArgumentException.class); | ||
Linkers.brandResourceLinker() | ||
.relatedBrandResourceByZipCode() | ||
.replace(BrandResourcePathParameters.CODE, "aBD2"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
jax-rs-linker/src/main/java/fr/vidal/oss/jax_rs_linker/api/NoPathParameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
package fr.vidal.oss.jax_rs_linker.api; | ||
|
||
import com.google.common.base.Optional; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public enum NoPathParameters implements PathParameters { | ||
; | ||
|
||
@Override | ||
public String placeholder() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public Optional<Pattern> regex() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
jax-rs-linker/src/main/java/fr/vidal/oss/jax_rs_linker/api/PathParameters.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
package fr.vidal.oss.jax_rs_linker.api; | ||
|
||
import com.google.common.base.Optional; | ||
|
||
import java.util.regex.Pattern; | ||
|
||
public interface PathParameters { | ||
String placeholder(); | ||
Optional<Pattern> regex(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.