parent
1028ad79fd
commit
80f633198a
@ -0,0 +1,15 @@
|
||||
package com.stackify.test.conditions;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
|
||||
@Target({ ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ExtendWith(DisabledOnEnvironmentCondition.class)
|
||||
public @interface DisabledOnEnvironment {
|
||||
String[] value();
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
package com.stackify.test.conditions;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
|
||||
import org.junit.jupiter.api.extension.TestExecutionCondition;
|
||||
import org.junit.jupiter.api.extension.TestExtensionContext;
|
||||
import org.junit.platform.commons.support.AnnotationSupport;
|
||||
|
||||
import com.stackify.utils.ConnectionUtil;
|
||||
|
||||
public class DisabledOnEnvironmentCondition implements TestExecutionCondition {
|
||||
|
||||
@Override
|
||||
public ConditionEvaluationResult evaluate(TestExtensionContext context) {
|
||||
Properties props = new Properties();
|
||||
String env = "";
|
||||
try {
|
||||
props.load(ConnectionUtil.class.getResourceAsStream("/application.properties"));
|
||||
env = props.getProperty("env");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
Optional<DisabledOnEnvironment> disabled = AnnotationSupport.findAnnotation(context.getElement().get(), DisabledOnEnvironment.class);
|
||||
if (disabled.isPresent()) {
|
||||
String[] envs = disabled.get().value();
|
||||
if (Arrays.asList(envs).contains(env)) {
|
||||
return ConditionEvaluationResult.disabled("Disabled on environment " + env);
|
||||
}
|
||||
}
|
||||
|
||||
return ConditionEvaluationResult.enabled("Enabled on environment "+env);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1 @@
|
||||
env=dev
|
@ -23,6 +23,8 @@ import java.util.List;
|
||||
import com.stackify.daos.UserDAO;
|
||||
import com.stackify.models.User;
|
||||
|
||||
import com.stackify.test.conditions.DisabledOnEnvironment;
|
||||
|
||||
public class UsersTest implements DatabaseConnectionTest {
|
||||
|
||||
private static UserDAO userDAO;
|
||||
@ -110,7 +112,7 @@ public class UsersTest implements DatabaseConnectionTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
@DisabledOnEnvironment({ "dev", "prod")
|
||||
void testFail() {
|
||||
fail("this test fails");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user