use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceEntityThrowsAnAlreadyUpdatedExceptionWhenTheRevDoesNotMatch.
@Test(expected = AlreadyUpdatedException.class)
public void replaceEntityThrowsAnAlreadyUpdatedExceptionWhenTheRevDoesNotMatch() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testthings").get();
UUID id = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id).withVre("test").withType("thing").withProperty("isLatest", true).withProperty("rev", 2)).wrap();
TinkerPopOperations instance = forGraphWrapperAndMappings(graphManager, vres);
UpdateEntity updateEntity = new UpdateEntity(id, Lists.newArrayList(), 1);
long timeStamp = Instant.now().toEpochMilli();
updateEntity.setModified(new Change(timeStamp, "userId", null));
instance.replaceEntity(collection, updateEntity);
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method doKeywordQuickSearchUsesAnIndexToRetrieveTheResults.
@Test
public void doKeywordQuickSearchUsesAnIndexToRetrieveTheResults() {
Vres vres = createConfiguration();
GremlinEntityFetcher entityFetcher = new GremlinEntityFetcher();
UUID id1 = UUID.randomUUID();
UUID id2 = UUID.randomUUID();
UUID id3 = UUID.randomUUID();
String keywordType = "keywordType";
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(id1).withType("keyword").withVre("test").withProperty("rev", 1).withProperty("testkeyword_displayName", "matching").isLatest(true).withProperty("keyword_type", keywordType).withLabel("testkeyword")).withVertex(v -> v.withTimId(id2).withType("keyword").withVre("test").withProperty("rev", 1).withProperty("testkeyword_displayName", "also matching").isLatest(true).withProperty("keyword_type", keywordType).withLabel("testkeyword")).withVertex(v -> v.withTimId(id3).withType("keyword").withVre("test").withProperty("rev", 1).withProperty("testkeyword_displayName", "different name").isLatest(true).withProperty("keyword_type", keywordType).withLabel("testkeyword")).wrap();
IndexHandler indexHandler = mock(IndexHandler.class);
when(indexHandler.hasQuickSearchIndexFor(any(Collection.class))).thenReturn(true);
when(indexHandler.findKeywordsByQuickSearch(any(Collection.class), any(), anyString())).thenReturn(graphManager.getGraph().traversal().V().has("tim_id", within(id1.toString(), id2.toString())));
TinkerPopOperations instance = new TinkerPopOperations(graphManager, mock(ChangeListener.class), entityFetcher, vres, indexHandler);
Collection collection = vres.getCollection("testkeywords").get();
QuickSearch quickSearch = QuickSearch.fromQueryString("matching");
List<QuickSearchResult> result = instance.doKeywordQuickSearch(collection, keywordType, quickSearch, 3);
assertThat(result.stream().map(e -> e.getId()).collect(toList()), contains(id1, id2));
verify(indexHandler).findKeywordsByQuickSearch(collection, quickSearch, keywordType);
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection 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);
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method retractRemovesThePredicateWhenNoValueTypesAreConnected.
@Test
public void retractRemovesThePredicateWhenNoValueTypesAreConnected() {
TinkerPopGraphManager graphManager = newGraph().wrap();
TinkerPopOperations instance = forGraphWrapper(graphManager);
Vre vre = minimalCorrectVre(instance, "vre");
Collection defaultCollection = vre.getCollectionForTypeName(defaultEntityTypeName(vre));
RdfProperty stringProperty = new RdfProperty("http://example.org/propName", "value", "http://www.w3.org/1999/02/22-rdf-syntax-ns#langString");
instance.assertProperty(vre, "http://example.org/1", stringProperty);
instance.retractProperty(vre, "http://example.org/1", stringProperty);
List<PredicateInUse> predicates = instance.getPredicatesFor(defaultCollection);
assertThat(predicates, is(empty()));
}
use of nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection in project timbuctoo by HuygensING.
the class TinkerPopOperationsTest method replaceRelationUpdatesTheModifiedInformation.
@Test
public void replaceRelationUpdatesTheModifiedInformation() throws Exception {
Vres vres = createConfiguration();
Collection collection = vres.getCollection("testrelations").get();
UUID typeId = UUID.randomUUID();
UUID sourceId = UUID.randomUUID();
UUID targetId = UUID.randomUUID();
UUID relId = UUID.randomUUID();
TinkerPopGraphManager graphManager = newGraph().withVertex(v -> v.withTimId(typeId.toString()).withType("relationtype").withProperty("relationtype_regularName", "regularName").withProperty("rev", 1).withProperty("isLatest", true)).withVertex(v -> v.withTimId(sourceId.toString()).withProperty("rev", 1).withVre("test").withType("thing").withProperty("isLatest", true).withOutgoingRelation("regularName", "otherVertex", r -> r.withTim_id(relId).withAccepted("testrelation", true).withTypeId(typeId).withRev(1).addType("testrelation"))).withVertex("otherVertex", v -> v.withTimId(targetId.toString()).withProperty("rev", 1).withVre("test").withType("thing").withProperty("isLatest", true)).wrap();
IndexHandler indexHandler = mock(IndexHandler.class);
when(indexHandler.findEdgeById(relId)).thenReturn(Optional.of(graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).next()));
TinkerPopOperations instance = forGraphMappingsAndIndex(graphManager, vres, indexHandler);
UpdateRelation updateRelation = new UpdateRelation(relId, 1, false);
long timeStamp = Instant.now().toEpochMilli();
String userId = "userId";
updateRelation.setModified(new Change(timeStamp, userId, null));
instance.replaceRelation(collection, updateRelation);
Edge newEdge = graphManager.getGraph().traversal().E().has("tim_id", relId.toString()).has("isLatest", true).next();
assertThat(getModificationInfo("modified", newEdge), is(jsnO("timeStamp", jsn(timeStamp), "userId", jsn(userId))));
}
Aggregations