|
| 1 | +/* |
| 2 | + * Copyright (C) 2001-2026 Food and Agriculture Organization of the |
| 3 | + * United Nations (FAO-UN), United Nations World Food Programme (WFP) |
| 4 | + * and United Nations Environment Programme (UNEP) |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2 of the License, or (at |
| 9 | + * your option) any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, but |
| 12 | + * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | + * General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this program; if not, write to the Free Software |
| 18 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
| 19 | + * |
| 20 | + * Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2, |
| 21 | + * Rome - Italy. email: geonetwork@osgeo.org |
| 22 | + */ |
| 23 | + |
| 24 | +package org.fao.geonet.schemas; |
| 25 | + |
| 26 | +import org.fao.geonet.schema.iso19139.ISO19139Namespaces; |
| 27 | +import org.fao.geonet.schema.iso19139.ISO19139SchemaPlugin; |
| 28 | +import org.fao.geonet.utils.Xml; |
| 29 | +import org.jdom.Element; |
| 30 | +import org.junit.Test; |
| 31 | + |
| 32 | +import java.util.HashMap; |
| 33 | +import java.util.Map; |
| 34 | + |
| 35 | +import static org.hamcrest.CoreMatchers.equalTo; |
| 36 | +import static org.junit.Assert.assertThat; |
| 37 | +import static org.xmlunit.matchers.EvaluateXPathMatcher.hasXPath; |
| 38 | + |
| 39 | +public class DoiRemoveProcessTest extends XslProcessTest { |
| 40 | + |
| 41 | + public DoiRemoveProcessTest() { |
| 42 | + super(); |
| 43 | + this.setXslFilename("process/doi-remove.xsl"); |
| 44 | + this.setXmlFilename("schemas/xsl/process/input_with_doi.xml"); |
| 45 | + this.setNs(ISO19139SchemaPlugin.allNamespaces); |
| 46 | + this.getNs().put("gmx", ISO19139Namespaces.GMX.getURI()); |
| 47 | + this.getNs().put("xlink", ISO19139Namespaces.XLINK.getURI()); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void mustNotAlterARecordWhenNoParameterProvided() throws Exception { |
| 52 | + super.testMustNotAlterARecordWhenNoParameterProvided(); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void testRemoveDoi() throws Exception { |
| 57 | + Element inputElement = Xml.loadFile(xmlFile); |
| 58 | + String inputString = Xml.getString(inputElement); |
| 59 | + |
| 60 | + String doi = "https://doi.org/11.1111/da165110-88fd-11da-a88f-000d939bc5d8"; |
| 61 | + |
| 62 | + assertThat(inputString, hasXPath("count(//gmd:onLine[*/gmd:linkage/gmd:URL = '" + doi + "'])", equalTo("1")).withNamespaceContext(ns)); |
| 63 | + assertThat(inputString, hasXPath("count(//gmd:identifier[*/gmd:code/gmx:Anchor/@xlink:href = '" + doi + "'])", equalTo("1")).withNamespaceContext(ns)); |
| 64 | + |
| 65 | + |
| 66 | + // 2. Run the process |
| 67 | + Map<String, Object> params = new HashMap<>(); |
| 68 | + params.put("doi", doi); |
| 69 | + |
| 70 | + Element resultElement = Xml.transform(inputElement, xslFile, params); |
| 71 | + String resultString = Xml.getString(resultElement); |
| 72 | + |
| 73 | + // 3. Verify it is removed |
| 74 | + |
| 75 | + assertThat(resultString, hasXPath("count(//gmd:onLine[*/gmd:linkage/gmd:URL = '" + doi + "'])", equalTo("0")).withNamespaceContext(ns)); |
| 76 | + assertThat(resultString, hasXPath("count(//gmd:identifier[*/gmd:code/gmx:Anchor/@xlink:href = '" + doi + "'])", equalTo("0")).withNamespaceContext(ns)); |
| 77 | + } |
| 78 | +} |
0 commit comments