eb84555fcc7d0cf3a75bc767197dc8522cd78e3b
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / AuthnStatement20Test.h
1 /*
2  *  Copyright 2001-2007 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/saml2/core/Assertions.h>
19 #include <saml/util/SAMLConstants.h>
20
21 using namespace opensaml::saml2;
22
23 class AuthnStatement20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
24     DateTime* expectedAuthnInstant;
25     XMLCh* expectedSessionIndex;
26     DateTime* expectedSessionNotOnOrAfter;
27
28 public:
29     void setUp() {
30         expectedAuthnInstant = new DateTime(XMLString::transcode("1984-08-26T10:01:30.043Z"));
31         expectedAuthnInstant->parseDateTime();
32         expectedSessionIndex = (XMLString::transcode("abc123"));
33         expectedSessionNotOnOrAfter = new DateTime(XMLString::transcode("1984-08-26T10:11:30.043Z"));
34         expectedSessionNotOnOrAfter->parseDateTime();
35
36         singleElementFile = data_path + "saml2/core/impl/AuthnStatement.xml";
37         singleElementOptionalAttributesFile = data_path + "saml2/core/impl/AuthnStatementOptionalAttributes.xml";
38         childElementsFile  = data_path + "saml2/core/impl/AuthnStatementChildElements.xml";    
39         SAMLObjectBaseTestCase::setUp();
40     }
41     
42     void tearDown() {
43         delete expectedAuthnInstant;
44         XMLString::release(&expectedSessionIndex);
45         delete expectedSessionNotOnOrAfter;
46         SAMLObjectBaseTestCase::tearDown();
47     }
48
49     void testSingleElementUnmarshall() {
50         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
51         AuthnStatement* statement = dynamic_cast<AuthnStatement*>(xo.get());
52         TS_ASSERT(statement!=NULL);
53
54         TSM_ASSERT_EQUALS("AuthnInstant attribute", expectedAuthnInstant->getEpoch(), statement->getAuthnInstant()->getEpoch());
55         TS_ASSERT(statement->getSessionIndex()==NULL);
56         TS_ASSERT(statement->getSessionNotOnOrAfter()==NULL);
57
58         TS_ASSERT(statement->getSubjectLocality()==NULL);
59         TS_ASSERT(statement->getAuthnContext()==NULL);
60     }
61
62     void testSingleElementOptionalAttributesUnmarshall() {
63         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
64         AuthnStatement* statement = dynamic_cast<AuthnStatement*>(xo.get());
65         TS_ASSERT(statement!=NULL);
66
67         TSM_ASSERT_EQUALS("AuthnInstant attribute", expectedAuthnInstant->getEpoch(), statement->getAuthnInstant()->getEpoch());
68         assertEquals("SessionIndex attribute", expectedSessionIndex, statement->getSessionIndex());
69         TSM_ASSERT_EQUALS("SessionNotOnOrAfter attribute", expectedSessionNotOnOrAfter->getEpoch(), statement->getSessionNotOnOrAfter()->getEpoch());
70
71         TS_ASSERT(statement->getSubjectLocality()==NULL);
72         TS_ASSERT(statement->getAuthnContext()==NULL);
73
74     }
75
76     void testChildElementsUnmarshall() {
77         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
78         AuthnStatement* statement= dynamic_cast<AuthnStatement*>(xo.get());
79         TS_ASSERT(statement!=NULL);
80
81         TS_ASSERT(statement->getAuthnInstant()==NULL);
82         TS_ASSERT(statement->getSessionIndex()==NULL);
83         TS_ASSERT(statement->getSessionNotOnOrAfter()==NULL);
84
85         TS_ASSERT(statement->getSubjectLocality()!=NULL);
86         TS_ASSERT(statement->getAuthnContext()!=NULL);
87
88     }
89
90     void testSingleElementMarshall() {
91         AuthnStatement* statement=AuthnStatementBuilder::buildAuthnStatement();
92         statement->setAuthnInstant(expectedAuthnInstant);
93         assertEquals(expectedDOM, statement);
94     }
95
96     void testSingleElementOptionalAttributesMarshall() {
97         AuthnStatement* statement=AuthnStatementBuilder::buildAuthnStatement();
98         statement->setAuthnInstant(expectedAuthnInstant);
99         statement->setSessionIndex(expectedSessionIndex);
100         statement->setSessionNotOnOrAfter(expectedSessionNotOnOrAfter);
101         assertEquals(expectedOptionalAttributesDOM, statement);
102     }
103
104     void testChildElementsMarshall() {
105         AuthnStatement* statement=AuthnStatementBuilder::buildAuthnStatement();
106         statement->setSubjectLocality(SubjectLocalityBuilder::buildSubjectLocality());
107         statement->setAuthnContext(AuthnContextBuilder::buildAuthnContext());
108         assertEquals(expectedChildElementsDOM, statement);
109     }
110
111 };