source: protocol/src/test/java/geniusweb/protocol/session/SessionResultTest.java@ 1

Last change on this file since 1 was 1, checked in by bart, 5 years ago

Initial Release

File size: 7.7 KB
Line 
1package geniusweb.protocol.session;
2
3import static org.junit.Assert.assertEquals;
4
5import java.io.IOException;
6import java.net.URISyntaxException;
7import java.util.Arrays;
8import java.util.HashMap;
9import java.util.List;
10import java.util.Map;
11
12import org.junit.Before;
13import org.junit.Test;
14
15import com.fasterxml.jackson.core.JsonProcessingException;
16import com.fasterxml.jackson.databind.ObjectMapper;
17
18import geniusweb.issuevalue.Bid;
19import geniusweb.issuevalue.DiscreteValue;
20import geniusweb.issuevalue.Value;
21import geniusweb.protocol.SessionResult;
22import geniusweb.references.PartyRef;
23import geniusweb.references.PartyWithProfile;
24import geniusweb.references.ProfileRef;
25import tudelft.utilities.junit.GeneralTests;
26
27public class SessionResultTest extends GeneralTests<SessionResult> {
28 private final ObjectMapper jackson = new ObjectMapper();
29 private final RuntimeException error = new RuntimeException("test");
30
31 private final String ISSUE1 = "issue1";
32 // private final String errorstring =
33 // "\"error\":{\"java.lang.RuntimeException\":{\"cause\":null,\"stackTrace\":[{\"methodName\":\"<init>\",\"fileName\":\"SessionResultTest.java\",\"lineNumber\":29,\"className\":\"events.SessionResultTest\",\"nativeMethod\":false},{\"methodName\":\"newInstance0\",\"fileName\":\"NativeConstructorAccessorImpl.java\",\"lineNumber\":-2,\"className\":\"sun.reflect.NativeConstructorAccessorImpl\",\"nativeMethod\":true},{\"methodName\":\"newInstance\",\"fileName\":\"NativeConstructorAccessorImpl.java\",\"lineNumber\":62,\"className\":\"sun.reflect.NativeConstructorAccessorImpl\",\"nativeMethod\":false},{\"methodName\":\"newInstance\",\"fileName\":\"DelegatingConstructorAccessorImpl.java\",\"lineNumber\":45,\"className\":\"sun.reflect.DelegatingConstructorAccessorImpl\",\"nativeMethod\":false},{\"methodName\":\"newInstance\",\"fileName\":\"Constructor.java\",\"lineNumber\":423,\"className\":\"java.lang.reflect.Constructor\",\"nativeMethod\":false},{\"methodName\":\"createTest\",\"fileName\":\"BlockJUnit4ClassRunner.java\",\"lineNumber\":217,\"className\":\"org.junit.runners.BlockJUnit4ClassRunner\",\"nativeMethod\":false},{\"methodName\":\"runReflectiveCall\",\"fileName\":\"BlockJUnit4ClassRunner.java\",\"lineNumber\":266,\"className\":\"org.junit.runners.BlockJUnit4ClassRunner$1\",\"nativeMethod\":false},{\"methodName\":\"run\",\"fileName\":\"ReflectiveCallable.java\",\"lineNumber\":12,\"className\":\"org.junit.internal.runners.model.ReflectiveCallable\",\"nativeMethod\":false},{\"methodName\":\"methodBlock\",\"fileName\":\"BlockJUnit4ClassRunner.java\",\"lineNumber\":263,\"className\":\"org.junit.runners.BlockJUnit4ClassRunner\",\"nativeMethod\":false},{\"methodName\":\"runChild\",\"fileName\":\"BlockJUnit4ClassRunner.java\",\"lineNumber\":78,\"className\":\"org.junit.runners.BlockJUnit4ClassRunner\",\"nativeMethod\":false},{\"methodName\":\"runChild\",\"fileName\":\"BlockJUnit4ClassRunner.java\",\"lineNumber\":57,\"className\":\"org.junit.runners.BlockJUnit4ClassRunner\",\"nativeMethod\":false},{\"methodName\":\"run\",\"fileName\":\"ParentRunner.java\",\"lineNumber\":290,\"className\":\"org.junit.runners.ParentRunner$3\",\"nativeMethod\":false},{\"methodName\":\"schedule\",\"fileName\":\"ParentRunner.java\",\"lineNumber\":71,\"className\":\"org.junit.runners.ParentRunner$1\",\"nativeMethod\":false},{\"methodName\":\"runChildren\",\"fileName\":\"ParentRunner.java\",\"lineNumber\":288,\"className\":\"org.junit.runners.ParentRunner\",\"nativeMethod\":false},{\"methodName\":\"access$000\",\"fileName\":\"ParentRunner.java\",\"lineNumber\":58,\"className\":\"org.junit.runners.ParentRunner\",\"nativeMethod\":false},{\"methodName\":\"evaluate\",\"fileName\":\"ParentRunner.java\",\"lineNumber\":268,\"className\":\"org.junit.runners.ParentRunner$2\",\"nativeMethod\":false},{\"methodName\":\"run\",\"fileName\":\"ParentRunner.java\",\"lineNumber\":363,\"className\":\"org.junit.runners.ParentRunner\",\"nativeMethod\":false},{\"methodName\":\"run\",\"fileName\":\"JUnit4TestReference.java\",\"lineNumber\":86,\"className\":\"org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference\",\"nativeMethod\":false},{\"methodName\":\"run\",\"fileName\":\"TestExecution.java\",\"lineNumber\":38,\"className\":\"org.eclipse.jdt.internal.junit.runner.TestExecution\",\"nativeMethod\":false},{\"methodName\":\"runTests\",\"fileName\":\"RemoteTestRunner.java\",\"lineNumber\":538,\"className\":\"org.eclipse.jdt.internal.junit.runner.RemoteTestRunner\",\"nativeMethod\":false},{\"methodName\":\"runTests\",\"fileName\":\"RemoteTestRunner.java\",\"lineNumber\":760,\"className\":\"org.eclipse.jdt.internal.junit.runner.RemoteTestRunner\",\"nativeMethod\":false},{\"methodName\":\"run\",\"fileName\":\"RemoteTestRunner.java\",\"lineNumber\":460,\"className\":\"org.eclipse.jdt.internal.junit.runner.RemoteTestRunner\",\"nativeMethod\":false},{\"methodName\":\"main\",\"fileName\":\"RemoteTestRunner.java\",\"lineNumber\":206,\"className\":\"org.eclipse.jdt.internal.junit.runner.RemoteTestRunner\",\"nativeMethod\":false}],\"message\":\"test\",\"localizedMessage\":\"test\",\"suppressed\":[]}}";
34 private SessionResult result1, result1a, result2, result3, result4;
35 private String errorstring; // created dynamically: eclipse and maven
36 // generate different stacktrace.
37 private String jsonstring;
38
39 @Before
40 public void before() throws URISyntaxException, JsonProcessingException {
41 errorstring = "\"error\":{\"java.lang.RuntimeException\":"
42 + jackson.writeValueAsString(error) + "}";
43 System.out.println(errorstring);
44 jsonstring = "{\"participants\":[{\"party\":\"party1\",\"profile\":\"profile1\"},{\"party\":\"party2\",\"profile\":\"profile2\"}],\"agreement\":{\"issuevalues\":{\"issue1\":\"a\"}},"
45 + errorstring + "}";
46
47 PartyWithProfile partyprofile1 = new PartyWithProfile(
48 new PartyRef("party1"), new ProfileRef("profile1"));
49 PartyWithProfile partyprofile2 = new PartyWithProfile(
50 new PartyRef("party2"), new ProfileRef("profile2"));
51
52 Map<String, Value> issuevalues1 = new HashMap<>();
53 issuevalues1.put(ISSUE1, new DiscreteValue("a"));
54 Bid bid1 = new Bid(issuevalues1);
55
56 // different order but that shouldn't matter
57 Map<String, Value> issuevalues2 = new HashMap<>();
58 issuevalues2.put(ISSUE1, new DiscreteValue("b"));
59 Bid bid2 = new Bid(issuevalues2);
60
61 result1 = new SessionResult(Arrays.asList(partyprofile1, partyprofile2),
62 bid1, error);
63 result1a = new SessionResult(
64 Arrays.asList(partyprofile1, partyprofile2), bid1, error);
65 result2 = new SessionResult(Arrays.asList(partyprofile1, partyprofile2),
66 bid2, error);
67 result3 = new SessionResult(Arrays.asList(partyprofile2, partyprofile1),
68 bid2, error);
69 result4 = new SessionResult(Arrays.asList(partyprofile1, partyprofile2),
70 bid1, null);
71 }
72
73 @Override
74 public List<List<SessionResult>> getGeneralTestData() {
75 return Arrays.asList(Arrays.asList(result1, result1a),
76 Arrays.asList(result2), Arrays.asList(result3),
77 Arrays.asList(result4));
78 }
79
80 @Override
81 public List<String> getGeneralTestStrings() {
82 return Arrays.asList(
83 "SessionResult.*party1.*profile1.*,.*party2.*profile2.*Bid.*issue1=\"a\".*java.lang.RuntimeException.*test.*",
84 "SessionResult.*party1.*profile1.*,.*party2.*profile2.*Bid.*issue1=\"b\".*java.lang.RuntimeException.*test.*",
85 "SessionResult.*party2.*profile2.*,.*party1.*profile1.*Bid.*issue1=\"b\".*java.lang.RuntimeException.*test.*",
86 "SessionResult.*party1.*profile1.*,.*party2.*profile2.*Bid.*issue1=\"a\".*null.*");
87 }
88
89 @Test
90 public void serializeTest() throws JsonProcessingException {
91 System.out.println(jackson.writeValueAsString(result1));
92 assertEquals(jsonstring, jackson.writeValueAsString(result1));
93 }
94
95 @Test
96 public void deserializeTest() throws IOException {
97 SessionResult act = jackson.readValue(jsonstring, SessionResult.class);
98 assertEquals(result1, act);
99 }
100
101}
Note: See TracBrowser for help on using the repository browser.