This repository has been archived by the owner on Oct 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
68 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package gov.adlnet.xapi; | ||
|
||
import gov.adlnet.xapi.model.Actor; | ||
import gov.adlnet.xapi.model.Agent; | ||
import gov.adlnet.xapi.model.Group; | ||
import gov.adlnet.xapi.model.IStatementObject; | ||
import gov.adlnet.xapi.model.adapters.ActorAdapter; | ||
import gov.adlnet.xapi.model.adapters.StatementObjectAdapter; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class ActorAdapterTest extends TestCase { | ||
private Gson gson; | ||
public ActorAdapterTest(){ | ||
GsonBuilder builder = new GsonBuilder(); | ||
builder.registerTypeAdapter(Actor.class, new ActorAdapter()); | ||
gson = builder.create(); | ||
} | ||
public void testDeserializeActor() { | ||
String data = "{\"mbox\": \"mailto:[email protected]\",\"name\": \"test user\",\"objectType\": \"Agent\"}"; | ||
Actor a = gson.fromJson(data, Actor.class); | ||
assert a.getClass() == Agent.class; | ||
} | ||
public void testDeserializeActorNoType() { | ||
String data = "{\"mbox\": \"mailto:[email protected]\",\"name\": \"test user\"}"; | ||
Actor a = gson.fromJson(data, Actor.class); | ||
assert a.getClass() == Agent.class; | ||
} | ||
public void testDeserializeActorGroup() { | ||
String data = "{\"mbox\": \"mailto:[email protected]\",\"name\": \"test user\",\"objectType\": \"Group\"}"; | ||
Actor a = gson.fromJson(data, Actor.class); | ||
assert a.getClass() == Group.class; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package gov.adlnet.xapi; | ||
|
||
import gov.adlnet.xapi.model.Actor; | ||
import gov.adlnet.xapi.model.Agent; | ||
import gov.adlnet.xapi.model.IStatementObject; | ||
import gov.adlnet.xapi.model.Statement; | ||
import gov.adlnet.xapi.model.Verbs; | ||
import gov.adlnet.xapi.model.adapters.*; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class StatementAdapterTest extends TestCase { | ||
private String testString = "{\"actor\":{\"mbox\":\"mailto:[email protected]\"}, \"verb\":{\"id\":\"http://adlnet.gov/expapi/verbs/asked\"}, \"object\":{\"id\":\"q://do/you/like/green-eggs-n-ham\"}}"; | ||
|
||
private Gson gson; | ||
public StatementAdapterTest(){ | ||
GsonBuilder builder = new GsonBuilder(); | ||
builder.registerTypeAdapter(Actor.class, new ActorAdapter()); | ||
builder.registerTypeAdapter(IStatementObject.class, new StatementObjectAdapter()); | ||
gson = builder.create(); | ||
} | ||
public void testDeserializeStatement() { | ||
Statement a = gson.fromJson(testString, Statement.class); | ||
assert a.getActor().getClass() == Agent.class; | ||
assert a.getActor().getMbox().equals("mailto:[email protected]"); | ||
assert a.getVerb().getId().equals("http://adlnet.gov/expapi/verbs/asked"); | ||
} | ||
} |