Skip to content

Commit

Permalink
Added SystemEvent withEventTime() method to set event time.
Browse files Browse the repository at this point in the history
  • Loading branch information
abrighton committed Jun 6, 2024
1 parent bf746b7 commit 6e0c735
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,13 @@ class JsonContractTest extends AnyFunSpec with Matchers {
val arrayDataParam = arrayDataKey.set(ArrayData.fromArray(a1), ArrayData.fromArrays[Byte](10, 20, 30, 40, 50))

val systemEvent = SystemEvent(eventId, prefix, eventName, eventTime, Set(arrayDataParam))
val systemEvent2 = SystemEvent(prefix, eventName, Set(arrayDataParam)).withEventTime(eventTime).copy(eventId = eventId)
val systemEventToJson = JsonSupport.writeEvent(systemEvent)
val systemEventToJson2 = JsonSupport.writeEvent(systemEvent2)

val expectedSystemEventJson = Json.parse(Source.fromResource("json/system_event.json").mkString)
systemEventToJson shouldEqual expectedSystemEventJson
systemEventToJson2 shouldEqual expectedSystemEventJson
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ case class SystemEvent private[csw] (
*/
override protected def create(data: Set[Parameter[?]]): SystemEvent =
copy(eventId = Id(), eventTime = UTCTime.now(), paramSet = data)

/**
* Returns a new SystemEvent with the same values and the given time and a new id
*/
def withEventTime(eventTime: UTCTime): SystemEvent =
copy(eventId = Id(), eventTime = eventTime)
}

object SystemEvent {
Expand Down

0 comments on commit 6e0c735

Please sign in to comment.