Skip to content

Commit a9f9e07

Browse files
committed
add test
1 parent e667f25 commit a9f9e07

File tree

10 files changed

+31231
-0
lines changed

10 files changed

+31231
-0
lines changed

schemas/iso19115-3.2018/pom.xml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@
3434
<groupId>org.xmlunit</groupId>
3535
<artifactId>xmlunit-matchers</artifactId>
3636
</dependency>
37+
<dependency>
38+
<scope>test</scope>
39+
<groupId>org.apache.commons</groupId>
40+
<artifactId>commons-text</artifactId>
41+
<version>1.13.0</version>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.owasp.esapi</groupId>
45+
<artifactId>esapi</artifactId>
46+
<version>2.5.4.0</version>
47+
<exclusions>
48+
<exclusion>
49+
<groupId>log4j</groupId>
50+
<artifactId>log4j</artifactId>
51+
</exclusion>
52+
</exclusions>
53+
<scope>test</scope>
54+
</dependency>
3755
</dependencies>
3856

3957
<build>
@@ -53,6 +71,26 @@
5371
<testResource>
5472
<directory>src/main/plugin/iso19115-3.2018</directory>
5573
</testResource>
74+
<testResource>
75+
<directory>../../web/src/main/webapp</directory>
76+
<targetPath>gn-site</targetPath>
77+
</testResource>
78+
<testResource>
79+
<directory>src/main/plugin/iso19115-3.2018</directory>
80+
<targetPath>gn-site/WEB-INF/data/config/schema_plugins/iso19115-3.2018</targetPath>
81+
</testResource>
82+
<testResource>
83+
<directory>../iso19139/src/main/plugin/iso19139</directory>
84+
<targetPath>gn-site/WEB-INF/data/config/schema_plugins/iso19139</targetPath>
85+
</testResource>
86+
<testResource>
87+
<directory>../dublin-core/src/main/plugin/dublin-core</directory>
88+
<targetPath>gn-site/WEB-INF/data/config/schema_plugins/dublin-core</targetPath>
89+
</testResource>
90+
<testResource>
91+
<directory>../iso19110/src/main/plugin/iso19110</directory>
92+
<targetPath>gn-site/WEB-INF/data/config/schema_plugins/iso19110</targetPath>
93+
</testResource>
5694
</testResources>
5795

