Search in sources :

Example 36 with TinkerPopGraphManager

use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.

the class TinkerPopOperationsTest method createEntityAddsAnEntityWithItsPropertiesToTheDatabase.

@Test
public void createEntityAddsAnEntityWithItsPropertiesToTheDatabase() throws Exception {
    TinkerPopGraphManager graphManager = newGraph().wrap();
    Vres vres = createConfiguration();
    final Collection collection = vres.getCollection("testthings").get();
    final TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
    List<TimProperty<?>> properties = Lists.newArrayList();
    properties.add(new StringProperty("prop1", "val1"));
    properties.add(new StringProperty("prop2", "val2"));
    CreateEntity createEntity = withProperties(properties);
    instance.createEntity(collection, Optional.empty(), createEntity);
    assertThat(graphManager.getGraph().traversal().V().has("tim_id", createEntity.getId().toString()).has("testthing_prop1", "val1").has("testthing_prop2", "val2").hasNext(), is(true));
}
Also used : CreateEntity(nl.knaw.huygens.timbuctoo.core.dto.CreateEntity) Vres(nl.knaw.huygens.timbuctoo.model.vre.Vres) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) CreateCollection(nl.knaw.huygens.timbuctoo.core.dto.CreateCollection) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) StringProperty(nl.knaw.huygens.timbuctoo.core.dto.property.StringProperty) Test(org.junit.Test)

Example 37 with TinkerPopGraphManager

use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.

the class LoadSaveVreTest method initGraph.

private Tuple<DataStoreOperations, Graph> initGraph(Consumer<TestGraphBuilder> init) {
    TestGraphBuilder testGraphBuilder = newGraph();
    init.accept(testGraphBuilder);
    TinkerPopGraphManager graphManager = testGraphBuilder.wrap();
    return tuple(TinkerPopOperationsStubs.forGraphWrapper(graphManager), graphManager.getGraph());
}
Also used : TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) TestGraphBuilder(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder)

Example 38 with TinkerPopGraphManager

use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.

the class LoadSaveVresTest method onlyReloadReloadsTheConfigurationsFromTheGraph.

@Test
public void onlyReloadReloadsTheConfigurationsFromTheGraph() throws JsonProcessingException {
    TinkerPopGraphManager graphManager = newGraph().withVertex(v -> {
        v.withLabel(Vre.DATABASE_LABEL).withProperty(Vre.VRE_NAME_PROPERTY_NAME, "VreA");
    }).wrap();
    TransactionEnforcer transactionEnforcer = TransactionEnforcerStubs.forGraphWrapper(graphManager);
    DatabaseConfiguredVres instance = new DatabaseConfiguredVres(transactionEnforcer);
    assertThat(instance.getVre("VreA"), instanceOf(Vre.class));
    assertThat(instance.getVre("VreB"), CoreMatchers.equalTo(null));
    // TODO find a clearer way to write this test.
    // This call overrides the GraphManager pointer, so the DatabaseConfiguredVres has an empty database again.
    graphManager = newGraph().withVertex(v -> {
        v.withLabel(Vre.DATABASE_LABEL).withProperty(Vre.VRE_NAME_PROPERTY_NAME, "VreB");
    }).wrap();
    assertThat(instance.getVre("VreA"), instanceOf(Vre.class));
    assertThat(instance.getVre("VreB"), CoreMatchers.equalTo(null));
    instance.reload();
    assertThat(instance.getVre("VreB"), instanceOf(Vre.class));
    assertThat(instance.getVre("VreA"), CoreMatchers.equalTo(null));
}
Also used : CoreMatchers(org.hamcrest.CoreMatchers) TransactionEnforcerStubs(nl.knaw.huygens.timbuctoo.core.TransactionEnforcerStubs) TransactionEnforcer(nl.knaw.huygens.timbuctoo.core.TransactionEnforcer) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) HashMap(java.util.HashMap) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) TransactionEnforcerStubs.forGraphWrapper(nl.knaw.huygens.timbuctoo.core.TransactionEnforcerStubs.forGraphWrapper) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) DatabaseConfiguredVres(nl.knaw.huygens.timbuctoo.model.vre.vres.DatabaseConfiguredVres) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) DatabaseConfiguredVres(nl.knaw.huygens.timbuctoo.model.vre.vres.DatabaseConfiguredVres) TransactionEnforcer(nl.knaw.huygens.timbuctoo.core.TransactionEnforcer) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) Test(org.junit.Test)

Example 39 with TinkerPopGraphManager

use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.

the class Neo4JIndexHandlerTest method findByIdReturnsAnEmptyTraversalWhenNoResultsAreFound.

