Skip to content

Commit

Permalink
Revert "MET-5473: Upgrade to jdk 21 builder (#639)"
Browse files Browse the repository at this point in the history
This reverts commit 0f9e8b4.
  • Loading branch information
stzanakis committed Nov 24, 2023
1 parent 0f9e8b4 commit 274b408
Show file tree
Hide file tree
Showing 17 changed files with 139 additions and 123 deletions.
4 changes: 2 additions & 2 deletions metis-authentication/metis-authentication-rest-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock-standalone</artifactId>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import eu.europeana.metis.exception.GenericMetisException;
import eu.europeana.metis.exception.StructuredExceptionWrapper;
import jakarta.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.TransactionException;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.http.HttpStatus;
Expand Down
6 changes: 0 additions & 6 deletions metis-common/metis-common-mongo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<version>${version.embedded.mongo}</version>
</dependency>
<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.process</artifactId>
<version>4.10.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,85 +1,75 @@
package eu.europeana.metis.mongo.embedded;

import de.flapdoodle.embed.mongo.commands.ImmutableMongodArguments;
import de.flapdoodle.embed.mongo.commands.MongodArguments;
import de.flapdoodle.embed.mongo.Command;
import de.flapdoodle.embed.mongo.MongodExecutable;
import de.flapdoodle.embed.mongo.MongodStarter;
import de.flapdoodle.embed.mongo.config.Defaults;
import de.flapdoodle.embed.mongo.config.MongodConfig;
import de.flapdoodle.embed.mongo.config.Net;
import de.flapdoodle.embed.mongo.distribution.Version;
import de.flapdoodle.embed.mongo.transitions.ImmutableMongod;
import de.flapdoodle.embed.mongo.transitions.Mongod;
import de.flapdoodle.embed.mongo.transitions.RunningMongodProcess;
import de.flapdoodle.embed.process.io.ImmutableProcessOutput;
import de.flapdoodle.embed.process.io.ProcessOutput;
import de.flapdoodle.embed.process.io.Processors;
import de.flapdoodle.embed.process.io.Slf4jLevel;
import de.flapdoodle.reverse.TransitionWalker;
import de.flapdoodle.reverse.transitions.Start;
import de.flapdoodle.embed.process.config.RuntimeConfig;
import de.flapdoodle.embed.process.config.io.ProcessOutput;
import de.flapdoodle.embed.process.runtime.Network;
import eu.europeana.metis.network.NetworkUtil;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
* Starts an in memory Mongo database. This class is to be used for unit testing on localhost.
*/
public class EmbeddedLocalhostMongo {

private static final Logger LOGGER = LoggerFactory.getLogger(EmbeddedLocalhostMongo.class);

private static final String DEFAULT_MONGO_HOST = "127.0.0.1";
private static final ImmutableProcessOutput processOutput = ProcessOutput.builder()
.commands(Processors.logTo(LOGGER, Slf4jLevel.DEBUG))
.output(Processors.logTo(LOGGER, Slf4jLevel.INFO))
.error(Processors.logTo(LOGGER, Slf4jLevel.ERROR))
.build();

private static final ImmutableMongodArguments mongodArguments = MongodArguments.defaults()
.withSyncDelay(0)
.withStorageEngine("ephemeralForTest")
.withUseNoJournal(true);
private static final Logger LOGGER = LoggerFactory.getLogger(EmbeddedLocalhostMongo.class);

private TransitionWalker.ReachedState<RunningMongodProcess> runningMongodProcessReachedState;
private int mongoPort;
private static final String DEFAULT_MONGO_HOST = "127.0.0.1";
private MongodExecutable mongodExecutable;
private int mongoPort;

/**
* Constructor for default object for localhost mongo
*/
public EmbeddedLocalhostMongo() {
//Nothing to do
}
/**
* Constructor for default object for localhost mongo
*/
public EmbeddedLocalhostMongo() {
//Nothing to do
}

/**
* Starts a local host mongo.
*/
public void start() {
if (runningMongodProcessReachedState == null) {
try {
mongoPort = new NetworkUtil().getAvailableLocalPort();
ImmutableMongod mongod = Mongod.instance()
.withNet(Start.to(Net.class).initializedWith(Net.builder().bindIp(DEFAULT_MONGO_HOST).port(mongoPort).isIpv6(true).build()))
.withProcessOutput(Start.to(ProcessOutput.class).initializedWith(processOutput))
.withMongodArguments(Start.to(MongodArguments.class).initializedWith(mongodArguments));
/**
* Starts a local host mongo.
*/
public void start() {
if (mongodExecutable == null) {
try {
mongoPort = new NetworkUtil().getAvailableLocalPort();
RuntimeConfig runtimeConfig = Defaults.runtimeConfigFor(Command.MongoD, LOGGER)
.processOutput(ProcessOutput.getDefaultInstanceSilent())
.build();

runningMongodProcessReachedState = mongod.start(Version.Main.V4_4);
MongodConfig mongodConfig = MongodConfig.builder()
.version(Version.V4_0_12)
.net(new Net(DEFAULT_MONGO_HOST, mongoPort, Network.localhostIsIPv6()))
.build();

} catch (IOException e) {
LOGGER.error("Exception when starting embedded mongo", e);
}
}
MongodStarter runtime = MongodStarter.getInstance(runtimeConfig);
mongodExecutable = runtime.prepare(mongodConfig);
mongodExecutable.start();
} catch (IOException e) {
LOGGER.error("Exception when starting embedded mongo", e);
}
}
}

public String getMongoHost() {
return DEFAULT_MONGO_HOST;
}
public String getMongoHost() {
return DEFAULT_MONGO_HOST;
}

public int getMongoPort() {
return mongoPort;
}
public int getMongoPort() {
return mongoPort;
}

/**
* Stop a previously started local host mongo.
*/
public void stop() {
runningMongodProcessReachedState.close();
}
/**
* Stop a previously started local host mongo.
*/
public void stop() {
mongodExecutable.stop();
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package eu.europeana.metis.utils;

import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.PosixFilePermission;
import java.util.EnumSet;
import java.util.LinkedHashSet;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.apache.commons.io.FileUtils;
import org.junit.jupiter.api.Test;

class TempFileUtilsTest {

Expand All @@ -27,9 +27,22 @@ void createSecureTempFile() throws IOException {
}

@Test
void createSecureTempFileDeleteOnExit() throws IOException {
void createSecureTempFileDeleteOnExit()
throws ClassNotFoundException, IOException, NoSuchFieldException, IllegalAccessException {
final Path secureTempFile = TempFileUtils.createSecureTempFileDeleteOnExit("prefix", "suffix");
assertFilePermissions(secureTempFile);

final LinkedHashSet<String> filesForDeletion = getFileListMarkedForDeletion();
assertTrue(filesForDeletion.contains(secureTempFile.toString()));
}

private LinkedHashSet<String> getFileListMarkedForDeletion()
throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
//Check that deletion on exit is in place
final Class<?> deleteOnExitHook = Class.forName("java.io.DeleteOnExitHook");
final Field filesField = deleteOnExitHook.getDeclaredField("files");
filesField.setAccessible(true);
return castList(filesField.get(null));
}

private LinkedHashSet<String> castList(Object objectList) {
Expand Down
7 changes: 0 additions & 7 deletions metis-core/metis-core-rest/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,6 @@
</exclusion>
</exclusions>
</dependency>
<!-- Overwrite Lombok coming from ecloud dependencies so that jdk 21 will compile-->
<!-- Remove it once the transitive dependency of lombok is updated or removed.-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.30</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package eu.europeana.metis.core.rest.exception;

import eu.europeana.metis.exception.GenericMetisException;
import eu.europeana.metis.core.exceptions.NoDatasetFoundException;
import eu.europeana.metis.core.exceptions.NoWorkflowFoundException;
import eu.europeana.metis.exception.GenericMetisException;
import eu.europeana.metis.exception.StructuredExceptionWrapper;
import jakarta.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponse;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageNotReadableException;
Expand Down
6 changes: 3 additions & 3 deletions metis-core/metis-core-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>eu.europeana.metis</groupId>
<artifactId>metis-transformation-service</artifactId>
<groupId>eu.europeana.metis</groupId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down Expand Up @@ -83,8 +83,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock-standalone</artifactId>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down
1 change: 1 addition & 0 deletions metis-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.spring.boot>2.7.5</version.spring.boot>
</properties>

<modules>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package eu.europeana.metis.dereference.rest.exceptions;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.net.URISyntaxException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.net.URISyntaxException;

/**
* Generic Exception Handler Created by ymamakis on 2/25/16.
**/
Expand All @@ -22,7 +21,8 @@ public class RestResponseExceptionHandler{

@ResponseBody
@ExceptionHandler({Exception.class})
public ServerError handleResponse(HttpServletResponse response, HttpServletRequest req, Exception exception) {
public ServerError handleResponse(HttpServletResponse response, HttpServletRequest req,
Exception exception) {
final ResponseStatus annotationResponseStatus = AnnotationUtils
.findAnnotation(exception.getClass(), ResponseStatus.class);
HttpStatus status = annotationResponseStatus == null ? HttpStatus.INTERNAL_SERVER_ERROR
Expand Down
11 changes: 9 additions & 2 deletions metis-enrichment/metis-enrichment-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock-standalone</artifactId>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock-jre8</artifactId>
<version>${version.wiremock-jre}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>eu.europeana.metis</groupId>
Expand All @@ -56,6 +58,11 @@
<artifactId>jackson-databind</artifactId>
<version>${version.jackson}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${version.spring}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,21 @@
import java.util.TreeSet;
import java.util.stream.Stream;

import static com.github.tomakehurst.wiremock.client.WireMock.*;
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.*;

class EnrichmentWorkerImplTest {

Expand All @@ -66,10 +73,10 @@ private static Stream<Arguments> providedInputRecords() {
return Stream.of(
Arguments.of(getResourceFileContent("enrichment/sample_enrichment_exception.rdf"), RecordStatus.STOP),
Arguments.of(getResourceFileContent("enrichment/sample_dereference_not_found.rdf"), RecordStatus.STOP),
// Arguments.of(getResourceFileContent("enrichment/sample_dereference_redirect.rdf"), RecordStatus.CONTINUE),
// Arguments.of(getResourceFileContent("enrichment/sample_enrichment_noentity.rdf"), RecordStatus.CONTINUE),
Arguments.of(getResourceFileContent("enrichment/sample_enrichment_failure.rdf"), RecordStatus.STOP)
// Arguments.of(getResourceFileContent("enrichment/sample_enrichment_success.rdf"), RecordStatus.CONTINUE)
Arguments.of(getResourceFileContent("enrichment/sample_dereference_redirect.rdf"), RecordStatus.CONTINUE),
Arguments.of(getResourceFileContent("enrichment/sample_enrichment_noentity.rdf"), RecordStatus.CONTINUE),
Arguments.of(getResourceFileContent("enrichment/sample_enrichment_failure.rdf"), RecordStatus.STOP),
Arguments.of(getResourceFileContent("enrichment/sample_enrichment_success.rdf"), RecordStatus.CONTINUE)
);
}

Expand Down
6 changes: 3 additions & 3 deletions metis-harvesting/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
<version>${version.saxon.he}</version>
</dependency>
<dependency>
<groupId>org.wiremock</groupId>
<artifactId>wiremock-standalone</artifactId>
<version>${version.org.wiremock}</version>
<groupId>com.github.tomakehurst</groupId>
<artifactId>wiremock</artifactId>
<version>${version.com.github.tomakehurst.wiremock}</version>
<scope>test</scope>
<exclusions>
<exclusion>
Expand Down
2 changes: 2 additions & 0 deletions metis-indexing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${version.spring.test}</version>
<scope>test</scope>
</dependency>
<!-- testcontainers -->
<dependency>
Expand Down
Loading

0 comments on commit 274b408

Please sign in to comment.