5896
<plugins>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.fao.geonet.api.records.formatters;
2+
3+
import org.jdom.JDOMException;
4+
5+
import java.io.IOException;
6+
7+
public class SchemaLocalizations {
8+
9+
public static SchemaLocalizations create(String schema, final String lang3) throws IOException, JDOMException {
10+
return new SchemaLocalizations();
11+
}
12+
13+
public static SchemaLocalizations create(String schema) throws IOException, JDOMException {
14+
return new SchemaLocalizations();
15+
}
16+
17+
public String codelistValueLabel(String codelist, String value) throws Exception {
18+
return String.format("cl_%s#%s", codelist, value);
19+
}
20+
21+
public String nodeLabel(String qualifiedNodeName, String qualifiedParentNodeName, String qualifiedXpath) {
22+
return qualifiedNodeName;
23+
}
24+
25+
public String nodeLabel(String qualifiedNodeName, String qualifiedParentNodeName) throws Exception {
26+
return qualifiedNodeName;
27+
}
28+
29+
public String codelistValueDesc(String codelist, String value) throws Exception {
30+
return "";
31+
}
32+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (C) 2001-2017 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.kernel.security.keycloak;
25+
26+
public final class KeycloakXslUtil {
27+
28+
public static String getRealm() {
29+
return "keycloak-realm";
30+
}
31+
32+
public static String getAuthServerBaseUrl() {
33+
return "keycloak_auth_server_base_url";
34+
}
35+
36+
public static String getClientId() {
37+
return "keycloak_clientid";
38+
}
39+
40+
public static String getInitOnLoad() {
41+
return "keycloak_init_on_load";
42+
}
43+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* Copyright (C) 2001-2024 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+
package org.fao.geonet.schema;
24+
25+
import org.fao.geonet.utils.PrefixUrlRewrite;
26+
import org.fao.geonet.utils.ResolverWrapper;
27+
import org.fao.geonet.utils.TransformerFactoryFactory;
28+
import org.fao.geonet.utils.Xml;
29+
import org.fao.geonet.utils.nio.NioPathAwareCatalogResolver;
30+
import org.jdom.Document;
31+
import org.jdom.Element;
32+
import org.jdom.output.Format;
33+
import org.jdom.output.XMLOutputter;
34+
import org.junit.AfterClass;
35+
import org.junit.BeforeClass;
36+
import org.junit.Test;
37+
38+
import java.lang.reflect.Field;
39+
import java.net.URISyntaxException;
40+
import java.nio.file.Path;
41+
import java.util.Map;
42+
43+
import static org.fao.geonet.schema.TestSupport.getResource;
44+
import static org.fao.geonet.schema.TestSupport.getResourceInsideSchema;
45+
46+
public class FullViewTest {
47+
48+
private static final boolean GENERATE_EXPECTED_FILE = false;
49+
50+
private static Field resolverMapField;
51+
52+
@BeforeClass
53+
public static void initSaxon() {
54+
TransformerFactoryFactory.init("net.sf.saxon.TransformerFactoryImpl");
55+
}
56+
57+
@BeforeClass
58+
public static void initOasis() throws NoSuchFieldException, IllegalAccessException, URISyntaxException {
59+
resolverMapField = ResolverWrapper.class.getDeclaredField("resolverMap");
60+
resolverMapField.setAccessible(true);
61+
((Map<?, ?>) resolverMapField.get(null)).clear();
62+
63+
String catFiles = getResource("gn-site/WEB-INF/oasis-catalog.xml") + ";" + addRequiredSchemasAndDisableConflictingOne();
64+
System.setProperty("jeeves.xml.catalog.files", catFiles);
65+
ResolverWrapper.createResolverForSchema("DEFAULT", null);
66+
ResolverWrapper.getInstance().setBlankXSLFile(getResource("config/blank.xsl").toAbsolutePath().toString());
67+
NioPathAwareCatalogResolver.addRewriteDirective(
68+
new PrefixUrlRewrite("sharedFormatterDir/",
69+
getResource("gn-site/WEB-INF/data/data/formatter").toAbsolutePath() + "/"));
70+
}
71+
72+
@AfterClass
73+
public static void clearOasis() throws IllegalAccessException {
74+
((Map<?,?>) resolverMapField.get(null)).clear();
75+
}
76+
77+
78+
@Test
79+
public void fullView() throws Exception {
80+
Path xslFile = getResourceInsideSchema("formatter/xsl-view/view.xsl");
81+
Path xmlFile = getResource("UpperRhineCastles-ISO19115-3-full-view-form.xml");
82+
Element source = Xml.loadFile(xmlFile);
83+
84+
Element transformed = Xml.transform(source, xslFile, Map.of("view", "advanced", "approved", "true", "root", "div"));
85+
86+
87+
XMLOutputter xmlOutputter = new XMLOutputter(Format.getPrettyFormat().setLineSeparator("\n"));
88+
String actual = xmlOutputter.outputString(new Document(transformed));
89+
TestSupport.assertGeneratedDataByteMatchExpected("UpperRhineCastles-ISO19115-3-full-view.html", actual, GENERATE_EXPECTED_FILE);
90+
}
91+
92+
private static Path addRequiredSchemasAndDisableConflictingOne() throws URISyntaxException {
93+
return getResource("config/schemaplugin-uri-catalog.xml");
94+
}
95+
}

schemas/iso19115-3.2018/src/test/java/org/fao/geonet/util/XslUtil.java

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
*/
2323
package org.fao.geonet.util;
2424

25+
import org.apache.commons.text.StringEscapeUtils;
26+
import org.owasp.esapi.reference.DefaultEncoder;
27+
28+
import java.util.List;
29+
2530
public class XslUtil {
2631
public static String twoCharLangCode(String iso3code) {
2732
return iso3code.substring(0, 2);
@@ -55,4 +60,83 @@ public static String twoCharLangCode(String iso3code, String defaultValue) {
5560
return defaultValue;
5661
}
5762
}
63+
64+
public static String escapeForJson(String value) {
65+
return StringEscapeUtils.escapeJson(value);
66+
}
67+
68+
public static String getIsoLanguageLabel(String code, String language) {
69+
return "dutch";
70+
}
71+
72+
public static String getIndexField(Object appName, Object uuid, Object field, Object lang) {
73+
return "";
74+
}
75+
76+
public static String getDefaultUrl(String uuid, String language) {
77+
return "www.geonet.org";
78+
}
79+
80+
public static String getSiteUrl() {
81+
return "";
82+
}
83+
84+
public static String getCodelistTranslation(Object codelist, Object value, Object langCode) {
85+
return String.format("%s--%s--%s", codelist, value, langCode);
86+
}
87+
88+
89+
public static List<String> getKeywordHierarchy(String keyword, String thesaurusId, String langCode) {
90+
return List.of();
91+
}
92+
93+
public static String getBuildNumber() {
94+
return "buildNumber-666";
95+
}
96+
97+
98+
public static String encodeForJavaScript(String str) {
99+
return DefaultEncoder.getInstance().encodeForJavaScript(str);
100+
}
101+
102+
public static boolean isDisableLoginForm() {
103+
return false;
104+
}
105+
106+
public static boolean isShowLoginAsLink() {
107+
return false;
108+
}
109+
110+
public static boolean isUserProfileUpdateEnabled() {
111+
return true;
112+
}
113+
114+
public static boolean isUserGroupUpdateEnabled() {
115+
return true;
116+
}
117+
118+
public static String getUiConfigurationJsonProperty(String key, String path) {
119+
return key + "-" + path;
120+
}
121+
122+
public static String getWebAnalyticsService() {
123+
return "";
124+
}
125+
126+
public static String getWebAnalyticsJavascriptCode() {
127+
return "";
128+
}
129+
130+
public static String getUiConfiguration(String key) {
131+
return "{}";
132+
}
133+
134+
public static String getSecurityProvider() {
135+
return "";
136+
}
137+
138+
public static boolean isAuthenticated() {
139+
return false;
140+
}
141+
58142
}

0 commit comments

Comments
 (0)