Permalink
Browse files

finished up fixture

added happy flow scenario and not happy flow
fixed domain behaviour
  • Loading branch information...
1 parent f4c934e commit 94807b776984cd5f27ec8f15d6a4f45ab79e6c04 @TizianoPerrucci committed Jan 21, 2012
View
@@ -1,3 +1,6 @@
*.idea*
*.iml
target
+FitNesseRoot/ErrorLogs
+FitNesseRoot/RecentChanges
+FitNesseRoot/files/testResults
@@ -0,0 +1,4 @@
+|table: MAC Expectation |
+|I'm a easy drinker with a slim bodyframe |
+|when I drink a countless amount of high spirits |
+|my reaction is expected to be as slow as molasses in January|
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<properties>
+ <Edit>true</Edit>
+ <Files>true</Files>
+ <Properties>true</Properties>
+ <RecentChanges>true</RecentChanges>
+ <Refactor>true</Refactor>
+ <Search>true</Search>
+ <Test/>
+ <Versions>true</Versions>
+ <WhereUsed>true</WhereUsed>
+</properties>
@@ -0,0 +1,4 @@
+|table: MAC Expectation |
+|I'm a heavy drinker with a big boned bodyframe |
+|when I drink a countless amount of high spirits|
+|my reaction is expected to be grease lightning |
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<properties>
+ <Edit>true</Edit>
+ <Files>true</Files>
+ <Properties>true</Properties>
+ <RecentChanges>true</RecentChanges>
+ <Refactor>true</Refactor>
+ <Search>true</Search>
+ <Test/>
+ <Versions>true</Versions>
+ <WhereUsed>true</WhereUsed>
+</properties>
@@ -0,0 +1,2 @@
+|import |
+|nl.mac.fixture|
@@ -0,0 +1,11 @@
+<?xml version="1.0"?>
+<properties>
+ <Edit>true</Edit>
+ <Files>true</Files>
+ <Properties>true</Properties>
+ <RecentChanges>true</RecentChanges>
+ <Refactor>true</Refactor>
+ <Search>true</Search>
+ <Versions>true</Versions>
+ <WhereUsed>true</WhereUsed>
+</properties>
@@ -4,6 +4,7 @@
!define SLIM_PORT {9000}
!define COMMAND_PATTERN {java -Xmx1024m -Xms200m -cp %p %m -v}
#!define COMMAND_PATTERN {java -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=1044 -cp %p %m}
-!define CM_SYSTEM {fitnesse.wiki.cmSystems.GitCmSystem}
+#!define CM_SYSTEM {fitnesse.wiki.cmSystems.GitCmSystem}
-!pomFile ./pom.xml
+!path ./target/scala-2.9.1/classes
+!pomFile ./pom.xml@compile
View
@@ -48,6 +48,8 @@
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
+
+ <!--TODO target dir-->
<!--
<configuration>
<outputDir>target/scala-${scala.version}</outputDir>
@@ -107,6 +109,7 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.scala-tools.testing</groupId>
@@ -0,0 +1,6 @@
+log4j.rootLogger=INFO, CONSOLE
+
+# Console logger, useful for debugging.
+log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
+log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
+log4j.appender.CONSOLE.layout.ConversionPattern=%d{HH:mm:ss,SSS} [%t] %p [%c] - %m%n
@@ -53,12 +53,12 @@ class DrinkingGrammar extends JavaTokenParsers with PackratParsers {
case "as slow as molasses in January" => BodyReactions.slow;
case "ready steady" => BodyReactions.ready;
case "quick and dirty" => BodyReactions.quick;
- case "grease lightning!" => BodyReactions.fast;
+ case "grease lightning" => BodyReactions.fast;
}
def notValidExpression(exp: String): String = {
- "Expression '" + exp + "' IS NOT VALID! (talk with your tester ;))"
+ "Expression '" + exp + "' IS NOT VALID: talk with your tester! ;)"
}
@@ -44,10 +44,10 @@ import nl.mac.model.Moderations._
object BodyReactions extends Enumeration {
type BodyReaction = Value
- val slow = Value(1)
- val ready = Value(2)
- val quick = Value(3)
- val fast = Value(4)
+ val fast = Value(1)
+ val quick = Value(2)
+ val ready = Value(3)
+ val slow = Value(4)
}
import nl.mac.model.BodyReactions._
@@ -1,69 +0,0 @@
-package nl.mac.fixture
-
-import org.apache.log4j.Logger
-
-class DrinkingExpectation() {
- val log: Logger = Logger.getLogger(classOf[DrinkingExpectation])
-
- def doTable(content: java.util.List[java.util.List[String]]) : java.util.List[java.util.List[String]] = {
- import scala.collection.JavaConversions._
-
- val sb = new StringBuilder()
-
- var first = true
- val iterator: Iterator[java.util.List[String]] = content.iterator()
- while (iterator.hasNext) {
- if (!first) {
- val row: java.util.List[String] = iterator.next()
- sb.append(row.toArray.toList.mkString).append("\n")
- }
- first = false
- }
-
- val sentence = sb.toString()
-
- /*val p = new AnvrGrammar(tourOperator)
- def empty = java.util.Arrays.asList("")
- def pass = java.util.Arrays.asList("pass")
- def fail(msg : String ) = java.util.Arrays.asList("fail:"+msg)
- log.info("Sentence to parse: " + sentence);
-
- p.parseAll(p.anvrPackage, sentence) match {
- case p.Success(anvrPackage, _) =>
- finalizePackageWithInferredData(anvrPackage)
- val pushed: Boolean = transferModel(anvrPackage)
- log.info("Domain object: " + anvrPackage.toString)
- content map (x => if (pushed) pass else fail(x.head + "BR/>Problems pushing the msg. See log for details"))
-
- case p.NoSuccess(msg, input) =>
- log.error("Specification is NOT parsed successfully, input '" + input.toString + "', at position: " + input.pos.toString)
- log.error(p.toString)
- val errorLine: Int = input.pos.line - 1
- val result = content map (x => empty)
- result += empty // Added one line more for showing errors at the end of the grammar
- content += empty
- for (i <- 0 to errorLine) result(i) = pass
- val errorLineAndArrow: String = content(errorLine).head + "<BR/>" + "&nbsp;" * (input.pos.column - 1) + "^"
- val detailedError: String = "<BR/>Error:" + msg
- result(errorLine) = fail("<span class=\"code\">" +errorLineAndArrow + "</span>" +detailedError);
- result
- }*/
-
- Nil
- }
-
-
- /*def transferModel(anvrPackage: AnvrPackage): Boolean = {
- try {
- val array: Array[Byte] = Marshal.dump(anvrPackage)
-
- FileUtils.writeByteArrayToFile(new File("target/classes/AnvrModel"), array)
-
- new ScpExecutor(getTestInputIp, getTestInputUser, getTestInputPass).transferTo("AnvrModel", "/home/elmar/test-input/g7/" + tourOperator)
- }
- catch {
- case _ => false
- }
- }*/
-
-}
@@ -0,0 +1,74 @@
+package nl.mac.fixture
+
+import org.apache.log4j.Logger
+import nl.mac.dsl.DrinkingGrammar
+import nl.mac.model.BodyReactions._
+import nl.mac.model.{BodyReactions, MorningAfterReaction}
+
+class MACExpectation() {
+ val log: Logger = Logger.getLogger(classOf[MACExpectation])
+
+ def doTable(content: java.util.List[java.util.List[String]]): java.util.List[java.util.List[String]] = {
+ import scala.collection.JavaConversions._
+
+ val sb = new StringBuilder()
+
+ var first = true
+ val iterator: Iterator[java.util.List[String]] = content.iterator()
+ while (iterator.hasNext) {
+ if (!first) {
+ val row: java.util.List[String] = iterator.next()
+ sb.append(row.toArray.toList.mkString).append("\n")
+ }
+ first = false
+ }
+
+ val sentence = sb.toString()
+
+ def empty = java.util.Arrays.asList("")
+ def pass = java.util.Arrays.asList("pass")
+ def fail(msg: String) = java.util.Arrays.asList("fail:" + msg)
+ log.info("Sentence to parse: " + sentence);
+
+ val p = new DrinkingGrammar
+ p.parseAll(p.morningAfterReaction, sentence) match {
+ case p.Success(morningAfterReaction, _) =>
+ log.info("Domain object: " + morningAfterReaction.toString)
+
+ val expectedReation = morningAfterReaction.reaction
+ val answerReaction = call(morningAfterReaction)
+
+ val result = new java.util.ArrayList[java.util.List[String]]()
+
+ content.zipWithIndex.foreach {
+ case (line, index) =>
+ if (index != content.size - 1) result.append(pass)
+ else if (answerReaction.equals(morningAfterReaction)) result.append(pass)
+ else {
+ result.append(fail(line.head + "<br/><br/>Expected expression: '%s', instead of: '%s'" format(answerReaction, expectedReation)))
+ }
+ }
+
+ result
+
+ case p.NoSuccess(msg, input) =>
+ log.error("Specification is NOT parsed successfully, input '" + input.toString + "', at position: " + input.pos.toString)
+ log.error(p.toString)
+ val errorLine: Int = input.pos.line - 1
+ val result = content map (x => empty)
+ result += empty // Added one line more for showing errors at the end of the grammar
+ content += empty
+ for (i <- 0 to errorLine) result(i) = pass
+ val errorLineAndArrow: String = content(errorLine).head + "<BR/>" + "&nbsp;" * (input.pos.column - 1) + "^"
+ val detailedError: String = "<BR/>Error:" + msg
+ result(errorLine) = fail("<span class=\"code\">" + errorLineAndArrow + "</span>" + detailedError);
+ result
+ }
+ }
+
+ def call(macReaction: MorningAfterReaction): BodyReaction = {
+ //TODO move result transformation to application
+ BodyReactions.apply((Querier.query(macReaction.state).toDouble / 4).toInt)
+ }
+
+}
@@ -2,11 +2,14 @@ package nl.mac.fixture
import org.springframework.web.client.RestTemplate
import nl.mac.model._
+import org.apache.log4j.Logger
object Querier {
val baseUrl = "http://localhost:8080/reaction/"
- val restTemplate = new RestTemplate()
+
+ private val restTemplate = new RestTemplate()
+ private val log: Logger = Logger.getLogger(classOf[MACExpectation])
def query(state: DrinkingState): String = {
val h = DrinkingHabits.withName(state.persona.habits.toString).id
@@ -17,8 +20,9 @@ object Querier {
doRequest(baseUrl + "%s/%s/%s/%s" format (h, w, p, m))
}
- def doRequest(url: String): String = {
+ private def doRequest(url: String): String = {
val response = restTemplate.getForObject(url, classOf[String]);
+ log.info("The application said: [%s]" format response.trim)
response.substring(response.indexOf(':') + 1).trim
}
}
@@ -7,15 +7,15 @@ class QuerierTest extends SpecificationWithJUnit {
"i shouldn't be drunk" in {
val state = DrinkingState(Persona(DrinkingHabits.heavy, BodyWeights.heavy), Drink(Moderations.few, AlcoholicPercentages.beerLow))
- val response: Double = query(state).toDouble
+ val response: Double = Querier.query(state).toDouble
response must be greaterThanOrEqualTo 4
response must be lessThan 10
}
"i should be drunk" in {
val state = DrinkingState(Persona(DrinkingHabits.easy, BodyWeights.slim), Drink(Moderations.many, AlcoholicPercentages.spiritHigh))
- val response: Double = query(state).toDouble
+ val response: Double = Querier.query(state).toDouble
response must be greaterThan 10
}

0 comments on commit 94807b7

Please sign in to comment.