Search in sources :

Example 1 with CreateEntity

use of nl.knaw.huygens.timbuctoo.core.dto.CreateEntity in project timbuctoo by HuygensING.

the class TinkerPopOperationsTest method createEntityThrowsAnIoExceptionWhenItEncountersAnUnknownProperty.

@Test(expected = IOException.class)
public void createEntityThrowsAnIoExceptionWhenItEncountersAnUnknownProperty() 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("unknowProp", "val2"));
    CreateEntity createEntity = withProperties(properties);
    instance.createEntity(collection, Optional.empty(), createEntity);
}
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 2 with CreateEntity

use of nl.knaw.huygens.timbuctoo.core.dto.CreateEntity in project timbuctoo by HuygensING.

the class TinkerPopOperationsTest method createEntitySetsTheRevToOne.

// TODO move the TimbuctooActions
@Test
public void createEntitySetsTheRevToOne() throws Exception {
    TinkerPopGraphManager graphManager = newGraph().wrap();
    Vres vres = createConfiguration();
    Collection collection = vres.getCollection("testthings").get();
    TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
    List<TimProperty<?>> properties = Lists.newArrayList();
    CreateEntity createEntity = withProperties(properties);
    instance.createEntity(collection, Optional.empty(), createEntity);
    assertThat(graphManager.getGraph().traversal().V().has("tim_id", createEntity.getId().toString()).has("rev", 1).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) Test(org.junit.Test)

Example 3 with CreateEntity

use of nl.knaw.huygens.timbuctoo.core.dto.CreateEntity 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 4 with CreateEntity

use of nl.knaw.huygens.timbuctoo.core.dto.CreateEntity in project timbuctoo by HuygensING.

the class TinkerPopOperationsTest method createEntitySetsCreatedAndModified.

@Test
public void createEntitySetsCreatedAndModified() throws Exception {
    TinkerPopGraphManager graphManager = newGraph().wrap();
    Vres vres = createConfiguration();
    Collection collection = vres.getCollection("testthings").get();
    TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
    List<TimProperty<?>> properties = Lists.newArrayList();
    String userId = "userId";
    long timeStamp = Instant.now().toEpochMilli();
    CreateEntity createEntity = withProperties(properties, userId, timeStamp);
    instance.createEntity(collection, Optional.empty(), createEntity);
    assertThat(graphManager.getGraph().traversal().V().has("tim_id", createEntity.getId().toString()).next().value("created"), sameJSONAs(String.format("{\"timeStamp\": %s,\"userId\": \"%s\"}", timeStamp, userId)));
    assertThat(graphManager.getGraph().traversal().V().has("tim_id", createEntity.getId().toString()).next().value("modified"), sameJSONAs(String.format("{\"timeStamp\": %s,\"userId\": \"%s\"}", timeStamp, userId)));
}
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) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 5 with CreateEntity

use of nl.knaw.huygens.timbuctoo.core.dto.CreateEntity in project timbuctoo by HuygensING.

the class TinkerPopOperationsTest method createEntitySetsTypesWithTheCollectionAndTheBaseCollection.

@Test
public void createEntitySetsTypesWithTheCollectionAndTheBaseCollection() throws Exception {
    TinkerPopGraphManager graphManager = newGraph().wrap();
    Vres vres = createConfiguration();
    Collection collection = vres.getCollection("testthings").get();
    TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
    List<TimProperty<?>> properties = Lists.newArrayList();
    CreateEntity createEntity = withProperties(properties);
    instance.createEntity(collection, Optional.empty(), createEntity);
    assertThat(graphManager.getGraph().traversal().V().has("tim_id", createEntity.getId().toString()).next().value("types"), allOf(containsString("testthing"), containsString("thing")));
}
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) Test(org.junit.Test)

Aggregations

CreateEntity (nl.knaw.huygens.timbuctoo.core.dto.CreateEntity)8 CreateCollection (nl.knaw.huygens.timbuctoo.core.dto.CreateCollection)7 Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)7 TimProperty (nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty)7 Vres (nl.knaw.huygens.timbuctoo.model.vre.Vres)7 TinkerPopGraphManager (nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager)7 Test (org.junit.Test)7 StringProperty (nl.knaw.huygens.timbuctoo.core.dto.property.StringProperty)2 UUID (java.util.UUID)1 ImmutableCreateEntity (nl.knaw.huygens.timbuctoo.core.dto.ImmutableCreateEntity)1 Change (nl.knaw.huygens.timbuctoo.model.Change)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.anyString (org.mockito.Matchers.anyString)1