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.
Browse files
Browse the repository at this point in the history
- Move REST part into package rest - Add api package and retest/Selenium dependencies - Use scalamock for mocking - Add scalafmt sbt plugin and rules file - Refactor DSL code
- Loading branch information
Showing
30 changed files
with
369 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
/bin/ | ||
/target/ | ||
/.classpath | ||
/.settings | ||
/.idea | ||
/bin | ||
/target | ||
/project/project | ||
/project/target |
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 @@ | ||
maxColumn = 160 |
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
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 @@ | ||
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.5.1") |
26 changes: 0 additions & 26 deletions
26
src/main/scala/de/retest/guistatemachine/JsonFormatForIdMap.scala
This file was deleted.
Oops, something went wrong.
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,6 @@ | ||
package de.retest.guistatemachine.api | ||
|
||
/** | ||
* Interaction from the user with the GUI. | ||
*/ | ||
case class Action(a : org.openqa.selenium.interactions.Action) |
8 changes: 8 additions & 0 deletions
8
src/main/scala/de/retest/guistatemachine/api/Descriptors.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,8 @@ | ||
package de.retest.guistatemachine.api | ||
|
||
import de.retest.ui.descriptors.RootElement | ||
|
||
/** | ||
* Set of root elements which identifies a state. | ||
*/ | ||
case class Descriptors(rootElements: Set[RootElement]) |
29 changes: 29 additions & 0 deletions
29
src/main/scala/de/retest/guistatemachine/api/GuiStateMachine.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,29 @@ | ||
package de.retest.guistatemachine.api | ||
|
||
/** | ||
* API to create a NFA which represents the current state machine of an automatic GUI test generation with the help of a genetic algorithm. | ||
* Simulated actions by the user are mapped to transitions in the state machine. | ||
* States are identified by descriptors. | ||
* There can be ambigious states which makes the finite state machine non-deterministic. | ||
*/ | ||
trait GuiStateMachine { | ||
|
||
/** | ||
* Gets a state identified by descriptors and with its initial never explored actions. | ||
* @param descriptors The descriptors which identify the state. | ||
* @param neverExploredActions All actions which have never been explored from the state. | ||
* @return The state identified by the descriptors. If there has not been any state yet, it will be added. | ||
*/ | ||
def getState(descriptors: Descriptors, neverExploredActions: Set[Action]): State | ||
|
||
/** | ||
* Executes an action from a state leading to the current state described by descriptors. | ||
* | ||
* @param from The state the action is executed from | ||
* @param a The action which is executed by the user. | ||
* @param descriptors The descriptors which identify the state which the action leads to and which is returned by this method. | ||
* @param neverExploredActions The never explored actions of the state which the action leads to and which is returned by this method. | ||
* @return The current state which the transition of a leads to. | ||
*/ | ||
def executeAction(from: State, a: Action, descriptors: Descriptors, neverExploredActions: Set[Action]): State | ||
} |
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,15 @@ | ||
package de.retest.guistatemachine.api | ||
|
||
/** | ||
* A state should be identified by its corresponding [[Descriptors]]. | ||
* It consists of actions which have not been explored yet and transitions which build up the state machine. | ||
*/ | ||
trait State { | ||
def getNeverExploredActions: Set[Action] | ||
|
||
/** | ||
* NFA states can lead to different states by consuming the same symbol. | ||
* Hence, we have a set of states per action. | ||
*/ | ||
def getTransitions: Map[Action, Set[State]] | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/scala/de/retest/guistatemachine/api/impl/GuiStateMachineImpl.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,25 @@ | ||
package de.retest.guistatemachine.api.impl | ||
|
||
import de.retest.guistatemachine.api.{Action, Descriptors, GuiStateMachine, State} | ||
|
||
import scala.collection.mutable.HashMap | ||
|
||
object GuiStateMachineImpl extends GuiStateMachine { | ||
val states = new HashMap[Descriptors, State] | ||
|
||
override def getState(descriptors: Descriptors, neverExploredActions: Set[Action]): State = { | ||
if (states.contains(descriptors)) { | ||
states(descriptors) | ||
} else { | ||
val s = new StateImpl(descriptors, neverExploredActions.to) | ||
states += (descriptors -> s) | ||
s | ||
} | ||
} | ||
|
||
override def executeAction(from: State, a: Action, descriptors: Descriptors, neverExploredActions: Set[Action]): State = { | ||
val to = getState(descriptors, neverExploredActions) | ||
from.asInstanceOf[StateImpl].addTransition(a, to) | ||
to | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
src/main/scala/de/retest/guistatemachine/api/impl/StateImpl.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.api.impl | ||
|
||
import de.retest.guistatemachine.api.{Action, Descriptors, State} | ||
|
||
import scala.collection.immutable.{HashMap, HashSet} | ||
|
||
class StateImpl(val descriptors: Descriptors, var neverExploredActions: Set[Action]) extends State { | ||
|
||
/** | ||
* TODO #4 Currently, there is no MultiMap trait for immutable maps. | ||
*/ | ||
var transitions = new HashMap[Action, Set[State]] | ||
|
||
override def getNeverExploredActions: Set[Action] = neverExploredActions | ||
override def getTransitions: Map[Action, Set[State]] = transitions | ||
|
||
def addTransition(a: Action, to: State): Unit = { | ||
if (!transitions.contains(a)) { | ||
transitions = transitions + (a -> HashSet(to)) | ||
// TODO #4 This is not done in the legacy code: | ||
neverExploredActions -= a | ||
} else { | ||
transitions = transitions + (a -> (transitions(a) + to)) | ||
} | ||
} | ||
|
||
/** | ||
* Overriding this method is required to allow the usage of a set of states. | ||
* Comparing the descriptors should check for the equality of all root elements which compares the identifying attributes and the contained components | ||
* for each root element. | ||
*/ | ||
override def equals(obj: Any): Boolean = { | ||
if (obj.isInstanceOf[StateImpl]) { | ||
val other = obj.asInstanceOf[StateImpl] | ||
this.descriptors eq other.descriptors | ||
} else { | ||
super.equals(obj) | ||
} | ||
} | ||
|
||
override def hashCode(): Int = this.descriptors.hashCode() | ||
} |
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.dsl | ||
|
||
abstract class Action | ||
trait Action |
4 changes: 2 additions & 2 deletions
4
src/main/scala/de/retest/guistatemachine/dsl/FinalState.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,6 +1,6 @@ | ||
package de.retest.guistatemachine.dsl | ||
|
||
/** | ||
* There can be more than one end state. | ||
* NFAs can have more than one final state. | ||
*/ | ||
abstract class FinalState extends State | ||
trait FinalState extends State |
5 changes: 4 additions & 1 deletion
5
src/main/scala/de/retest/guistatemachine/dsl/InitialState.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,6 @@ | ||
package de.retest.guistatemachine.dsl | ||
|
||
abstract class InitialState extends State | ||
/** | ||
* NFAs have only one initial state. | ||
*/ | ||
trait InitialState extends State |
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
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
30 changes: 30 additions & 0 deletions
30
src/main/scala/de/retest/guistatemachine/rest/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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package de.retest.guistatemachine.rest | ||
|
||
import de.retest.guistatemachine.model.Map | ||
import de.retest.guistatemachine.model.Id | ||
import spray.json.JsValue | ||
import spray.json.JsonFormat | ||
import spray.json.RootJsonFormat | ||
|
||
/** | ||
* Transforms a [[de.retest.guistatemachine.model.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 [[de.retest.guistatemachine.model.Map]]. | ||
* This transformer requires a JSON format for the type `K`. | ||
*/ | ||
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 = | ||
jsonFormat0.write(obj.values.map { field => | ||
(field._1.id.toString -> field._2) | ||
}) | ||
|
||
override def read(json: JsValue): Map[T] = { | ||
val map = jsonFormat0.read(json) | ||
new Map[T](map.map { x => | ||
(Id(x._1.toLong) -> x._2) | ||
}) | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
.../retest/guistatemachine/RestService.scala → ...st/guistatemachine/rest/RestService.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
Oops, something went wrong.