@Test
public void findByIdReturnsAnEmptyTraversalWhenNoResultsAreFound() {
    UUID id1 = UUID.randomUUID();
    TinkerPopGraphManager tinkerPopGraphManager = newGraph().withVertex(v -> v.withTimId(id1.toString()).withProperty("keyword_type", "keywordType").withProperty("displayName", "query")).wrap();
    Neo4jIndexHandler instance = new Neo4jIndexHandler(tinkerPopGraphManager);
    Optional<Vertex> result = instance.findById(id1);
    assertThat(result.isPresent(), is(false));
}
Also used : Matchers.empty(org.hamcrest.Matchers.empty) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Matchers.not(org.hamcrest.Matchers.not) Test(org.junit.Test) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Assert.assertThat(org.junit.Assert.assertThat) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Optional(java.util.Optional) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) Matchers.is(org.hamcrest.Matchers.is) Transaction(org.neo4j.graphdb.Transaction) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) UUID(java.util.UUID) Test(org.junit.Test)

Example 40 with TinkerPopGraphManager

use of nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager in project timbuctoo by HuygensING.

the class Neo4JIndexHandlerTest method findByQuickSearchReturnsAnEmtptyTraversalWhenNoVerticesAreFound.

@Test
public void findByQuickSearchReturnsAnEmtptyTraversalWhenNoVerticesAreFound() {
    String id1 = UUID.randomUUID().toString();
    String id2 = UUID.randomUUID().toString();
    String id3 = UUID.randomUUID().toString();
    TinkerPopGraphManager tinkerPopGraphManager = newGraph().withVertex(v -> v.withTimId(id1).withProperty("displayName", "query")).withVertex(v -> v.withTimId(id2).withProperty("displayName", "query2")).withVertex(v -> v.withTimId(id3).withProperty("displayName", "other")).wrap();
    Neo4jIndexHandler instance = new Neo4jIndexHandler(tinkerPopGraphManager);
    addToQuickSearchIndex(instance, collection, tinkerPopGraphManager.getGraph().traversal().V().has("tim_id", id1).next());
    addToQuickSearchIndex(instance, collection, tinkerPopGraphManager.getGraph().traversal().V().has("tim_id", id2).next());
    addToQuickSearchIndex(instance, collection, tinkerPopGraphManager.getGraph().traversal().V().has("tim_id", id3).next());
    QuickSearch quickSearch = QuickSearch.fromQueryString("queryWithoutResult");
    GraphTraversal<Vertex, Vertex> vertices = instance.findByQuickSearch(collection, quickSearch);
    assertThat(vertices.map(v -> v.get().value("tim_id")).toList(), is(empty()));
}
Also used : Matchers.empty(org.hamcrest.Matchers.empty) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Matchers.not(org.hamcrest.Matchers.not) Test(org.junit.Test) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) UUID(java.util.UUID) Mockito.when(org.mockito.Mockito.when) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Assert.assertThat(org.junit.Assert.assertThat) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) EdgeMatcher.likeEdge(nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) Optional(java.util.Optional) OptionalPresentMatcher.present(nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present) Matchers.is(org.hamcrest.Matchers.is) Transaction(org.neo4j.graphdb.Transaction) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) VertexMatcher.likeVertex(nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) QuickSearch(nl.knaw.huygens.timbuctoo.core.dto.QuickSearch) Test(org.junit.Test)

Aggregations

TinkerPopGraphManager (nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager)137 Test (org.junit.Test)135 TestGraphBuilder.newGraph (nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph)93 Vre (nl.knaw.huygens.timbuctoo.model.vre.Vre)91 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)91 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)90 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)90 Optional (java.util.Optional)89 Mockito.mock (org.mockito.Mockito.mock)89 Matchers.is (org.hamcrest.Matchers.is)87 OptionalPresentMatcher.present (nl.knaw.huygens.hamcrest.OptionalPresentMatcher.present)84 Edge (org.apache.tinkerpop.gremlin.structure.Edge)84 Matchers.not (org.hamcrest.Matchers.not)84 Mockito.when (org.mockito.Mockito.when)84 UUID (java.util.UUID)83 VreStubs.minimalCorrectVre (nl.knaw.huygens.timbuctoo.model.vre.VreStubs.minimalCorrectVre)77 QuickSearch (nl.knaw.huygens.timbuctoo.core.dto.QuickSearch)73 EdgeMatcher.likeEdge (nl.knaw.huygens.timbuctoo.util.EdgeMatcher.likeEdge)73 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)73 Matchers.empty (org.hamcrest.Matchers.empty)73