Skip to content

Commit

Permalink
MET-6037 update unit tests to support fix changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeortizquan committed Jul 26, 2024
1 parent e7b6d00 commit c1da7e9
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 156 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package eu.europeana.indexing;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import eu.europeana.indexing.base.IndexingTestUtils;
import eu.europeana.indexing.exception.IndexingException;
Expand All @@ -18,6 +21,9 @@
*/
class IndexerPreprocessorTest {

private static final String CONTENT_TIER_URI = "http://www.europeana.eu/schemas/epf/contentTier";
private static final String METADATA_TIER_URI = "http://www.europeana.eu/schemas/epf/metadataTier";

/**
* Preprocess record.
*
Expand All @@ -26,16 +32,46 @@ class IndexerPreprocessorTest {
*/
@Test
void preprocessRecord() throws SerializationException, IndexingException {
// given
final RdfConversionUtils conversionUtils = new RdfConversionUtils();
final RDF inputRdf = conversionUtils.convertStringToRdf(
IndexingTestUtils.getResourceFileContent("europeana_record_to_sample_index_rdf.xml"));
final IndexingProperties indexingProperties = new IndexingProperties(Date.from(Instant.now()),
true,
List.of(), true, true);

// when
TierResults results = IndexerPreprocessor.preprocessRecord(inputRdf, indexingProperties);

assertEquals("4", results.getMediaTier().toString());
assertEquals("B", results.getMetadataTier().toString());
// then
List<String> tierProvidedData = inputRdf.getAggregationList()
.stream()
.map(provideddata -> provideddata.getHasQualityAnnotationList()
.stream()
.map(q -> q.getQualityAnnotation().getHasBody()
.getResource()).toList())
.findFirst().orElse(null);

List<String> tierEuropeanaData = inputRdf.getEuropeanaAggregationList()
.stream()
.map(eudata -> eudata.getHasQualityAnnotationList()
.stream()
.map(q -> q.getQualityAnnotation().getHasBody().getResource())
.toList())
.findFirst().orElse(null);

// verify two different aggregation has different calculations
assertArrayEquals(new String[]{CONTENT_TIER_URI + "1", METADATA_TIER_URI + "A"}, tierProvidedData.toArray());
assertArrayEquals(new String[]{CONTENT_TIER_URI + "1", METADATA_TIER_URI + "B"}, tierEuropeanaData.toArray());

// verify return of tier calculation
assertEquals("1", results.getMediaTier().toString());
assertEquals("A", results.getMetadataTier().toString());

// verify return is equal to aggregation and not europeana aggregation
assertTrue(tierProvidedData.contains(CONTENT_TIER_URI + results.getMediaTier().toString()) &&
tierProvidedData.contains(METADATA_TIER_URI + results.getMetadataTier().toString()));
assertFalse(tierEuropeanaData.contains(CONTENT_TIER_URI + results.getMediaTier().toString()) &&
tierEuropeanaData.contains(METADATA_TIER_URI + results.getMetadataTier().toString()));
}
}
Loading

0 comments on commit c1da7e9

Please sign in to comment.