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