Skip to content

Commit

Permalink
feat(openchallenges): add coverage tools to OC organization service (#…
Browse files Browse the repository at this point in the history
…2344)

* Configure test to use h2 db

* Disable hibernate and elastic in unit test

* Fix unit tests

* Upgrade to Gradle v8.4

* Exclude some files from the test
  • Loading branch information
tschaffter authored Nov 9, 2023
1 parent 7536af1 commit ff5590d
Show file tree
Hide file tree
Showing 9 changed files with 173 additions and 20 deletions.
28 changes: 23 additions & 5 deletions apps/openchallenges/organization-service/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ repositories {
}

dependencies {
implementation "org.hibernate.search:hibernate-search-mapper-orm:${hibernateSearchVersion}"
implementation "org.hibernate.search:hibernate-search-backend-elasticsearch:${hibernateSearchVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
compileOnly "org.projectlombok:lombok:${lombokVersion}"
implementation 'com.google.code.findbugs:jsr305:3.0.2'
Expand All @@ -35,6 +33,8 @@ dependencies {
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${fasterxmlVersion}"
implementation "org.flywaydb:flyway-core:${flywaydbVersion}"
implementation "org.flywaydb:flyway-mysql:${flywaydbVersion}"
implementation "org.hibernate.search:hibernate-search-backend-elasticsearch:${hibernateSearchVersion}"
implementation "org.hibernate.search:hibernate-search-mapper-orm:${hibernateSearchVersion}"
implementation "org.keycloak:keycloak-admin-client:${keycloakVersion}"
implementation "org.keycloak:keycloak-spring-boot-starter:${keycloakVersion}"
implementation "org.sagebionetworks:util:${openchallengesVersion}"
Expand All @@ -45,10 +45,11 @@ dependencies {
implementation "org.springframework.boot:spring-boot-starter-validation:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-web:${springBootVersion}"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:${springCloudVersion}"
implementation "org.springframework.cloud:spring-cloud-starter-openfeign:${springCloudVersion}"
implementation "org.springframework.data:spring-data-commons:${springDataVersion}"
runtimeOnly 'mysql:mysql-connector-java:8.0.30'
testImplementation "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
implementation "org.springframework.cloud:spring-cloud-starter-openfeign:${springCloudVersion}"
testRuntimeOnly 'com.h2database:h2:2.1.214'

// Enable distributed tracing
implementation "org.springframework.cloud:spring-cloud-starter-sleuth:${springCloudVersion}"
Expand Down Expand Up @@ -78,8 +79,7 @@ bootBuildImage {
}

test {
// This instruction makes the test fail
// useJUnitPlatform()
useJUnitPlatform()

testLogging.showStandardStreams = true

Expand All @@ -100,6 +100,24 @@ jacocoTestReport {
reports {
xml.required = true
}

afterEvaluate {
def autoGenerated = [
'**/api/*.*',
'**/configuration/EnumConverterConfiguration*.*',
'**/configuration/Flyway*.*',
'**/configuration/HibernateSearch*.*',
'**/configuration/HomeController*.*',
'**/configuration/Keycloak*.*',
'**/configuration/SpringDocConfiguration*.*',
'**/model/dto/**',
'**/RFC3339DateFormat.*'
]
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: autoGenerated
)
}))
}
}

sonar {
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
35 changes: 22 additions & 13 deletions apps/openchallenges/organization-service/gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,11 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +131,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then
done
fi

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.

set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Expand Down
92 changes: 92 additions & 0 deletions apps/openchallenges/organization-service/gradlew.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
@rem
@rem ##########################################################################

@rem Set local scope for the variables with windows NT shell
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi

@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:findJavaFromJavaHome
set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe

if exist "%JAVA_EXE%" goto execute

echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
echo.
echo Please set the JAVA_HOME variable in your environment to match the
echo location of your Java installation.

goto fail

:execute
@rem Setup the command line

set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar


@rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*

:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal

:omega
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@
import org.hibernate.search.mapper.orm.Search;
import org.hibernate.search.mapper.orm.massindexing.MassIndexer;
import org.hibernate.search.mapper.orm.session.SearchSession;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Configuration
@ConditionalOnProperty(
value = "spring.jpa.properties.hibernate.search.enabled",
havingValue = "true")
public class HibernateSearchIndexBuild implements ApplicationListener<ApplicationReadyEvent> {

private final EntityManager entityManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
class OpenApiGeneratorApplicationTests {
class OrganizationServiceApplicationTests {

@Test
void contextLoads() {}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
openchallenges-organization-service:
welcome-message: 'Welcome to the organization service (test)'

spring:
application:
name: openchallenges-organization-service
profiles:
active: test
cloud:
config:
enabled: false
discovery:
enabled: false
datasource:
url: jdbc:h2:mem:challenge
username: openchallenges
password: changeme
flyway:
enabled: false
jpa:
properties:
hibernate:
search:
enabled: false
autoconfigure:
# Stop hibernate search from sniffing the nodes of a non-existent local elastic search server
exclude: org.springframework.boot.autoconfigure.elasticsearch.ElasticsearchRestClientAutoConfiguration
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mock-maker-inline

0 comments on commit ff5590d

Please sign in to comment.