Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first version of tests for expected RDF #32

Closed
wants to merge 12 commits into from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
activitystreams2-examples.html
node_modules
27 changes: 27 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "w3c-socialwg-activitystreams",
"version": "0.0.0",
"description": "Draft Member submission of Activity Streams 2.0",
"main": "index.js",
"scripts": {
"test": "./node_modules/.bin/mocha tests"
},
"repository": {
"type": "git",
"url": "git://github.com/jasnell/w3c-socialwg-activitystreams.git"
},
"author": "",
"license": "OWFa 1.0",
"bugs": {
"url": "https://github.com/jasnell/w3c-socialwg-activitystreams/issues"
},
"homepage": "https://github.com/jasnell/w3c-socialwg-activitystreams",
"devDependencies": {
"cheerio": "~0.17.0",
"mocha": "~1.21.5",
"chai": "~1.9.2",
"rdf-interfaces": "~0.1.0",
"rdf-ext": "~0.1.5",
"rdf-test-utils": "~0.1.0"
}
}
58 changes: 58 additions & 0 deletions tests/examples.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var expect = require('chai').expect;
var helper = require('./helper');
var rdf = require('rdf-interfaces');
require('rdf-ext')(rdf);
var utils = require('rdf-test-utils')(rdf);

function basicCompare(name, done){
new rdf.TurtleParser().parse(helper.getFixture(name), function(expected){
new rdf.JsonLdParser().parse(helper.getExample(name), function(example){
utils.compareGraph(expected, example, function(comparison, a, b){
expect(comparison).to.be.true;
done();
});
});
});
}

describe('Minimal Activity', function(){
it('should match expected RDF', function(done){
basicCompare('example-1', done);
});
});

describe('Basic Activity', function(){
it('should match expected RDF', function(done){
basicCompare('example-2', done);
});
});

describe('Extended Activity', function(){
it('should match expected RDF', function(done){
basicCompare('example-3', done);
});
});

describe('Object', function(){
it('should match expected RDF', function(done){
basicCompare('object', done);
});
});

describe('Activity', function(){
it('should match expected RDF', function(done){
basicCompare('activities', done);
});
});

describe('Collection', function(){
it('should match expected RDF', function(done){
basicCompare('collections', done);
});
});

describe('Potential Action', function(){
it('should match expected RDF', function(done){
basicCompare('actions', done);
});
});
37 changes: 37 additions & 0 deletions tests/helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var fs = require('fs');
var $ = require('cheerio');

// cache in memory
var examples = {};
var fixtures = {};
var context;


var doc = $.load(fs.readFileSync('./activitystreams2.html').toString());

var getContext = function(){
if(!context){
context = JSON.parse(fs.readFileSync('./activitystreams2-context.jsonld').toString());
}
return context;
};

var getExample = function(name) {
if (!examples[name]) {
examples[name] = JSON.parse(doc('#' + name + ' pre.example').text());
// set context
examples[name]['@context'] = getContext()['@context'];
}
return examples[name];
};

var getFixture = function(name) {
if (!fixtures[name]) {
fixtures[name] = fs.readFileSync('./tests/turtle/' + name).toString();
}
return fixtures[name];
};

module.exports.getContext = getContext;
module.exports.getExample = getExample;
module.exports.getFixture = getFixture;
20 changes: 20 additions & 0 deletions tests/turtle/actions
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
@prefix as: <http://activitystrea.ms/2.0/> .

<urn:example:notes:1> a <urn:example:types:note> .

_:b0 a <urn:example:actions:ShareAction>;
as:object <urn:example:notes:1> .

_:b1 a as:HttpRequest;
as:handlerFor _:b0;
as:method "POST"^^<xsd:string>;
as:url <http://example.org/share?id=1> .

_:b2 a <urn:example:actions:SaveAction>;
as:object <urn:example:notes:1> .

_:b3 a as:EmbeddedView;
as:handlerFor _:b2;
as:content "<p>...</p>";
as:mediaType "text/html" .

9 changes: 9 additions & 0 deletions tests/turtle/activities
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@prefix as: <http://activitystrea.ms/2.0/> .

<urn:example:activity:1> a as:Activity;
as:actor <http://example.org/profiles/joe>;
as:object <http://example.com/notes/1>;
as:published "2014-09-30T12:34:56Z"^^<xsd:dateTime>;
as:verb <urn:example:verb:like> .

