source: geniuswebcore/test/geniusweb/protocol/session/SessionResultTest.py

Last change on this file was 111, checked in by ruud, 2 months ago

Modifications for automatic java to python conversion. Overloaded methods now have different names.

File size: 5.9 KB
Line 
1# Generated from java by J2P
2from __future__ import annotations
3from decimal import Decimal
4from geniusweb.actions.PartyId import PartyId
5from geniusweb.inform.Agreements import Agreements
6from geniusweb.issuevalue.Bid import Bid
7from geniusweb.issuevalue.DiscreteValue import DiscreteValue
8from geniusweb.issuevalue.Value import Value
9from geniusweb.protocol.session.SessionResult import SessionResult
10from geniusweb.references.Parameters import Parameters
11from geniusweb.references.PartyRef import PartyRef
12from geniusweb.references.PartyWithParameters import PartyWithParameters
13from geniusweb.references.PartyWithProfile import PartyWithProfile
14from geniusweb.references.ProfileRef import ProfileRef
15from pyson.ObjectMapper import ObjectMapper
16from tudelft.utilities.exception.ExceptionContainer import ExceptionContainer
17from typing import Dict
18from typing import List
19from typing import Optional
20from unitpy.GeneralTests import GeneralTests
21from unitpy.RunWith import RunWith
22from unitpy.Runner import JUnit4ClassRunner
23from unitpy.Runner import runTests
24from unitpy.Test import Test
25from unittest import TestCase
26from uri.uri import URI
27import json
28
29
30@RunWith(JUnit4ClassRunner)
31class 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))"
100SessionResultTest._static_init_()
101
102class Test(TestCase):
103 def test(self):
104 runTests(SessionResultTest)
Note: See TracBrowser for help on using the repository browser.