Skip to content

Commit 04dafac

Browse files
committed
make scripts and interactive mode run again
1 parent 4eaa3a2 commit 04dafac

File tree

8 files changed

+28
-35
lines changed

8 files changed

+28
-35
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,15 @@ object InteractiveOcppTest {
125125
val ops: Ocpp1XTest.V1XOps = new Ocpp1XTest.V1XOps
126126
with expectations.Ops[VersionFamily.V1X.type, CentralSystemReq, CentralSystemRes, CentralSystemReqRes, ChargePointReq, ChargePointRes, ChargePointReqRes]
127127
with shortsend.OpsV1X {
128-
def connectionData = connDat
128+
def connection = connDat
129129

130130
implicit val csmsMessageTypes = VersionFamily.V1XCentralSystemMessages
131131
implicit val csMessageTypes = VersionFamily.V1XChargePointMessages
132132
implicit val executionContext = global
133133
}
134134

135135
val promptCommands: InteractiveOcpp1XTest.V1XPromptCommands = new InteractiveOcpp1XTest.V1XPromptCommands {
136-
def connectionData = connDat
136+
def connection = connDat
137137
}
138138
}.asInstanceOf[OcppTest[vfam.type]]
139139

@@ -149,15 +149,15 @@ object InteractiveOcppTest {
149149

150150
val ops: Ocpp20Test.V20Ops = new Ocpp20Test.V20Ops
151151
with expectations.Ops[VersionFamily.V20.type, CsmsRequest, CsmsResponse, CsmsReqRes, CsRequest, CsResponse, CsReqRes] {
152-
def connectionData = connDat
152+
def connection = connDat
153153

154154
implicit val csmsMessageTypes = VersionFamily.V20CsmsMessages
155155
implicit val csMessageTypes = VersionFamily.V20CsMessages
156156
implicit val executionContext = global
157157
}
158158

159159
val promptCommands: InteractiveOcpp20Test.V20PromptCommands = new InteractiveOcpp20Test.V20PromptCommands {
160-
def connectionData = connDat
160+
def connection = connDat
161161
}
162162
}.asInstanceOf[OcppTest[vfam.type]]
163163
}
@@ -173,12 +173,12 @@ object InteractiveOcppTest {
173173
InReqRes[_ <: InReq, _ <: OutRes] <: ReqRes[_, _]
174174
] {
175175

176-
protected def connectionData: DocileConnection[VFam, VersionBound, OutReq, InRes, OutReqRes, InReq, OutRes, InReqRes]
176+
protected def connection: DocileConnection[VFam, VersionBound, OutReq, InRes, OutReqRes, InReq, OutRes, InReqRes]
177177

178178
def q: Unit =
179-
connectionData.receivedMsgManager.currentQueueContents foreach println
179+
connection.receivedMsgManager.currentQueueContents foreach println
180180

181181
def whoami: Unit =
182-
println(connectionData.chargePointIdentity)
182+
println(connection.chargePointIdentity)
183183
}
184184
}

