Convert from NULL macro to nullptr, remove unused zlib code.
[shibboleth/cpp-opensaml.git] / samltest / saml1 / core / impl / AuthenticationStatementTest.h
1 /*
2  *  Copyright 2001-2010 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "internal.h"
18 #include <saml/saml1/core/Assertions.h>
19
20 using namespace opensaml::saml1;
21
22 class AuthenticationStatementTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
23     XMLCh* expectedAuthenticationMethod;
24     XMLCh* expectedAuthenticationInstant;
25
26 public:
27     void setUp() {
28         expectedAuthenticationInstant=XMLString::transcode("1970-01-02T01:01:02.123Z");
29         expectedAuthenticationMethod=XMLString::transcode("trustme");
30         singleElementFile = data_path + "saml1/core/impl/singleAuthenticationStatement.xml";
31         singleElementOptionalAttributesFile = data_path + "saml1/core/impl/singleAuthenticationStatementAttributes.xml";
32         childElementsFile  = data_path + "saml1/core/impl/AuthenticationStatementWithChildren.xml";    
33         SAMLObjectBaseTestCase::setUp();
34     }
35     
36     void tearDown() {
37         XMLString::release(&expectedAuthenticationInstant);
38         XMLString::release(&expectedAuthenticationMethod);
39         SAMLObjectBaseTestCase::tearDown();
40     }
41
42     void testSingleElementUnmarshall() {
43         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
44         AuthenticationStatement& as = dynamic_cast<AuthenticationStatement&>(*xo.get());
45         TSM_ASSERT("AuthenticationMethod attribute present", as.getAuthenticationMethod()==nullptr);
46         TSM_ASSERT("AuthenticationInstant attribute present", as.getAuthenticationInstant()==nullptr);
47
48         TSM_ASSERT("Subject element", as.getSubject()==nullptr);
49         TSM_ASSERT("SubjectLocality element", as.getSubjectLocality()==nullptr);
50         TSM_ASSERT_EQUALS("AuthorityBinding element count", 0, as.getAuthorityBindings().size());
51     }
52
53     void testSingleElementOptionalAttributesUnmarshall() {
54         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
55         AuthenticationStatement& as = dynamic_cast<AuthenticationStatement&>(*xo.get());
56
57         assertEquals("AuthenticationMethod attribute", expectedAuthenticationMethod, as.getAuthenticationMethod());
58         assertEquals("AuthenticationInstant attribute", expectedAuthenticationInstant, as.getAuthenticationInstant()->getRawData());
59     }
60
61     void testChildElementsUnmarshall() {
62         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
63         AuthenticationStatement& as1 = dynamic_cast<AuthenticationStatement&>(*xo.get());
64         as1.releaseThisAndChildrenDOM();
65         auto_ptr<AuthenticationStatement> as2(as1.cloneAuthenticationStatement());
66         AuthenticationStatement& as=*as2.get();
67
68         TSM_ASSERT("Subject element", as.getSubject()!=nullptr);
69         TSM_ASSERT("SubjectLocality element", as.getSubjectLocality()!=nullptr);
70
71         TSM_ASSERT_EQUALS("AuthorityBinding element count", 2, as.getAuthorityBindings().size());
72         as.getAuthorityBindings().erase(as.getAuthorityBindings().begin());
73         TSM_ASSERT_EQUALS("AuthorityBinding element count", 1, as.getAuthorityBindings().size());
74     }
75
76     void testSingleElementMarshall() {
77         assertEquals(expectedDOM, AuthenticationStatementBuilder::buildAuthenticationStatement());
78     }
79
80     void testSingleElementOptionalAttributesMarshall() {
81         AuthenticationStatement* as=AuthenticationStatementBuilder::buildAuthenticationStatement();
82         as->setAuthenticationInstant(expectedAuthenticationInstant);
83         as->setAuthenticationMethod(expectedAuthenticationMethod);
84         assertEquals(expectedOptionalAttributesDOM, as);
85     }
86
87     void testChildElementsMarshall() {
88         AuthenticationStatement* as=AuthenticationStatementBuilder::buildAuthenticationStatement();
89         as->setSubject(SubjectBuilder::buildSubject());
90         as->setSubjectLocality(SubjectLocalityBuilder::buildSubjectLocality());
91         as->getAuthorityBindings().push_back(AuthorityBindingBuilder::buildAuthorityBinding());
92         as->getAuthorityBindings().push_back(AuthorityBindingBuilder::buildAuthorityBinding());
93         assertEquals(expectedChildElementsDOM, as);
94     }
95
96 };