Skip to content

Commit

Permalink
Update test dependencies to be able to execute with Java 17
Browse files Browse the repository at this point in the history
- Retrieve newer test dependencies from 2022-12 orbit and consume missing via org.eclipse.emfcloud.modelserver.tests bundle
  - Add hamcrest dependency libs to tests bundle, as there is otherwise a plugin clash as junit consumes the former 1.3 version
- Introduce MockitoUtil that replaces Mockito's internal 'FieldSetter' class (which was removed with the newer version)
  • Loading branch information
ndoschek committed Jan 12, 2023
1 parent 1afcbb6 commit fbd5edb
Show file tree
Hide file tree
Showing 20 changed files with 132 additions and 46 deletions.
17 changes: 12 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@
<emfjson.jackson.version>2.0.0</emfjson.jackson.version>
<commons.io.version>2.8.0</commons.io.version>
<junit.version>4.13.2</junit.version>
<mockito.core.version>2.23.0</mockito.core.version>
<hamcrest.core.version>1.3</hamcrest.core.version>
<mockito.version>4.8.1</mockito.version>
<hamcrest.version>2.2</hamcrest.version>
<net.bytebuddy.version>1.12.16</net.bytebuddy.version>
<org.objenesis.version>3.3</org.objenesis.version>
<json-patch.version>1.13</json-patch.version>

<!-- External Dependency Versions: Versions of dependencies that are not
Expand All @@ -118,7 +120,7 @@
<jetty.version>9.4.44.v20210927</jetty.version>
<jetty.websocket.version>9.4.44.v20210927</jetty.websocket.version>
<javalin.version>4.3.0</javalin.version>
<mockito.inline.version>3.2.4</mockito.inline.version>
<mockito.inline.version>4.8.1</mockito.inline.version>
<gmazzo.okhttp.mock.version>1.5.0</gmazzo.okhttp.mock.version>

