public class ArpTests extends TestCase {
+ DOMParser parser = new DOMParser();
+
public ArpTests(String name) {
super(name);
BasicConfigurator.resetConfiguration();
BasicConfigurator.configure();
}
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ try {
+ parser.setFeature("http://xml.org/sax/features/validation", true);
+ parser.setFeature("http://apache.org/xml/features/validation/schema", true);
+ parser.setEntityResolver(new EntityResolver() {
+ public InputSource resolveEntity(String publicId, String systemId)
+ throws SAXException {
+ InputStream stream;
+ try {
+ stream = new FileInputStream("src/schemas/ARP.xsd");
+ if (stream != null) {
+ return new InputSource(stream);
+ }
+ throw new SAXException("Could not load entity: Null input stream");
+ } catch (FileNotFoundException e) {
+ throw new SAXException("Could not load entity: " + e);
+ }
+ }
+ });
+
+ parser.setErrorHandler(new ErrorHandler() {
+ public void error(SAXParseException arg0) throws SAXException {
+ throw new SAXException("Error parsing xml file: " + arg0);
+ }
+ public void fatalError(SAXParseException arg0) throws SAXException {
+ throw new SAXException("Error parsing xml file: " + arg0);
+ }
+ public void warning(SAXParseException arg0) throws SAXException {
+ throw new SAXException("Error parsing xml file: " + arg0);
+ }
+ });
+ } catch (Exception e) {
+ fail("Failed to setup xml parser: " + e);
+ }
+
+ }
+
public void testArpMarshalling() {
//Test ARP description
try {
InputStream inStream = new FileInputStream("test/arp1.xml");
- DOMParser parser = new DOMParser();
parser.parse(new InputSource(inStream));
Arp arp1 = new Arp();
arp1.marshall(parser.getDocument().getDocumentElement());
//Test case where ARP description does not exist
try {
InputStream inStream = new FileInputStream("test/arp2.xml");
- DOMParser parser = new DOMParser();
parser.parse(new InputSource(inStream));
Arp arp2 = new Arp();
arp2.marshall(parser.getDocument().getDocumentElement());
//Lookup a function that doesn't exist
MatchFunction noFunction =
- ArpEngine.lookupMatchFunction(new URI("urn:mace:shibboleth:arp:matchFunction:dummy"));
+ ArpEngine.lookupMatchFunction(
+ new URI("urn:mace:shibboleth:arp:matchFunction:dummy"));
assertNull("ArpEngine did not return null on dummy function.", noFunction);
//Lookup some real functions
MatchFunction exactSharFunction =
- ArpEngine.lookupMatchFunction(new URI("urn:mace:shibboleth:arp:matchFunction:exactShar"));
- assertNotNull("ArpEngine did not properly load the Exact SHAR function.", exactSharFunction);
+ ArpEngine.lookupMatchFunction(
+ new URI("urn:mace:shibboleth:arp:matchFunction:exactShar"));
+ assertNotNull(
+ "ArpEngine did not properly load the Exact SHAR function.",
+ exactSharFunction);
MatchFunction resourceTreeFunction =
- ArpEngine.lookupMatchFunction(new URI("urn:mace:shibboleth:arp:matchFunction:resourceTree"));
+ ArpEngine.lookupMatchFunction(
+ new URI("urn:mace:shibboleth:arp:matchFunction:resourceTree"));
assertNotNull(
"ArpEngine did not properly load the Resource Tree SHAR function.",
resourceTreeFunction);
MatchFunction regexFunction =
- ArpEngine.lookupMatchFunction(new URI("urn:mace:shibboleth:arp:matchFunction:regexMatch"));
+ ArpEngine.lookupMatchFunction(
+ new URI("urn:mace:shibboleth:arp:matchFunction:regexMatch"));
assertNotNull("ArpEngine did not properly load the Regex function.", regexFunction);
/*
assertTrue(
"Regex function: false negative",
regexFunction.match("^shar[1-9]?\\.example\\.edu$", "shar1.example.edu"));
- assertTrue("Regex function: false negative", regexFunction.match(".*\\.edu", "shar.example.edu"));
+ assertTrue(
+ "Regex function: false negative",
+ regexFunction.match(".*\\.edu", "shar.example.edu"));
assertTrue(
"Regex function: false positive",
!regexFunction.match("^shar[1-9]\\.example\\.edu$", "shar.example.edu"));
} catch (ArpRepositoryException e) {
fail("Failed to create memory-based Arp Repository" + e);
}
- assertNotNull("Failed to create memory-based Arp Repository: Factory returned null.", repository);
+ assertNotNull(
+ "Failed to create memory-based Arp Repository: Factory returned null.",
+ repository);
/*
* Exercise the Memory Arp Repository
siteArp1,
repository.getSitePolicy());
repository.remove(repository.getSitePolicy());
- assertNull("Memorty Repository does not properly delete Site ARPs.", repository.getSitePolicy());
+ assertNull(
+ "Memorty Repository does not properly delete Site ARPs.",
+ repository.getSitePolicy());
} catch (ArpRepositoryException e) {
fail("Error adding Site ARP to Memory Repository.");
}
try {
Principal principal1 = new AAPrincipal("TestPrincipal");
URL url1 = new URL("http://www.example.edu/");
- URI[] list1 =
- { new URI("urn:mace:eduPerson:1.0:eduPersonAffiliation")};
+ URI[] list1 = { new URI("urn:mace:eduPerson:1.0:eduPersonAffiliation")};
URI[] list2 =
{
new URI("urn:mace:eduPerson:1.0:eduPersonAffiliation"),
//Test with just a site ARP
InputStream inStream = new FileInputStream("test/arp1.xml");
- DOMParser parser = new DOMParser();
parser.parse(new InputSource(inStream));
Arp arp1 = new Arp();
arp1.marshall(parser.getDocument().getDocumentElement());
repository.update(arp1);
ArpEngine engine = new ArpEngine(repository, props);
URI[] possibleAttributes =
- engine.listPossibleReleaseAttributes(
- principal1,
- "shar.example.edu",
- url1);
+ engine.listPossibleReleaseAttributes(principal1, "shar.example.edu", url1);
assertEquals(
"Incorrectly computed possible release set (1).",
new HashSet(Arrays.asList(possibleAttributes)),
arp7.marshall(parser.getDocument().getDocumentElement());
repository.update(arp7);
possibleAttributes =
- engine.listPossibleReleaseAttributes(
- principal1,
- "shar.example.edu",
- url1);
+ engine.listPossibleReleaseAttributes(principal1, "shar.example.edu", url1);
assertEquals(
"Incorrectly computed possible release set (2).",
new HashSet(Arrays.asList(possibleAttributes)),
arp6.marshall(parser.getDocument().getDocumentElement());
repository.update(arp6);
possibleAttributes =
- engine.listPossibleReleaseAttributes(
- principal1,
- "shar.example.edu",
- url1);
+ engine.listPossibleReleaseAttributes(principal1, "shar.example.edu", url1);
assertEquals(
"Incorrectly computed possible release set (3).",
new HashSet(Arrays.asList(possibleAttributes)),
fail("Failed to create memory-based Arp Repository" + e);
}
- DOMParser parser = new DOMParser();
- try {
- parser.setFeature("http://xml.org/sax/features/validation", true);
- parser.setFeature("http://apache.org/xml/features/validation/schema", true);
- parser.setEntityResolver(new EntityResolver() {
- public InputSource resolveEntity(String publicId, String systemId) throws SAXException {
- InputStream stream;
- try {
- stream = new FileInputStream("src/schemas/ARP.xsd");
- if (stream != null) {
- return new InputSource(stream);
- }
- throw new SAXException("Could not load entity: Null input stream");
- } catch (FileNotFoundException e) {
- throw new SAXException("Could not load entity: " + e);
- }
- }
- });
-
- parser.setErrorHandler(new ErrorHandler() {
- public void error(SAXParseException arg0) throws SAXException {
- throw new SAXException("Error parsing xml file: " + arg0);
- }
- public void fatalError(SAXParseException arg0) throws SAXException {
- throw new SAXException("Error parsing xml file: " + arg0);
- }
- public void warning(SAXParseException arg0) throws SAXException {
- throw new SAXException("Error parsing xml file: " + arg0);
- }
- });
- } catch (Exception e) {
- fail("Failed to setup xml parser: " + e);
- }
try {
arpApplicationTest1(repository, props, parser);
* Target: Any
* Attribute: Any value release,
*/
- void arpApplicationTest1(ArpRepository repository, Properties props, DOMParser parser) throws Exception {
+ void arpApplicationTest1(ArpRepository repository, Properties props, DOMParser parser)
+ throws Exception {
//Gather the Input
String rawArp =
* Target: Any
* Attribute: Any value release, implicit deny
*/
- void arpApplicationTest2(ArpRepository repository, Properties props, DOMParser parser) throws Exception {
+ void arpApplicationTest2(ArpRepository repository, Properties props, DOMParser parser)
+ throws Exception {
//Gather the Input
String rawArp =
* Target: Any
* Attribute: One value release
*/
- void arpApplicationTest3(ArpRepository repository, Properties props, DOMParser parser) throws Exception {
+ void arpApplicationTest3(ArpRepository repository, Properties props, DOMParser parser)
+ throws Exception {
//Gather the Input
String rawArp =
* Target: Any
* Attribute: Any value except one release, canonical representation
*/
- void arpApplicationTest4(ArpRepository repository, Properties props, DOMParser parser) throws Exception {
+ void arpApplicationTest4(ArpRepository repository, Properties props, DOMParser parser)
+ throws Exception {
//Gather the Input
String rawArp =
TestAttribute testAttribute =
new TestAttribute(
"urn:mace:eduPerson:1.0:eduPersonAffiliation",
- new Object[] { "member@example.edu", "faculty@example.edu", "employee@example.edu" });
+ new Object[] {
+ "member@example.edu",
+ "faculty@example.edu",
+ "employee@example.edu" });
TestAttribute filteredAttribute =
new TestAttribute(
"urn:mace:eduPerson:1.0:eduPersonAffiliation",
* Target: Any
* Attribute: Any value except one release, expanded representation
*/
- void arpApplicationTest5(ArpRepository repository, Properties props, DOMParser parser) throws Exception {
+ void arpApplicationTest5(ArpRepository repository, Properties props, DOMParser parser)
+ throws Exception {
//Gather the Input
String rawArp =
TestAttribute testAttribute =
new TestAttribute(
"urn:mace:eduPerson:1.0:eduPersonAffiliation",
- new Object[] { "member@example.edu", "faculty@example.edu", "employee@example.edu" });
+ new Object[] {
+ "member@example.edu",
+ "faculty@example.edu",
+ "employee@example.edu" });
TestAttribute filteredAttribute =
new TestAttribute(
"urn:mace:eduPerson:1.0:eduPersonAffiliation",
* Target: Any
* Attribute: Any value except two release, expanded representation
*/
- void arpApplicationTest6(ArpRepository repository, Properties props, DOMParser parser) throws Exception {
+ void arpApplicationTest6(ArpRepository repository, Properties props, DOMParser parser)
+ throws Exception {
//Gather the Input
String rawArp =
TestAttribute testAttribute =
new TestAttribute(
"urn:mace:eduPerson:1.0:eduPersonAffiliation",
- new Object[] { "member@example.edu", "faculty@example.edu", "employee@example.edu" });
+ new Object[] {
+ "member@example.edu",
+ "faculty@example.edu",
+ "employee@example.edu" });
TestAttribute filteredAttribute =
new TestAttribute(
"urn:mace:eduPerson:1.0:eduPersonAffiliation",
* Target: Any
* Attribute: Two value release, canonical representation
*/
- void arpApplicationTest7(ArpRepository repository, Properties props, DOMParser parser) throws Exception {
+ void arpApplicationTest7(ArpRepository repository, Properties props, DOMParser parser)
+ throws Exception {
//Gather the Input
String rawArp =
TestAttribute testAttribute =
new TestAttribute(
"urn:mace:eduPerson:1.0:eduPersonAffiliation",
- new Object[] { "member@example.edu", "faculty@example.edu", "employee@example.edu" });
+ new Object[] {
+ "member@example.edu",
+ "faculty@example.edu",
+ "employee@example.edu" });
TestAttribute filteredAttribute =
new TestAttribute(
"urn:mace:eduPerson:1.0:eduPersonAffiliation",
* Target: Any
* Attribute: Two value release, expanded representation
*/
- void arpApplicationTest8(ArpRepository repository, Properties props, DOMParser parser) throws Exception {
+ void arpApplicationTest8(ArpRepository repository, Properties props, DOMParser parser)
+ throws Exception {
//Gather the Input
String rawArp =
TestAttribute testAttribute =
new TestAttribute(
"urn:mace:eduPerson:1.0:eduPersonAffiliation",
- new Object[] { "member@example.edu", "faculty@example.edu", "employee@example.edu" });
+ new Object[] {
+ "member@example.edu",
+ "faculty@example.edu",
+ "employee@example.edu" });
TestAttribute filteredAttribute =
new TestAttribute(
"urn:mace:eduPerson:1.0:eduPersonAffiliation",
* Target: Any
* Attribute: Any value deny
*/
- void arpApplicationTest9(ArpRepository repository, Properties props, DOMParser parser) throws Exception {
+ void arpApplicationTest9(ArpRepository repository, Properties props, DOMParser parser)
+ throws Exception {
//Gather the Input
String rawArp =
new HashSet(Arrays.asList(releaseAttributes)),
new HashSet(Arrays.asList(new ArpAttribute[] { testAttribute1, testAttribute2 })));
}
-
+
/**
* ARPs: A user ARP only
* Target: Any
* Attribute: Any value release,
*/
- void arpApplicationTest19(ArpRepository repository, Properties props, DOMParser parser) throws Exception {
+ void arpApplicationTest19(ArpRepository repository, Properties props, DOMParser parser)
+ throws Exception {
//Gather the Input
String rawArp =
new HashSet(Arrays.asList(releaseAttributes)),
new HashSet(Arrays.asList(new ArpAttribute[] { testAttribute })));
}
-
+
/**
* ARPs: A site ARP and user ARP
* Target: various
TestAttribute preferredLanguageInput =
new TestAttribute("urn:mace:inetOrgPerson:preferredLanguage", new Object[] { "EO" });
-
- TestAttribute entitlementOutput =
+
+ TestAttribute entitlementOutput =
new TestAttribute(
"urn:mace:eduPerson:1.0:eduPersonEntitlement",
- new Object[] {
- "urn:example:lovesIceCream",
- "urn:example:contract:4657483" });
-
+ new Object[] { "urn:example:lovesIceCream", "urn:example:contract:4657483" });
+
TestAttribute affiliationOutput =
new TestAttribute(
"urn:mace:eduPerson:1.0:eduPersonAffiliation",
- new Object[] {
- "member@example.edu",
- "employee@example.edu" });
+ new Object[] { "member@example.edu", "employee@example.edu" });
//Add the site ARP
parser.parse(new InputSource(new StringReader(rawSiteArp)));
assertEquals(
"ARP application test 20: ARP not applied as expected.",
new HashSet(Arrays.asList(releaseAttributes)),
- new HashSet(Arrays.asList(new ArpAttribute[] { entitlementOutput, affiliationOutput, principalNameInput, preferredLanguageInput })));
+ new HashSet(
+ Arrays.asList(
+ new ArpAttribute[] {
+ entitlementOutput,
+ affiliationOutput,
+ principalNameInput,
+ preferredLanguageInput })));
}
-
+
/**
* ARPs: A site ARP and user ARP
* Target: various
TestAttribute preferredLanguageInput =
new TestAttribute("urn:mace:inetOrgPerson:preferredLanguage", new Object[] { "EO" });
-
- TestAttribute entitlementOutput =
+
+ TestAttribute entitlementOutput =
new TestAttribute(
"urn:mace:eduPerson:1.0:eduPersonEntitlement",
new Object[] { "urn:example:contract:113455" });
-
+
TestAttribute affiliationOutput =
new TestAttribute(
"urn:mace:eduPerson:1.0:eduPersonAffiliation",
assertEquals(
"ARP application test 21: ARP not applied as expected.",
new HashSet(Arrays.asList(releaseAttributes)),
- new HashSet(Arrays.asList(new ArpAttribute[] { entitlementOutput, affiliationOutput, preferredLanguageInput })));
+ new HashSet(
+ Arrays.asList(
+ new ArpAttribute[] {
+ entitlementOutput,
+ affiliationOutput,
+ preferredLanguageInput })));
}
public class TestAttribute implements ArpAttribute {