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

Commit

Permalink
Fix unit tests and route priority #1
Browse files Browse the repository at this point in the history
  • Loading branch information
tdauth committed Oct 26, 2018
1 parent 0feb461 commit e5ae54b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 20 deletions.
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,16 @@ Therefore, calling systems do not depend on the concrete implementation and it c
[![Build Status](https://travis-ci.org/retest/gui-state-machine-api.svg?branch=master)](https://travis-ci.org/retest/gui-state-machine-api)
[![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)

## Manual Build
Use the command `sbt compile` to build the project manually.

## Manual Run
Use the command `sbt run` to start the REST service.

## Standalone Distribution
Use the command `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`.

## Eclipse Support
Use the command `sbt eclipse` to generate a project for Eclipse.
## SBT Commands
* `sbt compile` to build the project manually.
* `sbt run` to start the REST service.
* `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`.
* `sbt eclipse` to generate a project for Eclipse.
* `sbt test` to execute all unit tests.
* `sbt coverage` to generate coverage data.
* `sbt coverageReport` to generate a HTML coverage report.
* `sbt scalastyle` to make a check with ScalaStyle.
* `sbt doc` to generate the scaladoc API documentation.

## Bash Scripts for REST Calls
The directory [scripts](./scripts) contains a number of Bash scripts which use `curl` to send REST calls to a running server.
Expand Down
17 changes: 10 additions & 7 deletions src/main/scala/de/retest/guistatemachine/RestService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ trait RestService {

/**
* Creates the complete route for the REST service with all possible paths.
* Note that the order of path prefixes is important.
* For example, if "application/LongNumber" comes before "application/LongNumber/bla", the second path
* will always be ignored.
*/
def getRoute(persistence: Persistence): Route =
get {
Expand All @@ -43,13 +46,6 @@ trait RestService {
path("applications") {
complete(persistence.getApplications())
} ~
pathPrefix("application" / LongNumber) { id =>
val app = persistence.getApplication(Id(id))
app match {
case Some(x) => complete(x)
case None => complete(StatusCodes.NotFound)
}
} ~
pathPrefix("application" / LongNumber / "test-suites") { id =>
val testSuites = persistence.getTestSuites(Id(id))
testSuites match {
Expand All @@ -63,6 +59,13 @@ trait RestService {
case Some(x) => complete(x)
case None => complete(StatusCodes.NotFound)
}
} ~
pathPrefix("application" / LongNumber) { id =>
val app = persistence.getApplication(Id(id))
app match {
case Some(x) => complete(x)
case None => complete(StatusCodes.NotFound)
}
}
} ~
post {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import akka.http.scaladsl.model.StatusCode

class RestServiceSpec extends WordSpec with Matchers with ScalatestRouteTest with RestService {

val sut = getRoute(new Persistence)
val persistence = new Persistence
val sut = getRoute(persistence)

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

0 comments on commit e5ae54b

Please sign in to comment.