<!-- Release Dependencies for M2 -->
Expand Down Expand Up @@ -482,12 +484,17 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>${mockito.core.version}</version>
<version>${mockito.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<version>${mockito.version}</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>${hamcrest.core.version}</version>
<version>${hamcrest.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde?>
<!-- generated with https://github.com/eclipse-cbi/targetplatform-dsl -->
<target name="EMF.cloud Model Server Targetplatform" sequenceNumber="1651661937">
<target name="EMF.cloud Model Server Targetplatform" sequenceNumber="1673534083">
<locations>
<location includeMode="planner" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="false" type="InstallableUnit">
<unit id="org.eclipse.platform.feature.group" version="4.23.0.v20220308-0722"/>
<unit id="org.eclipse.emf.transaction.feature.group" version="1.12.0.201805140824"/>
<unit id="org.eclipse.emf.sdk.feature.group" version="2.29.0.v20220226-1304"/>
<repository location="http://download.eclipse.org/releases/2022-03"/>
</location>
<location includeMode="planner" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="false" type="InstallableUnit">
<unit id="javax.servlet" version="3.1.0.v201410161800"/>
<repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20220302172233/repository"/>
</location>
<location includeMode="planner" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="false" type="InstallableUnit">
<unit id="org.apache.logging.log4j" version="2.17.1.v20220106-2156"/>
<unit id="com.google.gson" version="2.8.9.v20220111-1409"/>
<unit id="com.google.inject" version="5.0.1.v20210324-2015"/>
<unit id="com.google.guava" version="30.1.0.v20210127-2300"/>
<unit id="com.google.gson" version="2.9.1.v20220915-1632"/>
<unit id="com.google.inject" version="5.0.1.v20221112-0806"/>
<unit id="com.google.guava" version="30.1.0.v20221112-0806"/>
<unit id="org.apache.commons.io" version="2.8.0.v20210415-0900"/>
<unit id="org.mockito" version="2.23.0.v20200310-1642"/>
<unit id="net.bytebuddy.byte-buddy" version="1.9.0.v20181107-1410"/>
<unit id="net.bytebuddy.byte-buddy-agent" version="1.9.0.v20181106-1534"/>
<unit id="org.objenesis" version="2.6.0.v20180420-1519"/>
<unit id="org.hamcrest" version="1.1.0.v20090501071000"/>
<unit id="com.fasterxml.jackson.core.jackson-annotations" version="2.12.1.v20210128-1726"/>
<unit id="com.fasterxml.jackson.core.jackson-core" version="2.12.1.v20210128-1726"/>
<unit id="com.fasterxml.jackson.core.jackson-databind" version="2.12.1.v20210128-1726"/>
<unit id="org.mockito.mockito-core" version="4.8.1.v20221103-2317"/>
<unit id="net.bytebuddy.byte-buddy" version="1.12.18.v20221114-2102"/>
<unit id="net.bytebuddy.byte-buddy-agent" version="1.12.18.v20221114-2102"/>
<unit id="org.objenesis" version="3.3.0.v20221103-2317"/>
<unit id="com.fasterxml.jackson.core.jackson-annotations" version="2.13.2.v20220426-1653"/>
<unit id="com.fasterxml.jackson.core.jackson-core" version="2.13.2.v20220426-1653"/>
<unit id="com.fasterxml.jackson.core.jackson-databind" version="2.13.2.v20220426-1653"/>
<unit id="org.junit" version="4.13.2.v20211018-1956"/>
<unit id="javax.servlet" version="3.1.0.v201410161800"/>
<unit id="org.aopalliance" version="1.0.0.v201105210816"/>
<repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20220302172233/repository"/>
<unit id="org.aopalliance" version="1.0.0.v20220404-1927"/>
<repository location="https://download.eclipse.org/tools/orbit/downloads/drops/R20221123021534/repository"/>
</location>
<location includeMode="planner" includeAllPlatforms="false" includeSource="true" includeConfigurePhase="false" type="InstallableUnit">
<unit id="org.eclipse.emfcloud.emfjson-jackson" version="2.0.0"/>
Expand All @@ -39,4 +41,4 @@
<repository location="https://download.eclipse.org/jetty/updates/jetty-bundles-9.x/9.4.44.v20210927/"/>
</location>
</locations>
</target>
</target>
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@ location "http://download.eclipse.org/releases/2022-03" {
}

location "https://download.eclipse.org/tools/orbit/downloads/drops/R20220302172233/repository" {
javax.servlet [3.1.0,4.0.0)
}

location "https://download.eclipse.org/tools/orbit/downloads/drops/R20221123021534/repository" {
org.apache.logging.log4j [2.17.1,3.0.0)
com.google.gson [2.8.9,3.0.0)
com.google.inject [5.0.1,6.0.0)
com.google.guava [30.1.0,31.0.0)
org.apache.commons.io [2.8.0,3.0.0)
org.mockito [2.23.0,3.0.0)
net.bytebuddy.byte-buddy [1.9.0,2.0.0)
net.bytebuddy.byte-buddy-agent [1.9.0,2.0.0)
org.objenesis [2.6.0,3.0.0)
org.hamcrest [1.1.0,2.0.0)
org.mockito.mockito-core [4.8.1,5.0.0)
net.bytebuddy.byte-buddy [1.12.18,2.0.0)
net.bytebuddy.byte-buddy-agent [1.12.18,2.0.0)
org.objenesis [3.3.0,4.0.0)
com.fasterxml.jackson.core.jackson-annotations [2.12.1,3.0.0)
com.fasterxml.jackson.core.jackson-core [2.12.1,3.0.0)
com.fasterxml.jackson.core.jackson-databind [2.12.1,3.0.0)
org.junit [4.13.2,5.0.0)
javax.servlet [3.1.0,4.0.0)
org.aopalliance [1.0.0,2.0.0)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ Require-Bundle: com.fasterxml.jackson.core.jackson-annotations;bundle-version="[
org.eclipse.emfcloud.modelserver.tests;bundle-version="[0.7.0,1.0.0)",
org.eclipse.emfcloud.emfjson-jackson;bundle-version="[2.0.0,3.0.0)",
org.junit;bundle-version="[4.12.0,5.0.0)",
org.mockito;bundle-version="[2.23.0,3.0.0)",
org.mockito.mockito-core;bundle-version="[4.8.1,5.0.0)",
net.bytebuddy.byte-buddy;bundle-version="[1.9.0,2.0.0)",
net.bytebuddy.byte-buddy-agent;bundle-version="[1.9.0,2.0.0)",
org.objenesis;bundle-version="[2.6.0,3.0.0)",
org.hamcrest;bundle-version="[1.1.0,2.0.0)"
org.objenesis;bundle-version="[3.3.0,4.0.0)"
Bundle-ClassPath: .
Bundle-Vendor: EclipseSource
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,4 @@ Require-Bundle: com.fasterxml.jackson.core.jackson-annotations;bundle-version="[
org.eclipse.emfcloud.emfjson-jackson;bundle-version="[2.0.0,3.0.0)",
org.junit;bundle-version="[4.12.0,5.0.0)"
Export-Package: org.eclipse.emfcloud.modelserver.edit
Import-Package: org.eclipse.emfcloud.modelserver.tests.util
Bundle-Vendor: EclipseSource
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ Require-Bundle: com.fasterxml.jackson.core.jackson-annotations;bundle-version="[
org.eclipse.emfcloud.modelserver.tests;bundle-version="[0.7.0,1.0.0)",
org.eclipse.emfcloud.emfjson-jackson;bundle-version="[2.0.0,3.0.0)",
org.junit;bundle-version="[4.12.0,5.0.0)",
org.mockito;bundle-version="[2.23.0,3.0.0)",
org.objenesis;bundle-version="[2.6.0,3.0.0)"
org.mockito.mockito-core;bundle-version="[4.8.1,5.0.0)",
org.objenesis;bundle-version="[3.3.0,4.0.0)"
Import-Package: javax.inject;version="1.0.0",
org.apache.logging.log4j;version="[2.17.1,3.0.0)",
org.apache.logging.log4j.core;version="[2.17.1,3.0.0)",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/********************************************************************************
* Copyright (c) 2019-2022 EclipseSource and others.
* Copyright (c) 2019-2023 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -39,6 +39,7 @@
import org.eclipse.emfcloud.modelserver.emf.configuration.ServerConfiguration;
import org.eclipse.emfcloud.modelserver.emf.util.JsonPatchHelper;
import org.eclipse.emfcloud.modelserver.jsonschema.Json;
import org.eclipse.emfcloud.modelserver.tests.util.MockitoUtil;
import org.eclipse.jetty.websocket.api.Session;
import org.hamcrest.CustomTypeSafeMatcher;
import org.hamcrest.Description;
Expand All @@ -48,7 +49,6 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.internal.util.reflection.FieldSetter;
import org.mockito.junit.MockitoJUnitRunner;

import com.fasterxml.jackson.databind.JsonNode;
Expand Down Expand Up @@ -235,7 +235,7 @@ private void initializeValidClientContext(final String sessionId) throws NoSuchF
when(validClientCtx.getSessionId()).thenReturn(sessionId);
when(validClientCtx.pathParam(ModelServerPathParametersV1.MODEL_URI)).thenReturn(modelUri);
Field sessionField = WsContext.class.getDeclaredField("session");
FieldSetter.setField(validClientCtx, sessionField, session);
MockitoUtil.setField(validClientCtx, sessionField, session);

when(codecs.findFormat(validClientCtx)).thenReturn(ModelServerPathParametersV1.FORMAT_JSON);

Expand All @@ -251,15 +251,15 @@ private void initializeWsMessageContext(final String sessionId) throws NoSuchFie
when(repository.hasModel(modelUri)).thenReturn(true);

Field sessionField = WsContext.class.getDeclaredField("session");
FieldSetter.setField(messageClientCtx, sessionField, session);
MockitoUtil.setField(messageClientCtx, sessionField, session);
}

@SuppressWarnings({ "checkstyle:ThrowsCount" })
private void initializeInvalidClientContext() throws NoSuchFieldException, SecurityException {
String modelUri = "tedioustesturi";

when(invalidClientCtx.pathParam(ModelServerPathParametersV1.MODEL_URI)).thenReturn(modelUri);
FieldSetter.setField(invalidClientCtx, WsContext.class.getDeclaredField("session"), session);
MockitoUtil.setField(invalidClientCtx, WsContext.class.getDeclaredField("session"), session);
}

@Before
Expand Down
6 changes: 4 additions & 2 deletions tests/org.eclipse.emfcloud.modelserver.tests/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry exported="true" kind="lib" path="lib/mockito-inline-3.2.4.jar" sourcepath="lib/mockito-inline-3.2.4-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/okhttp-mock-1.5.0.jar" sourcepath="lib/okhttp-mock-1.5.0-sources.jar"/>
<classpathentry kind="src" path="src/">
<attributes>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="lib/hamcrest-2.2.jar" sourcepath="lib/hamcrest-2.2-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/hamcrest-core-2.2.jar" sourcepath="lib/hamcrest-core-2.2-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/mockito-inline-4.8.1.jar" sourcepath="lib/mockito-inline-4.8.1-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/okhttp-mock-1.5.0.jar" sourcepath="lib/okhttp-mock-1.5.0-sources.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: org.eclipse.emf.common;bundle-version="[2.17.0,3.0.0)",
org.eclipse.emf.ecore;bundle-version="[2.20.0,3.0.0)",
org.eclipse.emf.edit;bundle-version="[2.16.0,3.0.0)",
org.eclipse.emfcloud.modelserver.lib;bundle-version="[0.7.0,1.0.0)",
org.hamcrest.library;bundle-version="[1.3.0,2.0.0)",
org.hamcrest.core;bundle-version="[1.3.0,2.0.0)"
org.eclipse.emfcloud.modelserver.lib;bundle-version="[0.7.0,1.0.0)"
Export-Package: okhttp3.mock,
okhttp3.mock.matchers,
org.eclipse.emfcloud.modelserver.tests.util
org.eclipse.emfcloud.modelserver.tests.util,
org.hamcrest
Bundle-ClassPath: .,
lib/mockito-inline-3.2.4.jar,
lib/hamcrest-2.2.jar,
lib/hamcrest-core-2.2.jar,
lib/mockito-inline-4.8.1.jar,
lib/okhttp-mock-1.5.0.jar
Bundle-Vendor: EclipseSource
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ source.. = src/
output.. = target/classes/
bin.includes = META-INF/,\
.,\
lib/hamcrest-2.2.jar,\
lib/hamcrest-core-2.2.jar,\
lib/okhttp-mock-1.5.0.jar,\
lib/mockito-inline-3.2.4.jar
lib/mockito-inline-4.8.1.jar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
32 changes: 32 additions & 0 deletions tests/org.eclipse.emfcloud.modelserver.tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@
<artifactId>okhttp-mock</artifactId>
<version>${gmazzo.okhttp.mock.version}</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>${hamcrest.version}</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>${hamcrest.version}</version>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -61,6 +71,28 @@
<version>${gmazzo.okhttp.mock.version}</version>
<classifier>sources</classifier>
</artifactItem>
<artifactItem>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>${hamcrest.version}</version>
</artifactItem>
<artifactItem>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>${hamcrest.version}</version>
<classifier>sources</classifier>
</artifactItem>
<artifactItem>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>${hamcrest.version}</version>
</artifactItem>
<artifactItem>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
<version>${hamcrest.version}</version>
<classifier>sources</classifier>
</artifactItem>
</artifactItems>
<overWriteIfNewer>true</overWriteIfNewer>
<outputDirectory>lib</outputDirectory>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/********************************************************************************
* Copyright (c) 2023 EclipseSource and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0, or the MIT License which is
* available at https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: EPL-2.0 OR MIT
********************************************************************************/
package org.eclipse.emfcloud.modelserver.tests.util;

import java.lang.reflect.Field;

/**
* Additional Mockito utils.
*/
public final class MockitoUtil {

/**
* Not instantiable by clients.
*/
private MockitoUtil() {
super();
}

/**
* Replaces Mockito's removed internal 'FieldSetter' class.
* Was formerly imported via 'import org.mockito.internal.util.reflection.FieldSetter;'
*/
public static void setField(final Object object, final Field field, final Object value) {
try {
field.setAccessible(true);
field.set(object, value);
} catch (IllegalAccessException e) {
throw new RuntimeException("Failed to set value for field '" + field.getName() + "' of object", e);
}
}

}

0 comments on commit fbd5edb

Please sign in to comment.