@SuppressWarnings("unchecked")
  // CHECKSTYLE:OFF
  public static AuthnRequest createAuthnRequest(
      String serviceURL,
      boolean forceAuthn,
      boolean isPassive,
      String protocolBinding,
      SAMLVersion version,
      Issuer issuer,
      NameIDPolicy nameIDPolicy,
      RequestedAuthnContext requestedAuthnCtx) {
    // CHECKSTYLE:ON
    if (authnRequestBuilder == null) {
      authnRequestBuilder =
          (SAMLObjectBuilder<AuthnRequest>)
              builderFactory.getBuilder(AuthnRequest.DEFAULT_ELEMENT_NAME);
    }
    AuthnRequest authnRequest = authnRequestBuilder.buildObject();
    authnRequest.setAssertionConsumerServiceURL(serviceURL);
    authnRequest.setForceAuthn(forceAuthn);
    authnRequest.setID("_" + UUID.randomUUID());
    authnRequest.setIsPassive(isPassive);
    authnRequest.setIssueInstant(new DateTime());
    authnRequest.setProtocolBinding(protocolBinding);
    authnRequest.setVersion(version);

    authnRequest.setIssuer(issuer);
    authnRequest.setNameIDPolicy(nameIDPolicy);
    authnRequest.setRequestedAuthnContext(requestedAuthnCtx);

    return authnRequest;
  }
  /** {@inheritDoc} */
  @Test
  public void testSingleElementOptionalAttributesMarshall() {
    QName qname =
        new QName(
            SAMLConstants.SAML20P_NS,
            AuthnRequest.DEFAULT_ELEMENT_LOCAL_NAME,
            SAMLConstants.SAML20P_PREFIX);
    AuthnRequest req = (AuthnRequest) buildXMLObject(qname);

    super.populateRequiredAttributes(req);
    super.populateOptionalAttributes(req);

    req.setForceAuthn(expectedForceAuthn);
    req.setIsPassive(expectedIsPassive);
    req.setProtocolBinding(expectedProtocolBinding);
    req.setAssertionConsumerServiceIndex(expectedAssertionConsumerServiceIndex);
    req.setAssertionConsumerServiceURL(expectedAssertionConsumerServiceURL);
    req.setAttributeConsumingServiceIndex(expectedAttributeConsumingServiceIndex);
    req.setProviderName(expectedProviderName);

    assertXMLEquals(expectedOptionalAttributesDOM, req);
  }
  /** Test the proper behavior of the XSBooleanValue attributes. */
  @Test
  public void testXSBooleanAttributes() {
    AuthnRequest req = (AuthnRequest) buildXMLObject(AuthnRequest.DEFAULT_ELEMENT_NAME);

    // ForceAuthn attribute
    req.setForceAuthn(Boolean.TRUE);
    Assert.assertEquals(
        req.isForceAuthn(), Boolean.TRUE, "Unexpected value for boolean attribute found");
    Assert.assertNotNull(req.isForceAuthnXSBoolean(), "XSBooleanValue was null");
    Assert.assertEquals(
        req.isForceAuthnXSBoolean(),
        new XSBooleanValue(Boolean.TRUE, false),
        "XSBooleanValue was unexpected value");
    Assert.assertEquals(
        req.isForceAuthnXSBoolean().toString(),
        "true",
        "XSBooleanValue string was unexpected value");

    req.setForceAuthn(Boolean.FALSE);
    Assert.assertEquals(
        req.isForceAuthn(), Boolean.FALSE, "Unexpected value for boolean attribute found");
    Assert.assertNotNull(req.isForceAuthnXSBoolean(), "XSBooleanValue was null");
    Assert.assertEquals(
        req.isForceAuthnXSBoolean(),
        new XSBooleanValue(Boolean.FALSE, false),
        "XSBooleanValue was unexpected value");
    Assert.assertEquals(
        req.isForceAuthnXSBoolean().toString(),
        "false",
        "XSBooleanValue string was unexpected value");

    req.setForceAuthn((Boolean) null);
    Assert.assertEquals(
        req.isForceAuthn(), Boolean.FALSE, "Unexpected default value for boolean attribute found");
    Assert.assertNull(req.isForceAuthnXSBoolean(), "XSBooleanValue was not null");

    // IsPassive attribute
    req.setIsPassive(Boolean.TRUE);
    Assert.assertEquals(
        req.isPassive(), Boolean.TRUE, "Unexpected value for boolean attribute found");
    Assert.assertNotNull(req.isPassiveXSBoolean(), "XSBooleanValue was null");
    Assert.assertEquals(
        req.isPassiveXSBoolean(),
        new XSBooleanValue(Boolean.TRUE, false),
        "XSBooleanValue was unexpected value");
    Assert.assertEquals(
        req.isPassiveXSBoolean().toString(), "true", "XSBooleanValue string was unexpected value");

    req.setIsPassive(Boolean.FALSE);
    Assert.assertEquals(
        req.isPassive(), Boolean.FALSE, "Unexpected value for boolean attribute found");
    Assert.assertNotNull(req.isPassiveXSBoolean(), "XSBooleanValue was null");
    Assert.assertEquals(
        req.isPassiveXSBoolean(),
        new XSBooleanValue(Boolean.FALSE, false),
        "XSBooleanValue was unexpected value");
    Assert.assertEquals(
        req.isPassiveXSBoolean().toString(), "false", "XSBooleanValue string was unexpected value");

    req.setIsPassive((Boolean) null);
    Assert.assertEquals(
        req.isPassive(), Boolean.FALSE, "Unexpected default value for boolean attribute found");
    Assert.assertNull(req.isPassiveXSBoolean(), "XSBooleanValue was not null");
  }