View Javadoc
1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements. See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership. The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.commons.rdf.api;
19  
20  import static org.junit.Assert.*;
21  
22  import org.junit.Test;
23  
24  public class DefaultGraphTest {
25  
26      DummyGraph graph = new DummyGraph();
27  
28      @Test
29      public void close() throws Exception {
30          graph.close(); // no-op
31      }
32  
33      @SuppressWarnings("deprecation")
34      @Test
35      public void defaultGetTriples() throws Exception {
36          assertFalse(graph.streamCalled);
37          assertFalse(graph.filteredStreamCalled);
38          assertEquals(1L, graph.getTriples().count());
39          assertTrue(graph.streamCalled);
40          assertFalse(graph.filteredStreamCalled);
41      }
42  
43      @SuppressWarnings("deprecation")
44      @Test
45      public void defaultGetTriplesFiltered() throws Exception {
46          assertFalse(graph.streamCalled);
47          assertFalse(graph.filteredStreamCalled);
48          assertEquals(1L, graph.getTriples(null,null,null).count());
49          assertFalse(graph.streamCalled);
50          assertTrue(graph.filteredStreamCalled);
51          // Ensure arguments are passed on to graph.stream(s,p,o);
52          assertEquals(0L, graph.getTriples(new DummyIRI(0),null,null).count());
53      }
54  
55      @Test
56      public void defaultIterate() throws Exception {
57          assertFalse(graph.streamCalled);
58          assertFalse(graph.filteredStreamCalled);
59          for (final Triple t : graph.iterate()) {
60              assertEquals(t, new DummyTriple());
61          }
62          assertTrue(graph.streamCalled);
63          assertFalse(graph.filteredStreamCalled);
64      }
65  
66      @Test
67      public void defaultFilteredIterate() throws Exception {
68          assertFalse(graph.streamCalled);
69          assertFalse(graph.filteredStreamCalled);
70          for (final Triple t : graph.iterate(null, new DummyIRI(2), null)) {
71              assertEquals(t, new DummyTriple());
72          }
73          assertTrue(graph.filteredStreamCalled);
74          assertFalse(graph.streamCalled);
75      }
76  
77  }
78