core/src/main/scala/chargepoint/docile/dsl/CoreOps.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ trait CoreOps[
4444
val logger = Logger(LoggerFactory.getLogger("script"))
4545
def say(m: String): Unit = logger.info(m)
4646

47-
protected def connectionData: DocileConnection[VFam, _, OutReq, InRes, OutReqRes, InReq, OutRes, InReqRes]
47+
protected def connection: DocileConnection[VFam, _, OutReq, InRes, OutReqRes, InReq, OutRes, InReqRes]
4848

4949
/**
5050
* Send an OCPP request to the Central System under test.
@@ -59,20 +59,20 @@ trait CoreOps[
5959
* @tparam Q
6060
*/
6161
def send[Q <: OutReq](req: Q)(implicit reqRes: OutReqRes[Q, _ <: InRes]): Unit =
62-
connectionData.ocppClient match {
62+
connection.ocppClient match {
6363
case None =>
6464
throw ExpectationFailed("Trying to send an OCPP message while not connected")
6565
case Some (client) =>
6666
outgoingLogger.info(s"$req")
6767
client.send(req)(reqRes) onComplete {
6868
case Success(res) =>
6969
incomingLogger.info(s"$res")
70-
connectionData.receivedMsgManager.enqueue(
70+
connection.receivedMsgManager.enqueue(
7171
IncomingMessage(res)
7272
)
7373
case Failure(OcppException(ocppError)) =>
7474
incomingLogger.info(s"$ocppError")
75-
connectionData.receivedMsgManager.enqueue(
75+
connection.receivedMsgManager.enqueue(
7676
IncomingMessage(ocppError)
7777
)
7878
case Failure(e) =>
@@ -83,17 +83,17 @@ trait CoreOps[
8383

8484
// WIP an operation to add a default handler for a certain subset of incoming messages
8585
def handlingIncomingMessages[T](proc: IncomingMessageProcessor[_])(f: => T): T = {
86-
connectionData.pushIncomingMessageHandler(proc)
86+
connection.pushIncomingMessageHandler(proc)
8787
val result = f
88-
connectionData.popIncomingMessageHandler()
88+
connection.popIncomingMessageHandler()
8989

9090
result
9191
}
9292

9393
def awaitIncoming(num: Int)(implicit awaitTimeout: AwaitTimeout): Seq[IncomingMessage] = {
9494

9595
val timeout = awaitTimeout.toDuration
96-
def getMsgs = connectionData.receivedMsgManager.dequeue(num)
96+
def getMsgs = connection.receivedMsgManager.dequeue(num)
9797

9898
Try(Await.result(getMsgs, timeout)) match {
9999
case Success(msgs) => msgs
@@ -108,7 +108,7 @@ trait CoreOps[
108108
* This can be used in interactive mode to get out of a situation where you've received a bunch of messages that you
109109
* don't really care about, and you want to get on with things.
110110
*/
111-
def flushQ(): Unit = connectionData.receivedMsgManager.flush()
111+
def flushQ(): Unit = connection.receivedMsgManager.flush()
112112

113113
def fail(message: String): Nothing = throw ExpectationFailed(message)
114114

core/src/main/scala/chargepoint/docile/dsl/OcppTest.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@ trait DocileConnection[
236236
connectionLogger.info(s"Gracefully disconnected from endpoint $endpoint")
237237
ocppClient = None
238238
}(executionContext)
239+
240+
ocppClient = Some(connection)
239241
}
240242

241243
/** Template method to be implemented by version-specific extending classes to establish a connection for that

core/src/main/scala/chargepoint/docile/dsl/expectations/Ops.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ trait Ops[
2121
] {
2222
self: CoreOps[VFam, OutReq, InRes, OutReqRes, InReq, OutRes, InReqRes] =>
2323

24+
// TODO document why we need this subset of IncomingMessageProcessor
2425
sealed trait IncomingRequestProcessor[+T] extends IncomingMessageProcessor[T]
2526

2627
def expectIncoming[T](proc: IncomingMessageProcessor[T])(implicit awaitTimeout: AwaitTimeout): T = {
@@ -129,13 +130,13 @@ trait Ops[
129130
error restrictedBy { case e@OcppError(`code`, _) => e }
130131

131132

132-
def getConfigurationReq = requestMatching { case r: GetConfigurationReq => r }
133+
def getConfigurationReq: IncomingRequestProcessor[GetConfigurationReq] = requestMatching { case r: GetConfigurationReq => r }
133134
def changeConfigurationReq = requestMatching { case r: ChangeConfigurationReq => r }
134135
def getDiagnosticsReq = requestMatching { case r: GetDiagnosticsReq => r }
135136
def changeAvailabilityReq = requestMatching { case r: ChangeAvailabilityReq => r }
136-
def getLocalListVersionReq = requestMatching { case r if r == GetLocalListVersionReq => r }
137+
def getLocalListVersionReq = requestMatching { case r: GetLocalListVersionReq.type => r }
137138
def sendLocalListReq = requestMatching { case r: SendLocalListReq => r }
138-
def clearCacheReq = requestMatching { case r if r == ClearCacheReq => r }
139+
def clearCacheReq: IncomingRequestProcessor[ClearCacheReq.type] = requestMatching { case r: ClearCacheReq.type => r }
139140
def resetReq = requestMatching { case r: ResetReq => r }
140141
def updateFirmwareReq = requestMatching { case r: UpdateFirmwareReq => r }
141142
def remoteStartTransactionReq = requestMatching { case r: RemoteStartTransactionReq => r }

core/src/main/scala/chargepoint/docile/dsl/shortsend/OpsV1X.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ trait OpsV1X {
4040
def bootNotification(
4141
chargePointVendor: String = "The New Motion BV",
4242
chargePointModel: String = "Test Basic",
43-
chargePointSerialNumber: Option[String] = Some(connectionData.chargePointIdentity),
44-
chargeBoxSerialNumber: Option[String] = Some(connectionData.chargePointIdentity),
43+
chargePointSerialNumber: Option[String] = Some(connection.chargePointIdentity),
44+
chargeBoxSerialNumber: Option[String] = Some(connection.chargePointIdentity),
4545
firmwareVersion: Option[String] = Some("1.0.0"),
4646
iccid: Option[String] = None,
4747
imsi: Option[String] = None,

core/src/main/scala/chargepoint/docile/dsl/shortsend/OpsV20.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ trait OpsV20 {
4343

4444
def bootNotification(
4545
chargingStation: ChargingStation = ChargingStation(
46-
serialNumber = Some(connectionData.chargePointIdentity),
46+
serialNumber = Some(connection.chargePointIdentity),
4747
model = "Docile",
4848
vendorName = "The New Motion BV",
4949
firmwareVersion = Some("1.0.0"),

core/src/test/scala/chargepoint/docile/dsl/expectations/OpsSpec.scala

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ class OpsSpec extends Specification {
2323
mock send GetConfigurationReq(keys = List())
2424
mock send ClearCacheReq
2525

26-
val result: Seq[ChargePointReq] =
27-
28-
expectAllIgnoringUnmatched(
26+
val result: Seq[ChargePointReq] = expectAllIgnoringUnmatched(
2927
clearCacheReq respondingWith ClearCacheRes(accepted = true)
3028
)
3129

@@ -80,21 +78,13 @@ class OpsSpec extends Specification {
8078
](err))
8179
}
8280

83-
val ops: Ops[
84-
V1X.type,
85-
CentralSystemReq,
86-
CentralSystemRes,
87-
CentralSystemReqRes,
88-
ChargePointReq,
89-
ChargePointRes,
90-
ChargePointReqRes
91-
] = new Ops[V1X.type, CentralSystemReq, CentralSystemRes, CentralSystemReqRes, ChargePointReq, ChargePointRes, ChargePointReqRes]
81+
val ops = new Ops[V1X.type, CentralSystemReq, CentralSystemRes, CentralSystemReqRes, ChargePointReq, ChargePointRes, ChargePointReqRes]
9282
with CoreOps[V1X.type, CentralSystemReq, CentralSystemRes, CentralSystemReqRes, ChargePointReq, ChargePointRes, ChargePointReqRes] {
9383
implicit val csMessageTypes = V1XChargePointMessages
9484
implicit val csmsMessageTypes = V1XCentralSystemMessages
9585
implicit val executionContext = global
9686

97-
override protected def connectionData: DocileConnection[
87+
override protected def connection: DocileConnection[
9888
V1X.type,
9989
Version1X,
10090
CentralSystemReq,

core/src/test/scala/chargepoint/docile/dsl/ocpp20transactions/OpsSpec.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class OpsSpec extends Specification {
5858
CsResponse,
5959
CsReqRes
6060
] with Ops {
61-
protected lazy val connectionData = sys.error("This test should not do anything with the OCPP connection")
61+
protected lazy val connection = sys.error("This test should not do anything with the OCPP connection")
6262
val csmsMessageTypes = V20CsmsMessages
6363
val csMessageTypes = V20CsMessages
6464
implicit val executionContext = ExecutionContext.global

0 commit comments

Comments
 (0)