Skip to content

Commit

Permalink
Merge pull request #49 from okabe-is/ModifyStatement
Browse files Browse the repository at this point in the history
Modify parameterized constructor, Statement(StringOfJSON), of Statement
  • Loading branch information
brianjmiller committed Dec 30, 2015
2 parents 3b2dc54 + 261ea34 commit 80316ee
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ target/test-classes/
.classpath
.project
.settings/
/target/
8 changes: 4 additions & 4 deletions src/main/java/com/rusticisoftware/tincan/Statement.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public Statement(JsonNode jsonNode) throws URISyntaxException, MalformedURLExcep
}

public Statement(StringOfJSON jsonStr) throws IOException, URISyntaxException {
super(jsonStr);
this(jsonStr.toJSONNode());
}

public Statement(Agent actor, Verb verb, StatementTarget object, Result result, Context context) {
Expand All @@ -104,21 +104,21 @@ public ObjectNode toJSONNode(TCAPIVersion version) {
if (this.authority != null) {
node.put("authority", this.getAuthority().toJSONNode(version));
}

//Include 0.95 specific fields if asking for 0.95 version
if (TCAPIVersion.V095.equals(version)) {
if (this.getVoided() != null) {
node.put("voided", this.getVoided());
}
}

//Include 1.0.x specific fields if asking for 1.0.x version
if (version.ordinal() <= TCAPIVersion.V100.ordinal()) {
if (this.getVersion() != null) {
node.put("version", this.getVersion().toString());
}
}

return node;
}

Expand Down
76 changes: 66 additions & 10 deletions src/test/java/com/rusticisoftware/tincan/StatementTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,51 +25,107 @@
import org.joda.time.DateTime;
import org.junit.Test;

import com.rusticisoftware.tincan.json.StringOfJSON;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
/**
* Description
*/
public class StatementTest {

@Test
public void serializeDeserialize() throws Exception {

List<StatementTarget> statementTargets = new ArrayList<StatementTarget>();
statementTargets.add(new Activity("http://example.com/activity"));
statementTargets.add(getAgent("Target", "mbox", "mailto:[email protected]"));
statementTargets.add(new StatementRef(UUID.randomUUID()));

SubStatement sub = new SubStatement();
sub.setActor(getAgent("Sub", "mbox", "mailto:[email protected]"));
sub.setVerb(new Verb("http://example.com/verb"));
sub.setObject(new Activity("http://example.com/sub-activity"));
statementTargets.add(sub);


Statement st = new Statement();
st.setActor(getAgent("Joe", "mbox", "mailto:[email protected]"));

st.setAttachments(new ArrayList<Attachment>());
Attachment att = new Attachment();
att.setSha2("abc");
st.getAttachments().add(att);

st.setAuthority(getAgent("Authority", "mbox", "mailto:[email protected]"));

st.setContext(new Context());
st.getContext().setLanguage("en-US");

st.setId(UUID.randomUUID());

st.setResult(new Result());
st.getResult().setCompletion(true);

st.setStored(new DateTime());
st.setTimestamp(new DateTime());
st.setVerb(new Verb("http://example.com/verb"));

for (StatementTarget target : statementTargets) {
st.setObject(target);
assertSerializeDeserialize(st);
}
}


/**
* To assert that {@Link Statement(StringOfJSON)} converts all textbased-elements in StringOfJSON to {@Link Statement}
*
* @throws Exception
*/
@Test
public void StatementConstructorTest() throws Exception {

List<StatementTarget> statementTargets = new ArrayList<StatementTarget>();
statementTargets.add(new Activity("http://example.com/activity"));
statementTargets.add(getAgent("Target", "mbox", "mailto:[email protected]"));
statementTargets.add(new StatementRef(UUID.randomUUID()));

SubStatement sub = new SubStatement();
sub.setActor(getAgent("Sub", "mbox", "mailto:[email protected]"));
sub.setVerb(new Verb("http://example.com/verb"));
sub.setObject(new Activity("http://example.com/sub-activity"));
statementTargets.add(sub);

Statement st = new Statement();
st.setActor(getAgent("Joe", "mbox", "mailto:[email protected]"));

st.setAttachments(new ArrayList<Attachment>());
Attachment att = new Attachment();
att.setSha2("abc");
st.getAttachments().add(att);

st.setAuthority(getAgent("Authority", "mbox", "mailto:[email protected]"));

st.setContext(new Context());
st.getContext().setLanguage("en-US");

st.setId(UUID.randomUUID());

st.setResult(new Result());
st.getResult().setCompletion(true);

st.setStored(new DateTime());
st.setTimestamp(new DateTime());
st.setVerb(new Verb("http://example.com/verb"));


for (StatementTarget target : statementTargets) {
st.setObject(target);

Statement tmpStatement = new Statement(new StringOfJSON(st.toJSON()));

assertThat(st.toJSON(), is(tmpStatement.toJSON()));
}
}
}

0 comments on commit 80316ee

Please sign in to comment.