Search in sources :

Example 1 with Database

use of nl.knaw.huygens.timbuctoo.rdf.Database in project timbuctoo by HuygensING.

the class TinkerPopOperationsTest method getEntitiesWithUnknownTypeDoesNotReturnEntitiesWithACollection.

@Test
public void getEntitiesWithUnknownTypeDoesNotReturnEntitiesWithACollection() {
    TinkerPopGraphManager wrap = newGraph().wrap();
    TinkerPopOperations instance = forGraphWrapper(wrap);
    final Database legacyRdfDatabase = new Database(wrap);
    Vre vre = instance.ensureVreExists("vre");
    instance.addCollectionToVre(vre, CreateCollection.defaultCollection("vre"));
    Vre admin = instance.ensureVreExists("Admin");
    instance.addCollectionToVre(admin, CreateCollection.defaultCollection("Admin"));
    vre = instance.loadVres().getVre("vre");
    instance.assertEntity(vre, "http://example.org/entity1");
    instance.assertEntity(vre, "http://example.org/entity2");
    nl.knaw.huygens.timbuctoo.rdf.Collection collection = legacyRdfDatabase.findOrCreateCollection("vre", NodeFactory.createURI("http://example.org/myCollection").getURI(), NodeFactory.createURI("http://example.org/myCollection").getLocalName());
    Optional<Entity> entity = legacyRdfDatabase.findEntity("vre", NodeFactory.createURI("http://example.org/entity1"));
    entity.get().addToCollection(collection);
    List<String> entitiesWithUnknownType = instance.getEntitiesWithUnknownType(vre);
    assertThat(entitiesWithUnknownType, containsInAnyOrder("http://example.org/entity2"));
}
Also used : ReadEntity(nl.knaw.huygens.timbuctoo.core.dto.ReadEntity) CreateEntity(nl.knaw.huygens.timbuctoo.core.dto.CreateEntity) UpdateEntity(nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity) Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) TinkerPopGraphManager(nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager) Database(nl.knaw.huygens.timbuctoo.rdf.Database) Vre(nl.knaw.huygens.timbuctoo.model.vre.Vre) VreStubs.minimalCorrectVre(nl.knaw.huygens.timbuctoo.model.vre.VreStubs.minimalCorrectVre) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 2 with Database

use of nl.knaw.huygens.timbuctoo.rdf.Database in project timbuctoo by HuygensING.

the class CollectionMembershipTripleProcessorTest method processLogsAnExceptionWhenTheEntityAlreadyIsPartOfACollectionWhenAsserted.

@Test
public void processLogsAnExceptionWhenTheEntityAlreadyIsPartOfACollectionWhenAsserted() {
    Database database = mock(Database.class);
    Collection collectionFromTriple = mock(Collection.class);
    Collection archetypeCollection = mock(Collection.class);
    when(collectionFromTriple.getArchetype()).thenReturn(Optional.of(archetypeCollection));
    when(database.findOrCreateCollection(anyString(), anyString(), anyString())).thenReturn(collectionFromTriple);
    Collection defaultCollection = mock(Collection.class);
    when(database.getDefaultCollection("vreName")).thenReturn(defaultCollection);
    Entity entity = mock(Entity.class);
    when(entity.isInKnownCollection()).thenReturn(true);
    when(database.findOrCreateEntity("vreName", SUBJECT_URI)).thenReturn(entity);
    RdfImportSession rdfImportSession = mock(RdfImportSession.class);
    RdfImportErrorReporter errorReporter = mock(RdfImportErrorReporter.class);
    when(rdfImportSession.getErrorReporter()).thenReturn(errorReporter);
    CollectionMembershipTripleProcessor instance = new CollectionMembershipTripleProcessor(database, rdfImportSession);
    instance.process("vreName", SUBJECT_URI, PREDICATE_URI, OBJECT_URI, true);
    verify(errorReporter).multipleRdfTypes(SUBJECT_URI, OBJECT_URI);
}
Also used : Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) RdfImportSession(nl.knaw.huygens.timbuctoo.core.RdfImportSession) RdfImportErrorReporter(nl.knaw.huygens.timbuctoo.core.RdfImportErrorReporter) Database(nl.knaw.huygens.timbuctoo.rdf.Database) Collection(nl.knaw.huygens.timbuctoo.rdf.Collection) Test(org.junit.Test)

Example 3 with Database

use of nl.knaw.huygens.timbuctoo.rdf.Database in project timbuctoo by HuygensING.

the class CollectionMembershipTripleProcessorTest method processRemovesTheEntityToTheRequestedCollectionIfItIsARetraction.

