1 | package negotiator.repository.boa;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 |
|
---|
5 | import java.io.StringReader;
|
---|
6 | import java.io.StringWriter;
|
---|
7 |
|
---|
8 | import javax.xml.bind.JAXBContext;
|
---|
9 | import javax.xml.bind.JAXBException;
|
---|
10 | import javax.xml.bind.Marshaller;
|
---|
11 | import javax.xml.bind.Unmarshaller;
|
---|
12 |
|
---|
13 | import org.junit.Before;
|
---|
14 | import org.junit.Test;
|
---|
15 |
|
---|
16 | import genius.core.boaframework.AcceptanceStrategy;
|
---|
17 | import genius.core.boaframework.OMStrategy;
|
---|
18 | import genius.core.boaframework.OfferingStrategy;
|
---|
19 | import genius.core.boaframework.OpponentModel;
|
---|
20 | import genius.core.exceptions.InstantiateException;
|
---|
21 | import genius.core.repository.ParticipantRepItem;
|
---|
22 | import genius.core.repository.PartyRepItem;
|
---|
23 | import genius.core.repository.boa.BoaPartyRepItem;
|
---|
24 | import genius.core.repository.boa.BoaRepItem;
|
---|
25 | import genius.core.repository.boa.BoaWithSettingsRepItem;
|
---|
26 | import genius.core.repository.boa.ParameterList;
|
---|
27 |
|
---|
28 | public class ParticipantRepItemTest {
|
---|
29 |
|
---|
30 | private BoaPartyRepItem boaparty;
|
---|
31 | private PartyRepItem classparty;
|
---|
32 |
|
---|
33 | @Before
|
---|
34 | public void before() throws InstantiateException {
|
---|
35 | BoaRepItem<OfferingStrategy> bs = new BoaRepItem<OfferingStrategy>("class1.path");
|
---|
36 | BoaRepItem<AcceptanceStrategy> ac = new BoaRepItem<AcceptanceStrategy>("class2.path");
|
---|
37 | BoaRepItem<OpponentModel> om = new BoaRepItem<OpponentModel>("class3.path");
|
---|
38 | BoaRepItem<OMStrategy> os = new BoaRepItem<OMStrategy>("class4.path");
|
---|
39 | ParameterList params = new ParameterList();
|
---|
40 |
|
---|
41 | BoaWithSettingsRepItem<OfferingStrategy> boa1 = new BoaWithSettingsRepItem<OfferingStrategy>(bs, params);
|
---|
42 | BoaWithSettingsRepItem<AcceptanceStrategy> boa2 = new BoaWithSettingsRepItem<AcceptanceStrategy>(ac, params);
|
---|
43 | BoaWithSettingsRepItem<OpponentModel> boa3 = new BoaWithSettingsRepItem<OpponentModel>(om, params);
|
---|
44 | BoaWithSettingsRepItem<OMStrategy> boa4 = new BoaWithSettingsRepItem<OMStrategy>(os, params);
|
---|
45 |
|
---|
46 | boaparty = new BoaPartyRepItem("test", boa1, boa2, boa3, boa4);
|
---|
47 |
|
---|
48 | classparty = new PartyRepItem("agents.nastyagent.Accepter");
|
---|
49 | }
|
---|
50 |
|
---|
51 | @Test
|
---|
52 | public void testSerializeClassParty() throws JAXBException {
|
---|
53 |
|
---|
54 | StringWriter writer = new StringWriter();
|
---|
55 |
|
---|
56 | JAXBContext context = JAXBContext.newInstance(ParticipantRepItem.class);
|
---|
57 | Marshaller m = context.createMarshaller();
|
---|
58 | m.marshal(classparty, writer);
|
---|
59 | System.out.println(writer.toString());
|
---|
60 | }
|
---|
61 |
|
---|
62 | @Test
|
---|
63 | public void testSerializeBoa() throws JAXBException {
|
---|
64 |
|
---|
65 | StringWriter writer = new StringWriter();
|
---|
66 |
|
---|
67 | JAXBContext context = JAXBContext.newInstance(ParticipantRepItem.class);
|
---|
68 | Marshaller m = context.createMarshaller();
|
---|
69 | m.marshal(boaparty, writer);
|
---|
70 | System.out.println(writer.toString());
|
---|
71 | }
|
---|
72 |
|
---|
73 | @Test
|
---|
74 | public void testDeserializeBoa() throws JAXBException {
|
---|
75 | JAXBContext jaxbContext = JAXBContext.newInstance(ParticipantRepItem.class);
|
---|
76 | Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
---|
77 | String TEXT = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
---|
78 | + "<boaparty partyName=\"test\"><properties/><biddingStrategy><item classpath=\"class1.path\"/>"
|
---|
79 | + "</biddingStrategy><acceptanceStrategy><item classpath=\"class2.path\"/></acceptanceStrategy>"
|
---|
80 | + "<opponentModel><item classpath=\"class3.path\"/></opponentModel>"
|
---|
81 | + "<omStrategy><item classpath=\"class4.path\"/></omStrategy></boaparty>";
|
---|
82 | StringReader reader = new StringReader(TEXT);
|
---|
83 | BoaPartyRepItem element = (BoaPartyRepItem) unmarshaller.unmarshal(reader);
|
---|
84 | System.out.println(element);
|
---|
85 |
|
---|
86 | assertEquals(boaparty, element);
|
---|
87 | }
|
---|
88 |
|
---|
89 | @Test
|
---|
90 | public void testDeserializeClassParty() throws JAXBException {
|
---|
91 | JAXBContext jaxbContext = JAXBContext.newInstance(ParticipantRepItem.class);
|
---|
92 | Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
---|
93 | String TEXT = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><party classPath=\"agents.nastyagent.Accepter\"><properties/></party>";
|
---|
94 | StringReader reader = new StringReader(TEXT);
|
---|
95 | PartyRepItem element = (PartyRepItem) unmarshaller.unmarshal(reader);
|
---|
96 | System.out.println(element);
|
---|
97 |
|
---|
98 | assertEquals(classparty, element);
|
---|
99 | }
|
---|
100 |
|
---|
101 | @Test
|
---|
102 | public void testUniqueName() {
|
---|
103 | System.out.println(boaparty.getUniqueName());
|
---|
104 | assertEquals("boa-class1.path-class2.path-class3.path-class4.path", boaparty.getUniqueName());
|
---|
105 | }
|
---|
106 |
|
---|
107 | }
|
---|