Search in sources :

Example 46 with Collection

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

the class ChangeListenerTest method callsOnPropertyUpdateOnReplaceEntity.

@Test
public void callsOnPropertyUpdateOnReplaceEntity() throws Exception {
    ChangeListener changeListener = new ChangeListenerImpl(vertex -> {
        assertThat(vertex, likeVertex().withProperty("isLatest", true).withProperty("rev", 2));
        Long prevVersions = stream(vertex.vertices(Direction.BOTH, VERSION_OF)).collect(Collectors.counting());
        assertThat(prevVersions, is(1L));
    });
    UUID id = UUID.randomUUID();
    ChangeListener spy = spy(changeListener);
    DataStoreOperations instance = forReplaceCall(spy, id, 1);
    UpdateEntity updateEntity = new UpdateEntity(id, newArrayList(), 1);
    updateEntity.setModified(new Change());
    Collection collectionMock = mock(Collection.class);
    instance.replaceEntity(collectionMock, updateEntity);
    verify(spy).onPropertyUpdate(same(collectionMock), any(), any());
}
Also used : DataStoreOperations(nl.knaw.huygens.timbuctoo.core.DataStoreOperations) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Change(nl.knaw.huygens.timbuctoo.model.Change) UUID(java.util.UUID) Test(org.junit.Test)

Example 47 with Collection

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

the class FulltextIndexChangeListenerTest method onCreateHandlesWwDocumentsUsingCustomLogic.

@Test
public void onCreateHandlesWwDocumentsUsingCustomLogic() {
    IndexHandler indexHandler = mock(IndexHandler.class);
    GraphWrapper graphWrapper = newGraph().withVertex("doc", v -> v.withProperty("wwdocument_name", "foo").withOutgoingRelation("isCreatedBy", "authorA", r -> r.withAccepted("wwrelation", true).withIsLatest(true)).withOutgoingRelation("isCreatedBy", "authorB", r -> r.withAccepted("wwrelation", true).withIsLatest(true))).withVertex("authorA", v -> v.withProperty("wwperson_name", "authorA")).withVertex("authorB", v -> v.withProperty("wwperson_name", "authorB")).wrap();
    FulltextIndexChangeListener instance = new FulltextIndexChangeListener(indexHandler, graphWrapper);
    Collection collection = new VresBuilder().withVre("womenwriters", "ww", vre -> vre.withCollection("wwdocuments", coll -> coll.withDisplayName(localProperty("wwdocument_name"))).withCollection("wwpersons", coll -> coll.withDisplayName(localProperty("wwperson_name")))).build().getCollection("wwdocuments").get();
    Vertex vertex = graphWrapper.getGraph().traversal().V().next();
    instance.onCreate(collection, vertex);
    verify(indexHandler).upsertIntoQuickSearchIndex(collection, "authorA; authorB foo", vertex, null);
}
Also used : GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) PropertyTypes.localProperty(nl.knaw.huygens.timbuctoo.model.properties.PropertyTypes.localProperty) IndexHandler(nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) Optional(java.util.Optional) Test(org.junit.Test) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) TestGraphBuilder.newGraph(nl.knaw.huygens.timbuctoo.util.TestGraphBuilder.newGraph) Mockito.mock(org.mockito.Mockito.mock) Mockito.verify(org.mockito.Mockito.verify) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) IndexHandler(nl.knaw.huygens.timbuctoo.database.tinkerpop.IndexHandler) GraphWrapper(nl.knaw.huygens.timbuctoo.server.GraphWrapper) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) VresBuilder(nl.knaw.huygens.timbuctoo.model.vre.vres.VresBuilder) Test(org.junit.Test)

Example 48 with Collection

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

the class TinkerPopPropertyConverterTest method fromThrowsAnUnknownPropertyExceptionWhenThePropertyDoesNotExistInTheCollection.

@Test(expected = UnknownPropertyException.class)
public void fromThrowsAnUnknownPropertyExceptionWhenThePropertyDoesNotExistInTheCollection() throws UnknownPropertyException, IOException {
    Collection collection = mock(Collection.class);
    when(collection.getProperty(PROPERTY_NAME)).thenReturn(Optional.empty());
    TinkerPopPropertyConverter instance = new TinkerPopPropertyConverter(collection);
    instance.from(PROPERTY_NAME, STRING_VALUE);
}
Also used : TinkerPopPropertyConverter(nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Test(org.junit.Test)

Example 49 with Collection

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

the class TinkerPopPropertyConverterTest method fromReturnsADatablePropertyWithADecodedStringValue.

// Datable tests
@Test
public void fromReturnsADatablePropertyWithADecodedStringValue() throws Exception {
    Collection collection = mock(Collection.class);
    ReadableProperty readableProperty = mock(ReadableProperty.class);
    when(readableProperty.getUniqueTypeId()).thenReturn("datable");
    when(collection.getProperty(PROPERTY_NAME)).thenReturn(Optional.of(readableProperty));
    TinkerPopPropertyConverter instance = new TinkerPopPropertyConverter(collection);
    TimProperty<?> from = instance.from(PROPERTY_NAME, "\"1800\"");
    assertThat(from.getValue(), is("1800"));
}
Also used : ReadableProperty(nl.knaw.huygens.timbuctoo.model.properties.ReadableProperty) TinkerPopPropertyConverter(nl.knaw.huygens.timbuctoo.database.tinkerpop.conversion.TinkerPopPropertyConverter) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) Test(org.junit.Test)

Example 50 with Collection

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

the class JsonCrudService method createEntity.

private UUID createEntity(Collection collection, ObjectNode input, User user) throws IOException, PermissionFetchingException {
    List<TimProperty<?>> timProperties = jsonToEntityMapper.getDataProperties(collection, input);
    Optional<Collection> baseCollection = mappings.getCollectionForType(collection.getAbstractType());
    UUID id = timDbAccess.createEntity(collection, baseCollection, timProperties, user);
    return id;
}
Also used : TimProperty(nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty) Collection(nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection) UUID(java.util.UUID)

Aggregations

Collection (nl.knaw.huygens.timbuctoo.core.dto.dataset.Collection)147 Test (org.junit.Test)122 UUID (java.util.UUID)91 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)85 TimProperty (nl.knaw.huygens.timbuctoo.core.dto.property.TimProperty)81 TinkerPopGraphManager (nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager)80 Optional (java.util.Optional)77 List (java.util.List)76 CreateCollection (nl.knaw.huygens.timbuctoo.core.dto.CreateCollection)74 Matchers.containsInAnyOrder (org.hamcrest.Matchers.containsInAnyOrder)74 Vres (nl.knaw.huygens.timbuctoo.model.vre.Vres)73 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)72 IOException (java.io.IOException)71 Vre (nl.knaw.huygens.timbuctoo.model.vre.Vre)71 JsonBuilder.jsn (nl.knaw.huygens.timbuctoo.util.JsonBuilder.jsn)71 Matchers.is (org.hamcrest.Matchers.is)71 Change (nl.knaw.huygens.timbuctoo.model.Change)70 Matchers.not (org.hamcrest.Matchers.not)70 UpdateEntity (nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity)69 VertexMatcher.likeVertex (nl.knaw.huygens.timbuctoo.util.VertexMatcher.likeVertex)69