use of com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList in project java-driver by datastax.
the class Reflection method buildFromConfigList.
/**
* @param profileName if null, this is a global policy, use the default profile and look for a
* one-arg constructor. If not null, this is a per-profile policy, look for a two-arg
* constructor.
*/
public static <ComponentT> ImmutableList<ComponentT> buildFromConfigList(InternalDriverContext context, String profileName, DriverOption classNamesOption, Class<ComponentT> expectedSuperType, String... defaultPackages) {
DriverExecutionProfile config = (profileName == null) ? context.getConfig().getDefaultProfile() : context.getConfig().getProfile(profileName);
String configPath = classNamesOption.getPath();
LOG.debug("Creating a list of {} from config option {}", expectedSuperType.getSimpleName(), configPath);
if (!config.isDefined(classNamesOption)) {
LOG.debug("Option is not defined, skipping");
return ImmutableList.of();
}
List<String> classNames = config.getStringList(classNamesOption);
ImmutableList.Builder<ComponentT> components = ImmutableList.builder();
for (String className : classNames) {
components.add(resolveClass(context, profileName, expectedSuperType, configPath, className, defaultPackages));
}
return components.build();
}
use of com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList in project java-driver by datastax.
the class GraphTraversalITBase method should_handle_result_object_of_mixed_types.
/**
* Ensures that a traversal that returns a result of mixed types is interpreted as a {@link Map}
* with {@link Object} values. Also uses {@link
* org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal#by(org.apache.tinkerpop.gremlin.process.traversal.Traversal)}
* with an anonymous traversal to get inbound 'created' edges and folds them into a list.
*
* <p>Executes a vertex traversal that binds label 'a' and 'b' to vertex properties and label 'c'
* to vertices that have edges from that vertex.
*
* @test_category dse:graph
*/
@Test
public void should_handle_result_object_of_mixed_types() {
// find all software vertices and select name, language, and find all vertices that created such
// software.
GraphResultSet rs = session().execute(newInstance(graphTraversalSource().V().hasLabel("software").as("a", "b", "c").select("a", "b", "c").by("name").by("lang").by(__.in("created").fold())));
List<GraphNode> results = rs.all();
assertThat(results.size()).isEqualTo(2);
// Ensure that we got 'lop' and 'ripple' for property a.
assertThat(results).extracting(m -> m.getByKey("a").as(Object.class)).containsOnly("lop", "ripple");
for (GraphNode result : results) {
// The row should represent a map with a, b, and c keys.
assertThat(ImmutableList.<Object>copyOf(result.keys())).containsOnlyOnce("a", "b", "c");
// 'e' should not exist, thus it should be null.
assertThat(result.getByKey("e")).isNull();
// both software are written in java.
assertThat(result.getByKey("b").isNull()).isFalse();
assertThat(result.getByKey("b").asString()).isEqualTo("java");
GraphNode c = result.getByKey("c");
assertThat(c.isList()).isTrue();
if (result.getByKey("a").asString().equals("lop")) {
if (isGraphBinary()) {
// should contain three vertices
Assertions.assertThat(c.size()).isEqualTo(3);
} else {
// 'c' should contain marko, josh, peter.
// Ensure we have three vertices.
assertThat(c.size()).isEqualTo(3);
List<Vertex> vertices = Lists.newArrayList(c.getByIndex(0).asVertex(), c.getByIndex(1).asVertex(), c.getByIndex(2).asVertex());
assertThat(vertices).extracting(vertex -> vertex.property("name").value()).containsOnly("marko", "josh", "peter");
}
} else {
if (isGraphBinary()) {
// has only one label
Assertions.assertThat(c.size()).isEqualTo(1);
} else {
// ripple, 'c' should contain josh.
// Ensure we have 1 vertex.
assertThat(c.size()).isEqualTo(1);
Vertex vertex = c.getByIndex(0).asVertex();
assertThat(vertex).hasProperty("name", "josh");
}
}
}
}
Aggregations