|
15 | 15 | */ |
16 | 16 | package com.rusticisoftware.tincan; |
17 | 17 |
|
18 | | -import static com.rusticisoftware.tincan.TestUtils.assertSerializeDeserialize; |
19 | | -import static com.rusticisoftware.tincan.TestUtils.getAgent; |
| 18 | +import static com.rusticisoftware.tincan.TestUtils.*; |
| 19 | +import static org.hamcrest.CoreMatchers.*; |
| 20 | +import static org.junit.Assert.*; |
20 | 21 |
|
21 | 22 | import java.util.ArrayList; |
22 | 23 | import java.util.List; |
|
25 | 26 | import org.joda.time.DateTime; |
26 | 27 | import org.junit.Test; |
27 | 28 |
|
| 29 | +import com.rusticisoftware.tincan.json.StringOfJSON; |
| 30 | + |
28 | 31 | /** |
29 | 32 | * Description |
30 | 33 | */ |
31 | 34 | public class StatementTest { |
32 | 35 |
|
33 | 36 | @Test |
34 | 37 | public void serializeDeserialize() throws Exception { |
35 | | - |
| 38 | + |
36 | 39 | List<StatementTarget> statementTargets = new ArrayList<StatementTarget>(); |
37 | 40 | statementTargets.add(new Activity("http://example.com/activity")); |
38 | 41 | statementTargets. add( getAgent( "Target", "mbox", "mailto:[email protected]")); |
39 | 42 | statementTargets.add(new StatementRef(UUID.randomUUID())); |
40 | | - |
| 43 | + |
41 | 44 | SubStatement sub = new SubStatement(); |
42 | 45 | sub. setActor( getAgent( "Sub", "mbox", "mailto:[email protected]")); |
43 | 46 | sub.setVerb(new Verb("http://example.com/verb")); |
44 | 47 | sub.setObject(new Activity("http://example.com/sub-activity")); |
45 | 48 | statementTargets.add(sub); |
46 | | - |
47 | | - |
| 49 | + |
| 50 | + |
48 | 51 | Statement st = new Statement(); |
49 | 52 | st. setActor( getAgent( "Joe", "mbox", "mailto:[email protected]")); |
50 | 53 |
|
51 | 54 | st.setAttachments(new ArrayList<Attachment>()); |
52 | 55 | Attachment att = new Attachment(); |
53 | 56 | att.setSha2("abc"); |
54 | 57 | st.getAttachments().add(att); |
55 | | - |
| 58 | + |
56 | 59 | st. setAuthority( getAgent( "Authority", "mbox", "mailto:[email protected]")); |
57 | | - |
| 60 | + |
58 | 61 | st.setContext(new Context()); |
59 | 62 | st.getContext().setLanguage("en-US"); |
60 | | - |
| 63 | + |
61 | 64 | st.setId(UUID.randomUUID()); |
62 | | - |
| 65 | + |
63 | 66 | st.setResult(new Result()); |
64 | 67 | st.getResult().setCompletion(true); |
65 | | - |
| 68 | + |
66 | 69 | st.setStored(new DateTime()); |
67 | 70 | st.setTimestamp(new DateTime()); |
68 | 71 | st.setVerb(new Verb("http://example.com/verb")); |
69 | | - |
| 72 | + |
70 | 73 | for (StatementTarget target : statementTargets) { |
71 | 74 | st.setObject(target); |
72 | 75 | assertSerializeDeserialize(st); |
73 | 76 | } |
74 | 77 | } |
| 78 | + |
| 79 | + |
| 80 | + /** |
| 81 | + * To assert that {@Link Statement(StringOfJSON)} converts all textbased-elements in StringOfJSON to {@Link Statement} |
| 82 | + * |
| 83 | + * @throws Exception |
| 84 | + */ |
| 85 | + @Test |
| 86 | + public void StatementConstructorTest() throws Exception { |
| 87 | + |
| 88 | + List<StatementTarget> statementTargets = new ArrayList<StatementTarget>(); |
| 89 | + statementTargets.add(new Activity("http://example.com/activity")); |
| 90 | + statementTargets. add( getAgent( "Target", "mbox", "mailto:[email protected]")); |
| 91 | + statementTargets.add(new StatementRef(UUID.randomUUID())); |
| 92 | + |
| 93 | + SubStatement sub = new SubStatement(); |
| 94 | + sub. setActor( getAgent( "Sub", "mbox", "mailto:[email protected]")); |
| 95 | + sub.setVerb(new Verb("http://example.com/verb")); |
| 96 | + sub.setObject(new Activity("http://example.com/sub-activity")); |
| 97 | + statementTargets.add(sub); |
| 98 | + |
| 99 | + Statement st = new Statement(); |
| 100 | + st. setActor( getAgent( "Joe", "mbox", "mailto:[email protected]")); |
| 101 | + |
| 102 | + st.setAttachments(new ArrayList<Attachment>()); |
| 103 | + Attachment att = new Attachment(); |
| 104 | + att.setSha2("abc"); |
| 105 | + st.getAttachments().add(att); |
| 106 | + |
| 107 | + st. setAuthority( getAgent( "Authority", "mbox", "mailto:[email protected]")); |
| 108 | + |
| 109 | + st.setContext(new Context()); |
| 110 | + st.getContext().setLanguage("en-US"); |
| 111 | + |
| 112 | + st.setId(UUID.randomUUID()); |
| 113 | + |
| 114 | + st.setResult(new Result()); |
| 115 | + st.getResult().setCompletion(true); |
| 116 | + |
| 117 | + st.setStored(new DateTime()); |
| 118 | + st.setTimestamp(new DateTime()); |
| 119 | + st.setVerb(new Verb("http://example.com/verb")); |
| 120 | + |
| 121 | + |
| 122 | + for (StatementTarget target : statementTargets) { |
| 123 | + st.setObject(target); |
| 124 | + |
| 125 | + Statement tmpStatement = new Statement(new StringOfJSON(st.toJSON())); |
| 126 | + |
| 127 | + assertThat(st.toJSON(), is(tmpStatement.toJSON())); |
| 128 | + } |
| 129 | + } |
75 | 130 | } |
0 commit comments