From e5ae54bb6c67b457901744b931ec457d26fb4be1 Mon Sep 17 00:00:00 2001 From: Tamino Dauth Date: Fri, 26 Oct 2018 12:25:58 +0200 Subject: [PATCH] Fix unit tests and route priority #1 --- README.md | 22 +++++++++---------- .../retest/guistatemachine/RestService.scala | 17 ++++++++------ .../guistatemachine/RestServiceSpec.scala | 3 ++- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 45d18ec..1669c5b 100644 --- a/README.md +++ b/README.md @@ -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-/gui-state-machine-api-assembly-.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-/gui-state-machine-api-assembly-.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. diff --git a/src/main/scala/de/retest/guistatemachine/RestService.scala b/src/main/scala/de/retest/guistatemachine/RestService.scala index b1f3347..a7ac748 100644 --- a/src/main/scala/de/retest/guistatemachine/RestService.scala +++ b/src/main/scala/de/retest/guistatemachine/RestService.scala @@ -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 { @@ -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 { @@ -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 { diff --git a/src/test/scala/de/retest/guistatemachine/RestServiceSpec.scala b/src/test/scala/de/retest/guistatemachine/RestServiceSpec.scala index 41920c0..2b4dd8c 100644 --- a/src/test/scala/de/retest/guistatemachine/RestServiceSpec.scala +++ b/src/test/scala/de/retest/guistatemachine/RestServiceSpec.scala @@ -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 {