@Test public void countStatements() { // Insert some Triples into the Fluo app. final List<RyaStatement> triples = new ArrayList<>(); triples.add( RyaStatement.builder().setSubject(new RyaIRI("http://Alice")).setPredicate(new RyaIRI("http://talksTo")).setObject(new RyaIRI("http://Bob")).build() ); triples.add( RyaStatement.builder().setSubject(new RyaIRI("http://Bob")).setPredicate(new RyaIRI("http://talksTo")).setObject(new RyaIRI("http://Alice")).build() ); triples.add( RyaStatement.builder().setSubject(new RyaIRI("http://Charlie")).setPredicate(new RyaIRI("http://talksTo")).setObject(new RyaIRI("http://Bob")).build() ); triples.add( RyaStatement.builder().setSubject(new RyaIRI("http://David")).setPredicate(new RyaIRI("http://talksTo")).setObject(new RyaIRI("http://Bob")).build() ); triples.add( RyaStatement.builder().setSubject(new RyaIRI("http://Eve")).setPredicate(new RyaIRI("http://talksTo")).setObject(new RyaIRI("http://Bob")).build() ); try(FluoClient fluoClient = FluoFactory.newClient(super.getFluoConfiguration())) { new InsertTriples().insert(fluoClient, triples, Optional.<String>absent()); // Load some statements into the Fluo app. final BigInteger count = new CountStatements().countStatements(fluoClient); // Ensure the count matches the expected values. assertEquals(BigInteger.valueOf(5), count); } } }
private static RyaStatement buildVisibilityTestRyaStatement(final String documentVisibility) { final RyaStatementBuilder builder = new RyaStatementBuilder(); builder.setPredicate(new RyaIRI("http://temp.com")); builder.setSubject(new RyaIRI("http://subject.com")); builder.setObject(new RyaIRI("http://object.com")); builder.setContext(new RyaIRI("http://context.com")); builder.setColumnVisibility(documentVisibility != null ? documentVisibility.getBytes() : null); final RyaStatement statement = builder.build(); return statement; } }
@Test public void testAdd() throws RyaDAOException, MongoException, IOException { final MongoDBRyaDAO dao = new MongoDBRyaDAO(); try { dao.setConf(conf); dao.init(); final RyaStatementBuilder builder = new RyaStatementBuilder(); builder.setPredicate(new RyaIRI("http://temp.com")); builder.setSubject(new RyaIRI("http://subject.com")); builder.setObject(new RyaIRI("http://object.com")); final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME)); final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName()); dao.add(builder.build()); assertEquals(coll.count(),1); } finally { dao.destroy(); } }
@Test public void testDeleteWildcardSubjectWithContext() throws RyaDAOException, MongoException, IOException { final MongoDBRyaDAO dao = new MongoDBRyaDAO(); try { dao.setConf(conf); dao.init(); final RyaStatementBuilder builder = new RyaStatementBuilder(); builder.setPredicate(new RyaIRI("http://temp.com")); builder.setSubject(new RyaIRI("http://subject.com")); builder.setObject(new RyaIRI("http://object.com")); builder.setContext(new RyaIRI("http://context.com")); final RyaStatement statement = builder.build(); final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME)); final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName()); dao.add(statement); assertEquals(coll.count(),1); final RyaStatementBuilder builder2 = new RyaStatementBuilder(); builder2.setPredicate(new RyaIRI("http://temp.com")); builder2.setObject(new RyaIRI("http://object.com")); builder2.setContext(new RyaIRI("http://context3.com")); final RyaStatement query = builder2.build(); dao.delete(query, conf); assertEquals(coll.count(),1); } finally { dao.destroy(); } }
@Test public void testDeleteWildcardSubjectWithContext() throws RyaDAOException, MongoException, IOException { final MongoDBRyaDAO dao = new MongoDBRyaDAO(); try { dao.setConf(conf); dao.init(); final RyaStatementBuilder builder = new RyaStatementBuilder(); builder.setPredicate(new RyaIRI("http://temp.com")); builder.setSubject(new RyaIRI("http://subject.com")); builder.setObject(new RyaIRI("http://object.com")); builder.setContext(new RyaIRI("http://context.com")); builder.setColumnVisibility(new DocumentVisibility("A&B&C").flatten()); final RyaStatement statement = builder.build(); final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME)); final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName()); dao.add(statement); assertEquals(1, coll.count()); final RyaStatementBuilder builder2 = new RyaStatementBuilder(); builder2.setPredicate(new RyaIRI("http://temp.com")); builder2.setObject(new RyaIRI("http://object.com")); builder2.setContext(new RyaIRI("http://context3.com")); final RyaStatement query = builder2.build(); dao.delete(query, conf); assertEquals(1, coll.count()); } finally { dao.destroy(); } }
@Test public void testDelete() throws RyaDAOException, MongoException, IOException { final MongoDBRyaDAO dao = new MongoDBRyaDAO(); try { dao.setConf(conf); dao.init(); final RyaStatementBuilder builder = new RyaStatementBuilder(); builder.setPredicate(new RyaIRI("http://temp.com")); builder.setSubject(new RyaIRI("http://subject.com")); builder.setObject(new RyaIRI("http://object.com")); final RyaStatement statement = builder.build(); final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME)); final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName()); dao.add(statement); assertEquals(coll.count(),1); dao.delete(statement, conf); assertEquals(coll.count(),0); } finally { dao.destroy(); } }
@Test public void testDelete() throws RyaDAOException, MongoException, IOException { final MongoDBRyaDAO dao = new MongoDBRyaDAO(); try { dao.setConf(conf); dao.init(); final RyaStatementBuilder builder = new RyaStatementBuilder(); builder.setPredicate(new RyaIRI("http://temp.com")); builder.setSubject(new RyaIRI("http://subject.com")); builder.setObject(new RyaIRI("http://object.com")); builder.setColumnVisibility(new DocumentVisibility("C").flatten()); final RyaStatement statement = builder.build(); final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME)); final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName()); dao.add(statement); assertEquals(1, coll.count()); dao.delete(statement, conf); assertEquals(0, coll.count()); } finally { dao.destroy(); } }
@Test public void testAdd() throws RyaDAOException, MongoException, IOException { final MongoDBRyaDAO dao = new MongoDBRyaDAO(); try { dao.setConf(conf); dao.init(); final RyaStatementBuilder builder = new RyaStatementBuilder(); builder.setPredicate(new RyaIRI("http://temp.com")); builder.setSubject(new RyaIRI("http://subject.com")); builder.setObject(new RyaIRI("http://object.com")); builder.setColumnVisibility(new DocumentVisibility("B").flatten()); final MongoDatabase db = conf.getMongoClient().getDatabase(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME)); final MongoCollection<Document> coll = db.getCollection(conf.getTriplesCollectionName()); dao.add(builder.build()); assertEquals(coll.count(),1); final Document dbo = coll.find().first(); assertTrue(dbo.containsKey(DOCUMENT_VISIBILITY)); assertTrue(dbo.containsKey(TIMESTAMP)); } finally { dao.destroy(); } }
private void insert(final Resource subject, final IRI predicate, final Value object, final int derivationLevel) throws RyaDAOException { final RyaStatementBuilder builder = new RyaStatementBuilder(); builder.setSubject(RdfToRyaConversions.convertResource(subject)); builder.setPredicate(RdfToRyaConversions.convertIRI(predicate)); builder.setObject(RdfToRyaConversions.convertValue(object)); final RyaStatement rstmt = builder.build(); if (derivationLevel > 0) { final DBObject obj = new SimpleMongoDBStorageStrategy().serialize(builder.build()); obj.put("derivation_level", derivationLevel); getRyaDbCollection().insert(obj); } else { dao.add(rstmt); } }
@Test public void testDeleteWildcard() throws RyaDAOException { final MongoDBRyaDAO dao = new MongoDBRyaDAO(); try { dao.setConf(conf); dao.init(); final RyaStatementBuilder builder = new RyaStatementBuilder(); builder.setPredicate(new RyaIRI("http://temp.com")); builder.setColumnVisibility(new DocumentVisibility("A").flatten()); dao.delete(builder.build(), conf); } finally { dao.destroy(); } }
private RyaStatement getStatement(final String s, final String p, final String o) { final RyaStatementBuilder builder = new RyaStatementBuilder(); if (s != null) { builder.setSubject(new RyaIRI(s)); } if (p != null) { builder.setPredicate(new RyaIRI(p)); } if (o != null) { builder.setObject(new RyaIRI(o)); } return builder.build(); }
private static RyaStatement statement(final int v) { final RyaStatementBuilder builder = new RyaStatementBuilder(); builder.setPredicate(ryaIRI(v)); builder.setSubject(ryaIRI(v)); builder.setObject(ryaIRI(v)); return builder.build(); } }
@Test public void testDeleteWildcard() throws RyaDAOException { final MongoDBRyaDAO dao = new MongoDBRyaDAO(); try { dao.setConf(conf); dao.init(); final RyaStatementBuilder builder = new RyaStatementBuilder(); builder.setPredicate(new RyaIRI("http://temp.com")); dao.delete(builder.build(), conf); } finally { dao.destroy(); } }