1 | # Generated from java by J2P
|
---|
2 | from __future__ import annotations
|
---|
3 | from decimal import Decimal
|
---|
4 | from geniusweb.actions.Action import Action
|
---|
5 | from geniusweb.actions.LearningDone import LearningDone
|
---|
6 | from geniusweb.actions.PartyId import PartyId
|
---|
7 | from pyson.ObjectMapper import ObjectMapper
|
---|
8 | from typing import List
|
---|
9 | from typing import Optional
|
---|
10 | from unitpy.GeneralTests import GeneralTests
|
---|
11 | from unitpy.RunWith import RunWith
|
---|
12 | from unitpy.Runner import JUnit4ClassRunner
|
---|
13 | from unitpy.Runner import runTests
|
---|
14 | from unitpy.Test import Test
|
---|
15 | from unittest import TestCase
|
---|
16 | import json
|
---|
17 |
|
---|
18 |
|
---|
19 | @RunWith(JUnit4ClassRunner)
|
---|
20 | class LearningDoneTest(GeneralTests):
|
---|
21 |
|
---|
22 | #Override
|
---|
23 | def getGeneralTestData(self) -> Optional[List[Optional[List[Optional[LearningDone]]]]]:
|
---|
24 | return [[self.__done,self.__done1],(lambda _: _ if type(_)==list else [_])(self.__done2)]
|
---|
25 |
|
---|
26 | #Override
|
---|
27 | def getGeneralTestStrings(self) -> Optional[List[Optional[str]]]:
|
---|
28 | return ["LearningDone\\[.*" + str(self.__id) + ".*\\]","LearningDone\\[.*" + str(self.__idb) + ".*\\]"]
|
---|
29 |
|
---|
30 | @Test()
|
---|
31 | def serializeEndNegoTest(self) -> None:
|
---|
32 | # System.out.println(jackson.writeValueAsString(done));
|
---|
33 | TestCase().assertEqual(self.__endnegostring,json.dumps(self.__jackson.toJson(self.__done),separators=(',', ':')))
|
---|
34 |
|
---|
35 | @Test()
|
---|
36 | def deserializeEndNegoTest(self) -> None:
|
---|
37 | act:Optional[Action] = self.__jackson.parse(json.loads(self.__endnegostring, parse_float=lambda _:Decimal(_)),Action)
|
---|
38 | TestCase().assertEqual(self.__done,act)
|
---|
39 |
|
---|
40 | def __init__(self):
|
---|
41 | self.__jackson:Optional[ObjectMapper] = ObjectMapper()
|
---|
42 | self.__id:Optional[PartyId] = PartyId("party1")
|
---|
43 | self.__idb:Optional[PartyId] = PartyId("party2")
|
---|
44 | self.__done:Optional[LearningDone] = LearningDone(self.__id)
|
---|
45 | self.__done1:Optional[LearningDone] = LearningDone(self.__id)
|
---|
46 | self.__done2:Optional[LearningDone] = LearningDone(self.__idb)
|
---|
47 | self.__endnegostring:Optional[str] = "{\"LearningDone\":{\"actor\":\"party1\"}}"
|
---|
48 | super().__init__()
|
---|
49 |
|
---|
50 | class Test(TestCase):
|
---|
51 | def test(self):
|
---|
52 | runTests(LearningDoneTest)
|
---|