Skip to content

Commit

Permalink
fixup! WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
tristantarrant committed Sep 10, 2021
1 parent ccbfeb6 commit 2ddbb0c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 29 deletions.
Expand Up @@ -13,23 +13,50 @@
*/
public class SkipJunit implements TestRule {
private final OS[] oses;
private final int jdkMajorVersion;

public SkipJunit(OS... oses) {
this.oses = Objects.requireNonNull(oses);
this.jdkMajorVersion = -1;
}

public SkipJunit(int jdkMajorVersion) {
this.jdkMajorVersion = jdkMajorVersion;
this.oses = null;
}

@Override
public Statement apply(Statement base, Description description) {
OS os = OS.getCurrentOs();
if (!Arrays.asList(oses).contains(os))
return base;

return new IgnoreStatement(description, os);
if (oses != null) {
OS os = OS.getCurrentOs();
if (!Arrays.asList(oses).contains(os)) {
return base;
} else {
return new Statement() {
@Override
public void evaluate() {
throw new AssumptionViolatedException("Ignoring test " + description.getDisplayName() + " on OS " + os);
}
};
}
} else {
int version = getJDKVersion();
if (version >= jdkMajorVersion) {
return new Statement() {
@Override
public void evaluate() {
throw new AssumptionViolatedException("Ignoring test " + description.getDisplayName() + " on JDK " + version);
}
};
} else {
return base;
}
}
}

/**
* Use within a {@code @Test} method to skip that method on some OSes.
* Use in a {@code @BeforeClass} method to skip all methods in a class on some OSes.
* Use within a {@code @Test} method to skip that method on some OSes. Use in a {@code @BeforeClass} method to skip
* all methods in a class on some OSes.
*/
public static void skipOnOS(OS... oses) {
OS os = OS.getCurrentOs();
Expand All @@ -38,8 +65,8 @@ public static void skipOnOS(OS... oses) {
}

/**
* Use within a {@code @Test} method to run this test only on certain OSes.
* Use in a {@code @BeforeClass} method to run all methods in a class only on some OSes.
* Use within a {@code @Test} method to run this test only on certain OSes. Use in a {@code @BeforeClass} method to
* run all methods in a class only on some OSes.
*/
public static void onlyOnOS(OS... oses) {
OS os = OS.getCurrentOs();
Expand All @@ -61,24 +88,4 @@ private static int getJDKVersion() {
version = Integer.parseInt(parts[1]);
return version;
}

private static class IgnoreStatement extends Statement {

private final Description method;

private final OS os;

IgnoreStatement(Description method, OS os) {
this.method = method;
this.os = os;
}

@Override
public void evaluate() {
String msg = "Skipping test " + method.getDisplayName() + " on " + os;
System.out.println(msg);
throw new AssumptionViolatedException(msg);
}
}

}
Expand Up @@ -13,6 +13,7 @@
import javax.security.auth.login.LoginException;

import org.infinispan.commons.test.ThreadLeakChecker;
import org.infinispan.commons.test.skip.SkipJunit;
import org.infinispan.security.AuthorizationPermission;
import org.infinispan.security.PrincipalRoleMapper;
import org.infinispan.test.integration.security.tasks.AbstractKrb5ConfServerSetupTask;
Expand All @@ -34,6 +35,7 @@
import org.jboss.security.SecurityConstants;
import org.jboss.security.negotiation.AdvancedLdapLoginModule;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.ClassRule;
import org.junit.runner.RunWith;

/**
Expand All @@ -51,6 +53,9 @@
})
public class KrbLdapAuthenticationIT extends AbstractAuthentication {

@ClassRule
public static SkipJunit skip = new SkipJunit(13);

private static final String TRUE = Boolean.TRUE.toString(); // TRUE

public static final String ADMIN_ROLE = "AdminIspnRole";
Expand Down
Expand Up @@ -10,6 +10,7 @@
import javax.security.auth.login.LoginException;

import org.infinispan.commons.test.ThreadLeakChecker;
import org.infinispan.commons.test.skip.SkipJunit;
import org.infinispan.security.AuthorizationPermission;
import org.infinispan.security.PrincipalRoleMapper;
import org.infinispan.security.mappers.IdentityRoleMapper;
Expand All @@ -27,6 +28,7 @@
import org.jboss.as.test.integration.security.common.config.SecurityDomain;
import org.jboss.as.test.integration.security.common.config.SecurityModule;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.ClassRule;
import org.junit.runner.RunWith;

/**
Expand All @@ -51,6 +53,9 @@ public class LdapAuthenticationIT extends AbstractAuthentication {
public static final String UNPRIVILEGED_ROLE = "unprivileged";
public static final String UNPRIVILEGED_PASSWD = "weakPassword";

@ClassRule
public static SkipJunit skip = new SkipJunit(13);

@Deployment
@TargetsContainer(DEFAULT_DEPLOY_CONTAINER)
public static WebArchive getDeployment() {
Expand Down

0 comments on commit 2ddbb0c

Please sign in to comment.