1 | # Generated from java by J2P
|
---|
2 | from __future__ import annotations
|
---|
3 | from decimal import Decimal
|
---|
4 | from geniusweb.actions.PartyId import PartyId
|
---|
5 | from geniusweb.inform.Agreements import Agreements
|
---|
6 | from geniusweb.issuevalue.Bid import Bid
|
---|
7 | from geniusweb.issuevalue.DiscreteValue import DiscreteValue
|
---|
8 | from geniusweb.issuevalue.Value import Value
|
---|
9 | from geniusweb.protocol.session.SessionResult import SessionResult
|
---|
10 | from geniusweb.references.Parameters import Parameters
|
---|
11 | from geniusweb.references.PartyRef import PartyRef
|
---|
12 | from geniusweb.references.PartyWithParameters import PartyWithParameters
|
---|
13 | from geniusweb.references.PartyWithProfile import PartyWithProfile
|
---|
14 | from geniusweb.references.ProfileRef import ProfileRef
|
---|
15 | from pyson.ObjectMapper import ObjectMapper
|
---|
16 | from tudelft.utilities.exception.ExceptionContainer import ExceptionContainer
|
---|
17 | from typing import Dict
|
---|
18 | from typing import List
|
---|
19 | from typing import Optional
|
---|
20 | from unitpy.GeneralTests import GeneralTests
|
---|
21 | from unitpy.RunWith import RunWith
|
---|
22 | from unitpy.Runner import JUnit4ClassRunner
|
---|
23 | from unitpy.Runner import runTests
|
---|
24 | from unitpy.Test import Test
|
---|
25 | from unittest import TestCase
|
---|
26 | from uri.uri import URI
|
---|
27 | import json
|
---|
28 |
|
---|
29 |
|
---|
30 | @RunWith(JUnit4ClassRunner)
|
---|
31 | class SessionResultTest(GeneralTests):
|
---|
32 |
|
---|
33 | def __init__(self):
|
---|
34 | self.__error:BaseException = BaseException("test")
|
---|
35 | self.__ISSUE1:str = "issue1"
|
---|
36 | self.__result1:SessionResult = None
|
---|
37 | self.__result1a:SessionResult = None
|
---|
38 | self.__result2:SessionResult = None
|
---|
39 | self.__result3:SessionResult = None
|
---|
40 | self.__result4:SessionResult = None
|
---|
41 | self.__result5:SessionResult = None
|
---|
42 | self.__jsonstring:str = "{\"participants\":{\"party1\":{\"party\":{\"partyref\":\"party2\",\"parameters\":{}},\"profile\":\"profile2\"},\"party3\":{\"party\":{\"partyref\":\"party1\",\"parameters\":{}},\"profile\":\"profile1\"}},\"agreements\":{\"party2\":{\"issuevalues\":{\"issue1\":\"a\"}},\"party1\":{\"issuevalues\":{\"issue1\":\"a\"}}},\"penalties\":{\"party2\":0.2,\"party1\":0.1},\"error\":null}"
|
---|
43 | self.__nopenalties:Dict[PartyId,float] = dict()
|
---|
44 | self.__penalties:Dict[PartyId,float] = dict()
|
---|
45 | self.__PARTY1:PartyId = PartyId("party1")
|
---|
46 | self.__PARTY2:PartyId = PartyId("party2")
|
---|
47 | self.__PARTY3:PartyId = PartyId("party3")
|
---|
48 | super().__init__()
|
---|
49 | self.__penalties[self.__PARTY1]=0.1
|
---|
50 | self.__penalties[self.__PARTY2]=0.2
|
---|
51 | self.__nopenalties[self.__PARTY1]=0.
|
---|
52 | self.__nopenalties[self.__PARTY2]=0.
|
---|
53 | errorstring:str = "\"error\":{\"java.lang.RuntimeException\":" + json.dumps(SessionResultTest.__jackson.toJson(self.__error),separators=(',', ':')) + "}"
|
---|
54 | party1:PartyWithParameters = PartyWithParameters(PartyRef(URI("party1")),Parameters({}))
|
---|
55 | party2:PartyWithParameters = PartyWithParameters(PartyRef(URI("party2")),Parameters({}))
|
---|
56 | partyprofile1:PartyWithProfile = PartyWithProfile(party1,ProfileRef(URI("profile1")))
|
---|
57 | partyprofile2:PartyWithProfile = PartyWithProfile(party2,ProfileRef(URI("profile2")))
|
---|
58 | issuevalues1:Dict[str,Value] = dict()
|
---|
59 | issuevalues1[self.__ISSUE1]=DiscreteValue("a")
|
---|
60 | bid1:Bid = Bid(issuevalues1)
|
---|
61 | agreement1:Agreements = Agreements({}).With(Agreements.create(bid1,set([self.__PARTY1,self.__PARTY2])))
|
---|
62 | # different order but that shouldn't matter
|
---|
63 | issuevalues2:Dict[str,Value] = dict()
|
---|
64 | issuevalues2[self.__ISSUE1]=DiscreteValue("b")
|
---|
65 | bid2:Bid = Bid(issuevalues2)
|
---|
66 | agreement2:Agreements = Agreements({}).With(Agreements.create(bid2,set([self.__PARTY1,self.__PARTY3])))
|
---|
67 | partiesmap:Dict[PartyId,PartyWithProfile] = dict()
|
---|
68 | partiesmap[self.__PARTY1]=partyprofile1
|
---|
69 | partiesmap[self.__PARTY2]=partyprofile2
|
---|
70 | partiesmap2:Dict[PartyId,PartyWithProfile] = dict()
|
---|
71 | partiesmap2[self.__PARTY1]=partyprofile2
|
---|
72 | partiesmap2[self.__PARTY3]=partyprofile1
|
---|
73 | self.__result1=SessionResult(partiesmap,agreement1,self.__nopenalties,None)
|
---|
74 | self.__result1a=SessionResult(partiesmap,agreement1,self.__nopenalties,None)
|
---|
75 | self.__result2=SessionResult(partiesmap,agreement2,self.__nopenalties,None)
|
---|
76 | self.__result3=SessionResult(partiesmap2,agreement1,self.__nopenalties,None)
|
---|
77 | self.__result4=SessionResult(partiesmap2,agreement1,self.__penalties,None)
|
---|
78 | self.__result5=SessionResult(partiesmap,agreement1,self.__nopenalties,ExceptionContainer.fromException(self.__error))
|
---|
79 |
|
---|
80 | #Override
|
---|
81 | def getGeneralTestData(self) -> Optional[List[Optional[List[Optional[SessionResult]]]]]:
|
---|
82 | return [[self.__result1,self.__result1a],(lambda _: _ if type(_)==list else [_])(self.__result2),(lambda _: _ if type(_)==list else [_])(self.__result3),(lambda _: _ if type(_)==list else [_])(self.__result4),(lambda _: _ if type(_)==list else [_])(self.__result5)]
|
---|
83 |
|
---|
84 | #Override
|
---|
85 | def getGeneralTestStrings(self) -> Optional[List[Optional[str]]]:
|
---|
86 | return ["SessionResult.*((party2.*profile2.*)|(party1.*profile1.*))+Agreements.*Bid.*issue1.*\"a\".*0\\.0.*0\\.0.*" + SessionResultTest.__NULL + ".*","SessionResult.*((party2.*profile2.*)|(party1.*profile1.*))+Agreements.*Bid.*issue1.*\"b\".*0\\.0.*0\\.0.*" + SessionResultTest.__NULL + ".*","SessionResult.*((party1.*profile2.*)|(party3.*profile1.*))+Agreements.*Bid.*issue1.*\"a\".*0\\.0.*0\\.0.*" + SessionResultTest.__NULL + ".*","SessionResult.*((party1.*profile2.*)|(party3.*profile1.*))+Agreements.*Bid.*issue1.*\"a\".*Bid.*,*issue1.*((party2.*0\\.2.*)|(party1.*0\\.1.*))+.*" + SessionResultTest.__NULL + ".*","(?s)SessionResult.*((party2.*profile2.*)|(party1.*profile1.*))+Agreements.*Bid.*issue1.*\"a\".*0\\.0.*0\\.0.*Exception.*test.*"]
|
---|
87 |
|
---|
88 | @Test()
|
---|
89 | def serializeTest(self) -> None:
|
---|
90 | TestCase().assertEqual(json.loads(self.__jsonstring),SessionResultTest.__jackson.toJson(self.__result4))
|
---|
91 |
|
---|
92 | @Test()
|
---|
93 | def deserializeTest(self) -> None:
|
---|
94 | act:SessionResult = SessionResultTest.__jackson.parse(json.loads(self.__jsonstring, parse_float=lambda _:Decimal(_)),SessionResult)
|
---|
95 | TestCase().assertEqual(self.__result4,act)
|
---|
96 | @staticmethod
|
---|
97 | def _static_init_():
|
---|
98 | SessionResultTest.__jackson:ObjectMapper = ObjectMapper()
|
---|
99 | SessionResultTest.__NULL:str = "((null)|(None))"
|
---|
100 | SessionResultTest._static_init_()
|
---|
101 |
|
---|
102 | class Test(TestCase):
|
---|
103 | def test(self):
|
---|
104 | runTests(SessionResultTest)
|
---|