Skip to content

Commit aee36fc

Browse files
committed
added some tests
modified CI
1 parent d104c26 commit aee36fc

File tree

9 files changed

+125
-16
lines changed

9 files changed

+125
-16
lines changed

.github/workflows/CI.yml

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,37 @@ jobs:
3333
- name: Build with Gradle
3434
run: ./gradlew clean build
3535
test:
36-
runs-on: ubuntu-latest
3736
strategy:
3837
matrix:
39-
jdk: [ 17 ]
38+
os: [ubuntu-latest, windows-latest, macos-latest]
39+
jdk: [17]
40+
python-version: [3.10]
41+
runs-on: ${{ matrix.os }}
4042
steps:
4143
- name: Checkout repo
4244
uses: actions/checkout@v2
4345
- name: Set up OpenJDK
4446
uses: actions/setup-java@v1
4547
with:
4648
java-version: ${{ matrix.jdk }}
47-
- name: Install python
48-
run: sudo apt install -y python3 python3-setuptools python3-pip
49+
- name: Set up Python ${{ matrix.python-version }}
50+
uses: actions/setup-python@v4
51+
with:
52+
python-version: ${{ matrix.python-version }}
53+
- name: Get Python location
54+
run: python -c "import os, sys; print(os.path.dirname(sys.executable))"
4955
- name: Update pip
50-
run: pip3 install --upgrade pip
56+
run: python3 -m pip install --upgrade pip
5157
- name: Grant execute permission for gradlew
5258
run: chmod +x gradlew
5359
- name: Clean
5460
run: ./gradlew clean
55-
- name: Test with Gradle
56-
run: ./gradlew test --scan --stacktrace
61+
- if: matrix.os == 'windows-latest'
62+
name: Test with Gradle on Windows
63+
run: ./gradlew test -DapplicationProperties=src/test/resources/test-config/application-test-windows.properties
64+
- if: matrix.os != 'windows-latest'
65+
name: Test with Gradle on ${{ matrix.os }}
66+
run: ./gradlew test -DapplicationProperties=src/test/resources/test-config/application-test.properties
5767
- name: Generate report
5868
run: ./gradlew jacocoTestReport
5969
- name: Codecov

