Package com.tinkerpop.blueprints

Examples of com.tinkerpop.blueprints.Graph


* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
public class FramedVertexSetTest extends TestCase {

    public void testFramedSet() {
        Graph graph = TinkerGraphFactory.createTinkerGraph();
        FramedGraph<Graph> framedGraph = new FramedGraph<Graph>(graph);
        Set<Vertex> vertices = new HashSet<Vertex>();
        vertices.add(graph.getVertex(1));
        vertices.add(graph.getVertex(4));
        vertices.add(graph.getVertex(6));
        FramedVertexSet<Person> set = new FramedVertexSet<Person>(framedGraph, vertices, Person.class);
        assertEquals(set.size(), 3);
        assertTrue(set.contains(graph.getVertex(1)));
        assertTrue(set.contains(graph.getVertex(4)));
        assertTrue(set.contains(graph.getVertex(6)));
        assertTrue(set.contains(framedGraph.frame(graph.getVertex(1), Person.class)));
        assertTrue(set.contains(framedGraph.frame(graph.getVertex(4), Person.class)));
        assertTrue(set.contains(framedGraph.frame(graph.getVertex(6), Person.class)));

        int counter = 0;
        for (Person person : set) {
            assertTrue(person.asVertex().getId().equals("1") || person.asVertex().getId().equals("4") || person.asVertex().getId().equals("6"));
            counter++;
View Full Code Here


    Mockito.verify(mockModule, Mockito.times(2)).configure(Mockito.any(TransactionalGraph.class), Mockito.any(FramedGraphConfiguration.class));
  }
 
  @Test
  public void testWrapping() {
    Graph wrapper = Mockito.mock(Graph.class);
    Mockito.when(mockModule.configure(Mockito.any(Graph.class), Mockito.any(FramedGraphConfiguration.class))).thenReturn(wrapper);
    FramedGraphFactory graphFactory = new FramedGraphFactory(mockModule);
    FramedGraph<Graph> framed = graphFactory.create(base);
   
    Mockito.verify(mockModule).configure(Mockito.any(Graph.class), Mockito.any(FramedGraphConfiguration.class));
   
    //Unwrapping the graph should retrieve the base graph.
    Assert.assertEquals(base, framed.getBaseGraph());

    //But using the framed graph should go through the wrappers installed by the module.
    Vertex vertex = Mockito.mock(Vertex.class);
    Mockito.when(wrapper.getVertex(1)).thenReturn(vertex);
    Assert.assertEquals(vertex, framed.getVertex(1));
  }
View Full Code Here

  }

