Skip to content

Commit

Permalink
TestSuite extension mechanism (#146)
Browse files Browse the repository at this point in the history
Make it easier to extend TestSuite with test cases and let
TomlConfigParser read in inherited fields as well.

# Checklist

The following aspects have been respected by the author of this pull
request, confirmed by both pull request assignee **and** reviewer:

* Adherence to coding conventions
  * [x] @maximilianpilz 
  * [x] @belagertem 
* Adherence to javadoc conventions
  * [x] @maximilianpilz 
  * [x] @belagertem 
* Changelog update (necessity checked and entry added or not added
respectively)
  * [x] @maximilianpilz 
  * [x] @belagertem 
* README update (necessity checked and entry added or not added
respectively)
  * [x] @maximilianpilz 
  * [x] @belagertem 
* config update (necessity checked and entry added or not added
respectively)
  * [x] @maximilianpilz 
  * [x] @belagertem 
* SDCcc executable ran against a test device (if necessary)
  * [x] @maximilianpilz 
  * [x] @belagertem
  • Loading branch information
maximilianpilz authored Mar 7, 2024
1 parent 664d736 commit 4be601f
Show file tree
Hide file tree
Showing 7 changed files with 140 additions and 47 deletions.
1 change: 0 additions & 1 deletion checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
<module name="MissingOverride"/>
<module name="PackageAnnotation"/>

<module name="HideUtilityClassConstructor"/>
<module name="InnerTypeLast"/>
<module name="InterfaceIsType"/>
<module name="MutableException"/>
Expand Down
71 changes: 52 additions & 19 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,6 @@
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${execPluginVersion}</version>
<configuration>
<skip>true</skip>
<executable>${java.home}/bin/java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>com.draeger.medical.sdccc.TestSuite</argument>
<argument>-c</argument>
<argument>${project.basedir}/../configuration/config.toml</argument>
<argument>-t</argument>
<argument>${project.basedir}/../configuration/test_configuration.toml</argument>
</arguments>
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>license-maven-plugin</artifactId>
Expand Down Expand Up @@ -92,6 +73,58 @@
</configuration>
</plugin>

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${execPluginVersion}</version>
<configuration>
<skip>true</skip>
<executable>${java.home}/bin/java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>com.draeger.medical.sdccc.TestSuite</argument>
<argument>-c</argument>
<argument>${project.basedir}/../configuration/config.toml</argument>
<argument>-t</argument>
<argument>${project.basedir}/../configuration/test_configuration.toml</argument>
</arguments>
</configuration>
</plugin>

</plugins>
</build>

<profiles>
<profile>
<id>exec-sdccc</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${execPluginVersion}</version>
<executions>
<execution>
<id>951d1725-bb0b-40db-9d4e-d1947a8318ed</id>
<configuration>
<skip>false</skip>
<executable>${java.home}/bin/java</executable>
<arguments>
<argument>-classpath</argument>
<classpath/>
<argument>com.draeger.medical.sdccc.TestSuite</argument>
<argument>-c</argument>
<argument>${project.basedir}/../configuration/config.toml</argument>
<argument>-t</argument>
<argument>${project.basedir}/../configuration/test_configuration.toml</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
27 changes: 17 additions & 10 deletions sdccc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -423,19 +423,26 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${execPluginVersion}</version>
<configuration>
<skip>false</skip>
<executable>${java.home}/bin/java</executable>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>exec-sdccc</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>${execPluginVersion}</version>
<configuration>
<skip>false</skip>
<executable>${java.home}/bin/java</executable>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>executable</id>
<build>
Expand Down Expand Up @@ -472,7 +479,7 @@
<fileVersion>${revision}.0</fileVersion>
<txtFileVersion>${revision}${changelist}</txtFileVersion>
<fileDescription>${project.name}</fileDescription>
<copyright>2023 Draegerwerk AG &amp; Co. KGaA</copyright>
<copyright>2024 Draegerwerk AG &amp; Co. KGaA</copyright>
<productVersion>${revision}.0</productVersion>
<txtProductVersion>${revision}${changelist}</txtProductVersion>
<productName>${project.name}</productName>
Expand Down
55 changes: 50 additions & 5 deletions sdccc/src/main/java/com/draeger/medical/sdccc/TestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,21 @@ public class TestSuite {
private final TestClient client;
private final boolean testExecutionLogging;

/**
* Used by the main injector to create a TestSuite instance.
* It is also useful for extending the TestSuite class.
*
* @param injector a reference to the injector injecting here
* @param testRunObserver observer for invalidating test runs
* @param sdcTestDirectories directories to search for test cases
* @param testRunDir directory to run the tests in and store artifacts
* @param testExecutionLogging whether logging of test case starts etc. shall be done
* @param messageGenerator utility for generating messages to send
* @param testRunInformation utility where information of the test run is stored
* @param client client to use for direct tests
*/
@Inject
TestSuite(
public TestSuite(
final Injector injector,
final TestRunObserver testRunObserver,
@Named(TestSuiteConfig.SDC_TEST_DIRECTORIES) final String[] sdcTestDirectories,
Expand Down Expand Up @@ -428,7 +441,11 @@ private static Injector createInjector(final Module... override) {
.with(override));
}

private static Injector createTestRunInjector(final CommandLineOptions cmdLine, final File testRunDir)
private static Injector createTestRunInjector(
final CommandLineOptions cmdLine,
final File testRunDir,
final Class<? extends EnabledTestConfig> enabledTestConfigClass,
final String[] sdcTestDirectories)
throws IOException {

final AbstractConfigurationModule baseConfigModule = new AbstractConfigurationModule() {
Expand Down Expand Up @@ -509,12 +526,13 @@ protected void defaultConfigure() {
baseConfigModule.bind(TestSuiteConfig.CONSUMER_DEVICE_LOCATION_FLOOR, String.class, null);
baseConfigModule.bind(TestSuiteConfig.CONSUMER_DEVICE_LOCATION_ROOM, String.class, null);
baseConfigModule.bind(TestSuiteConfig.CONSUMER_DEVICE_LOCATION_BED, String.class, null);
baseConfigModule.bind(TestSuiteConfig.SDC_TEST_DIRECTORIES, String[].class, sdcTestDirectories);

configModuleParser.parseToml(configFileStream, configModule);
}
try (final var testConfigFileStream =
new FileInputStream(cmdLine.getTestConfigPath().toFile())) {
final var testConfigModuleParser = new TomlConfigParser(EnabledTestConfig.class);
final var testConfigModuleParser = new TomlConfigParser(enabledTestConfigClass);
testConfigModuleParser.parseToml(testConfigFileStream, testConfigModule);
}

Expand Down Expand Up @@ -620,12 +638,38 @@ public static void setupSwingTheme()
* @param args array of command line arguments
*/
public static void main(final String[] args) throws IOException {
final var cmdLine = initialize(args);

runWithArgs(cmdLine, EnabledTestConfig.class, DefaultTestSuiteConfig.DEFAULT_DIRECTORIES);
}

/**
* Set required system properties and parse the command line arguments.
*
* @param args array of command line arguments
* @return parsed command line arguments
*/
public static CommandLineOptions initialize(final String[] args) {
// improve xml interaction performance
setSystemProperties();

// parse command line options
final var cmdLine = new CommandLineOptions(args);
return new CommandLineOptions(args);
}

/**
* Run the test suite with the given already parsed command line arguments and the
* specified enabled test config constants.
*
* @param cmdLine parsed command line arguments
* @param enabledTestConfigClass class containing test identifier constants
* @param sdcTestDirectories directories to search for test cases
*/
public static void runWithArgs(
final CommandLineOptions cmdLine,
final Class<? extends EnabledTestConfig> enabledTestConfigClass,
final String[] sdcTestDirectories)
throws IOException {
// setup logging
final var testRunDir = TestRunConfig.createTestRunDirectory(
cmdLine.getTestRunDirectory().orElse(null));
Expand All @@ -648,7 +692,8 @@ public static void main(final String[] args) throws IOException {
LOG.warn("Error while setting swing look and feel options.", e);
}

final Injector injector = createTestRunInjector(cmdLine, testRunDir);
final Injector injector =
createTestRunInjector(cmdLine, testRunDir, enabledTestConfigClass, sdcTestDirectories);

final TriggerOnErrorOrWorseLogAppender triggerOnErrorOrWorseLogAppender =
findTriggerOnErrorOrWorseLogAppender(logConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package com.draeger.medical.sdccc.configuration;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.somda.sdc.common.guice.AbstractConfigurationModule;

/**
Expand All @@ -16,6 +17,17 @@
*/
public class DefaultTestSuiteConfig extends AbstractConfigurationModule {

@SuppressFBWarnings(
value = {"MS_MUTABLE_ARRAY"},
justification = "In case this is wrong there will be an error (for test cases that couldn't be found)"
+ " and thus this being wrong due to modification will always be noticed.")
public static final String[] DEFAULT_DIRECTORIES = {
"com.draeger.medical.sdccc.tests.biceps",
"com.draeger.medical.sdccc.tests.mdpws",
"com.draeger.medical.sdccc.tests.dpws",
"com.draeger.medical.sdccc.tests.glue",
};

private static final int BUFFER_SIZE = 100;

@Override
Expand Down Expand Up @@ -80,12 +92,7 @@ void configureTestParameter() {
}

void configureInternalSettings() {
bind(TestSuiteConfig.SDC_TEST_DIRECTORIES, String[].class, new String[] {
"com.draeger.medical.sdccc.tests.biceps",
"com.draeger.medical.sdccc.tests.mdpws",
"com.draeger.medical.sdccc.tests.dpws",
"com.draeger.medical.sdccc.tests.glue",
});
bind(TestSuiteConfig.SDC_TEST_DIRECTORIES, String[].class, DEFAULT_DIRECTORIES);
}

protected void configureCommlogSettings() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This Source Code Form is subject to the terms of the MIT License.
* Copyright (c) 2023 Draegerwerk AG & Co. KGaA.
* Copyright (c) 2023, 2024 Draegerwerk AG & Co. KGaA.
*
* SPDX-License-Identifier: MIT
*/
Expand All @@ -11,7 +11,7 @@
* Constants used to map the content of the configuration for enabled
* test cases.
*/
public final class EnabledTestConfig {
public class EnabledTestConfig {

// BICEPS
private static final String BICEPS = "BICEPS.";
Expand Down Expand Up @@ -124,5 +124,8 @@ public final class EnabledTestConfig {
public static final String GLUE_R0080 = GLUE + "R0080";
public static final String GLUE_813 = GLUE + "8-1-3";

private EnabledTestConfig() {}
/**
* Default constructor for extending the constants list.
*/
public EnabledTestConfig() {}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* This Source Code Form is subject to the terms of the MIT License.
* Copyright (c) 2023 Draegerwerk AG & Co. KGaA.
* Copyright (c) 2023, 2024 Draegerwerk AG & Co. KGaA.
*
* SPDX-License-Identifier: MIT
*/
Expand Down Expand Up @@ -38,13 +38,12 @@ public class TomlConfigParser {
* This parser only allows known keys and will throw an exception otherwise.
*
* @param constantsClass to verify toml keys against
* @throws IOException in case an error occurred during parsing.
*/
public TomlConfigParser(final Class constantsClass) {
// track allowed keys
this.allowedKeys = new HashSet<>();

Arrays.stream(constantsClass.getDeclaredFields()).forEach(field -> {
Arrays.stream(constantsClass.getFields()).forEach(field -> {
if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) {
try {
allowedKeys.add((String) field.get(null));
Expand Down

0 comments on commit 4be601f

Please sign in to comment.