1 | import json
|
---|
2 | from typing import List
|
---|
3 | import unittest
|
---|
4 |
|
---|
5 | from pyson.ObjectMapper import ObjectMapper
|
---|
6 | from unitpy.GeneralTests import GeneralTests
|
---|
7 | from uri.uri import URI
|
---|
8 |
|
---|
9 | from geniusweb.references.PartyRef import PartyRef
|
---|
10 |
|
---|
11 |
|
---|
12 | class PartyRefTest (unittest.TestCase, GeneralTests[PartyRef]):
|
---|
13 |
|
---|
14 | asJson = "\"ws:localhost/party1\""
|
---|
15 |
|
---|
16 | party1 = PartyRef( URI("ws:localhost/party1"))
|
---|
17 | party1a = PartyRef( URI("ws:localhost/party1"))
|
---|
18 | party2 = PartyRef(URI("ws:localhost/party2"))
|
---|
19 | party3 = PartyRef( URI("http:localhost/party3"))
|
---|
20 |
|
---|
21 |
|
---|
22 | def getGeneralTestData(self) -> List[List[PartyRef]]:
|
---|
23 | return [ [self.party1, self.party1a],[self.party2], [self.party3]]
|
---|
24 |
|
---|
25 | def getGeneralTestStrings(self) -> List[str] :
|
---|
26 | return ["PartyRef.*party1.", "PartyRef.*party2.",
|
---|
27 | "PartyRef.*party3."]
|
---|
28 |
|
---|
29 | def testSmoke(self) :
|
---|
30 | PartyRef(URI("ws:localhost"))
|
---|
31 |
|
---|
32 | def testNull(self):
|
---|
33 | self.assertRaises(ValueError, lambda:PartyRef(None))
|
---|
34 |
|
---|
35 | def testSerialize(self) :
|
---|
36 | jackson = ObjectMapper()
|
---|
37 |
|
---|
38 | jsonobj = jackson.toJson(self.party1)
|
---|
39 | print(json.dumps(jsonobj))
|
---|
40 | self.assertEqual(self.asJson, json.dumps(jsonobj))
|
---|
41 |
|
---|
42 | def testDeserialize(self):
|
---|
43 | jackson = ObjectMapper()
|
---|
44 | p = jackson.parse(json.loads(self.asJson), PartyRef);
|
---|
45 | print(p)
|
---|
46 | self.assertEqual(self.party1, p)
|
---|