Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes for integration tests #8625

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,12 @@
<transportPort>9300</transportPort>
<httpPort>9200</httpPort>
<environmentVariables><ES_JAVA_OPTS>-Xmx2g</ES_JAVA_OPTS></environmentVariables>
<instanceSettings>
<properties>
<!-- Problem with elastic - if you don't have enough disk space (90+% full), it will NOT start. -->
<cluster.routing.allocation.disk.threshold_enabled>false</cluster.routing.allocation.disk.threshold_enabled>
</properties>
</instanceSettings>
</configuration>
<executions>
<execution>
Expand Down
8 changes: 7 additions & 1 deletion services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@
<include>**/*.java</include>
</includes>
<runOrder>alphabetical</runOrder>
<forkCount>${system.numCores}</forkCount>
<forkCount>1</forkCount>
</configuration>
<executions>
<execution>
Expand Down Expand Up @@ -392,6 +392,12 @@
<transportPort>9300</transportPort>
<httpPort>9200</httpPort>
<environmentVariables><ES_JAVA_OPTS>-Xmx2g</ES_JAVA_OPTS></environmentVariables>
<instanceSettings>
<properties>
<!-- Problem with elastic - if you don't have enough disk space (90+% full), it will NOT start. -->
<cluster.routing.allocation.disk.threshold_enabled>false</cluster.routing.allocation.disk.threshold_enabled>
</properties>
</instanceSettings>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@

package org.fao.geonet.api.registries.vocabularies;

import java.nio.file.Files;
import org.fao.geonet.constants.Geonet;
import org.fao.geonet.domain.User;
import org.fao.geonet.kernel.GeonetworkDataDirectory;
import org.fao.geonet.kernel.SpringLocalServiceInvoker;
import org.fao.geonet.services.AbstractServiceIntegrationTest;
import org.fao.geonet.utils.Xml;
Expand Down Expand Up @@ -210,45 +212,63 @@ public void testConvertCsvToSkosDefaultTitleAndNamespace() throws Exception {
"taxref.csv", scheme.getChildText("title", NAMESPACE_DC));
}

// see finally block in #testImportOntologyToSkos
// this is required to locate the file to be deleted.
@Autowired
GeonetworkDataDirectory geonetworkDataDirectory;


@Test
public void testImportOntologyToSkos() throws Exception {
createServiceContext();
User user = new User().setId(USER_ID);
HttpSession session = loginAs(user);
MockHttpSession mockHttpSession = loginAsAdmin();

MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(session.getServletContext());
request.setRequestURI("/srv/api/registries/vocabularies");
MockMultipartFile file = new MockMultipartFile(
"file",
"mobility-theme.owl",
null,
getClass().getClassLoader().getResourceAsStream("mobility-theme.owl"));
request.addFile(file);
request.setSession(session);
request.setParameter("type", "external");
request.setParameter("dir", "theme");
MockHttpServletResponse response = new MockHttpServletResponse();
invoker.invoke(request, response);
assertEquals(200, response.getStatus());


MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
MvcResult result = mockMvc.perform(get("/srv/api/registries/vocabularies/external.theme.mobility-theme")
.accept("application/xml")
.session(mockHttpSession))
.andExpect(status().isOk())
.andReturn();

Element thesaurus = Xml.loadString(result.getResponse().getContentAsString(), false);
Element scheme = (Element) thesaurus.getChildren("ConceptScheme", SKOS_NAMESPACE).get(0);
assertEquals(
"https://w3id.org/mobilitydcat-ap/mobility-theme", scheme.getAttributeValue("about", RDF_NAMESPACE));
assertEquals(
"Mobility Theme", scheme.getChildText("title", NAMESPACE_DCT));

List concepts = thesaurus.getChildren("Concept", SKOS_NAMESPACE);
assertEquals(121, concepts.size());
try {
createServiceContext();
User user = new User().setId(USER_ID);
HttpSession session = loginAs(user);
MockHttpSession mockHttpSession = loginAsAdmin();

MockMultipartHttpServletRequest request = new MockMultipartHttpServletRequest(session.getServletContext());
request.setRequestURI("/srv/api/registries/vocabularies");
MockMultipartFile file = new MockMultipartFile(
"file",
"mobility-theme.owl",
null,
getClass().getClassLoader().getResourceAsStream("mobility-theme.owl"));
request.addFile(file);
request.setSession(session);
request.setParameter("type", "external");
request.setParameter("dir", "theme");
MockHttpServletResponse response = new MockHttpServletResponse();
invoker.invoke(request, response);
assertEquals(200, response.getStatus());


MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
MvcResult result = mockMvc.perform(get("/srv/api/registries/vocabularies/external.theme.mobility-theme")
.accept("application/xml")
.session(mockHttpSession))
.andExpect(status().isOk())
.andReturn();

Element thesaurus = Xml.loadString(result.getResponse().getContentAsString(), false);
Element scheme = (Element) thesaurus.getChildren("ConceptScheme", SKOS_NAMESPACE).get(0);
assertEquals(
"https://w3id.org/mobilitydcat-ap/mobility-theme", scheme.getAttributeValue("about", RDF_NAMESPACE));
assertEquals(
"Mobility Theme", scheme.getChildText("title", NAMESPACE_DCT));

List concepts = thesaurus.getChildren("Concept", SKOS_NAMESPACE);
assertEquals(121, concepts.size());
}
finally {
//clean up
// this test case uploads a thesaurus.
// if you don't delete it, then, on the next run, it will be picked up and you'll get an error because
// the thesaurus already exists. This will clean up and there will not be a problem on the next run.
// This is typically only an issue if you are running the test locally - on the build server it gets a
// new, clean, filesystem so there isn't a problem.
var uploadedThesauras = geonetworkDataDirectory.resolveWebResource(
Copy link
Member

@josegar74 josegar74 Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not use var as probably we have to backport this to 4.2.x, please change to use Path and add the import.

"WEB-INF/data/config/codelist/external/thesauri/theme/mobility-theme.rdf");
Files.deleteIfExists(uploadedThesauras);
}
}
}
Loading