-
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.
Modify parameterized constructors, Statement(StringOfJSON), of Statement
- Loading branch information
okabe_JYSSH26
committed
Dec 7, 2015
1 parent
293db93
commit ac35d36
Showing
3 changed files
with
79 additions
and
24 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 |
---|---|---|
|
@@ -15,8 +15,9 @@ | |
*/ | ||
package com.rusticisoftware.tincan; | ||
|
||
import static com.rusticisoftware.tincan.TestUtils.assertSerializeDeserialize; | ||
import static com.rusticisoftware.tincan.TestUtils.getAgent; | ||
import static com.rusticisoftware.tincan.TestUtils.*; | ||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.junit.Assert.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
@@ -25,51 +26,105 @@ | |
import org.joda.time.DateTime; | ||
import org.junit.Test; | ||
|
||
import com.rusticisoftware.tincan.json.StringOfJSON; | ||
|
||
/** | ||
* 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())); | ||
} | ||
} | ||
} |