-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #49 from okabe-is/ModifyStatement
Modify parameterized constructor, Statement(StringOfJSON), of Statement
- Loading branch information
Showing
3 changed files
with
71 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,4 @@ target/test-classes/ | |
.classpath | ||
.project | ||
.settings/ | ||
/target/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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())); | ||
} | ||
} | ||
} |