  @Test
  public void testAdditionalTypes() {
    Graph graph = TinkerGraphFactory.createTinkerGraph();
    FramedGraphFactory factory = new FramedGraphFactory(new AbstractModule() {

      @Override
      public void doConfigure(FramedGraphConfiguration config) {
        config.addTypeResolver(new TypeResolver() {
View Full Code Here

  }

  @Test
  public void testExtendedTypes() {
    Graph graph = TinkerGraphFactory.createTinkerGraph();
    FramedGraphFactory factory = new FramedGraphFactory(new AbstractModule() {

      @Override
      public void doConfigure(FramedGraphConfiguration config) {
        config.addTypeResolver(new TypeResolver() {
View Full Code Here

    Assert.assertEquals(vertex, framed.getVertex(1));
  }
 
  @Test(expected=UnsupportedOperationException.class)
  public void testWrappingError() {
    Graph wrapper = Mockito.mock(Graph.class);
    Mockito.when(mockModule.configure(Mockito.any(Graph.class), Mockito.any(FramedGraphConfiguration.class))).thenReturn(wrapper);
    FramedGraphFactory graphFactory = new FramedGraphFactory(mockModule);
    TransactionalGraph baseTransactional = Mockito.mock(TransactionalGraph.class);
    graphFactory.create(baseTransactional);
  }
View Full Code Here

*/
public class FramedElementTest {

  @Test
    public void testGettingProperties() {
        Graph graph = TinkerGraphFactory.createTinkerGraph();
        FramedGraph<Graph> framedGraph = new FramedGraphFactory().create(graph);

        Person marko = framedGraph.getVertex(1, Person.class);
        assertEquals(marko.getName(), "marko");
        assertEquals(marko.getAge(), new Integer(29));

        Project lop = framedGraph.getVertex(3, Project.class);
        assertEquals(lop.getName(), "lop");
        assertEquals(lop.getLanguage(), "java");

        CreatedInfo markoCreatedLopInfo = framedGraph.getEdge(9, CreatedInfo.class);
        assertEquals(markoCreatedLopInfo.getWeight(), 0.4f, 0.1f);
        //Same with using deprecated Domain/Range annotations:
        Created markoCreatedLop = framedGraph.getEdge(9, Direction.OUT, Created.class);
        assertEquals(markoCreatedLop.getWeight(), 0.4f, 0.1f);
        CreatedBy lopCreatedByMarko = framedGraph.getEdge(9, Direction.IN, CreatedBy.class);
        assertEquals(lopCreatedByMarko.getWeight(), 0.4f, 0.1f);

        Person temp = framedGraph.frame(graph.addVertex(null), Person.class);
        assertNull(temp.getName());
        assertNull(temp.getAge());

    }
View Full Code Here

public class AbstractModuleTest {

  @Test
  public void testNoWrapping() {
    Graph baseGraph = Mockito.mock(Graph.class);
    TransactionalGraph baseTransactionalGraph = Mockito.mock(TransactionalGraph.class);
   
    FramedGraphConfiguration config = new FramedGraphConfiguration();
    AbstractModule module = Mockito.mock(AbstractModule.class);
    Mockito.when(module.doConfigure(Mockito.any(Graph.class), Mockito.any(FramedGraphConfiguration.class))).thenCallRealMethod();
   
   
    Graph configuredGraph = module.configure(baseGraph, config);
    Assert.assertEquals(baseGraph, configuredGraph);
    Mockito.verify(module).doConfigure(Mockito.any(Graph.class), Mockito.any(FramedGraphConfiguration.class));
    Mockito.verify(module).doConfigure(Mockito.any(FramedGraphConfiguration.class));
   
   
    Mockito.reset(module);
    Mockito.when(module.doConfigure(Mockito.any(TransactionalGraph.class), Mockito.any(FramedGraphConfiguration.class))).thenCallRealMethod();
    Graph configuredTransactionalGraph = module.configure(baseTransactionalGraph, config);
    Assert.assertEquals(baseTransactionalGraph, configuredTransactionalGraph);
    Mockito.verify(module).doConfigure(Mockito.any(TransactionalGraph.class), Mockito.any(FramedGraphConfiguration.class));
    Mockito.verify(module).doConfigure(Mockito.any(FramedGraphConfiguration.class));
  }
View Full Code Here

  }
 
 
  @Test
  public void testWrapping() {
    Graph baseGraph = Mockito.mock(Graph.class);
    TransactionalGraph baseTransactionalGraph = Mockito.mock(TransactionalGraph.class);
   
    Graph wrappedGraph = Mockito.mock(Graph.class);
    TransactionalGraph wrappedTransactionalGraph = Mockito.mock(TransactionalGraph.class);
   
    FramedGraphConfiguration config = new FramedGraphConfiguration();
    AbstractModule module = Mockito.mock(AbstractModule.class);
    Mockito.when(module.doConfigure(Mockito.any(Graph.class), Mockito.any(FramedGraphConfiguration.class))).thenReturn(wrappedGraph);
   
   
    Graph configuredGraph = module.configure(baseGraph, config);
    Assert.assertEquals(wrappedGraph, configuredGraph);
   
   
    Mockito.reset(module);
    Mockito.when(module.doConfigure(Mockito.any(TransactionalGraph.class), Mockito.any(FramedGraphConfiguration.class))).thenReturn(wrappedTransactionalGraph);
    Graph configuredTransactionalGraph = module.configure(baseTransactionalGraph, config);
    Assert.assertEquals(wrappedTransactionalGraph, configuredTransactionalGraph);
   
   
   
  }
View Full Code Here

    }

  @Test
    public void testSettingProperties() {
        Graph graph = TinkerGraphFactory.createTinkerGraph();
        FramedGraph<Graph> framedGraph = new FramedGraphFactory().create(graph);

        Person marko = framedGraph.getVertex(1, Person.class);
        assertEquals(marko.getName(), "marko");
        marko.setName("pavel");
View Full Code Here

        assertEquals(markoCreatedLop.getWeight(), 99.0f, 0.1f);
    }

    @Test
    public void testRemoveProperties() {
        Graph graph = TinkerGraphFactory.createTinkerGraph();
        FramedGraph<Graph> framedGraph = new FramedGraphFactory().create(graph);

        Person marko = framedGraph.getVertex(1, Person.class);
        assertEquals(marko.getAge(), new Integer(29));
        marko.removeAge();
View Full Code Here

TOP

Related Classes of com.tinkerpop.blueprints.Graph

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.