use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.
the class GraphRequestHandlerTest method should_return_results_for_statements.
@Test
@UseDataProvider("supportedGraphProtocolsWithDseVersions")
public void should_return_results_for_statements(GraphProtocol graphProtocol, Version dseVersion) throws IOException {
GraphRequestHandlerTestHarness.Builder builder = GraphRequestHandlerTestHarness.builder().withGraphProtocolForTestConfig(graphProtocol).withDseVersionInMetadata(dseVersion);
PoolBehavior node1Behavior = builder.customBehavior(node);
GraphRequestHandlerTestHarness harness = builder.build();
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
// ideally we would be able to provide a function here to
// produce results instead of a static predefined response.
// Function to which we would pass the harness instance or a (mocked)DriverContext.
// Since that's not possible in the RequestHandlerTestHarness API at the moment, we
// have to use another DseDriverContext and GraphBinaryModule here,
// instead of reusing the one in the harness' DriverContext
node1Behavior.setResponseSuccess(defaultDseFrameOf(singleGraphRow(graphProtocol, module)));
GraphSupportChecker graphSupportChecker = mock(GraphSupportChecker.class);
when(graphSupportChecker.isPagingEnabled(any(), any())).thenReturn(false);
when(graphSupportChecker.inferGraphProtocol(any(), any(), any())).thenReturn(graphProtocol);
GraphRequestAsyncProcessor p = Mockito.spy(new GraphRequestAsyncProcessor(harness.getContext(), graphSupportChecker));
when(p.getGraphBinaryModule()).thenReturn(module);
GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("mockQuery").setExecutionProfileName("test-graph");
GraphResultSet grs = new GraphRequestSyncProcessor(p).process(graphStatement, harness.getSession(), harness.getContext(), "test-graph");
List<GraphNode> nodes = grs.all();
assertThat(nodes.size()).isEqualTo(1);
GraphNode graphNode = nodes.get(0);
assertThat(graphNode.isVertex()).isTrue();
Vertex vRead = graphNode.asVertex();
assertThat(vRead.label()).isEqualTo("person");
assertThat(vRead.id()).isEqualTo(1);
if (!graphProtocol.isGraphBinary()) {
// GraphBinary does not encode properties regardless of whether they are present in the
// parent element or not :/
assertThat(vRead.property("name").id()).isEqualTo(11);
assertThat(vRead.property("name").value()).isEqualTo("marko");
}
}
use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.
the class GraphResultSetsTest method should_create_result_set_from_single_page.
@Test
public void should_create_result_set_from_single_page() {
// Given
AsyncGraphResultSet page1 = mockPage(false, 0, 1, 2);
// When
GraphResultSet resultSet = GraphResultSets.toSync(page1);
// Then
assertThat(resultSet.getRequestExecutionInfo()).isSameAs(page1.getRequestExecutionInfo());
Iterator<GraphNode> iterator = resultSet.iterator();
assertNextRow(iterator, 0);
assertNextRow(iterator, 1);
assertNextRow(iterator, 2);
assertThat(iterator.hasNext()).isFalse();
}
use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.
the class GraphTraversalMultiPropertiesIT method should_parse_multiple_cardinality_properties.
/**
* Ensures that a traversal that yields a vertex with a property name that is present multiple
* times that the properties are parsed and made accessible via {@link
* Vertex#properties(String...)}.
*
* @test_category dse:graph
*/
@Test
public void should_parse_multiple_cardinality_properties() {
// given a schema that defines multiple cardinality properties.
SESSION_RULE.session().execute(ScriptGraphStatement.newInstance(MULTI_PROPS));
// when adding a vertex with a multiple cardinality property
GraphResultSet result = SESSION_RULE.session().execute(newInstance(g.addV("multi_v").property("multi_prop", "Hello").property("multi_prop", "Sweet").property("multi_prop", "World")));
Vertex v = result.one().asVertex();
assertThat(v).hasProperty("multi_prop");
Iterator<VertexProperty<String>> multiProp = v.properties("multi_prop");
assertThat(multiProp).toIterable().extractingResultOf("value").containsExactly("Hello", "Sweet", "World");
}
use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.
the class GraphTraversalITBase method should_allow_use_of_dsl_graphson.
/**
* 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_graphson() throws Exception {
Assumptions.assumeThat(isGraphBinary()).isFalse();
SocialTraversalSource gSocial = socialTraversalSource();
GraphStatement gs = newInstance(gSocial.persons("marko").knows("vadas"));
GraphResultSet rs = session().execute(gs);
List<GraphNode> results = rs.all();
assertThat(results.size()).isEqualTo(1);
assertThat(results.get(0).asVertex()).hasProperty("name", "marko").hasProperty("age", 29).hasLabel("person");
}
use of com.datastax.dse.driver.api.core.graph.GraphResultSet in project java-driver by datastax.
the class GraphTraversalITBase method should_handle_subgraph_graphson.
/**
* Ensures that a traversal that returns a sub graph can be retrieved.
*
* <p>The subgraph is all members in a knows relationship, thus is all people who marko knows and
* the edges that connect them.
*/
@Test
public void should_handle_subgraph_graphson() {
Assumptions.assumeThat(isGraphBinary()).isFalse();
GraphResultSet rs = session().execute(newInstance(graphTraversalSource().E().hasLabel("knows").subgraph("subGraph").cap("subGraph")));
List<GraphNode> results = rs.all();
assertThat(results.size()).isEqualTo(1);
Graph graph = results.get(0).as(Graph.class);
assertThat(graph.edges()).toIterable().hasSize(2);
assertThat(graph.vertices()).toIterable().hasSize(3);
}
Aggregations