1 {-# LANGUAGE ScopedTypeVariables #-}
3 module TSN.XML.Heartbeat (
8 import Data.Tuple.Curry ( uncurryN )
9 import Test.Tasty ( TestTree, testGroup )
10 import Test.Tasty.HUnit ( (@?=), testCase )
11 import Text.XML.HXT.Core (
22 import TSN.DbImport ( ImportResult(..) )
23 import Xml ( pickle_unpickle )
29 time_stamp :: String }
32 pickle_message :: PU Message
35 xpWrap (from_tuple, to_tuple) $
36 xpTriple (xpElem "XML_File_ID" xpPrim)
37 (xpElem "heading" xpText)
38 (xpElem "time_stamp" xpText)
40 from_tuple = uncurryN Message
41 to_tuple m = (xml_file_id m,
45 instance XmlPickler Message where
46 xpickle = pickle_message
49 -- | Verify (and report) the received heartbeat. We always return
50 -- Nothing to avoid spurious "successfully imported..." notices.
52 verify :: XmlTree -> IO ImportResult
54 let root_element = unpickleDoc xpickle xml :: Maybe Message
55 return $ case root_element of
56 Nothing -> ImportFailed "Could not unpickle document in import_generic."
57 Just _ -> ImportSkipped "Heartbeat received. Thump."
60 heartbeat_tests :: TestTree
64 [ test_pickle_of_unpickle_is_identity ]
67 test_pickle_of_unpickle_is_identity :: TestTree
68 test_pickle_of_unpickle_is_identity =
69 testCase "pickle composed with unpickle is the identity" $ do
70 let path = "test/xml/Heartbeat.xml"
71 (expected :: [Message], actual) <- pickle_unpickle "message" path