@Test
public void processRemovesTheEntityToTheRequestedCollectionIfItIsARetraction() {
    Database database = mock(Database.class);
    Collection collectionFromTriple = mock(Collection.class);
    Collection archetypeCollection = mock(Collection.class);
    when(collectionFromTriple.getArchetype()).thenReturn(Optional.of(archetypeCollection));
    when(database.findOrCreateCollection(anyString(), anyString(), anyString())).thenReturn(collectionFromTriple);
    Collection defaultCollection = mock(Collection.class);
    when(database.getDefaultCollection("vreName")).thenReturn(defaultCollection);
    Entity entity = mock(Entity.class);
    when(database.findOrCreateEntity("vreName", SUBJECT_URI)).thenReturn(entity);
    CollectionMembershipTripleProcessor instance = new CollectionMembershipTripleProcessor(database, mock(RdfImportSession.class));
    instance.process("vreName", SUBJECT_URI, PREDICATE_URI, OBJECT_URI, false);
    InOrder inOrder = inOrder(entity, database);
    inOrder.verify(database).findOrCreateCollection("vreName", OBJECT_URI, OBJECT_NAME);
    inOrder.verify(entity).removeFromCollection(collectionFromTriple);
}
Also used : Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) RdfImportSession(nl.knaw.huygens.timbuctoo.core.RdfImportSession) InOrder(org.mockito.InOrder) Database(nl.knaw.huygens.timbuctoo.rdf.Database) Collection(nl.knaw.huygens.timbuctoo.rdf.Collection) Test(org.junit.Test)

Example 4 with Database

use of nl.knaw.huygens.timbuctoo.rdf.Database in project timbuctoo by HuygensING.

the class PersonNamesTripleProcessorTest method setUp.

@Before
public void setUp() throws Exception {
    RdfImportSession rdfImportSession = mock(RdfImportSession.class);
    database = mock(Database.class);
    instance = new PersonNamesTripleProcessor(rdfImportSession, database);
    entity = mock(Entity.class);
    given(entity.getPropertyValue(PROPERTY_NAME)).willReturn(Optional.empty());
    given(database.findOrCreateEntity(VRE_NAME, SUBJECT_URI)).willReturn(entity);
}
Also used : Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) RdfImportSession(nl.knaw.huygens.timbuctoo.core.RdfImportSession) Database(nl.knaw.huygens.timbuctoo.rdf.Database) Before(org.junit.Before)

Example 5 with Database

use of nl.knaw.huygens.timbuctoo.rdf.Database in project timbuctoo by HuygensING.

the class AltLabelTripleProcessorTest method setup.

@Before
public void setup() {
    final Database database = mock(Database.class);
    entity = mock(Entity.class);
    instance = new AltLabelTripleProcessor(database);
    given(database.findOrCreateEntity(VRE_NAME, SUBJECT_URI)).willReturn(entity);
}
Also used : Entity(nl.knaw.huygens.timbuctoo.rdf.Entity) Database(nl.knaw.huygens.timbuctoo.rdf.Database) Before(org.junit.Before)

Aggregations

Database (nl.knaw.huygens.timbuctoo.rdf.Database)7 Entity (nl.knaw.huygens.timbuctoo.rdf.Entity)7 RdfImportSession (nl.knaw.huygens.timbuctoo.core.RdfImportSession)4 Test (org.junit.Test)4 Collection (nl.knaw.huygens.timbuctoo.rdf.Collection)3 Before (org.junit.Before)3 RdfImportErrorReporter (nl.knaw.huygens.timbuctoo.core.RdfImportErrorReporter)1 CreateEntity (nl.knaw.huygens.timbuctoo.core.dto.CreateEntity)1 ReadEntity (nl.knaw.huygens.timbuctoo.core.dto.ReadEntity)1 UpdateEntity (nl.knaw.huygens.timbuctoo.core.dto.UpdateEntity)1 Vre (nl.knaw.huygens.timbuctoo.model.vre.Vre)1 VreStubs.minimalCorrectVre (nl.knaw.huygens.timbuctoo.model.vre.VreStubs.minimalCorrectVre)1 Relation (nl.knaw.huygens.timbuctoo.rdf.Relation)1 RelationType (nl.knaw.huygens.timbuctoo.rdf.RelationType)1 TinkerPopGraphManager (nl.knaw.huygens.timbuctoo.server.TinkerPopGraphManager)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 InOrder (org.mockito.InOrder)1 Matchers.anyString (org.mockito.Matchers.anyString)1