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