*/
@Test
public void testAuthnRequestExample() throws Exception {
String resourceName = "saml/v2/authnrequest/samlAuthnRequestExample.xml";
SAML2Request request = new SAML2Request();
AuthnRequestType authnRequestType = request.getAuthnRequestType(resourceName);
assertEquals("http://www.example.com/", authnRequestType.getDestination().toString());
assertEquals("urn:oasis:names:tc:SAML:2.0:consent:obtained", authnRequestType.getConsent());
assertEquals("http://www.example.com/", authnRequestType.getAssertionConsumerServiceURL().toString());
assertEquals(Integer.valueOf("0"), authnRequestType.getAttributeConsumingServiceIndex());
SubjectType subjectType = authnRequestType.getSubject();
assertNotNull(subjectType);
STSubType subType = subjectType.getSubType();
NameIDType nameIDType = (NameIDType) subType.getBaseID();
assertEquals("urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress", nameIDType.getFormat().toString());
assertEquals("j.doe@company.com", nameIDType.getValue());
ConditionsType conditionsType = authnRequestType.getConditions();
List<ConditionAbstractType> conditions = conditionsType.getConditions();
assertTrue(conditions.size() == 1);
ConditionAbstractType condition = conditions.get(0);
assertTrue(condition instanceof AudienceRestrictionType);
AudienceRestrictionType audienceRestrictionType = (AudienceRestrictionType) condition;
List<URI> audiences = audienceRestrictionType.getAudience();
assertTrue(audiences.size() == 1);
assertEquals("urn:foo:sp.example.org", audiences.get(0).toASCIIString());
RequestedAuthnContextType requestedAuthnContext = authnRequestType.getRequestedAuthnContext();
assertEquals("urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport", requestedAuthnContext
.getAuthnContextClassRef().get(0));
// Let us marshall it back to an output stream
ByteArrayOutputStream baos = new ByteArrayOutputStream();
request.marshall(authnRequestType, baos);
}