1 | package negotiator.persistent;
|
---|
2 |
|
---|
3 | import static org.junit.Assert.assertEquals;
|
---|
4 |
|
---|
5 | import java.io.ByteArrayInputStream;
|
---|
6 | import java.io.ByteArrayOutputStream;
|
---|
7 | import java.io.IOException;
|
---|
8 | import java.io.InputStream;
|
---|
9 | import java.io.ObjectInputStream;
|
---|
10 | import java.io.ObjectOutputStream;
|
---|
11 | import java.util.ArrayList;
|
---|
12 | import java.util.HashMap;
|
---|
13 | import java.util.List;
|
---|
14 | import java.util.Map;
|
---|
15 |
|
---|
16 | import org.junit.Before;
|
---|
17 | import org.junit.Test;
|
---|
18 |
|
---|
19 | import genius.core.Bid;
|
---|
20 | import genius.core.Deadline;
|
---|
21 | import genius.core.list.Tuple;
|
---|
22 | import genius.core.persistent.DefaultStandardInfo;
|
---|
23 |
|
---|
24 | public class StandardInfoTest {
|
---|
25 | private DefaultStandardInfo info;
|
---|
26 |
|
---|
27 | @Before
|
---|
28 | public void init() {
|
---|
29 | Map<String, String> profiles = new HashMap<>();
|
---|
30 | profiles.put("Agent1", "profile1");
|
---|
31 | profiles.put("Agent2", "profile2");
|
---|
32 |
|
---|
33 | List<Tuple<String, Double>> utilities = new ArrayList<>();
|
---|
34 | for (int n = 0; n < 10; n++) {
|
---|
35 | utilities.add(new Tuple<>("Agent" + (n % 2), new Double(Math.random())));
|
---|
36 | }
|
---|
37 |
|
---|
38 | Tuple<Bid, Double> agreement = new Tuple<>(null, null);
|
---|
39 | info = new DefaultStandardInfo(profiles, "Agent1", utilities, new Deadline(), agreement);
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Test
|
---|
43 | public void smokeTest() {
|
---|
44 | System.out.println(info);
|
---|
45 | }
|
---|
46 |
|
---|
47 | @Test
|
---|
48 | public void serializeTest() throws IOException, ClassNotFoundException {
|
---|
49 |
|
---|
50 | ByteArrayOutputStream outstream = new ByteArrayOutputStream();
|
---|
51 | ObjectOutputStream out = new ObjectOutputStream(outstream);
|
---|
52 | out.writeObject(info);
|
---|
53 | out.flush();
|
---|
54 | byte[] data = outstream.toByteArray();
|
---|
55 | System.out.println("Serialized data:" + data);
|
---|
56 | out.close();
|
---|
57 | outstream.close();
|
---|
58 |
|
---|
59 | InputStream fileIn = new ByteArrayInputStream(data);
|
---|
60 | ObjectInputStream in = new ObjectInputStream(fileIn);
|
---|
61 | DefaultStandardInfo info2 = (DefaultStandardInfo) in.readObject();
|
---|
62 | in.close();
|
---|
63 | fileIn.close();
|
---|
64 |
|
---|
65 | System.out.println("Deserialized:" + info2);
|
---|
66 |
|
---|
67 | assertEquals(info, info2);
|
---|
68 | }
|
---|
69 |
|
---|
70 | }
|
---|