@Override protected void addStatementInternal( final Resource subj, final URI pred, final Value obj, final Resource... contexts) throws SailException { try { if (_quad) { if (contexts == null || contexts.length == 0) { throw new IllegalArgumentException("A quadstore always needs a context."); } for (int i = 0; i < contexts.length; i++) { _crdf.addData(_factory.createStatement(subj, pred, obj, contexts[i])); } } else { _crdf.addData(_factory.createStatement(subj, pred, obj)); } } catch (CumulusStoreException e) { e.printStackTrace(); throw new SailException(e); } }
@Override protected void addStatementInternal( final Resource subj, final URI pred, final Value obj, final Resource... contexts) throws SailException { try { if (_quad) { if (contexts == null || contexts.length == 0) { throw new IllegalArgumentException("A quadstore always needs a context."); } for (int i = 0; i < contexts.length; i++) { _crdf.addData(_factory.createStatement(subj, pred, obj, contexts[i])); } } else { _crdf.addData(_factory.createStatement(subj, pred, obj)); } } catch (CumulusStoreException e) { e.printStackTrace(); throw new SailException(e); } }
/** * Loads the test data into the quad store. * @throws CumulusStoreException If the test data could not be loaded. */ @Before public void load() throws CumulusStoreException { _quadStore.addData(asList(_data).iterator()); assertEquals(_data.length, numOfRes(_quadStore.query(SELECT_ALL_QUADS_PATTERN))); }
/** * Setup fixture for each test. * * @throws Exception * hopefully never, otherwise the corresponding test fails. */ @Before public void beforeEachTest() throws Exception { _context = mock(ServletContext.class); when(_context.getAttribute(ConfigParams.SESAME_REPO)).thenReturn(REPOSITORY); when(_context.getAttribute(ConfigParams.STORE)).thenReturn(TRIPLE_STORE); when(_context.getAttribute(ConfigParams.LAYOUT)).thenReturn(ConfigValues.STORE_LAYOUT_TRIPLE); _classUnderTest = spy(new CRUDServlet()); _classUnderTest.init(); doReturn(_context).when(_classUnderTest).getServletContext(); doReturn(_context).when(_classUnderTest).getServletContext(); when(_context.getNamedDispatcher(anyString())).thenReturn(mock(RequestDispatcher.class)); TRIPLE_STORE.addData(_triples.iterator()); assertEquals( "Testset hasn't been properly load on triplestore.", _testSetSize, numOfRes(TRIPLE_STORE.query(SELECT_ALL_TRIPLES_PATTERN))); }
TRIPLE_STORE.addData(triple);
TRIPLE_STORE.addData(triple);
/** * Positive test for HTTP GET on CRUD servlet. * * @throws Exception hopefully never, otherwise the test fails. */ @Test public void getData() throws Exception { for (final String tripleAsString : _data) { final Statement triple = parseNX(tripleAsString).iterator().next(); TRIPLE_STORE.addData(triple); final Value entity = triple.getSubject(); final int howManyTriplesDescribingEntity = asList(TRIPLE_STORE.describe(entity, false)).size(); assertTrue("DESCRIBE for entity " + entity + " cannot have an empty result.", howManyTriplesDescribingEntity > 0); for (final String accept : MimeTypes.RDF_SERIALIZATIONS) { final File tmp = tmpFile(); final ServletOutputStream servletOutputStream = new StubServletOutputStream(tmp); final HttpServletResponse response = mock(HttpServletResponse.class); when(response.getOutputStream()).thenReturn(servletOutputStream); _classUnderTest.doGet(createMockHttpRequest(entity, null, null, null, null, accept), response); servletOutputStream.close(); assertEquals("CRUD GET on entity '" + entity + "' and accept '" + accept + "' failed", howManyTriplesDescribingEntity, parseAsList(new FileInputStream(tmp), RDFFormat.forMIMEType(accept)).size()); } } }
/** * Adds and then removes triples. * * @throws Exception never, otherwise the tests fail. */ @Test public void testAddAndRemove() throws Exception { _tripleStore.addData(parseNX( "<http://izeus1.scc.kit.edu/id/i1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://gridpedia.org/id/TestType> . ") .iterator()); _tripleStore.addData(parseNX( "<http://izeus1.scc.kit.edu/id/i2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://gridpedia.org/id/TestType> . ") .iterator()); assertEquals(2, numOfRes(_tripleStore.query(new Value[] { null, RDF.TYPE, buildResource("http://gridpedia.org/id/TestType") }))); _tripleStore.removeData(_tripleStore.query(new Value[] { buildResource("http://izeus1.scc.kit.edu/id/i1"), null, null })); assertEquals(1, numOfRes(_tripleStore.query(new Value[] { null, RDF.TYPE, buildResource("http://gridpedia.org/id/TestType") }))); }
/** * Adds and then removes triples. * * @throws Exception never, otherwise the tests fail. */ @Test public void testAddAndRemove() throws Exception { _tripleStore.addData(parseNX( "<http://izeus1.scc.kit.edu/id/i1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://gridpedia.org/id/TestType> . ") .iterator()); _tripleStore.addData(parseNX( "<http://izeus1.scc.kit.edu/id/i2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://gridpedia.org/id/TestType> . ") .iterator()); assertEquals(2, numOfRes(_tripleStore.query(new Value[] { null, RDF.TYPE, buildResource("http://gridpedia.org/id/TestType") }))); _tripleStore.removeData(_tripleStore.query(new Value[] { buildResource("http://izeus1.scc.kit.edu/id/i1"), null, null })); assertEquals(1, numOfRes(_tripleStore.query(new Value[] { null, RDF.TYPE, buildResource("http://gridpedia.org/id/TestType") }))); }