Search in sources :

Example 16 with GraphNode

use of com.datastax.dse.driver.api.core.graph.GraphNode in project java-driver by datastax.

the class GraphNodeTest method should_create_graph_node_for_map_for_non_string_key.

@Test
@UseDataProvider("graphson1_0and2_0")
public void should_create_graph_node_for_map_for_non_string_key(GraphProtocol graphProtocol) throws IOException {
    // when
    GraphNode graphNode = serdeAndCreateGraphNode(ImmutableMap.of(12, 1234), graphProtocol);
    // then
    assertThat(graphNode.isMap()).isTrue();
    Map<String, Integer> result = graphNode.asMap();
    assertThat(result).isEqualTo(ImmutableMap.of("12", 1234));
}
Also used : GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 17 with GraphNode

use of com.datastax.dse.driver.api.core.graph.GraphNode in project java-driver by datastax.

the class GraphNodeTest method should_create_graph_node_for_list.

@Test
@UseDataProvider(value = "allGraphProtocols")
public void should_create_graph_node_for_list(GraphProtocol graphVersion) throws IOException {
    // when
    GraphNode graphNode = serdeAndCreateGraphNode(ImmutableList.of("value"), graphVersion);
    // then
    assertThat(graphNode.isList()).isTrue();
    List<String> result = graphNode.asList();
    assertThat(result).isEqualTo(ImmutableList.of("value"));
}
Also used : GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 18 with GraphNode

use of com.datastax.dse.driver.api.core.graph.GraphNode in project java-driver by datastax.

the class GraphNodeTest method should_return_is_value_only_for_scalar_value.

@Test
@UseDataProvider(value = "allGraphProtocols")
public void should_return_is_value_only_for_scalar_value(GraphProtocol graphProtocol) throws IOException {
    // when
    GraphNode mapNode = serdeAndCreateGraphNode(ImmutableMap.of(12, 1234), graphProtocol);
    GraphNode setNode = serdeAndCreateGraphNode(ImmutableMap.of(12, 1234), graphProtocol);
    GraphNode listNode = serdeAndCreateGraphNode(ImmutableMap.of(12, 1234), graphProtocol);
    GraphNode vertexNode = serdeAndCreateGraphNode(new DetachedVertex("a", "l", null), graphProtocol);
    GraphNode edgeNode = serdeAndCreateGraphNode(new DetachedEdge("a", "l", Collections.emptyMap(), "v1", "l1", "v2", "l2"), graphProtocol);
    GraphNode pathNode = serdeAndCreateGraphNode(EmptyPath.instance(), graphProtocol);
    GraphNode propertyNode = serdeAndCreateGraphNode(new DetachedProperty<>("a", 1), graphProtocol);
    GraphNode vertexPropertyNode = serdeAndCreateGraphNode(new DetachedVertexProperty<>("id", "l", "v", null, new DetachedVertex("a", "l", null)), graphProtocol);
    GraphNode scalarValueNode = serdeAndCreateGraphNode(true, graphProtocol);
    // then
    assertThat(mapNode.isValue()).isFalse();
    assertThat(setNode.isValue()).isFalse();
    assertThat(listNode.isValue()).isFalse();
    assertThat(vertexNode.isValue()).isFalse();
    assertThat(edgeNode.isValue()).isFalse();
    assertThat(pathNode.isValue()).isFalse();
    assertThat(propertyNode.isValue()).isFalse();
    assertThat(vertexPropertyNode.isValue()).isFalse();
    assertThat(scalarValueNode.isValue()).isTrue();
}
Also used : DetachedVertex(org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex) DetachedEdge(org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdge) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 19 with GraphNode

use of com.datastax.dse.driver.api.core.graph.GraphNode in project java-driver by datastax.

the class GraphNodeTest method should_not_support_set_for_graphson_2_0.

@Test
public void should_not_support_set_for_graphson_2_0() throws IOException {
    // when
    GraphNode graphNode = serdeAndCreateGraphNode(ImmutableSet.of("value"), GRAPHSON_2_0);
    // then
    assertThat(graphNode.isSet()).isFalse();
}
Also used : GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) Test(org.junit.Test)

Example 20 with GraphNode

use of com.datastax.dse.driver.api.core.graph.GraphNode in project java-driver by datastax.

the class GraphNodeTest method should_throw_for_set_for_graphson_1_0.

@Test
public void should_throw_for_set_for_graphson_1_0() throws IOException {
    // when
    GraphNode graphNode = serdeAndCreateGraphNode(ImmutableSet.of("value"), GRAPHSON_1_0);
    // then
    assertThat(graphNode.isSet()).isFalse();
    assertThatThrownBy(graphNode::asSet).isExactlyInstanceOf(UnsupportedOperationException.class);
}
Also used : GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) Test(org.junit.Test)

Aggregations

GraphNode (com.datastax.dse.driver.api.core.graph.GraphNode)41 Test (org.junit.Test)34 AsyncGraphResultSet (com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet)19 GraphResultSet (com.datastax.dse.driver.api.core.graph.GraphResultSet)17 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)13 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)6 Path (org.apache.tinkerpop.gremlin.process.traversal.Path)4 FluentGraphStatement (com.datastax.dse.driver.api.core.graph.FluentGraphStatement)3 GraphStatement (com.datastax.dse.driver.api.core.graph.GraphStatement)3 ScriptGraphStatement (com.datastax.dse.driver.api.core.graph.ScriptGraphStatement)3 SocialTraversalSource (com.datastax.dse.driver.api.core.graph.SocialTraversalSource)3 GraphTestUtils.createGraphBinaryModule (com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule)3 GraphBinaryModule (com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule)3 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)3 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)3 PoolBehavior (com.datastax.oss.driver.internal.core.cql.PoolBehavior)3 ByteBuffer (java.nio.ByteBuffer)3 DetachedVertex (org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertex)3 ArrayDeque (java.util.ArrayDeque)2 Map (java.util.Map)2