Skip to content

Commit 02f7379

Browse files
ISO19139 / Add missing namespaces to doi remove process (#9261)
* ISO19139 / Add missing namespaces to doi remove process * Remove duplicated namespace --------- Co-authored-by: Juan Luis Rodríguez Ponce <juanluisrp@gmail.com>
1 parent f5835a0 commit 02f7379

3 files changed

Lines changed: 532 additions & 0 deletions

File tree

schemas/iso19139/src/main/plugin/iso19139/process/doi-remove.xsl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
33
xmlns:gco="http://www.isotc211.org/2005/gco"
44
xmlns:gmd="http://www.isotc211.org/2005/gmd"
5+
xmlns:gmx="http://www.isotc211.org/2005/gmx"
6+
xmlns:xlink="http://www.w3.org/1999/xlink"
57
xmlns:geonet="http://www.fao.org/geonetwork"
68
exclude-result-prefixes="#all">
79

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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

Comments
 (0)