diff --git a/src/main/scala/de/retest/guistatemachine/furrermodel/GuiApplication.scala b/src/main/scala/de/retest/guistatemachine/furrermodel/GuiApplication.scala deleted file mode 100644 index 39797e6..0000000 --- a/src/main/scala/de/retest/guistatemachine/furrermodel/GuiApplication.scala +++ /dev/null @@ -1,13 +0,0 @@ -package de.retest.guistatemachine.furrermodel - -/** - * The tested GUI application with an initial state and a number of test suites. - * - * @param id This ID is for the REST API only. - */ -class GuiApplication(val id : Long, initialState: State, testSuites: Seq[TestSuite]) { - - def getTestSuites: Seq[TestSuite] = testSuites - - def getInitialState: State = initialState -} \ No newline at end of file diff --git a/src/main/scala/de/retest/guistatemachine/furrermodel/GuiWidget.scala b/src/main/scala/de/retest/guistatemachine/furrermodel/GuiWidget.scala deleted file mode 100644 index 23fb920..0000000 --- a/src/main/scala/de/retest/guistatemachine/furrermodel/GuiWidget.scala +++ /dev/null @@ -1,8 +0,0 @@ -package de.retest.guistatemachine.furrermodel - -/** - * A visible widget on a [[GuiWindow]]. - * TODO #2 Add all different states for a widget for regression testing. - */ -trait GuiWidget { -} \ No newline at end of file diff --git a/src/main/scala/de/retest/guistatemachine/furrermodel/GuiWindow.scala b/src/main/scala/de/retest/guistatemachine/furrermodel/GuiWindow.scala deleted file mode 100644 index 1ae5c8c..0000000 --- a/src/main/scala/de/retest/guistatemachine/furrermodel/GuiWindow.scala +++ /dev/null @@ -1,11 +0,0 @@ -package de.retest.guistatemachine.furrermodel - -/** - * A visible window which the user can interact with. - */ -trait GuiWindow { - /** - * All visible widgets on the window. - */ - private val widgets = Seq[GuiWidget]() -} \ No newline at end of file diff --git a/src/main/scala/de/retest/guistatemachine/furrermodel/State.scala b/src/main/scala/de/retest/guistatemachine/furrermodel/State.scala deleted file mode 100644 index 409da29..0000000 --- a/src/main/scala/de/retest/guistatemachine/furrermodel/State.scala +++ /dev/null @@ -1,9 +0,0 @@ -package de.retest.guistatemachine.furrermodel - -class State { - private val windows = Set[GuiWindow]() - /** - * Actions which can be executed by the user in this state. - */ - private val availableActions = Set[UIAction]() -} \ No newline at end of file diff --git a/src/main/scala/de/retest/guistatemachine/furrermodel/TestCase.scala b/src/main/scala/de/retest/guistatemachine/furrermodel/TestCase.scala deleted file mode 100644 index 5792913..0000000 --- a/src/main/scala/de/retest/guistatemachine/furrermodel/TestCase.scala +++ /dev/null @@ -1,11 +0,0 @@ -package de.retest.guistatemachine.furrermodel - -class TestCase(initialState: State) { - private val actions = Seq[UIAction]() - - def length = actions.size - - def isValid = true // it is valid if all GUI actions can be executed - - def getUiPath = new UIPath(new PathState(initialState)) // TODO #2 generate the correct path, with the common initial state -} \ No newline at end of file diff --git a/src/main/scala/de/retest/guistatemachine/furrermodel/TestSuite.scala b/src/main/scala/de/retest/guistatemachine/furrermodel/TestSuite.scala deleted file mode 100644 index 2ea30c7..0000000 --- a/src/main/scala/de/retest/guistatemachine/furrermodel/TestSuite.scala +++ /dev/null @@ -1,9 +0,0 @@ -package de.retest.guistatemachine.furrermodel - -class TestSuite { - private val cases = Set[TestCase]() - - def size = cases.size - - def length = cases.foldLeft(0)((size, c) => size + c.length) -} \ No newline at end of file diff --git a/src/main/scala/de/retest/guistatemachine/furrermodel/UIAction.scala b/src/main/scala/de/retest/guistatemachine/furrermodel/UIAction.scala deleted file mode 100644 index 87510cc..0000000 --- a/src/main/scala/de/retest/guistatemachine/furrermodel/UIAction.scala +++ /dev/null @@ -1,5 +0,0 @@ -package de.retest.guistatemachine.furrermodel - -trait UIAction { - -} \ No newline at end of file diff --git a/src/main/scala/de/retest/guistatemachine/furrermodel/UIPath.scala b/src/main/scala/de/retest/guistatemachine/furrermodel/UIPath.scala deleted file mode 100644 index 8477557..0000000 --- a/src/main/scala/de/retest/guistatemachine/furrermodel/UIPath.scala +++ /dev/null @@ -1,25 +0,0 @@ -package de.retest.guistatemachine.furrermodel - -import scala.annotation.tailrec - -class PathTransition(val action: UIAction, val next: PathState) { -} - -class PathState(val state: State, val transition: PathTransition = null) { -} - -/** - * The path of a test case which starts with the initial state of the GUI application. - */ -class UIPath(initial: PathState) { - - /** - * @return The final state which is reached by the path. - */ - def getFinalState: PathState = { - @tailrec - def getNextPathState(current: PathState): PathState = if (current.transition eq null) current else getNextPathState(current.transition.next) - - getNextPathState(initial) - } -} \ No newline at end of file diff --git a/src/main/scala/de/retest/guistatemachine/persistence/Persistence.scala b/src/main/scala/de/retest/guistatemachine/persistence/Persistence.scala index 54f837e..0ae3a42 100644 --- a/src/main/scala/de/retest/guistatemachine/persistence/Persistence.scala +++ b/src/main/scala/de/retest/guistatemachine/persistence/Persistence.scala @@ -23,7 +23,7 @@ class Persistence { val apps = guiApplications apps.synchronized { val id = apps.apps.generateId - apps.apps.values = apps.apps.values + (id -> new GuiApplication(TestSuites(Map(new HashMap[Id, TestSuite])))) + apps.apps.values = apps.apps.values + (id -> GuiApplication(TestSuites(Map(new HashMap[Id, TestSuite])))) id } } diff --git a/src/test/scala/de/retest/guistatemachine/JsonFormatForIdMapSpec.scala b/src/test/scala/de/retest/guistatemachine/JsonFormatForIdMapSpec.scala index 3bc00dd..b462f9f 100644 --- a/src/test/scala/de/retest/guistatemachine/JsonFormatForIdMapSpec.scala +++ b/src/test/scala/de/retest/guistatemachine/JsonFormatForIdMapSpec.scala @@ -11,6 +11,8 @@ import de.retest.guistatemachine.model.Id import de.retest.guistatemachine.model.TestSuite import scala.collection.immutable.HashMap import de.retest.guistatemachine.model.Map +import de.retest.guistatemachine.model.GuiApplications +import de.retest.guistatemachine.model.GuiApplication class JsonFormatForIdMapSpec extends WordSpec with Matchers { @@ -18,6 +20,9 @@ class JsonFormatForIdMapSpec extends WordSpec with Matchers { implicit val testSuiteFormat = jsonFormat0(TestSuite) implicit val hashMapFormatTestSuites = new JsonFormatForIdMap[TestSuite] implicit val testSuitesFormat = jsonFormat1(TestSuites) + implicit val applicationFormat = jsonFormat1(GuiApplication) + implicit val hashMapFormatApplications = new JsonFormatForIdMap[GuiApplication] + implicit val applicationsFormat = jsonFormat1(GuiApplications) "The JSON format" should { "convert an empty test suite into JSON and back" in { @@ -37,6 +42,24 @@ class JsonFormatForIdMapSpec extends WordSpec with Matchers { transformedTestSuites.suites.values.isEmpty shouldEqual false transformedTestSuites.suites.values.contains(Id(0)) shouldEqual true } + + /** + * Tests nested fields which do both contain a Map. + */ + "convert an application into JSON and back" in { + val testSuites = TestSuites(Map(new HashMap[Id, TestSuite]())) + testSuites.suites.values = testSuites.suites.values + (Id(0) -> TestSuite()) + val apps = GuiApplications(Map(new HashMap[Id, GuiApplication]())) + apps.apps.values = apps.apps.values + (Id(0) -> new GuiApplication(testSuites)) + val json = apps.toJson + json.toString shouldEqual "{\"apps\":{\"0\":{\"testSuites\":{\"suites\":{\"0\":{}}}}}}" + val transformedApps = json.convertTo[GuiApplications] + transformedApps.apps.values.isEmpty shouldEqual false + transformedApps.apps.values.contains(Id(0)) shouldEqual true + val transformedSuites = transformedApps.apps.values(Id(0)).testSuites.suites.values + transformedSuites.isEmpty shouldEqual false + transformedSuites.contains(Id(0)) shouldEqual true + } } } \ No newline at end of file diff --git a/src/test/scala/de/retest/guistatemachine/RestServiceSpec.scala b/src/test/scala/de/retest/guistatemachine/RestServiceSpec.scala index aee5c2b..41920c0 100644 --- a/src/test/scala/de/retest/guistatemachine/RestServiceSpec.scala +++ b/src/test/scala/de/retest/guistatemachine/RestServiceSpec.scala @@ -26,6 +26,7 @@ class RestServiceSpec extends WordSpec with Matchers with ScalatestRouteTest wit "The service" should { "show the default text for the GET request with the path /" in { Get("/") ~> sut ~> check { + handled shouldEqual true val r = responseAs[String] r shouldEqual "GUI State Machine API" } @@ -42,6 +43,7 @@ class RestServiceSpec extends WordSpec with Matchers with ScalatestRouteTest wit "allow POST for path /create-application" in { Post("/create-application") ~> sut ~> check { + handled shouldEqual true responseAs[Id] shouldEqual Id(0) } } @@ -57,6 +59,8 @@ class RestServiceSpec extends WordSpec with Matchers with ScalatestRouteTest wit "return an empty list for the GET request with the path /application/0/test-suites" in { Get("/application/0/test-suites") ~> sut ~> check { + handled shouldEqual true + status shouldEqual StatusCodes.OK val r = responseAs[TestSuites] r.suites.values.size shouldEqual 0 } @@ -64,6 +68,7 @@ class RestServiceSpec extends WordSpec with Matchers with ScalatestRouteTest wit "allow POST for path /application/0/create-test-suite" in { Post("/application/0/create-test-suite") ~> sut ~> check { + handled shouldEqual true responseAs[Id] shouldEqual Id(0) } } @@ -79,6 +84,7 @@ class RestServiceSpec extends WordSpec with Matchers with ScalatestRouteTest wit "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" }