Skip to content

Commit 1106e9e

Browse files
author
Reinier Lamers
committed
split root project into core and command line
1 parent 2f5b4fb commit 1106e9e

File tree

29 files changed

+121
-93
lines changed

29 files changed

+121
-93
lines changed

aws-lambda/src/main/scala/chargepoint/docile/Lambda.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package chargepoint.docile
22

33
import java.net.URI
44

5-
import chargepoint.docile.test.{RunOnce, Runner, RunnerConfig}
5+
import chargepoint.docile.test.{ResultSummary, RunOnce, Runner, RunnerConfig}
66
import com.amazonaws.auth.DefaultAWSCredentialsProviderChain
77
import com.amazonaws.services.lambda.runtime.Context
88
import com.amazonaws.services.lambda.runtime.events.S3Event
@@ -66,7 +66,7 @@ object Lambda extends App {
6666

6767
Try(runner.run(runnerCfg)) match {
6868
case Success(testsPassed) =>
69-
val succeeded = Main.summarizeResults(testsPassed, reporter.print)
69+
val succeeded = ResultSummary.summarizeResults(testsPassed, reporter.print)
7070
writeReportToS3(script.name, reporter.report)
7171
sys.exit(if (succeeded) 0 else 1)
7272
case Failure(e) =>

build.sbt

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,40 @@ lazy val commonSettings = Seq(
1010
javacOptions ++= Seq("-source", "1.8", "-target", "1.8", "-Xlint")
1111
)
1212

13-
lazy val root = (project in file(".")).
14-
settings(
13+
lazy val commandLine = (project in file("cmd"))
14+
.dependsOn(core)
15+
.dependsOn(loader)
16+
.settings(
1517
commonSettings,
16-
name := "docile-charge-point",
18+
name := "docile-charge-point-command-line",
19+
libraryDependencies ++= commandLineDeps,
1720
mainClass := Some("chargepoint.docile.Main"),
1821
assemblyJarName in assembly := "docile.jar",
19-
connectInput in run := true,
20-
libraryDependencies ++= deps(scalaVersion.value)
22+
connectInput in run := true
2123
)
2224

23-
lazy val lambda = (project in file("aws-lambda")).
24-
dependsOn(root).
25+
lazy val core = (project in file("core")).
2526
settings(
27+
commonSettings,
28+
name := "docile-charge-point",
29+
libraryDependencies ++= coreDeps(scalaVersion.value)
30+
)
31+
32+
lazy val loader = (project in file("loader"))
33+
.dependsOn(core)
34+
.settings(
35+
commonSettings,
36+
name := "docile-charge-point-loader"
37+
)
38+
39+
lazy val lambda = (project in file("aws-lambda"))
40+
.dependsOn(core)
41+
.dependsOn(loader)
42+
.settings(
2643
commonSettings,
2744
name := "lambda-docile-charge-point",
2845
retrieveManaged := true,
29-
libraryDependencies ++= deps(scalaVersion.value) ++ awsDeps,
46+
libraryDependencies ++= awsDeps,
3047
mainClass := Some("chargepoint.docile.Lambda"),
3148
assemblyJarName in assembly := "docile-lambda.jar"
3249
)
@@ -35,18 +52,21 @@ assemblyJarName in assembly := "docile.jar"
3552

3653
connectInput in run := true
3754

38-
def deps(scalaVersion: String) = Seq(
39-
"com.lihaoyi" % "ammonite" % "1.6.5" cross CrossVersion.full,
55+
def coreDeps(scalaVersion: String) = Seq(
4056
"com.thenewmotion.ocpp" %% "ocpp-j-api" % "9.1.0",
41-
"org.rogach" %% "scallop" % "3.1.3",
4257
"org.scala-lang" % "scala-compiler" % scalaVersion,
43-
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.0",
4458
"org.slf4j" % "slf4j-api" % "1.7.25",
45-
"ch.qos.logback" % "logback-classic" % "1.2.3",
59+
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.0",
4660

4761
"org.specs2" %% "specs2-core" % "4.3.4" % "test"
4862
)
4963

64+
lazy val commandLineDeps = Seq(
65+
"com.lihaoyi" % "ammonite" % "1.6.5" cross CrossVersion.full,
66+
"org.rogach" %% "scallop" % "3.1.3",
67+
"ch.qos.logback" % "logback-classic" % "1.2.3"
68+
)
69+
5070
lazy val awsDeps = Seq(
5171
"com.amazonaws" % "aws-java-sdk-s3" % "1.11.337",
5272
"com.amazonaws" % "aws-java-sdk-lambda" % "1.11.337",

src/main/scala/chargepoint/docile/Main.scala renamed to cmd/src/main/scala/chargepoint/docile/Main.scala

Lines changed: 12 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package chargepoint.docile
22

33
import java.net.URI
4-
import javax.net.ssl.SSLContext
5-
import scala.util.{Failure, Success, Try}
4+
5+
import chargepoint.docile.dsl._
6+
import chargepoint.docile.test._
7+
import ResultSummary.summarizeResults
68
import ch.qos.logback.classic.{Level, Logger}
9+
import com.thenewmotion.ocpp.{Version, VersionFamily}
10+
import com.typesafe.scalalogging.{StrictLogging}
11+
import javax.net.ssl.SSLContext
712
import org.rogach.scallop._
813
import org.slf4j.LoggerFactory
9-
import com.typesafe.scalalogging.StrictLogging
10-
import com.thenewmotion.ocpp.Version
11-
import dsl._
12-
import test._
1314

1415
import scala.concurrent.ExecutionContext
16+
import scala.util.{Failure, Success, Try}
1517

1618
object Main extends App with StrictLogging {
1719

@@ -175,7 +177,7 @@ object Main extends App with StrictLogging {
175177

176178
val runner: Runner[_] =
177179
if (conf.interactive())
178-
Runner.interactive(conf.version().family)
180+
interactiveRunner(conf.version().family)
179181
else
180182
Runner.forFiles(conf.version().family, conf.files())
181183

@@ -192,63 +194,7 @@ object Main extends App with StrictLogging {
192194
sys.exit(2)
193195
}
194196

195-
def summarizeResults(testResults: Map[String, Seq[Map[String, TestResult]]], report:Any => Unit): Boolean = {
196-
197-
// we do result formatting differently depending on whether we're doing a
198-
// single run (one charge point, one pass through the test script), or if
199-
// we're doing a complex one (multiple charge point and/or multiple repeats)
200-
val isSingleRun = testResults.size == 1 && testResults.toSeq.headOption.exists(_._2.size == 1)
201-
if (isSingleRun) {
202-
val singleRunResult =
203-
testResults
204-
.headOption
205-
.flatMap(_._2.headOption)
206-
.getOrElse(Map.empty[String, TestResult])
207-
208-
summarizeSingleRun(singleRunResult, report)
209-
} else {
210-
summarizeComplexRun(testResults, report)
211-
}
212-
}
213-
214-
private def summarizeSingleRun(testResults: Map[String, TestResult], report: Any => Unit): Boolean = {
215-
val outcomes = testResults map { case (testName, outcome) =>
216-
217-
val outcomeDescription = outcome match {
218-
case TestFailed(ExpectationFailed(msg)) =>
219-
s"$msg"
220-
case TestFailed(ExecutionError(e)) =>
221-
s"💥 ${e.getClass.getSimpleName} ${e.getMessage}\n" +
222-
s"\t${e.getStackTrace.mkString("\n\t")}"
223-
case TestPassed =>
224-
s""
225-
}
226-
227-
report(s"$testName: $outcomeDescription")
228-
229-
outcome
230-
}
231-
232-
outcomes.collect({ case TestFailed(_) => }).isEmpty
233-
}
234-
235-
private def summarizeComplexRun(testResults: Map[String, Seq[Map[String, TestResult]]], report: Any => Unit): Boolean = {
236-
val countsPerChargePoint: Map[String, (Int, Int, Int)] = testResults.mapValues { runs =>
237-
runs.foldLeft((0, 0, 0)) { case (counts, results) =>
238-
val countsForRun = results.values.foldLeft((0,0,0)) {
239-
case ((f, e, p), TestFailed(ExpectationFailed(_))) => (f+1, e , p)
240-
case ((f, e, p), TestFailed(ExecutionError(_))) => (f , e+1, p)
241-
case ((f, e, p), TestPassed) => (f , e , p+1)
242-
}
243-
244-
(counts._1 + countsForRun._1, counts._2 + countsForRun._2, counts._3 + countsForRun._3)
245-
}
246-
}
247-
248-
countsPerChargePoint foreach { case (chargePointId, counts) =>
249-
report(s"$chargePointId: ${counts._1} failed / ${counts._2} errors / ${counts._3} passed")
250-
}
251-
252-
!countsPerChargePoint.values.exists(c => c._1 != 0 || c._2 != 0)
253-
}
197+
def interactiveRunner(vfam: VersionFamily): Runner[vfam.type] = new Runner[vfam.type](
198+
Seq(TestCase("Interactive test", () => InteractiveOcppTest(vfam)))
199+
)
254200
}

src/main/scala/chargepoint/docile/SslContext.scala renamed to cmd/src/main/scala/chargepoint/docile/SslContext.scala

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ package chargepoint.docile
33
import java.io.FileInputStream
44
import java.security.KeyStore
55

6-
import javax.net.ssl.KeyManagerFactory
7-
import javax.net.ssl.SSLContext
8-
import javax.net.ssl.TrustManagerFactory
6+
import javax.net.ssl.{KeyManagerFactory, SSLContext, TrustManagerFactory}
97

108
object SslContext {
119
def apply(

src/main/scala/chargepoint/docile/test/InteractiveOcppTest.scala renamed to cmd/src/main/scala/chargepoint/docile/test/InteractiveOcppTest.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package chargepoint.docile
22
package test
33

4-
import scala.language.higherKinds
5-
import scala.concurrent.ExecutionContext.global
4+
import chargepoint.docile.dsl._
65
import com.thenewmotion.ocpp.VersionFamily
7-
import com.thenewmotion.ocpp.messages.{Request, Response, ReqRes}
86
import com.thenewmotion.ocpp.messages.v1x.{CentralSystemReq, CentralSystemReqRes, CentralSystemRes, ChargePointReq, ChargePointReqRes, ChargePointRes}
9-
import com.thenewmotion.ocpp.messages.v20.{CsmsRequest, CsmsResponse, CsmsReqRes, CsRequest, CsResponse, CsReqRes}
10-
import dsl._
7+
import com.thenewmotion.ocpp.messages.v20._
8+
import com.thenewmotion.ocpp.messages.{ReqRes, Request, Response}
9+
10+
import scala.concurrent.ExecutionContext.global
11+
import scala.language.higherKinds
1112

1213
trait InteractiveOcppTest[VFam <: VersionFamily] {
1314

File renamed without changes.

0 commit comments

Comments
 (0)