Skip to content

Instantly share code, notes, and snippets.

@okram
Created February 6, 2013 17:11
Show Gist options
  • Save okram/4724100 to your computer and use it in GitHub Desktop.
Save okram/4724100 to your computer and use it in GitHub Desktop.
class GetPathTagCloudExtensionTest extends TestCase {
static {
Gremlin.load();
}
public void testCloud1() {
TransactionalGraph g = new TransactionalTinkerGraph();
AddArticleExtension aa = new AddArticleExtension();
JSONObject request = new JSONObject('''
{
uri:'http://mypaper',
keywords:[{uri:'keyword:blah',keyword:'blah'},{uri:'keyword:bam',keyword:'bam'}],
authors: [
{uri:'http://marko'}, {uri:'http://harish'}
]
}
''')
assertFalse(aa.evaluate(new RexsterResourceContext(null, null, null, request, null, null, null), g).isErrorResponse());
request = new JSONObject('''
{
uri:'http://theirpaper',
keywords:[{uri:'keyword:blah',keyword:'blah'},{uri:'keyword:peep',keyword:'peep'}],
authors: [
{uri:'http://harish'}, {uri:'http://herb'}
]
}
''')
assertFalse(aa.evaluate(new RexsterResourceContext(null, null, null, request, null, null, null), g).isErrorResponse());
GetPathTagCloudExtension gt = new GetPathTagCloudExtension();
request = new JSONObject('''
{
sourceIdentity: 'http://marko',
targetIdentity: 'http://herb',
keywordProperty : 'keyword',
maxTraversals : 2
}
''')
JSONObject result = gt.evaluate(new RexsterResourceContext(null, null, null, request, null, null, null), g).getJerseyResponse().getEntity();
assertEquals(result.getJSONObject(Tokens.TAG_CLOUD).length(), 3)
assertEquals(result.getJSONObject(Tokens.TAG_CLOUD)['bam'], 1);
assertEquals(result.getJSONObject(Tokens.TAG_CLOUD)['peep'], 1);
assertEquals(result.getJSONObject(Tokens.TAG_CLOUD)['blah'], 2);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment