use of eu.europeana.enrichment.utils.EntityMergeEngine in project metis-framework by europeana.
the class DereferencerImplTest method testDereferencerNullFlow.
@Test
void testDereferencerNullFlow() throws DereferenceException {
// Create mocks of the dependencies
final RemoteEntityResolver remoteEntityResolver = mock(RemoteEntityResolver.class);
final DereferenceClient dereferenceClient = mock(DereferenceClient.class);
final EntityMergeEngine entityMergeEngine = mock(EntityMergeEngine.class);
// Create dereferencer.
final Dereferencer dereferencer = spy(new DereferencerImpl(entityMergeEngine, remoteEntityResolver, dereferenceClient));
doReturn(Arrays.stream(new String[0]).collect(Collectors.toSet())).when(dereferencer).extractReferencesForDereferencing(any());
final RDF inputRdf = new RDF();
dereferencer.dereference(inputRdf);
verifyDereferenceNullFlow(dereferenceClient, dereferencer, inputRdf);
verifyMergeNullFlow(entityMergeEngine);
}
use of eu.europeana.enrichment.utils.EntityMergeEngine in project metis-framework by europeana.
the class EnricherImplTest method testEnricherHappyFlow.
@Test
void testEnricherHappyFlow() throws EnrichmentException {
// Create mocks
final RecordParser recordParser = Mockito.mock(RecordParser.class);
final RemoteEntityResolver remoteEntityResolver = Mockito.mock(RemoteEntityResolver.class);
doReturn(ENRICHMENT_RESULT).when(remoteEntityResolver).resolveByText(any());
final EntityMergeEngine entityMergeEngine = Mockito.mock(EntityMergeEngine.class);
// Create enricher.
final Enricher enricher = spy(new EnricherImpl(recordParser, remoteEntityResolver, entityMergeEngine));
doReturn(ENRICHMENT_EXTRACT_RESULT).when(recordParser).parseSearchTerms(any());
doReturn(Collections.emptySet()).when(recordParser).parseReferences(any());
final RDF inputRdf = new RDF();
enricher.enrichment(inputRdf);
verifyEnricherHappyFlow(recordParser, remoteEntityResolver, inputRdf);
verifyMergeHappyFlow(entityMergeEngine);
}
use of eu.europeana.enrichment.utils.EntityMergeEngine in project metis-framework by europeana.
the class DereferencerProvider method create.
/**
* Builds an {@link Dereferencer} according to the parameters that are set.
*
* @return An instance.
* @throws IllegalStateException When both the enrichment and dereference URLs are blank.
* @throws DereferenceException if the enrichment url is wrong and therefore the dereferencer
* was not successfully created
*/
public Dereferencer create() throws DereferenceException {
// Make sure that the worker can do something.
if (StringUtils.isBlank(dereferenceUrl) && StringUtils.isBlank(enrichmentUrl)) {
throw new IllegalStateException("Dereferencing must be enabled.");
}
// Do some logging.
if (dereferenceUrl == null) {
LOGGER.warn("Creating dereferencer for Europeana entities only.");
} else if (enrichmentUrl == null) {
LOGGER.warn("Creating dereferencer for non-Europeana entities only.");
} else {
LOGGER.info("Creating dereferencer for both Europeana and non-Europeana entities.");
}
// Create the dereference client if needed
final DereferenceClient dereferenceClient;
if (StringUtils.isNotBlank(dereferenceUrl)) {
dereferenceClient = new DereferenceClient(createRestTemplate(), dereferenceUrl);
} else {
dereferenceClient = null;
}
// Create the enrichment client if needed
final RemoteEntityResolver remoteEntityResolver;
if (StringUtils.isNotBlank(enrichmentUrl)) {
try {
remoteEntityResolver = new RemoteEntityResolver(new URL(enrichmentUrl), batchSizeEnrichment, createRestTemplate());
} catch (MalformedURLException e) {
LOGGER.debug("There was a problem with the input values");
throw new DereferenceException("Problems while building a new Dereferencer", e);
}
} else {
remoteEntityResolver = null;
}
// Done.
return new DereferencerImpl(new EntityMergeEngine(), remoteEntityResolver, dereferenceClient);
}
use of eu.europeana.enrichment.utils.EntityMergeEngine in project metis-framework by europeana.
the class DereferencerImplTest method testDereferencerHappyFlow.
@Test
void testDereferencerHappyFlow() throws DereferenceException {
// Create mocks of the dependencies
final RemoteEntityResolver remoteEntityResolver = mock(RemoteEntityResolver.class);
doReturn(ENRICHMENT_RESULT).when(remoteEntityResolver).resolveByText(anySet());
final DereferenceClient dereferenceClient = mock(DereferenceClient.class);
doReturn(DEREFERENCE_RESULT.get(0), DEREFERENCE_RESULT.subList(1, DEREFERENCE_RESULT.size()).toArray()).when(dereferenceClient).dereference(any());
final EntityMergeEngine entityMergeEngine = mock(EntityMergeEngine.class);
final Dereferencer dereferencer = spy(new DereferencerImpl(entityMergeEngine, remoteEntityResolver, dereferenceClient));
doReturn(Arrays.stream(DEREFERENCE_EXTRACT_RESULT).collect(Collectors.toSet())).when(dereferencer).extractReferencesForDereferencing(any());
final RDF inputRdf = new RDF();
dereferencer.dereference(inputRdf);
verifyDereferenceHappyFlow(dereferenceClient, dereferencer, inputRdf);
verifyMergeHappyFlow(entityMergeEngine);
}
use of eu.europeana.enrichment.utils.EntityMergeEngine in project metis-framework by europeana.
the class EnricherImplTest method testEnricherNullFlow.
@Test
void testEnricherNullFlow() throws EnrichmentException {
// Create mocks of the dependencies
final RecordParser recordParser = Mockito.mock(RecordParser.class);
final EntityMergeEngine entityMergeEngine = Mockito.mock(EntityMergeEngine.class);
final RemoteEntityResolver remoteEntityResolver = Mockito.mock(RemoteEntityResolver.class);
// Create enricher
final Enricher enricher = spy(new EnricherImpl(recordParser, remoteEntityResolver, entityMergeEngine));
doReturn(Collections.emptySet()).when(recordParser).parseSearchTerms(any());
doReturn(Collections.emptySet()).when(recordParser).parseReferences(any());
final RDF inputRdf = new RDF();
enricher.enrichment(inputRdf);
verifyEnricherNullFlow(remoteEntityResolver, recordParser, inputRdf);
verifyMergeNullFlow(entityMergeEngine);
}
Aggregations