Skip to content

Commit

Permalink
chore(plc4j): Added a new Unit-Test annotation to let a test only get…
Browse files Browse the repository at this point in the history
… executed if the "enable-all-tests" or "jenkins-build" profiles are enabled.
  • Loading branch information
chrisdutz committed Jul 11, 2022
1 parent 820d272 commit 56160bf
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.plc4x.java.spi.generation.*;
import org.apache.plc4x.java.spi.utils.Serializable;
import org.apache.plc4x.java.spi.utils.hex.Hex;
import org.apache.plc4x.test.RequireAllTestsFlag;
import org.apache.plc4x.test.RequirePcapNg;
import org.assertj.core.api.InstanceOfAssertFactories;
import org.assertj.core.presentation.HexadecimalRepresentation;
Expand Down Expand Up @@ -53,6 +54,7 @@

// Tests from http://kargs.net/captures
@RequirePcapNg
@RequireAllTestsFlag
@Tag("bacnet-regression")
public class RandomPackagesTest {

Expand Down
4 changes: 4 additions & 0 deletions plc4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@
<include>**/*Tests.java</include>
<include>**/*Spec.java</include>
</includes>
<environmentVariables>
<!-- Pass in to the build, if all tests should be run -->
<ENABLE_ALL_TESTS>${enable-all-tests}</ENABLE_ALL_TESTS>
</environmentVariables>
</configuration>
</plugin>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.plc4x.test;

import org.junit.jupiter.api.extension.ExtendWith;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
* Some tests are quite excessive, we can mark tests with this annotation
* for which we want the tests to only be executed if the "enable-all-checks"
* profile is enabled. (Actually it works by setting an environment variable
* named "ENABLE_ALL_TESTS" to "true".
*/
@Target({ ElementType.TYPE, ElementType.METHOD })
@Retention(RetentionPolicy.RUNTIME)
@ExtendWith(RequireAllTestsFlagCondition.class)
public @interface RequireAllTestsFlag {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.plc4x.test;

import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.ExtensionContext;

public class RequireAllTestsFlagCondition implements ExecutionCondition {

@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) {
String propertyValue = System.getenv("ENABLE_ALL_TESTS");
if("true".equalsIgnoreCase(propertyValue)) {
return ConditionEvaluationResult.enabled("ENABLE_ALL_TESTS variable set to 'true'.");
}
return ConditionEvaluationResult.disabled("ENABLE_ALL_TESTS variable not set to 'true', therefore disabling this test.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext ext
} else if (SystemUtils.IS_OS_WINDOWS) {
return ConditionEvaluationResult.disabled("Test disabled due to too old Npcap version. Please install from here: https://npcap.com/ as this version supports all needed features.");
} else {
return ConditionEvaluationResult.disabled("Test disabled due to too old libpcap version. Please install at least version 1.1.0 to support all features.");
return ConditionEvaluationResult.disabled("Test disabled due to too old libpcap version. Please install at least version 1.10.1 to support all features.");
}
}
} catch(Throwable e) {
Expand All @@ -68,7 +68,7 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext ext
if(SystemUtils.IS_OS_WINDOWS) {
return ConditionEvaluationResult.disabled("Test disabled due to missing or invalid Npcap version. Please install from here: https://npcap.com/ as this version supports all needed features.");
} else {
return ConditionEvaluationResult.disabled("Test disabled due to missing or invalid libpcap version. Please install at least version 1.1.0 to support all features.");
return ConditionEvaluationResult.disabled("Test disabled due to missing or invalid libpcap version. Please install at least version 1.10.1 to support all features.");
}
}

Expand Down
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@

<skip-code-generation-tests>true</skip-code-generation-tests>
<skip-dependency-cve-scan>true</skip-dependency-cve-scan>
<enable-all-tests>false</enable-all-tests>
</properties>

<modules>
Expand Down Expand Up @@ -1651,6 +1652,7 @@
<properties>
<skip-code-generation-tests>false</skip-code-generation-tests>
<skip-dependency-cve-scan>false</skip-dependency-cve-scan>
<enable-all-tests>true</enable-all-tests>
</properties>
</profile>

Expand All @@ -1659,6 +1661,7 @@
<properties>
<skip-code-generation-tests>false</skip-code-generation-tests>
<skip-dependency-cve-scan>false</skip-dependency-cve-scan>
<enable-all-tests>true</enable-all-tests>
</properties>
</profile>

Expand Down

0 comments on commit 56160bf

Please sign in to comment.