Last active
December 15, 2015 12:59
-
-
Save edgarRd/5264217 to your computer and use it in GitHub Desktop.
Stardog.js Transaction Add data
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
var stardog = require('../js/stardog'); | |
var qs = require('querystring'); | |
// ----------------------------------- | |
// Tests for transactions. | |
// ----------------------------------- | |
describe ("Getting and using transactions.", function() { | |
var conn; | |
var txId; | |
beforeEach(function() { | |
conn = new stardog.Connection(); | |
conn.setEndpoint("http://localhost:5822/"); | |
conn.setCredentials("admin", "admin"); | |
}); | |
afterEach(function() { | |
conn = null; | |
}); | |
it ("Should be able insert triples into a DB during a transaction.", function(done) { | |
var dbContent = '_:b0 <http://www.redhat.com/2013/schema-parser#rootNodeOf> <http://www.atmayoga.com.au/> . _:b0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/Blog> . _:b0 <http://www.w3.org/2002/07/owl#sameAs> <http://www.atmayoga.com.au#Example> . _:b0 <http://www.redhat.com/2013/schema-parser#itemtypeWithoutAnyProperty> <http://schema.org/Blog> . _:b1 <http://www.redhat.com/2013/schema-parser#nestedIn> _:b0 . _:e0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.redhat.com/2013/schema-parser#unintelligibleType> . _:e0 <http://www.redhat.com/2013/schema-parser#specifiedType> "http://schema.org/LocalBusinesss" . _:b10 <http://www.redhat.com/2013/schema-parser#missingItemScope> "http://schema.org/LocalBusinesss" . _:b10 <http://schema.org/name> "Atma Yoga" . _:b10 <http://schema.org/description> "Yoga studio in the Brisbane CBD." . _:b10 <http://schema.org/address> _:s0 . _:s0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://schema.org/PostalAddress> . _:s0 <http://schema.org/streetAddress> "1st Floor, 99 Elizabeth Street" . _:s0 <http://schema.org/addressLocality> "Brisbane" . _:e2 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.redhat.com/2013/schema-parser#unintelligibleProperty> . _:e2 <http://www.redhat.com/2013/schema-parser#specifiedProperty> "http://schema.org/telephonee" . _:N0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.redhat.com/2013/schema-parser#itemscopeWithoutItemtype> . _:N0 <http://www.redhat.com/2013/schema-parser#rootNodeOf> <http://www.atmayoga.com.au/> . _:e3 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.redhat.com/2013/schema-parser#orphanedProperty> . _:e3 <http://www.redhat.com/2013/schema-parser#specifiedProperty> <http://schema.org/author> . '; | |
conn.begin("nodeDB", function (dataB, responseB) { | |
expect(responseB.statusCode).toBe(200); | |
expect(dataB).toBeDefined(); | |
expect(dataB).not.toBeNull(); | |
txId = dataB; | |
conn.clearDB("nodeDB", txId, function (dataC, responseC) { | |
expect(responseC.statusCode).toBe(200); | |
// once cleared let's commit and then ask for the db size | |
conn.commit("nodeDB", txId, function (dataCom, responseCom) { | |
expect(responseCom.statusCode).toBe(200); | |
conn.getDBSize("nodeDB", function (dataS, responseS) { | |
expect(responseS.statusCode).toBe(200); | |
expect(dataS).toBeDefined(); | |
expect(dataS).not.toBe(null); | |
var sizeNum = parseInt(dataS); | |
expect(sizeNum).toBe(0); | |
// restore the db content | |
conn.begin("nodeDB", function (bodyB2, responseB2) { | |
expect(responseB2.statusCode).toBe(200); | |
expect(bodyB2).toBeDefined(); | |
expect(bodyB2).not.toBeNull(); | |
txId = bodyB2; | |
conn.addInTransaction("nodeDB", txId, dbContent, function (dataA, responseA) { | |
expect(responseA.statusCode).toBe(200); | |
// commit | |
conn.commit("nodeDB", txId, function (dataCom2, responseCom2) { | |
expect(responseCom2.statusCode).toBe(200); | |
// check that the data is stored | |
conn.getDBSize("nodeDB", function (dataS2, responseS2) { | |
expect(responseS2.statusCode).toBe(200); | |
expect(dataS2).toBeDefined(); | |
expect(dataS2).not.toBe(null); | |
var sizeNum = parseInt(dataS2); | |
console.log("db size: "+ sizeNum); | |
expect(sizeNum).not.toBe(0); | |
expect(sizeNum).toBeGreaterThan(1); | |
done(); | |
}); | |
}); | |
}, "text/turtle"); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment