Skip to content

Commit 80316ee

Browse files
committed
Merge pull request #49 from okabe-is/ModifyStatement
Modify parameterized constructor, Statement(StringOfJSON), of Statement
2 parents 3b2dc54 + 261ea34 commit 80316ee

File tree

3 files changed

+71
-14
lines changed

3 files changed

+71
-14
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ target/test-classes/
2626
.classpath
2727
.project
2828
.settings/
29+
/target/

src/main/java/com/rusticisoftware/tincan/Statement.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public Statement(JsonNode jsonNode) throws URISyntaxException, MalformedURLExcep
7979
}
8080

8181
public Statement(StringOfJSON jsonStr) throws IOException, URISyntaxException {
82-
super(jsonStr);
82+
this(jsonStr.toJSONNode());
8383
}
8484

8585
public Statement(Agent actor, Verb verb, StatementTarget object, Result result, Context context) {
@@ -104,21 +104,21 @@ public ObjectNode toJSONNode(TCAPIVersion version) {
104104
if (this.authority != null) {
105105
node.put("authority", this.getAuthority().toJSONNode(version));
106106
}
107-
107+
108108
//Include 0.95 specific fields if asking for 0.95 version
109109
if (TCAPIVersion.V095.equals(version)) {
110110
if (this.getVoided() != null) {
111111
node.put("voided", this.getVoided());
112112
}
113113
}
114-
114+
115115
//Include 1.0.x specific fields if asking for 1.0.x version
116116
if (version.ordinal() <= TCAPIVersion.V100.ordinal()) {
117117
if (this.getVersion() != null) {
118118
node.put("version", this.getVersion().toString());
119119
}
120120
}
121-
121+
122122
return node;
123123
}
124124

src/test/java/com/rusticisoftware/tincan/StatementTest.java

Lines changed: 66 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,51 +25,107 @@
2525
import org.joda.time.DateTime;
2626
import org.junit.Test;
2727

28+
import com.rusticisoftware.tincan.json.StringOfJSON;
29+
30+
import static org.hamcrest.CoreMatchers.is;
31+
import static org.junit.Assert.assertThat;
2832
/**
2933
* Description
3034
*/
3135
public class StatementTest {
3236

3337
@Test
3438
public void serializeDeserialize() throws Exception {
35-
39+
3640
List<StatementTarget> statementTargets = new ArrayList<StatementTarget>();
3741
statementTargets.add(new Activity("http://example.com/activity"));
3842
statementTargets.add(getAgent("Target", "mbox", "mailto:[email protected]"));
3943
statementTargets.add(new StatementRef(UUID.randomUUID()));
40-
44+
4145
SubStatement sub = new SubStatement();
4246
sub.setActor(getAgent("Sub", "mbox", "mailto:[email protected]"));
4347
sub.setVerb(new Verb("http://example.com/verb"));
4448
sub.setObject(new Activity("http://example.com/sub-activity"));
4549
statementTargets.add(sub);
46-
47-
50+
51+
4852
Statement st = new Statement();
4953
st.setActor(getAgent("Joe", "mbox", "mailto:[email protected]"));
5054

5155
st.setAttachments(new ArrayList<Attachment>());
5256
Attachment att = new Attachment();
5357
att.setSha2("abc");
5458
st.getAttachments().add(att);
55-
59+
5660
st.setAuthority(getAgent("Authority", "mbox", "mailto:[email protected]"));
57-
61+
5862
st.setContext(new Context());
5963
st.getContext().setLanguage("en-US");
60-
64+
6165
st.setId(UUID.randomUUID());
62-
66+
6367
st.setResult(new Result());
6468
st.getResult().setCompletion(true);
65-
69+
6670
st.setStored(new DateTime());
6771
st.setTimestamp(new DateTime());
6872
st.setVerb(new Verb("http://example.com/verb"));
69-
73+
7074
for (StatementTarget target : statementTargets) {
7175
st.setObject(target);
7276
assertSerializeDeserialize(st);
7377
}
7478
}
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+
}
75131
}

0 commit comments

Comments
 (0)