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

Commit

Permalink
Allow deletion of test suites, more restrictive path, fix Bash script
Browse files Browse the repository at this point in the history
  • Loading branch information
tdauth committed Oct 26, 2018
1 parent e5ae54b commit 6b310ab
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 5 deletions.
2 changes: 1 addition & 1 deletion scripts/test-suite.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/bin/bash
curl -H "Content-Type: application/json" -X GET http://localhost:8888/application/0/test-suites/0
curl -H "Content-Type: application/json" -X GET http://localhost:8888/application/0/test-suite/0
13 changes: 9 additions & 4 deletions src/main/scala/de/retest/guistatemachine/RestService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ trait RestService {
path("applications") {
complete(persistence.getApplications())
} ~
pathPrefix("application" / LongNumber / "test-suites") { id =>
path("application" / LongNumber / "test-suites") { id =>
val testSuites = persistence.getTestSuites(Id(id))
testSuites match {
case Some(x) => complete(x)
case None => complete(StatusCodes.NotFound)
}
} ~
pathPrefix("application" / LongNumber / "test-suite" / LongNumber) { (appId, suiteId) =>
path("application" / LongNumber / "test-suite" / LongNumber) { (appId, suiteId) =>
val suite = persistence.getTestSuite(Id(appId), Id(suiteId))
suite match {
case Some(x) => complete(x)
case None => complete(StatusCodes.NotFound)
}
} ~
pathPrefix("application" / LongNumber) { id =>
path("application" / LongNumber) { id =>
val app = persistence.getApplication(Id(id))
app match {
case Some(x) => complete(x)
Expand All @@ -80,7 +80,12 @@ trait RestService {
}
}
} ~ delete {
pathPrefix("application" / LongNumber) { id =>
path("application" / LongNumber / "test-suite" / LongNumber) { (appId, suiteId) =>
val r = persistence.deleteTestSuite(Id(appId), Id(suiteId))
complete(StatusCodes.OK)
}
} ~ delete {
path("application" / LongNumber) { id =>
val r = persistence.deleteApplication(Id(id))
complete(StatusCodes.OK)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,21 @@ class Persistence {
case None => None
}
}

def deleteTestSuite(applicationId: Id, testSuiteId: Id): Boolean = {
val app = getApplication(applicationId)
app match {
case Some(x) => {
val testSuites = x.testSuites
testSuites.synchronized {
if (testSuites.suites.values.contains(testSuiteId)) {
testSuites.suites.values = testSuites.suites.values - testSuiteId
true
} else {
false
}
}
}
}
}
}
12 changes: 12 additions & 0 deletions src/test/scala/de/retest/guistatemachine/RestServiceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class RestServiceSpec extends WordSpec with Matchers with ScalatestRouteTest wit
Post("/create-application") ~> sut ~> check {
handled shouldEqual true
responseAs[Id] shouldEqual Id(0)
persistence.getApplications.apps.values.size shouldEqual 1
}
}

Expand All @@ -71,6 +72,7 @@ class RestServiceSpec extends WordSpec with Matchers with ScalatestRouteTest wit
Post("/application/0/create-test-suite") ~> sut ~> check {
handled shouldEqual true
responseAs[Id] shouldEqual Id(0)
persistence.getTestSuites(Id(0)).get.suites.values.size shouldEqual 1
}
}

Expand All @@ -83,11 +85,21 @@ class RestServiceSpec extends WordSpec with Matchers with ScalatestRouteTest wit
}
}

"return status OK for the DELETE request with the path /application/0/test-suite/0" in {
Delete("/application/0/test-suite/0") ~> sut ~> check {
handled shouldEqual true
status shouldEqual StatusCodes.OK
responseAs[String] shouldEqual "OK"
persistence.getTestSuites(Id(0)).get.suites.values.size shouldEqual 0
}
}

"return status OK for the DELETE request with the path /application/0" in {
Delete("/application/0") ~> sut ~> check {
handled shouldEqual true
status shouldEqual StatusCodes.OK
responseAs[String] shouldEqual "OK"
persistence.getApplications().apps.values.size shouldEqual 0
}
}
}
Expand Down

0 comments on commit 6b310ab

Please sign in to comment.