Skip to content

Commit ac35d36

Browse files
author
okabe_JYSSH26
committed
Modify parameterized constructors, Statement(StringOfJSON), of Statement
1 parent 293db93 commit ac35d36

File tree

3 files changed

+79
-24
lines changed

3 files changed

+79
-24
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: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@
1818
import java.io.IOException;
1919
import java.net.MalformedURLException;
2020
import java.net.URISyntaxException;
21-
import java.util.List;
2221
import java.util.UUID;
2322

24-
import lombok.Data;
25-
import lombok.EqualsAndHashCode;
26-
import lombok.NoArgsConstructor;
27-
2823
import org.joda.time.DateTime;
2924
import org.joda.time.format.DateTimeFormatter;
3025
import org.joda.time.format.ISODateTimeFormat;
@@ -34,6 +29,10 @@
3429
import com.rusticisoftware.tincan.internal.StatementBase;
3530
import com.rusticisoftware.tincan.json.StringOfJSON;
3631

32+
import lombok.Data;
33+
import lombok.EqualsAndHashCode;
34+
import lombok.NoArgsConstructor;
35+
3736
/**
3837
* Statement Class
3938
*/
@@ -45,7 +44,7 @@ public class Statement extends StatementBase {
4544
private DateTime stored;
4645
private Agent authority;
4746
private TCAPIVersion version;
48-
47+
4948
@Deprecated
5049
private Boolean voided;
5150

@@ -66,20 +65,20 @@ public Statement(JsonNode jsonNode) throws URISyntaxException, MalformedURLExcep
6665
if (! authorityNode.isMissingNode()) {
6766
this.setAuthority(Agent.fromJson(authorityNode));
6867
}
69-
68+
7069
JsonNode voidedNode = jsonNode.path("voided");
7170
if (! voidedNode.isMissingNode()) {
7271
this.setVoided(voidedNode.asBoolean());
7372
}
74-
73+
7574
JsonNode versionNode = jsonNode.path("version");
7675
if (! versionNode.isMissingNode()) {
7776
this.setVersion(TCAPIVersion.fromString(versionNode.textValue()));
7877
}
7978
}
8079

8180
public Statement(StringOfJSON jsonStr) throws IOException, URISyntaxException {
82-
super(jsonStr);
81+
this(jsonStr.toJSONNode());
8382
}
8483

8584
public Statement(Agent actor, Verb verb, StatementTarget object, Result result, Context context) {
@@ -104,21 +103,21 @@ public ObjectNode toJSONNode(TCAPIVersion version) {
104103
if (this.authority != null) {
105104
node.put("authority", this.getAuthority().toJSONNode(version));
106105
}
107-
106+
108107
//Include 0.95 specific fields if asking for 0.95 version
109108
if (TCAPIVersion.V095.equals(version)) {
110109
if (this.getVoided() != null) {
111110
node.put("voided", this.getVoided());
112111
}
113112
}
114-
113+
115114
//Include 1.0.x specific fields if asking for 1.0.x version
116115
if (version.ordinal() <= TCAPIVersion.V100.ordinal()) {
117116
if (this.getVersion() != null) {
118117
node.put("version", this.getVersion().toString());
119118
}
120119
}
121-
120+
122121
return node;
123122
}
124123

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

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@
1515
*/
1616
package com.rusticisoftware.tincan;
1717

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.*;
2021

2122
import java.util.ArrayList;
2223
import java.util.List;
@@ -25,51 +26,105 @@
2526
import org.joda.time.DateTime;
2627
import org.junit.Test;
2728

29+
import com.rusticisoftware.tincan.json.StringOfJSON;
30+
2831
/**
2932
* Description
3033
*/
3134
public class StatementTest {
3235

3336
@Test
3437
public void serializeDeserialize() throws Exception {
35-
38+
3639
List<StatementTarget> statementTargets = new ArrayList<StatementTarget>();
3740
statementTargets.add(new Activity("http://example.com/activity"));
3841
statementTargets.add(getAgent("Target", "mbox", "mailto:[email protected]"));
3942
statementTargets.add(new StatementRef(UUID.randomUUID()));
40-
43+
4144
SubStatement sub = new SubStatement();
4245
sub.setActor(getAgent("Sub", "mbox", "mailto:[email protected]"));
4346
sub.setVerb(new Verb("http://example.com/verb"));
4447
sub.setObject(new Activity("http://example.com/sub-activity"));
4548
statementTargets.add(sub);
46-
47-
49+
50+
4851
Statement st = new Statement();
4952
st.setActor(getAgent("Joe", "mbox", "mailto:[email protected]"));
5053

5154
st.setAttachments(new ArrayList<Attachment>());
5255
Attachment att = new Attachment();
5356
att.setSha2("abc");
5457
st.getAttachments().add(att);
55-
58+
5659
st.setAuthority(getAgent("Authority", "mbox", "mailto:[email protected]"));
57-
60+
5861
st.setContext(new Context());
5962
st.getContext().setLanguage("en-US");
60-
63+
6164
st.setId(UUID.randomUUID());
62-
65+
6366
st.setResult(new Result());
6467
st.getResult().setCompletion(true);
65-
68+
6669
st.setStored(new DateTime());
6770
st.setTimestamp(new DateTime());
6871
st.setVerb(new Verb("http://example.com/verb"));
69-
72+
7073
for (StatementTarget target : statementTargets) {
7174
st.setObject(target);
7275
assertSerializeDeserialize(st);
7376
}
7477
}
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+
}
75130
}

0 commit comments

Comments
 (0)