forked from scalatra/scalatra
-
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.
Add an environment setting from either system property or init parame…
…ter.
- Loading branch information
1 parent
08c768c
commit 2e52ac9
Showing
2 changed files
with
50 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.scalatra | ||
|
||
import org.scalatest.matchers.ShouldMatchers | ||
import test.scalatest.ScalatraSuite | ||
|
||
class EnvironmentFilter extends ScalatraFilter { | ||
get("/*/environment") { | ||
environment | ||
} | ||
|
||
get("/*/is-development-mode") { | ||
isDevelopmentMode | ||
} | ||
} | ||
|
||
class EnvironmentFilterTest extends ScalatraSuite with ShouldMatchers { | ||
val devFilterHolder = addFilter(classOf[EnvironmentFilter], "/dev/*") | ||
|
||
val prodFilterHolder = addFilter(classOf[EnvironmentFilter], "/prod/*") | ||
prodFilterHolder.setInitParameter("org.scalatra.environment", "production") | ||
|
||
test("default environment is 'development'") { | ||
get("/dev/environment") { | ||
body should equal ("development") | ||
} | ||
} | ||
|
||
test("is development mode if environment is 'development'") { | ||
get("/dev/is-development-mode") { | ||
body should equal ("true") | ||
} | ||
} | ||
|
||
test("environment comes from org.scalatra.environment init parameter") { | ||
get("/prod/environment") { | ||
body should equal ("production") | ||
} | ||
} | ||
|
||
test("is not development mode if environment is 'production'") { | ||
get("/prod/is-development-mode") { | ||
body should equal ("false") | ||
} | ||
} | ||
} |