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/saml1/core/Assertions.h>
\r
20 using namespace opensaml::saml1;
\r
22 class AuthenticationStatementTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
\r
23 XMLCh* expectedAuthenticationMethod;
\r
24 XMLCh* expectedAuthenticationInstant;
\r
28 expectedAuthenticationInstant=XMLString::transcode("1970-01-02T01:01:02.123Z");
\r
29 expectedAuthenticationMethod=XMLString::transcode("trustme");
\r
30 singleElementFile = data_path + "saml1/core/impl/singleAuthenticationStatement.xml";
\r
31 singleElementOptionalAttributesFile = data_path + "saml1/core/impl/singleAuthenticationStatementAttributes.xml";
\r
32 childElementsFile = data_path + "saml1/core/impl/AuthenticationStatementWithChildren.xml";
\r
33 SAMLObjectBaseTestCase::setUp();
\r
37 XMLString::release(&expectedAuthenticationInstant);
\r
38 XMLString::release(&expectedAuthenticationMethod);
\r
39 SAMLObjectBaseTestCase::tearDown();
\r
42 void testSingleElementUnmarshall() {
\r
43 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
\r
44 AuthenticationStatement& as = dynamic_cast<AuthenticationStatement&>(*xo.get());
\r
45 TSM_ASSERT("AuthenticationMethod attribute present", as.getAuthenticationMethod()==NULL);
\r
46 TSM_ASSERT("AuthenticationInstant attribute present", as.getAuthenticationInstant()==NULL);
\r
48 TSM_ASSERT("Subject element", as.getSubject()==NULL);
\r
49 TSM_ASSERT("SubjectLocality element", as.getSubjectLocality()==NULL);
\r
50 TSM_ASSERT_EQUALS("AuthorityBinding element count", 0, as.getAuthorityBindings().size());
\r
53 void testSingleElementOptionalAttributesUnmarshall() {
\r
54 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
\r
55 AuthenticationStatement& as = dynamic_cast<AuthenticationStatement&>(*xo.get());
\r
57 TSM_ASSERT_SAME_DATA("AuthenticationMethod attribute", expectedAuthenticationMethod, as.getAuthenticationMethod(), XMLString::stringLen(expectedAuthenticationMethod));
\r
58 TSM_ASSERT_SAME_DATA("AuthenticationInstant attribute", expectedAuthenticationInstant, as.getAuthenticationInstant()->getRawData(), XMLString::stringLen(expectedAuthenticationInstant));
\r
61 void testChildElementsUnmarshall() {
\r
62 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
\r
63 AuthenticationStatement& as1 = dynamic_cast<AuthenticationStatement&>(*xo.get());
\r
64 as1.releaseThisAndChildrenDOM();
\r
65 auto_ptr<AuthenticationStatement> as2(as1.cloneAuthenticationStatement());
\r
66 AuthenticationStatement& as=*as2.get();
\r
68 TSM_ASSERT("Subject element", as.getSubject()!=NULL);
\r
69 TSM_ASSERT("SubjectLocality element", as.getSubjectLocality()!=NULL);
\r
71 TSM_ASSERT_EQUALS("AuthorityBinding element count", 2, as.getAuthorityBindings().size());
\r
72 as.getAuthorityBindings().erase(as.getAuthorityBindings().begin());
\r
73 TSM_ASSERT_EQUALS("AuthorityBinding element count", 1, as.getAuthorityBindings().size());
\r
76 void testSingleElementMarshall() {
\r
77 assertEquals(expectedDOM, AuthenticationStatementBuilder::buildAuthenticationStatement());
\r
80 void testSingleElementOptionalAttributesMarshall() {
\r
81 AuthenticationStatement* as=AuthenticationStatementBuilder::buildAuthenticationStatement();
\r
82 as->setAuthenticationInstant(expectedAuthenticationInstant);
\r
83 as->setAuthenticationMethod(expectedAuthenticationMethod);
\r
84 assertEquals(expectedOptionalAttributesDOM, as);
\r
87 void testChildElementsMarshall() {
\r
88 AuthenticationStatement* as=AuthenticationStatementBuilder::buildAuthenticationStatement();
\r
89 as->setSubject(SubjectBuilder::buildSubject());
\r
90 as->setSubjectLocality(SubjectLocalityBuilder::buildSubjectLocality());
\r
91 as->getAuthorityBindings().push_back(AuthorityBindingBuilder::buildAuthorityBinding());
\r
92 as->getAuthorityBindings().push_back(AuthorityBindingBuilder::buildAuthorityBinding());
\r
93 assertEquals(expectedChildElementsDOM, as);
\r