From eb805ebf9b27b91ef58c4dfc293e2a3315100b0d Mon Sep 17 00:00:00 2001 From: Alessia Bardi Date: Wed, 8 Jul 2020 16:34:48 +0200 Subject: [PATCH] test for checking structural equality in new and old records in elasticsearch --- .../elasticsearch/IndexedJsonTest.java | 25 +++ .../ariadneplus/elasticsearch/new.json | 162 ++++++++++++++++++ .../ariadneplus/elasticsearch/old.json | 57 ++++++ 3 files changed, 244 insertions(+) diff --git a/dnet-ariadneplus-graphdb-publisher/test/java/eu/dnetlib/ariadneplus/elasticsearch/IndexedJsonTest.java b/dnet-ariadneplus-graphdb-publisher/test/java/eu/dnetlib/ariadneplus/elasticsearch/IndexedJsonTest.java index 9b58937..f5151a0 100644 --- a/dnet-ariadneplus-graphdb-publisher/test/java/eu/dnetlib/ariadneplus/elasticsearch/IndexedJsonTest.java +++ b/dnet-ariadneplus-graphdb-publisher/test/java/eu/dnetlib/ariadneplus/elasticsearch/IndexedJsonTest.java @@ -1,4 +1,29 @@ package eu.dnetlib.ariadneplus.elasticsearch; +import org.apache.commons.io.IOUtils; +import org.json.JSONException; +import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.springframework.core.io.ClassPathResource; + +import java.io.IOException; + public class IndexedJsonTest { + + @Test + public void testSimple() throws JSONException { + String old = getJSONResult("eu/dnetlib/ariadneplus/elasticsearch/old.json"); + String the_new = getJSONResult("eu/dnetlib/ariadneplus/elasticsearch/new.json"); + JSONAssert.assertEquals(old, the_new, false); // Pass + //JSONAssert.assertEquals(old, the_new, true); // Fail + } + + private String getJSONResult(String s) { + try { + final ClassPathResource resource = new ClassPathResource(s); + return IOUtils.toString(resource.getInputStream(), "UTF-8"); + }catch(IOException e){ + return null; + } + } } diff --git a/dnet-ariadneplus-graphdb-publisher/test/resources/eu/dnetlib/ariadneplus/elasticsearch/new.json b/dnet-ariadneplus-graphdb-publisher/test/resources/eu/dnetlib/ariadneplus/elasticsearch/new.json index e69de29..9443beb 100644 --- a/dnet-ariadneplus-graphdb-publisher/test/resources/eu/dnetlib/ariadneplus/elasticsearch/new.json +++ b/dnet-ariadneplus-graphdb-publisher/test/resources/eu/dnetlib/ariadneplus/elasticsearch/new.json @@ -0,0 +1,162 @@ +{ + "aatSubjects": [ + { + "id": "", + "label": "", + "lang": "" + } + ], + "accessPolicy": "", + "accessRights": "", + "archaeologicalResourceType": { + "id": 0, + "name": "" + }, + "contributor": [ + { + "email": "", + "name": "", + "phone": "", + "type": "" + } + ], + "creator": [ + { + "email": "", + "name": "", + "phone": "", + "type": "" + } + ], + "derivedSubject": [ + { + "prefLabel": "", + "source": "" + } + ], + "description": "", + "distribution": [ + { + "accessURL": "", + "description": "", + "issued": "", + "modified": "", + "publisher": [ + { + "email": "", + "name": "", + "phone": "", + "type": "" + } + ], + "title": "" + } + ], + "publisher": [ + { + "email": "", + "name": "", + "phone": "", + "type": "" + } + ], + "title": "", + "hasItemMetadataStructure": [ + { + "characterSet": "" + } + ], + "hasMetadataRecord": [ + { + "conformsTo": [ + { + "characterSet": "", + "description": "" + } + ], + "xmlDoc": "" + } + ], + "identifier": "", + "isPartOf": [ + "" + ], + "issued": "", + "keyword": [ + "" + ], + "landingPage": "", + "language": "", + "legalResponsible": [ + { + "email": "", + "name": "", + "phone": "", + "type": "" + } + ], + "modified": "", + "nativeSubject": [ + { + "prefLabel": "", + "rdfAbout": "" + } + ], + "originalId": "580969", + "owner": [ + { + "email": "", + "name": "", + "phone": "", + "type": "" + } + ], + "resourceType": "", + "scientificResponsible": [ + { + "email": "", + "name": "", + "phone": "", + "type": "" + } + ], + "spatial": [ + { + "address": "", + "coordinateSystem": "", + "country": "", + "location": { + "lat": 0.0, + "lon": 0.0 + }, + "placeName": "", + "postcode": "" + } + ], + "technicalResponsible": [ + { + "email": "", + "name": "", + "phone": "", + "type": "" + } + ], + "temporal": [ + { + "from": "", + "periodName": "", + "until": "", + "uri": "" + } + ], + "accrualPeriodicity": "", + "audience": "", + "contactPoint": "", + "extent": "", + "providerId": "", + "packageId": "", + "placeName": "", + "postcode": "", + "rdfAbout": "", + "rights": "" + } \ No newline at end of file diff --git a/dnet-ariadneplus-graphdb-publisher/test/resources/eu/dnetlib/ariadneplus/elasticsearch/old.json b/dnet-ariadneplus-graphdb-publisher/test/resources/eu/dnetlib/ariadneplus/elasticsearch/old.json index e69de29..b986baf 100644 --- a/dnet-ariadneplus-graphdb-publisher/test/resources/eu/dnetlib/ariadneplus/elasticsearch/old.json +++ b/dnet-ariadneplus-graphdb-publisher/test/resources/eu/dnetlib/ariadneplus/elasticsearch/old.json @@ -0,0 +1,57 @@ +{ + "publisher": [ + { + "type": "", + "name": "" + } + ], + "identifier": "", + "description": "", + "language": "", + "title": "", + "archaeologicalResourceType": { + "id": 0, + "name": "" + }, + "issued": "", + "temporal": [ + { + "from": "", + "until": "" + } + ], + "isPartOf": [ + "" + ], + "originalId": "580969", + "modified": "", + "accessRights": "", + "accessPolicy": "", + "resourceType": "", + "providerId": "", + "packageId": "", + "spatial": [ + { + "placeName": "", + "country": "", + "location": { + "lat": 0.0, + "lon": 0.0 + }, + "coordinateSystem": "" + } + ], + "contributor": [ + { + "type": "", + "name": "" + } + ], + "landingPage": "", + "nativeSubject": [ + { + "prefLabel": "" + } + ] + } +} \ No newline at end of file