Search in sources :

Example 1 with GraphStatement

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

the class GraphTraversalITBase method should_return_zero_results_graphson_2.

/**
 * Ensures a traversal that yields no results is properly retrieved and is empty, using GraphSON2
 * and the TinkerPop transform results function.
 *
 * @test_category dse:graph
 */
@Test
public void should_return_zero_results_graphson_2() {
    Assumptions.assumeThat(isGraphBinary()).isFalse();
    GraphStatement simpleGraphStatement = ScriptGraphStatement.newInstance("g.V().hasLabel('notALabel')");
    GraphResultSet rs = session().execute(simpleGraphStatement);
    assertThat(rs.one()).isNull();
}
Also used : GraphStatement(com.datastax.dse.driver.api.core.graph.GraphStatement) FluentGraphStatement(com.datastax.dse.driver.api.core.graph.FluentGraphStatement) ScriptGraphStatement(com.datastax.dse.driver.api.core.graph.ScriptGraphStatement) AsyncGraphResultSet(com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet) GraphResultSet(com.datastax.dse.driver.api.core.graph.GraphResultSet) Test(org.junit.Test)

Example 2 with GraphStatement

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

the class GraphTraversalITBase method should_allow_use_of_dsl_graph_binary.

/**
 * A simple smoke test to ensure that a user can supply a custom {@link GraphTraversalSource} for
 * use with DSLs.
 *
 * @test_category dse:graph
 */
@Test
public void should_allow_use_of_dsl_graph_binary() throws Exception {
    Assumptions.assumeThat(isGraphBinary()).isTrue();
    SocialTraversalSource gSocial = socialTraversalSource();
    GraphStatement gs = newInstance(gSocial.persons("marko").knows("vadas").elementMap("name", "age"));
    GraphResultSet rs = session().execute(gs);
    List<GraphNode> results = rs.all();
    assertThat(results.size()).isEqualTo(1);
    assertThatContainsProperties(results.get(0).asMap(), "name", "marko", "age", 29);
    Assertions.assertThat(results.get(0).asMap().values()).contains("person");
}
Also used : GraphStatement(com.datastax.dse.driver.api.core.graph.GraphStatement) FluentGraphStatement(com.datastax.dse.driver.api.core.graph.FluentGraphStatement) ScriptGraphStatement(com.datastax.dse.driver.api.core.graph.ScriptGraphStatement) AsyncGraphResultSet(com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet) GraphResultSet(com.datastax.dse.driver.api.core.graph.GraphResultSet) GraphNode(com.datastax.dse.driver.api.core.graph.GraphNode) SocialTraversalSource(com.datastax.dse.driver.api.core.graph.SocialTraversalSource) Test(org.junit.Test)

Example 3 with GraphStatement

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

the class GraphSupportCheckerTest method should_pickup_graph_protocol_and_parse_from_string_config.

@Test
@UseDataProvider("graphProtocolStringsAndDseVersions")
public void should_pickup_graph_protocol_and_parse_from_string_config(String stringConfig, Version dseVersion) {
    GraphStatement graphStatement = mock(GraphStatement.class);
    DriverExecutionProfile executionProfile = mock(DriverExecutionProfile.class);
    when(executionProfile.isDefined(DseDriverOption.GRAPH_SUB_PROTOCOL)).thenReturn(Boolean.TRUE);
    when(executionProfile.getString(eq(DseDriverOption.GRAPH_SUB_PROTOCOL))).thenReturn(stringConfig);
    DefaultDriverContext context = mockNodesInMetadataWithVersions(mock(DefaultDriverContext.class), true, dseVersion);
    GraphProtocol inferredProtocol = new GraphSupportChecker().inferGraphProtocol(graphStatement, executionProfile, context);
    assertThat(inferredProtocol.toInternalCode()).isEqualTo(stringConfig);
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DefaultDriverContext(com.datastax.oss.driver.internal.core.context.DefaultDriverContext) GraphStatement(com.datastax.dse.driver.api.core.graph.GraphStatement) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 4 with GraphStatement

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

the class GraphSupportCheckerTest method should_not_support_paging_when_statement_profile_not_present.

@Test
public void should_not_support_paging_when_statement_profile_not_present() {
    // given
    GraphStatement graphStatement = mock(GraphStatement.class);
    InternalDriverContext context = protocolWithPagingSupport(true);
    contextGraphPagingEnabled(context, DISABLED);
    addNodeWithDseVersion(context, Collections.singletonList(Version.parse("6.8.0")));
    // when
    boolean pagingEnabled = new GraphSupportChecker().isPagingEnabled(graphStatement, context);
    // then
    assertThat(pagingEnabled).isEqualTo(false);
}
Also used : GraphStatement(com.datastax.dse.driver.api.core.graph.GraphStatement) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) Test(org.junit.Test)

Example 5 with GraphStatement

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

the class GraphSupportCheckerTest method should_use_correct_default_protocol_when_parsing.

@Test
@UseDataProvider("dseVersions6")
public void should_use_correct_default_protocol_when_parsing(Version dseVersion) {
    GraphStatement graphStatement = mock(GraphStatement.class);
    DriverExecutionProfile executionProfile = mock(DriverExecutionProfile.class);
    DefaultDriverContext context = mockNodesInMetadataWithVersions(mock(DefaultDriverContext.class), true, dseVersion);
    GraphProtocol inferredProtocol = new GraphSupportChecker().inferGraphProtocol(graphStatement, executionProfile, context);
    // For DSE 6.8 and newer, the default should be GraphSON binary
    // for DSE older than 6.8, the default should be GraphSON2
    assertThat(inferredProtocol).isEqualTo((dseVersion.compareTo(Version.parse("6.8.0")) < 0) ? GraphProtocol.GRAPHSON_2_0 : GraphProtocol.GRAPH_BINARY_1_0);
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DefaultDriverContext(com.datastax.oss.driver.internal.core.context.DefaultDriverContext) GraphStatement(com.datastax.dse.driver.api.core.graph.GraphStatement) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

GraphStatement (com.datastax.dse.driver.api.core.graph.GraphStatement)9 Test (org.junit.Test)9 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)4 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)4 AsyncGraphResultSet (com.datastax.dse.driver.api.core.graph.AsyncGraphResultSet)3 FluentGraphStatement (com.datastax.dse.driver.api.core.graph.FluentGraphStatement)3 GraphResultSet (com.datastax.dse.driver.api.core.graph.GraphResultSet)3 ScriptGraphStatement (com.datastax.dse.driver.api.core.graph.ScriptGraphStatement)3 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)3 GraphNode (com.datastax.dse.driver.api.core.graph.GraphNode)2 SocialTraversalSource (com.datastax.dse.driver.api.core.graph.SocialTraversalSource)2 DefaultDriverContext (com.datastax.oss.driver.internal.core.context.DefaultDriverContext)2