<urn:example:verb:like> as:displayName "like" .
13 changes: 13 additions & 0 deletions tests/turtle/collections
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
@prefix as: <http://activitystrea.ms/2.0/> .

_:b0 a as:Collection;
as:itemsPerPage "1"^^<xsd:nonNegativeInteger>;
as:next <http://example.org/foo?page=2>;
as:self <http://example.org/foo?page=1>;
as:totalItems "10"^^<xsd:nonNegativeInteger> .

_:b1 as:actor <urn:example:person:sally>;
as:memberOf _:b0;
as:object <http://example.org/foo>;
as:verb _:b2 .

6 changes: 6 additions & 0 deletions tests/turtle/example-1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
@prefix as: <http://activitystrea.ms/2.0/> .

_:b0 a as:Activity;
as:verb _:b1;
as:actor <urn:example:person:martin>;
as:object <http://example.org/foo.jpg> .
24 changes: 24 additions & 0 deletions tests/turtle/example-2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@prefix as: <http://activitystrea.ms/2.0/> .

_:b0 a as:Activity;
as:language "en";
as:verb _:b1;
as:actor <urn:example:person:martin>;
as:object <urn:example:blog:abc123/xyz>;
as:target <http://example.org/blog/>;
as:published "2011-02-10T15:04:55Z"^^<xsd:dateTime> .

<urn:example:person:martin> a <urn:example:types:person>;
as:displayName "Martin Smith";
as:image <http://example.org/martin/image.jpg>;
as:url <http://example.org/martin> .

<http://example.org/blog/> a <urn:example:types:blog>;
as:displayName "Martin's Blog" .

<http://example.org/martin/image.jpg> a as:Link;
as:mediaType "image/jpeg" .

<urn:example:blog:abc123/xyz> a <urn:example:types:article>;
as:displayName "Why I love Activity Streams";
as:url <http://example.org/blog/2011/02/entry> .
45 changes: 45 additions & 0 deletions tests/turtle/example-3
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@prefix as: <http://activitystrea.ms/2.0/> .

_:b0 a as:Collection;
as:totalItems "1"^^<xsd:nonNegativeInteger> .

_:b1 a as:Activity;
as:memberOf _:b0;
as:language "en";
as:displayName "Martin phost le fisean nua a albam."@ga;
as:displayName "Martin posted a new video to his album."@en;
as:verb _:b2;
as:actor <urn:example:person:martin>;
as:object <http://example.org/album/my_fluffy_cat.jpg>;
as:target <http://example.org/album/>;
as:generator <http://example.org/activities-app>;
as:provider <http://example.org/activity-stream>;
as:published "2011-02-10T15:04:55Z"^^<xsd:dateTime> .

<urn:example:person:martin> a <urn:example:types:person>;
as:displayName "Martin Smith";
as:image <http://example.org/martin/image>;
as:url <http://example.org/martin> .

<http://example.org/martin> a as:Link;
as:displayName "Martin's Profile" .

<http://example.org/martin/image> a as:Link, <http://example.org/ImageResource>;
as:height "250"^^<xsd:nonNegativeInteger>;
as:mediaType "image/jpeg";
as:width "250"^^<xsd:nonNegativeInteger> .

<http://example.org/album/my_fluffy_cat.jpg> a <http://example.org/Photo>;
as:image <http://example.org/album/my_fluffy_cat_thumb.jpg> .

<http://example.org/album/my_fluffy_cat_thumb.jpg> a as:Link;
as:mediaType "image/jpeg";
as:rel "preview" .

<http://example.org/album/> a <http://example.org/PhotoAlbum>;
as:displayName "Grianghraif Mairtin"@ga;
as:displayName "Martin's Photo Album"@en;
as:image <http://example.org/album/thumbnail.jpg> .

<http://example.org/album/thumbnail.jpg> a as:Link;
as:mediaType "image/jpeg" .
11 changes: 11 additions & 0 deletions tests/turtle/object
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@prefix as: <http://activitystrea.ms/2.0/> .

<http://example.org/foo> a <http://example.org/types/Note>;
as:author <urn:example:person:joe>;
as:displayName "This is a note";
as:language "en";
as:published "2014-08-21T12:34:56Z"^^<xsd:dateTime> .

<urn:example:person:joe> a <http://example.org/types/Person>;
as:displayName "Joe Smith" .