This repository has been archived by the owner on Mar 12, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Fix marshalling and unmarshalling for ID based maps and add unit test. - Allow deletion of applications and add unit test. - Revert inheritance of Map which does not work with case classes. - Add Bash scripts with REST calls.
- Loading branch information
Showing
15 changed files
with
117 additions
and
41 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,2 @@ | ||
#!/bin/bash | ||
curl -H "Content-Type: application/json" -X GET http://localhost:8888/application/0 |
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,2 @@ | ||
#!/bin/bash | ||
curl -H "Content-Type: application/json" -X POST http://localhost:8888/application/0/create-test-suite |
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,2 @@ | ||
#!/bin/bash | ||
curl -H "Content-Type: application/json" -X DELETE http://localhost:8888/application/0 |
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,2 @@ | ||
#!/bin/bash | ||
curl -H "Content-Type: application/json" -X GET http://localhost:8888/application/0/test-suites/0 |
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,2 @@ | ||
#!/bin/bash | ||
curl -H "Content-Type: application/json" -X GET http://localhost:8888/application/0/test-suites |
22 changes: 7 additions & 15 deletions
22
src/main/scala/de/retest/guistatemachine/JsonFormatForIdMap.scala
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 |
---|---|---|
@@ -1,30 +1,22 @@ | ||
package de.retest.guistatemachine | ||
|
||
import spray.json._ | ||
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ | ||
import spray.json.DefaultJsonProtocol._ | ||
|
||
import de.retest.guistatemachine.model.Id | ||
import de.retest.guistatemachine.model.Map | ||
import scala.collection.immutable.HashMap | ||
import spray.json.JsValue | ||
import spray.json.JsonFormat | ||
import spray.json.RootJsonFormat | ||
|
||
/** | ||
* Transforms a [[Map]] into a `scala.collection.immutable.Map[String, T]`, so it can be converted into valid JSON. | ||
* Besides, transforms a JSON object which is a `scala.collection.immutable.Map[String, T]` back into a [[Map]]. | ||
* This transformer requires a JSON format for the type `K`. | ||
*/ | ||
class JsonFormatForIdMap[T](implicit val jsonFormat: JsonFormat[T]) extends RootJsonFormat[Map[T]] { | ||
class JsonFormatForIdMap[T](implicit val jsonFormat0: JsonFormat[scala.collection.immutable.Map[String, T]], implicit val jsonFormat1: JsonFormat[T]) extends RootJsonFormat[Map[T]] { | ||
override def write(obj: Map[T]): JsValue = | ||
obj.values.map { field => (field._1.id.toString -> field._2) }.toJson | ||
jsonFormat0.write(obj.values.map { field => (field._1.id.toString -> field._2) }) | ||
|
||
override def read(json: JsValue): Map[T] = { | ||
val obj = json.asJsObject | ||
if (obj.fields.isEmpty) { | ||
new Map[T](new HashMap[Id, T]()) | ||
// TODO Fix conversation back into the Map type. | ||
} else { | ||
val map = json.asInstanceOf[scala.collection.immutable.Map[String, T]] | ||
new Map[T](map.map { x => (Id(x._1.toLong) -> x._2) }) | ||
} | ||
val map = jsonFormat0.read(json) | ||
new Map[T](map.map { x => (Id(x._1.toLong) -> x._2) }) | ||
} | ||
} |
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
2 changes: 1 addition & 1 deletion
2
src/main/scala/de/retest/guistatemachine/model/GuiApplications.scala
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package de.retest.guistatemachine.model | ||
|
||
final case class GuiApplications(var values: scala.collection.immutable.Map[Id, GuiApplication]) extends Map[GuiApplication](values) | ||
final case class GuiApplications(apps: Map[GuiApplication]) |
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
2 changes: 1 addition & 1 deletion
2
src/main/scala/de/retest/guistatemachine/model/TestSuites.scala
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package de.retest.guistatemachine.model | ||
|
||
final case class TestSuites(var values: scala.collection.immutable.Map[Id, TestSuite]) extends Map[TestSuite](values) | ||
final case class TestSuites(suites: Map[TestSuite]) |
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
42 changes: 42 additions & 0 deletions
42
src/test/scala/de/retest/guistatemachine/JsonFormatForIdMapSpec.scala
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,42 @@ | ||
package de.retest.guistatemachine | ||
|
||
import org.scalatest.WordSpec | ||
import org.scalatest.Matchers | ||
|
||
import akka.http.scaladsl.marshallers.sprayjson.SprayJsonSupport._ | ||
import spray.json.DefaultJsonProtocol._ | ||
import spray.json._ | ||
import de.retest.guistatemachine.model.TestSuites | ||
import de.retest.guistatemachine.model.Id | ||
import de.retest.guistatemachine.model.TestSuite | ||
import scala.collection.immutable.HashMap | ||
import de.retest.guistatemachine.model.Map | ||
|
||
class JsonFormatForIdMapSpec extends WordSpec with Matchers { | ||
|
||
implicit val idFormat = jsonFormat1(Id) | ||
implicit val testSuiteFormat = jsonFormat0(TestSuite) | ||
implicit val hashMapFormatTestSuites = new JsonFormatForIdMap[TestSuite] | ||
implicit val testSuitesFormat = jsonFormat1(TestSuites) | ||
|
||
"The JSON format" should { | ||
"convert an empty test suite into JSON and back" in { | ||
val testSuites = TestSuites(Map(new HashMap[Id, TestSuite]())) | ||
val json = testSuites.toJson | ||
json.toString shouldEqual "{\"suites\":{}}" | ||
val transformedTestSuites = json.convertTo[TestSuites] | ||
transformedTestSuites.suites.values.isEmpty shouldEqual true | ||
} | ||
|
||
"convert a test suite with elements into JSON and back" in { | ||
val testSuites = TestSuites(Map(new HashMap[Id, TestSuite]())) | ||
testSuites.suites.values = testSuites.suites.values + (Id(0) -> TestSuite()) | ||
val json = testSuites.toJson | ||
json.toString shouldEqual "{\"suites\":{\"0\":{}}}" | ||
val transformedTestSuites = json.convertTo[TestSuites] | ||
transformedTestSuites.suites.values.isEmpty shouldEqual false | ||
transformedTestSuites.suites.values.contains(Id(0)) shouldEqual true | ||
} | ||
} | ||
|
||
} |
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