source: src/test/java/negotiator/persistent/StandardInfoTest.java@ 50

Last change on this file since 50 was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 1.8 KB
RevLine 
[1]1package negotiator.persistent;
2
3import static org.junit.Assert.assertEquals;
4
5import java.io.ByteArrayInputStream;
6import java.io.ByteArrayOutputStream;
7import java.io.IOException;
8import java.io.InputStream;
9import java.io.ObjectInputStream;
10import java.io.ObjectOutputStream;
11import java.util.ArrayList;
12import java.util.HashMap;
13import java.util.List;
14import java.util.Map;
15
16import org.junit.Before;
17import org.junit.Test;
18
19import genius.core.Bid;
20import genius.core.Deadline;
21import genius.core.list.Tuple;
22import genius.core.persistent.DefaultStandardInfo;
23
24public 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}
Note: See TracBrowser for help on using the repository browser.