diff --git a/inspector-vc/src/test/java/org/oneedtech/inspect/vc/util/TestOB20Inspector.java b/inspector-vc/src/test/java/org/oneedtech/inspect/vc/util/TestOB20Inspector.java new file mode 100644 index 0000000..e3c51cf --- /dev/null +++ b/inspector-vc/src/test/java/org/oneedtech/inspect/vc/util/TestOB20Inspector.java @@ -0,0 +1,57 @@ +package org.oneedtech.inspect.vc.util; + +import java.net.URI; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.oneedtech.inspect.util.resource.ResourceType; +import org.oneedtech.inspect.util.spec.Specification; +import org.oneedtech.inspect.vc.Assertion; +import org.oneedtech.inspect.vc.OB20Inspector; +import org.oneedtech.inspect.vc.probe.JsonLDCompactionProve; + +/** + * OpenBadges 2.0 Test inspector. + * It's a subclass of main OB2.0 inspector, setting redirection of urls to local resources for testing + */ +public class TestOB20Inspector extends OB20Inspector { + protected final Map localDomains; + + protected TestOB20Inspector(TestBuilder builder) { + super(builder); + if (getBehavior(OB20Inspector.Behavior.ALLOW_LOCAL_REDIRECTION) == Boolean.TRUE) { + this.localDomains = builder.localDomains; + } else { + this.localDomains = Collections.emptyMap(); + } + } + + @Override + protected JsonLDCompactionProve getCompactionProbe(Assertion assertion) { + return new JsonLDCompactionProve(assertion.getContext().get(0), localDomains); + } + + public static class TestBuilder extends OB20Inspector.Builder { + final Map localDomains; + + public TestBuilder() { + super(); + // don't allow local redirections by default + super.behaviors.put(OB20Inspector.Behavior.ALLOW_LOCAL_REDIRECTION, true); + this.localDomains = new HashMap<>(); + } + + public TestBuilder add(URI localDomain, String resourcePath) { + localDomains.put(localDomain, resourcePath); + return this; + } + + @Override + public TestOB20Inspector build() { + set(Specification.OB20); + set(ResourceType.OPENBADGE); + return new TestOB20Inspector(this); + } + } +}