forked from hexagontk/hexagon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request hexagontk#629 from hexagonkt/develop
Add utility methods and fix parent POM
- Loading branch information
Showing
12 changed files
with
210 additions
and
42 deletions.
There are no files selected for viewing
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
2 changes: 2 additions & 0 deletions
2
http/src/main/kotlin/com/hexagonkt/http/patterns/PathPatterns.kt
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
18 changes: 18 additions & 0 deletions
18
http/src/main/kotlin/com/hexagonkt/http/patterns/WildcardPathPattern.kt
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,18 @@ | ||
package com.hexagonkt.http.patterns | ||
|
||
import com.hexagonkt.http.patterns.TemplatePathPattern.Companion.WILDCARD | ||
|
||
data class WildcardPathPattern(override val prefix: Boolean = false) : PathPattern { | ||
|
||
override val pattern: String = WILDCARD | ||
|
||
override fun addPrefix(prefix: String?): PathPattern = | ||
if (prefix == null) this | ||
else createPathPattern("$prefix$WILDCARD", this.prefix) | ||
|
||
override fun matches(requestUrl: String): Boolean = | ||
true | ||
|
||
override fun extractParameters(requestUrl: String): Map<String, String> = | ||
mapOf(1.toString() to requestUrl) | ||
} |
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
39 changes: 39 additions & 0 deletions
39
http/src/test/kotlin/com/hexagonkt/http/patterns/WildcardPathPatternTest.kt
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,39 @@ | ||
package com.hexagonkt.http.patterns | ||
|
||
import kotlin.test.Test | ||
import kotlin.test.* | ||
|
||
internal class WildcardPathPatternTest { | ||
|
||
@Test fun `Prefixes are matched if pattern is prefix`() { | ||
val regexPath = WildcardPathPattern() | ||
assert(regexPath.matches("/alpha/bravo/tango")) | ||
|
||
val regexPathPrefix = WildcardPathPattern(true) | ||
assert(regexPathPrefix.matches("/alpha/bravo/tango")) | ||
} | ||
|
||
@Test fun `Prefixes can be appended to patterns`() { | ||
val regexPath = WildcardPathPattern() | ||
assert(regexPath.addPrefix(null).matches("/alpha/bravo")) | ||
assertFalse(regexPath.addPrefix("/prefix").matches("/alpha/bravo")) | ||
assertTrue(regexPath.addPrefix("/prefix").matches("/prefix/alpha/bravo")) | ||
} | ||
|
||
@Test fun `A wildcard path have a single parameter`() { | ||
val pathWithoutData = WildcardPathPattern() | ||
assertEquals("*", pathWithoutData.pattern) | ||
assertEquals(mapOf("1" to "/alpha"), pathWithoutData.extractParameters("/alpha")) | ||
} | ||
|
||
@Test fun `Adding a prefix keep the prefix flag`() { | ||
WildcardPathPattern(true).addPrefix("/b").let { | ||
assertEquals("/b*", it.pattern) | ||
assertTrue(it.prefix) | ||
} | ||
WildcardPathPattern(false).addPrefix("/b").let { | ||
assertEquals("/b*", it.pattern) | ||
assertFalse(it.prefix) | ||
} | ||
} | ||
} |
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