Skip to content

Commit

Permalink
integration tests for aggregatedVia field
Browse files Browse the repository at this point in the history
  • Loading branch information
SrdjanStevanetic committed Dec 16, 2024
1 parent 363e9a6 commit 9bddcf9
Show file tree
Hide file tree
Showing 9 changed files with 179 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@
PROVIDES_AUDIENCE_ENGAGEMENT_ACTIVITY
})
public class Aggregator extends Organization {
private String mbox;
private String geographicScope;
List<String> heritageDomain;
List<String> providesSupportForMediaType;
List<String> providesSupportForDataActivity;
List<String> providesCapacityBuildingActivity;
List<String> providesAudienceEngagementActivity;
protected String mbox;
protected String geographicScope;
protected List<String> heritageDomain;
protected List<String> providesSupportForMediaType;
protected List<String> providesSupportForDataActivity;
protected List<String> providesCapacityBuildingActivity;
protected List<String> providesAudienceEngagementActivity;

public Aggregator() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -185,9 +184,9 @@ public void storeMultipleEntities(final List<SolrEntity<? extends Entity>> solrE
* @return SolrEntity instance
* @throws SolrServiceException if error occurs while executing query
*/
public <T extends Entity, U extends SolrEntity<T>> U searchById(
Class<U> classType, String entityId) throws SolrServiceException {

@SuppressWarnings("rawtypes")
public <T extends SolrEntity> T searchById(
Class<T> classType, String entityId) throws SolrServiceException {
QueryResponse rsp;
SolrQuery query = new SolrQuery();
query.set("q", EntitySolrFields.ID + ":\"" + entityId + "\"");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -272,10 +277,10 @@ public class IntegrationTestUtils {
ORGANIZATION_EUSKARIANA_ZOHO_RESPONSE);

/** Maps ZOHO organization names to mocked JSON responses */
public static Map<String, String> ZOHO_ORG_NAME_RESPONSE_MAP =
Map.of(
ORGANIZATION_EUSKARIANA_NAME,
ORGANIZATION_EUSKARIANA_ZOHO_RESPONSE);
public static Map<String, String> ZOHO_ORG_NAME_RESPONSE_MAP = new HashMap<String, String>();
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<String, String> ZOHO_ORG_URL_AGGREGATOR_RESPONSE_MAP =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -70,7 +77,13 @@ public class ZohoRecordTestDeserializer extends StdDeserializer<Record> {
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);
Expand Down Expand Up @@ -99,12 +112,18 @@ public Record deserialize(JsonParser p, DeserializationContext ctxt) throws IOEx
List<Choice<?>> values = new ArrayList<Choice<?>>();
currentNode.elements().forEachRemaining(v -> values.add(new Choice<String>(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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Organization",
"id": "https://crm.zoho.eu/crm/org20085137532/tab/Accounts/486281000004375001"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "Aggregator",
"id": "https://crm.zoho.eu/crm/org20085137532/tab/Accounts/486281000000939318"
}
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,18 @@
<field name="foaf_phone" type="string" indexed="false"
stored="true" multiValued="true" />
<field name="foaf_mbox" type="string" indexed="false"
stored="true" multiValued="false" />
<field name="edm_geographicScope" type="string" indexed="false"
stored="true" multiValued="false" />
<field name="edm_heritageDomain" type="string" indexed="false"
stored="true" multiValued="true" />
<field name="edm_providesSupportForMediaType" type="string" indexed="false"
stored="true" multiValued="true" />
<field name="edm_providesSupportForDataActivity" type="string" indexed="false"
stored="true" multiValued="true" />
<field name="edm_providesCapacityBuildingActivity" type="string" indexed="false"
stored="true" multiValued="true" />
<field name="edm_providesAudienceEngagementActivity" type="string" indexed="false"
stored="true" multiValued="true" />
<!-- these fields are all populated by controlled values. These are all
en, but in future may be expanded -->
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 9bddcf9

Please sign in to comment.