Skip to content
This repository was archived by the owner on Mar 12, 2020. It is now read-only.

Commit e5ae54b

Browse files
committed
Fix unit tests and route priority #1
1 parent 0feb461 commit e5ae54b

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

README.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,16 @@ Therefore, calling systems do not depend on the concrete implementation and it c
88
[![Build Status](https://travis-ci.org/retest/gui-state-machine-api.svg?branch=master)](https://travis-ci.org/retest/gui-state-machine-api)
99
[![Code Coverage](https://img.shields.io/codecov/c/github/retest/gui-state-machine-api/master.svg)](https://codecov.io/github/retest/gui-state-machine-api?branch=master)
1010

11-
## Manual Build
12-
Use the command `sbt compile` to build the project manually.
13-
14-
## Manual Run
15-
Use the command `sbt run` to start the REST service.
16-
17-
## Standalone Distribution
18-
Use the command `sbt assembly` to create a standalone JAR which includes all dependencies including the Scala libraries.
19-
The standalone JAR is generated as `target/scala-<scalaversion>/gui-state-machine-api-assembly-<version>.jar`.
20-
21-
## Eclipse Support
22-
Use the command `sbt eclipse` to generate a project for Eclipse.
11+
## SBT Commands
12+
* `sbt compile` to build the project manually.
13+
* `sbt run` to start the REST service.
14+
* `sbt assembly` to create a standalone JAR which includes all dependencies including the Scala libraries. The standalone JAR is generated as `target/scala-<scalaversion>/gui-state-machine-api-assembly-<version>.jar`.
15+
* `sbt eclipse` to generate a project for Eclipse.
16+
* `sbt test` to execute all unit tests.
17+
* `sbt coverage` to generate coverage data.
18+
* `sbt coverageReport` to generate a HTML coverage report.
19+
* `sbt scalastyle` to make a check with ScalaStyle.
20+
* `sbt doc` to generate the scaladoc API documentation.
2321

2422
## Bash Scripts for REST Calls
2523
The directory [scripts](./scripts) contains a number of Bash scripts which use `curl` to send REST calls to a running server.

src/main/scala/de/retest/guistatemachine/RestService.scala

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ trait RestService {
3434

3535
/**
3636
* Creates the complete route for the REST service with all possible paths.
37+
* Note that the order of path prefixes is important.
38+
* For example, if "application/LongNumber" comes before "application/LongNumber/bla", the second path
39+
* will always be ignored.
3740
*/
3841
def getRoute(persistence: Persistence): Route =
3942
get {
@@ -43,13 +46,6 @@ trait RestService {
4346
path("applications") {
4447
complete(persistence.getApplications())
4548
} ~
46-
pathPrefix("application" / LongNumber) { id =>
47-
val app = persistence.getApplication(Id(id))
48-
app match {
49-
case Some(x) => complete(x)
50-
case None => complete(StatusCodes.NotFound)
51-
}
52-
} ~
5349
pathPrefix("application" / LongNumber / "test-suites") { id =>
5450
val testSuites = persistence.getTestSuites(Id(id))
5551
testSuites match {
@@ -63,6 +59,13 @@ trait RestService {
6359
case Some(x) => complete(x)
6460
case None => complete(StatusCodes.NotFound)
6561
}
62+
} ~
63+
pathPrefix("application" / LongNumber) { id =>
64+
val app = persistence.getApplication(Id(id))
65+
app match {
66+
case Some(x) => complete(x)
67+
case None => complete(StatusCodes.NotFound)
68+
}
6669
}
6770
} ~
6871
post {

src/test/scala/de/retest/guistatemachine/RestServiceSpec.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import akka.http.scaladsl.model.StatusCode
2121

2222
class RestServiceSpec extends WordSpec with Matchers with ScalatestRouteTest with RestService {
2323

24-
val sut = getRoute(new Persistence)
24+
val persistence = new Persistence
25+
val sut = getRoute(persistence)
2526

2627
"The service" should {
2728
"show the default text for the GET request with the path /" in {

0 commit comments

Comments
 (0)