build.gradle

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ repositories {
3030

3131
ext {
3232
set('snippetsDir', file('build/generated-snippets'))
33+
applicationProperties = System.getProperty('applicationProperties', 'src/main/resources/application.properties')
3334
}
3435

3536
dependencies {
@@ -80,7 +81,9 @@ dependencies {
8081
test {
8182
outputs.dir snippetsDir
8283
finalizedBy jacocoTestReport
83-
environment 'spring.config.location', 'classpath:/test-config/'
84+
print("Running tests with configuration: ${applicationProperties}")
85+
environment 'spring.config.location', applicationProperties
86+
// environment 'spring.config.location', 'classpath:/test-config/'
8487
useJUnitPlatform()
8588
}
8689

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
66

output

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World!Input file: inputMapping schema file: schema

src/main/java/edu/kit/datamanager/mappingservice/util/ShellRunnerUtil.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,11 @@ public static MappingPluginState run(OutputStream output, OutputStream error, St
9090
* @throws MappingPluginException If an error occurs.
9191
*/
9292
public static MappingPluginState run(OutputStream output, OutputStream error, int timeOutInSeconds, String... command) throws MappingPluginException {
93+
if (output == null) throw new MappingPluginException(MappingPluginState.INVALID_INPUT, "Output stream is null.");
94+
if (error == null) throw new MappingPluginException(MappingPluginState.INVALID_INPUT, "Error stream is null.");
95+
if (timeOutInSeconds <= 0) throw new MappingPluginException(MappingPluginState.INVALID_INPUT, "Timeout is null or negative.");
96+
if (command == null || command.length == 0) throw new MappingPluginException(MappingPluginState.INVALID_INPUT, "No command given.");
97+
9398
ExecutorService pool = Executors.newSingleThreadExecutor();
9499
int result;
95100
MappingPluginState returnValue = MappingPluginState.SUCCESS;
@@ -123,13 +128,13 @@ public static MappingPluginState run(OutputStream output, OutputStream error, in
123128
throw new ExecutionException(new Throwable());
124129
}
125130
} catch (IOException ioe) {
126-
LOGGER.error("Failed to execute python.", ioe);
131+
LOGGER.error("Failed to execute command.", ioe);
127132
returnValue = MappingPluginState.EXECUTION_ERROR;
128133
} catch (TimeoutException te) {
129-
LOGGER.error("Python script did not return in expected timeframe of " + TIMEOUT + " seconds", te);
134+
LOGGER.error("Command did not return in expected timeframe of " + TIMEOUT + " seconds", te);
130135
returnValue = MappingPluginState.TIMEOUT;
131136
} catch (InterruptedException | ExecutionException e) {
132-
LOGGER.error("Failed to execute python script due to an unknown Exception.", e);
137+
LOGGER.error("Failed to execute command due to an unknown exception.", e);
133138
returnValue = MappingPluginState.UNKNOWN_ERROR;
134139
} finally {
135140
pool.shutdown();

src/main/resources/application.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ spring.jpa.hibernate.ddl-auto=update
3333
# Mapping-Service specific settings
3434
##################################################
3535
# Absolute path to the local python interpreter
36-
mapping-service.pythonLocation=file:///usr/bin/python3
36+
mapping-service.pythonLocation=file:///usr/bin/python4
3737

3838
# Absolute path to the local gemma mappings folder
3939
mapping-service.mappingSchemasLocation=file:///tmp/mapping-service/mappingSchemas

src/test/java/edu/kit/datamanager/mappingservice/plugins/PluginManagerTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,12 @@ void mapFileInvalidParameters() {
9999
@Test
100100
void mapFile() {
101101
try {
102-
File outputFile = new File("src/test/resources/testOutput");
103-
outputFile.delete();
104-
assertFalse(outputFile.exists());
102+
File outputFile = new File("/tmp/testOutput");
105103
PluginManager.soleInstance().mapFile("TEST_0.0.0", new File("mapping-schema").toPath(), new File("input").toPath(), outputFile.toPath());
106104
assertTrue(outputFile.exists());
107105
outputFile.delete();
108106
} catch (MappingPluginException e) {
107+
e.printStackTrace();
109108
fail("Mapping failed");
110109
}
111110
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2022 Karlsruhe Institute of Technology.
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License.
14+
*/
15+
16+
package edu.kit.datamanager.mappingservice.util;
17+
18+
import edu.kit.datamanager.mappingservice.plugins.MappingPluginException;
19+
import edu.kit.datamanager.mappingservice.plugins.MappingPluginState;
20+
import org.junit.jupiter.api.Test;
21+
22+
import static org.junit.jupiter.api.Assertions.*;
23+
24+
class ShellRunnerUtilTest {
25+
26+
@Test
27+
void runValid(){
28+
try {
29+
assertEquals(MappingPluginState.SUCCESS, ShellRunnerUtil.run("echo", "test"));
30+
assertEquals(MappingPluginState.SUCCESS, ShellRunnerUtil.run(5, "echo", "test"));
31+
assertEquals(MappingPluginState.SUCCESS, ShellRunnerUtil.run(System.out, System.err, "echo", "test"));
32+
} catch (MappingPluginException e) {
33+
fail(e);
34+
}
35+
}
36+
37+
@Test
38+
void runInvalid() {
39+
assertThrows(MappingPluginException.class, () -> ShellRunnerUtil.run(null));
40+
assertThrows(MappingPluginException.class, () -> ShellRunnerUtil.run("blablusdhflakjdsfh"));
41+
assertThrows(MappingPluginException.class, () -> ShellRunnerUtil.run(-5, "echo", "test"));
42+
assertThrows(MappingPluginException.class, () -> ShellRunnerUtil.run(null, System.err, "echo", "test"));
43+
assertThrows(MappingPluginException.class, () -> ShellRunnerUtil.run(System.err, null, "echo", "test"));
44+
assertThrows(MappingPluginException.class, () -> ShellRunnerUtil.run(1, "cat", "/dev/urandom"));
45+
assertThrows(MappingPluginException.class, () -> ShellRunnerUtil.run(1, "sudo", "cat", "/dev/urandom"));
46+
}
47+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#
2+
# Copyright 2022 Karlsruhe Institute of Technology.
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
# General Spring Boot Settings (do not change!)
17+
spring.main.allow-bean-definition-overriding=true
18+
spring.main.allow-circular-references=true
19+
server.port=8095
20+
# Data transfer settings, e.g. transfer compression and multipart message size.
21+
# The properties max-file-size and max-request-size define the maximum size of files
22+
# transferred to and from the repository. Setting them to -1 removes all limits.
23+
server.compression.enabled=false
24+
spring.servlet.multipart.max-file-size=100MB
25+
spring.servlet.multipart.max-request-size=100MB
26+
# Logging settings
27+
logging.level.root=ERROR
28+
logging.level.edu.kit.datamanager=INFO
29+
springdoc.swagger-ui.disable-swagger-default-url=true
30+
# Actuator settings
31+
info.app.name=Mapping-Service
32+
info.app.description=Generic mapping service supporting different mapping implementations.
33+
info.app.group=edu.kit.datamanager
34+
info.app.version=1.0.0
35+
management.endpoint.health.probes.enabled=true
36+
management.endpoints.web.exposure.include=*
37+
38+
##################################################
39+
# Mapping-Service specific settings
40+
##################################################
41+
# Absolute path to the local python interpreter
42+
mapping-service.pythonLocation=file:///usr/bin/python3
43+
# Absolute path to the local gemma mappings folder
44+
mapping-service.mappingSchemasLocation=file://mapping-service

0 commit comments

Comments
 (0)