2 * Copyright 2001-2006 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 #include "internal.h"
\r
18 #include <saml/saml2/core/Protocols.h>
\r
19 #include <saml/util/SAMLConstants.h>
\r
21 using namespace opensaml::saml2p;
\r
22 using namespace opensaml::saml2;
\r
24 class RequestedAuthnContext20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
\r
25 XMLCh* expectedComparison;
\r
29 expectedComparison = XMLString::transcode("exact");
\r
31 singleElementFile = data_path + "saml2/core/impl/RequestedAuthnContext.xml";
\r
32 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/RequestedAuthnContextOptionalAttributes.xml";
\r
33 childElementsFile = data_path + "saml2/core/impl/RequestedAuthnContextChildElements.xml";
\r
34 SAMLObjectBaseTestCase::setUp();
\r
38 XMLString::release(&expectedComparison);
\r
39 SAMLObjectBaseTestCase::tearDown();
\r
42 void testSingleElementUnmarshall() {
\r
43 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
\r
44 RequestedAuthnContext* rac = dynamic_cast<RequestedAuthnContext*>(xo.get());
\r
45 TS_ASSERT(rac !=NULL);
\r
46 TS_ASSERT(rac->getComparison()==NULL);
\r
48 TSM_ASSERT_EQUALS("# of AuthnContextClassRef child elements", 0, rac->getAuthnContextClassRefs().size());
\r
49 TSM_ASSERT_EQUALS("# of AuthnContextDeclRef child elements", 0, rac->getAuthnContextDeclRefs().size());
\r
52 void testSingleElementOptionalAttributesUnmarshall() {
\r
53 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
\r
54 RequestedAuthnContext* rac = dynamic_cast<RequestedAuthnContext*>(xo.get());
\r
55 TS_ASSERT(rac!=NULL);
\r
56 assertEquals("Comparison attribute", expectedComparison, rac->getComparison());
\r
58 TSM_ASSERT_EQUALS("# of AuthnContextClassRef child elements", 0, rac->getAuthnContextClassRefs().size());
\r
59 TSM_ASSERT_EQUALS("# of AuthnContextDeclRef child elements", 0, rac->getAuthnContextDeclRefs().size());
\r
62 void testChildElementsUnmarshall() {
\r
63 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
\r
64 RequestedAuthnContext* rac = dynamic_cast<RequestedAuthnContext*>(xo.get());
\r
65 TS_ASSERT(rac !=NULL);
\r
66 TS_ASSERT(rac->getComparison()==NULL);
\r
68 TSM_ASSERT_EQUALS("# of AuthnContextClassRef child elements", 3, rac->getAuthnContextClassRefs().size());
\r
69 TSM_ASSERT_EQUALS("# of AuthnContextDeclRef child elements", 0, rac->getAuthnContextDeclRefs().size());
\r
72 void testSingleElementMarshall() {
\r
73 RequestedAuthnContext* rac=RequestedAuthnContextBuilder::buildRequestedAuthnContext();
\r
74 assertEquals(expectedDOM, rac);
\r
77 void testSingleElementOptionalAttributesMarshall() {
\r
78 RequestedAuthnContext* rac=RequestedAuthnContextBuilder::buildRequestedAuthnContext();
\r
79 rac->setComparison(expectedComparison);
\r
80 assertEquals(expectedOptionalAttributesDOM, rac);
\r
83 void testChildElementsMarshall() {
\r
84 RequestedAuthnContext* rac=RequestedAuthnContextBuilder::buildRequestedAuthnContext();
\r
85 // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
\r
86 Namespace* ns = new Namespace(opensaml::SAMLConstants::SAML20_NS, opensaml::SAMLConstants::SAML20_PREFIX);
\r
87 rac->addNamespace(*ns);
\r
88 rac->getAuthnContextClassRefs().push_back(AuthnContextClassRefBuilder::buildAuthnContextClassRef());
\r
89 rac->getAuthnContextClassRefs().push_back(AuthnContextClassRefBuilder::buildAuthnContextClassRef());
\r
90 rac->getAuthnContextClassRefs().push_back(AuthnContextClassRefBuilder::buildAuthnContextClassRef());
\r
91 assertEquals(expectedChildElementsDOM, rac);
\r