From 9bddcf97f226874ec9f00eeb84c428706cd910f2 Mon Sep 17 00:00:00 2001 From: SrdjanStevanetic Date: Mon, 16 Dec 2024 15:23:54 +0100 Subject: [PATCH] integration tests for aggregatedVia field --- .../definitions/model/Aggregator.java | 14 +-- .../solr/service/SolrService.java | 51 +++++----- .../testutils/IntegrationTestUtils.java | 13 ++- .../testutils/ZohoRecordTestDeserializer.java | 25 ++++- .../web/EntityRegistrationIT.java | 93 +++++++++++++++++++ .../content/organization_register_arma.json | 4 + .../organization_register_euskariana.json | 4 + .../resources/solr-docker/conf/schema.xml | 12 +++ .../aggregator_zoho_euskariana_response.json | 4 +- 9 files changed, 179 insertions(+), 41 deletions(-) create mode 100644 entity-management-tests/src/integration-test/resources/content/organization_register_arma.json create mode 100644 entity-management-tests/src/integration-test/resources/content/organization_register_euskariana.json diff --git a/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/definitions/model/Aggregator.java b/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/definitions/model/Aggregator.java index dbbe7bef..b5650110 100644 --- a/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/definitions/model/Aggregator.java +++ b/entity-management-definitions/src/main/java/eu/europeana/entitymanagement/definitions/model/Aggregator.java @@ -68,13 +68,13 @@ PROVIDES_AUDIENCE_ENGAGEMENT_ACTIVITY }) public class Aggregator extends Organization { - private String mbox; - private String geographicScope; - List heritageDomain; - List providesSupportForMediaType; - List providesSupportForDataActivity; - List providesCapacityBuildingActivity; - List providesAudienceEngagementActivity; + protected String mbox; + protected String geographicScope; + protected List heritageDomain; + protected List providesSupportForMediaType; + protected List providesSupportForDataActivity; + protected List providesCapacityBuildingActivity; + protected List providesAudienceEngagementActivity; public Aggregator() { super(); diff --git a/entity-management-solr/src/main/java/eu/europeana/entitymanagement/solr/service/SolrService.java b/entity-management-solr/src/main/java/eu/europeana/entitymanagement/solr/service/SolrService.java index 75820a7b..4faefa0a 100644 --- a/entity-management-solr/src/main/java/eu/europeana/entitymanagement/solr/service/SolrService.java +++ b/entity-management-solr/src/main/java/eu/europeana/entitymanagement/solr/service/SolrService.java @@ -3,7 +3,27 @@ import static eu.europeana.entitymanagement.common.vocabulary.AppConfigConstants.BEAN_INDEXING_SOLR_CLIENT; import static eu.europeana.entitymanagement.common.vocabulary.AppConfigConstants.BEAN_JSON_MAPPER; import static eu.europeana.entitymanagement.common.vocabulary.AppConfigConstants.BEAN_SOLR_ENTITY_SUGGESTER_FILTER; - +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.solr.client.solrj.SolrClient; +import org.apache.solr.client.solrj.SolrQuery; +import org.apache.solr.client.solrj.SolrServerException; +import org.apache.solr.client.solrj.beans.BindingException; +import org.apache.solr.client.solrj.beans.DocumentObjectBinder; +import org.apache.solr.client.solrj.response.QueryResponse; +import org.apache.solr.client.solrj.response.UpdateResponse; +import org.apache.solr.common.SolrDocument; +import org.apache.solr.common.SolrDocumentList; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -21,34 +41,13 @@ import eu.europeana.entitymanagement.solr.SolrEntitySuggesterMixins.ConceptSuggesterMixin; import eu.europeana.entitymanagement.solr.SolrEntitySuggesterMixins.PlaceSuggesterMixin; import eu.europeana.entitymanagement.solr.SolrEntitySuggesterMixins.TimeSpanSuggesterMixin; -import eu.europeana.entitymanagement.solr.SolrSearchCursorIterator; import eu.europeana.entitymanagement.solr.SolrEntityUtils; +import eu.europeana.entitymanagement.solr.SolrSearchCursorIterator; import eu.europeana.entitymanagement.solr.exception.SolrServiceException; import eu.europeana.entitymanagement.solr.model.SolrConceptScheme; import eu.europeana.entitymanagement.solr.model.SolrEntity; import eu.europeana.entitymanagement.solr.model.SolrOrganization; import eu.europeana.entitymanagement.vocabulary.EntitySolrFields; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.SolrQuery; -import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.beans.BindingException; -import org.apache.solr.client.solrj.beans.DocumentObjectBinder; -import org.apache.solr.client.solrj.response.QueryResponse; -import org.apache.solr.client.solrj.response.UpdateResponse; -import org.apache.solr.common.SolrDocument; -import org.apache.solr.common.SolrDocumentList; -import org.springframework.beans.factory.InitializingBean; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Service; -import org.springframework.util.CollectionUtils; @Service(AppConfigConstants.BEAN_EM_SOLR_SERVICE) public class SolrService implements InitializingBean { @@ -185,9 +184,9 @@ public void storeMultipleEntities(final List> solrE * @return SolrEntity instance * @throws SolrServiceException if error occurs while executing query */ - public > U searchById( - Class classType, String entityId) throws SolrServiceException { - + @SuppressWarnings("rawtypes") + public T searchById( + Class classType, String entityId) throws SolrServiceException { QueryResponse rsp; SolrQuery query = new SolrQuery(); query.set("q", EntitySolrFields.ID + ":\"" + entityId + "\""); diff --git a/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/testutils/IntegrationTestUtils.java b/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/testutils/IntegrationTestUtils.java index 572fc17d..c5863d8e 100644 --- a/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/testutils/IntegrationTestUtils.java +++ b/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/testutils/IntegrationTestUtils.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; +import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.Optional; @@ -73,6 +74,10 @@ public class IntegrationTestUtils { "/content/organization_register_zoho_berger_museum.json"; public static final String ORGANIZATION_REGISTER_PCCE_ZOHO_JSON = "/content/organization_register_zoho_pcce.json"; + public static final String ORGANIZATION_REGISTER_EUSKARIANA_JSON = + "/content/organization_register_euskariana.json"; + public static final String ORGANIZATION_REGISTER_ARMA_JSON = + "/content/organization_register_arma.json"; public static final String PLACE_REGISTER_PARIS_JSON = "/content/place_register_paris.json"; public static final String PLACE_REGISTER_SWEDEN_JSON = "/content/place_register_sweden.json"; public static final String PLACE_REGISTER_HAGENBACH_JSON = @@ -272,10 +277,10 @@ public class IntegrationTestUtils { ORGANIZATION_EUSKARIANA_ZOHO_RESPONSE); /** Maps ZOHO organization names to mocked JSON responses */ - public static Map ZOHO_ORG_NAME_RESPONSE_MAP = - Map.of( - ORGANIZATION_EUSKARIANA_NAME, - ORGANIZATION_EUSKARIANA_ZOHO_RESPONSE); + public static Map ZOHO_ORG_NAME_RESPONSE_MAP = new HashMap(); + static { + ZOHO_ORG_NAME_RESPONSE_MAP.put(ORGANIZATION_EUSKARIANA_NAME, ORGANIZATION_EUSKARIANA_ZOHO_RESPONSE); + } /** Maps ZOHO organization urls to the aggregators mocked JSON responses */ public static Map ZOHO_ORG_URL_AGGREGATOR_RESPONSE_MAP = diff --git a/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/testutils/ZohoRecordTestDeserializer.java b/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/testutils/ZohoRecordTestDeserializer.java index 427edfe1..5bd15218 100644 --- a/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/testutils/ZohoRecordTestDeserializer.java +++ b/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/testutils/ZohoRecordTestDeserializer.java @@ -2,9 +2,14 @@ import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.ACCOUNT_NAME_FIELD; import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.ACRONYM_FIELD; +import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.AGGREGATING_FROM; +import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.AGGREGATORS; import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.ALTERNATIVE_FIELD; +import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.CAPACITY_BUILDING; import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.CITY_FIELD; import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.COUNTRY_FIELD; +import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.EUROPEANA_ID_FIELD; +import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.HERITAGE_DOMAIN; import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.HIDDEN_LABEL1_FIELD; import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.HIDDEN_LABEL2_FIELD; import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.HIDDEN_LABEL3_FIELD; @@ -19,9 +24,11 @@ import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.LATITUDE_FIELD; import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.LOGO_LINK_TO_WIKIMEDIACOMMONS_FIELD; import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.LONGITUDE_FIELD; +import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.NAME_FIELD; import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.OFFICIAL_LANGUAGE_FIELD; import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.ORGANIZATION_ROLE_FIELD; import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.PO_BOX_FIELD; +import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.PUBLIC_EMAIL; import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.SAME_AS_CODE_LENGTH; import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.SAME_AS_FIELD; import static eu.europeana.entitymanagement.zoho.utils.ZohoConstants.STREET_FIELD; @@ -70,7 +77,13 @@ public class ZohoRecordTestDeserializer extends StdDeserializer { HIDDEN_LABEL3_FIELD, HIDDEN_LABEL4_FIELD, HIDDEN_LABEL_FIELD, - INDUSTRY_FIELD); + INDUSTRY_FIELD, + HERITAGE_DOMAIN, + PUBLIC_EMAIL, + CAPACITY_BUILDING, + AGGREGATORS, + EUROPEANA_ID_FIELD, + AGGREGATING_FROM); public ZohoRecordTestDeserializer() { this(null); @@ -99,12 +112,18 @@ public Record deserialize(JsonParser p, DeserializationContext ctxt) throws IOEx List> values = new ArrayList>(); currentNode.elements().forEachRemaining(v -> values.add(new Choice(v.asText()))); record.addKeyValue(key, values); + }else if(currentNode.isObject()) { + System.out.println("object node: " + key); + if(AGGREGATORS.equals(key) || AGGREGATING_FROM.equals(key)) { + Record subRecord = new Record(); + subRecord.setId(currentNode.get(ID_FIELD).asLong()); + subRecord.addKeyValue(NAME_FIELD, currentNode.get(NAME_FIELD)); + record.addKeyValue(key, subRecord); + } }else if (currentNode.isContainerNode()){ System.out.println("container node: " + key); }else if(currentNode.isPojo()) { System.out.println("pojo node: " + key); - }else if(currentNode.isObject()) { - System.out.println("object node: " + key); } } diff --git a/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/web/EntityRegistrationIT.java b/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/web/EntityRegistrationIT.java index cac61d7e..04a98e2f 100644 --- a/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/web/EntityRegistrationIT.java +++ b/entity-management-tests/src/integration-test/java/eu/europeana/entitymanagement/web/EntityRegistrationIT.java @@ -20,6 +20,7 @@ import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import eu.europeana.entitymanagement.definitions.model.EntityRecord; +import eu.europeana.entitymanagement.solr.model.SolrAggregator; import eu.europeana.entitymanagement.solr.model.SolrOrganization; import eu.europeana.entitymanagement.testutils.IntegrationTestUtils; import eu.europeana.entitymanagement.utils.EntityRecordUtils; @@ -285,6 +286,98 @@ public void registerZohoOrganizationBergerShouldBeSuccessful() throws Exception assertTrue(org.getCountry().size()==2); } + @Test + public void zohoCheckAggregatedViaOverZohoOrgSearch() throws Exception { + /* + * 1. register zoho Euskariana organization (which is an aggregator) + */ + ResultActions response = + mockMvc.perform( + MockMvcRequestBuilders.post(IntegrationTestUtils.BASE_SERVICE_URL) + .content( + loadFile(IntegrationTestUtils.ORGANIZATION_REGISTER_EUSKARIANA_JSON)) + .contentType(MediaType.APPLICATION_JSON_VALUE)); + response + .andExpect(status().isAccepted()) + .andExpect(jsonPath("$.id", any(String.class))) + .andExpect(jsonPath("$.type", is(EntityTypes.Aggregator.getEntityType()))) + .andExpect(jsonPath("$.isAggregatedBy").isNotEmpty()) + // isAggregatedBy should contain 2 aggregates (for Europeana and zoho) + .andExpect(jsonPath("$.isAggregatedBy.aggregates", hasSize(2))) + //1. from the response, 2. the zoho id, 3. the aggregator id + .andExpect(jsonPath("$.sameAs", hasSize(3))) + .andExpect(jsonPath("$.heritageDomain", hasSize(1))) + .andExpect(jsonPath("$.prefLabel[*]", hasSize(2))) + // should have Europeana and Zoho proxies + .andExpect(jsonPath("$.proxies", hasSize(2))); + + // check if indexing is successfull by searching the organization in solr + SolrAggregator aggreg = emSolrService.searchById(SolrAggregator.class, + WebEntityFields.BASE_DATA_EUROPEANA_URI + EntityTypes.Aggregator.getEntityType().toLowerCase() + "/1"); + assertNotNull(aggreg.getHasAddress()); + assertNotNull(aggreg.getEuropeanaRole()); + assertNotNull(aggreg.getHeritageDomain()); + + /* + * 2. register zoho Arma organization, which is aggregated via the previously registered + * organization (Euskariana), and check the aggregatedVia field. + */ + response = + mockMvc.perform( + MockMvcRequestBuilders.post(IntegrationTestUtils.BASE_SERVICE_URL) + .content( + loadFile(IntegrationTestUtils.ORGANIZATION_REGISTER_ARMA_JSON)) + .contentType(MediaType.APPLICATION_JSON_VALUE)); + response + .andExpect(status().isAccepted()) + .andExpect(jsonPath("$.id", any(String.class))) + .andExpect(jsonPath("$.type", is(EntityTypes.Organization.getEntityType()))) + .andExpect(jsonPath("$.aggregatedVia", hasSize(1))); + } + + @Test + public void zohoCheckAggregatedViaOverZohoLinkingAndLocalDbSearch() throws Exception { + /* + * 1. register zoho Euskariana organization (which is an aggregator) + */ + ResultActions response = + mockMvc.perform( + MockMvcRequestBuilders.post(IntegrationTestUtils.BASE_SERVICE_URL) + .content( + loadFile(IntegrationTestUtils.ORGANIZATION_REGISTER_EUSKARIANA_JSON)) + .contentType(MediaType.APPLICATION_JSON_VALUE)); + + /* + * 2. remove the entry from the map that mocks the zoho response for the organization + * with the name of the aggregator + */ + IntegrationTestUtils.ZOHO_ORG_NAME_RESPONSE_MAP.clear(); + + /* + * 3. register zoho Arma organization, which is aggregated via the previously registered + * organization (Euskariana), and check the aggregatedVia field + */ + response = + mockMvc.perform( + MockMvcRequestBuilders.post(IntegrationTestUtils.BASE_SERVICE_URL) + .content( + loadFile(IntegrationTestUtils.ORGANIZATION_REGISTER_ARMA_JSON)) + .contentType(MediaType.APPLICATION_JSON_VALUE)); + response + .andExpect(status().isAccepted()) + .andExpect(jsonPath("$.id", any(String.class))) + .andExpect(jsonPath("$.type", is(EntityTypes.Organization.getEntityType()))) + .andExpect(jsonPath("$.aggregatedVia", hasSize(1))); + + /* + * 4. put back the removed entry from the map in step 2. + */ + IntegrationTestUtils.ZOHO_ORG_NAME_RESPONSE_MAP.put( + IntegrationTestUtils.ORGANIZATION_EUSKARIANA_NAME, + IntegrationTestUtils.ORGANIZATION_EUSKARIANA_ZOHO_RESPONSE); + + } + @Test void registerZohoOrganizationWithoutWikidataSameAsShouldBeSuccessful() throws Exception { // String expectedId = diff --git a/entity-management-tests/src/integration-test/resources/content/organization_register_arma.json b/entity-management-tests/src/integration-test/resources/content/organization_register_arma.json new file mode 100644 index 00000000..6bd6de0a --- /dev/null +++ b/entity-management-tests/src/integration-test/resources/content/organization_register_arma.json @@ -0,0 +1,4 @@ +{ + "type": "Organization", + "id": "https://crm.zoho.eu/crm/org20085137532/tab/Accounts/486281000004375001" +} \ No newline at end of file diff --git a/entity-management-tests/src/integration-test/resources/content/organization_register_euskariana.json b/entity-management-tests/src/integration-test/resources/content/organization_register_euskariana.json new file mode 100644 index 00000000..7046d9a3 --- /dev/null +++ b/entity-management-tests/src/integration-test/resources/content/organization_register_euskariana.json @@ -0,0 +1,4 @@ +{ + "type": "Aggregator", + "id": "https://crm.zoho.eu/crm/org20085137532/tab/Accounts/486281000000939318" +} \ No newline at end of file diff --git a/entity-management-tests/src/integration-test/resources/solr-docker/conf/schema.xml b/entity-management-tests/src/integration-test/resources/solr-docker/conf/schema.xml index ae8a37bd..3fca90b5 100644 --- a/entity-management-tests/src/integration-test/resources/solr-docker/conf/schema.xml +++ b/entity-management-tests/src/integration-test/resources/solr-docker/conf/schema.xml @@ -484,6 +484,18 @@ + + + + + + diff --git a/entity-management-tests/src/integration-test/resources/zoho-deref/aggregator_zoho_euskariana_response.json b/entity-management-tests/src/integration-test/resources/zoho-deref/aggregator_zoho_euskariana_response.json index 86a6507a..2c5cb9d9 100644 --- a/entity-management-tests/src/integration-test/resources/zoho-deref/aggregator_zoho_euskariana_response.json +++ b/entity-management-tests/src/integration-test/resources/zoho-deref/aggregator_zoho_euskariana_response.json @@ -1,7 +1,9 @@ { "Capacity_Building": [], "Public_Email": null, - "Heritage_Domain": [], + "Heritage_Domain": [ + "Cultural Heritage" + ], "Name": "Euskariana", "Last_Activity_Time": "2024-09-04T15:54:48+02:00", "Record_Image": null,