ExtensionAllowed { public boolean isExtensionAllowed(final ExtensionSegmentSet extensionSegmentSet) { boolean allowed = false; if (this.namespace.equals("*:*")) { allowed = true; } else if (this.namespace.equals(extensionSegmentSet.getNamespace() + ":*")) { allowed = true; } else if (this.namespace.equals(extensionSegmentSet.getNamespace() + ":" + extensionSegmentSet.getExtension())) { allowed = true; } return allowed; } ExtensionAllowed(final String namespace); boolean isExtensionAllowed(final ExtensionSegmentSet extensionSegmentSet); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void isExtensionAllowedAllowAll() { ExtensionAllowed configuration = new ExtensionAllowed("*:*"); ExtensionSegmentSet extensionSegmentSet = new ExtensionSegmentSet(this.mockTheUri("ns", "extension", ""), ExtensionPoint.GRAPH); Assert.assertTrue(configuration.isExtensionAllowed(extensionSegmentSet)); }
@Test public void isExtensionAllowedAllowAllInNamespace() { ExtensionAllowed configuration = new ExtensionAllowed("ns:*"); ExtensionSegmentSet extensionSegmentSet = new ExtensionSegmentSet(this.mockTheUri("ns", "extension", ""), ExtensionPoint.GRAPH); Assert.assertTrue(configuration.isExtensionAllowed(extensionSegmentSet)); extensionSegmentSet = new ExtensionSegmentSet(this.mockTheUri("bs", "extension", ""), ExtensionPoint.GRAPH); Assert.assertFalse(configuration.isExtensionAllowed(extensionSegmentSet)); }
@Test public void isExtensionAllowedAllowSpecificExtension() { ExtensionAllowed configuration = new ExtensionAllowed("ns:allowed"); ExtensionSegmentSet extensionSegmentSet = new ExtensionSegmentSet(this.mockTheUri("ns", "allowed", ""), ExtensionPoint.GRAPH); Assert.assertTrue(configuration.isExtensionAllowed(extensionSegmentSet)); extensionSegmentSet = new ExtensionSegmentSet(this.mockTheUri("ns", "not_allowed", ""), ExtensionPoint.GRAPH); Assert.assertFalse(configuration.isExtensionAllowed(extensionSegmentSet)); }
@Test public void isExtensionAllowedAllowDashedExtension() { ExtensionAllowed configuration = new ExtensionAllowed("ns-dash:allowed-dash"); ExtensionSegmentSet extensionSegmentSet = new ExtensionSegmentSet(this.mockTheUri("ns-dash", "allowed-dash", ""), ExtensionPoint.GRAPH); Assert.assertTrue(configuration.isExtensionAllowed(extensionSegmentSet)); extensionSegmentSet = new ExtensionSegmentSet(this.mockTheUri("ns", "not_allowed", ""), ExtensionPoint.GRAPH); Assert.assertFalse(configuration.isExtensionAllowed(extensionSegmentSet)); }
@Test(expected = IllegalArgumentException.class) public void isExtensionAllowedNullExtensionName() { ExtensionAllowed configuration = new ExtensionAllowed(null); ExtensionSegmentSet extensionSegmentSet = new ExtensionSegmentSet(this.mockTheUri("ns", "extension", ""), ExtensionPoint.GRAPH); configuration.isExtensionAllowed(extensionSegmentSet); }
@Test(expected = IllegalArgumentException.class) public void isExtensionAllowedInvalidExtensionName() { ExtensionAllowed configuration = new ExtensionAllowed("this doesn't work as an extension name"); ExtensionSegmentSet extensionSegmentSet = new ExtensionSegmentSet(this.mockTheUri("ns", "extension", ""), ExtensionPoint.GRAPH); configuration.isExtensionAllowed(extensionSegmentSet); }