Convert from NULL macro to nullptr, remove unused zlib code.
[shibboleth/cpp-opensaml.git] / samltest / saml1 / core / impl / AssertionTest.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 AssertionTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
23     int expectedMinorVersion;
24     XMLCh* expectedIssuer;
25     DateTime* expectedIssueInstant;
26     XMLCh* expectedID;
27
28 public:
29     void setUp() {
30         expectedID=XMLString::transcode("ident");
31         expectedMinorVersion=1;
32         expectedIssueInstant=new DateTime(XMLString::transcode("1970-01-02T01:01:02.100Z"));
33         expectedIssueInstant->parseDateTime();
34         expectedIssuer=XMLString::transcode("issuer");
35         singleElementFile = data_path + "saml1/core/impl/singleAssertion.xml";
36         singleElementOptionalAttributesFile = data_path + "saml1/core/impl/singleAssertionAttributes.xml";
37         childElementsFile  = data_path + "saml1/core/impl/AssertionWithChildren.xml";    
38         SAMLObjectBaseTestCase::setUp();
39     }
40     
41     void tearDown() {
42         XMLString::release(&expectedID);
43         XMLString::release(&expectedIssuer);
44         delete expectedIssueInstant;
45         SAMLObjectBaseTestCase::tearDown();
46     }
47
48     void testSingleElementUnmarshall() {
49         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
50         Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());
51         TSM_ASSERT("Issuer attribute", assertion.getIssuer()==nullptr);
52         TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), assertion.getIssueInstant()->getEpoch());
53         assertEquals("ID attribute", expectedID, assertion.getAssertionID());
54
55         TSM_ASSERT("Conditions element", assertion.getConditions()==nullptr);
56         TSM_ASSERT("Advice element", assertion.getAdvice()==nullptr);
57
58         TSM_ASSERT_EQUALS("Statement element count", 0, assertion.getStatements().size());
59         TSM_ASSERT_EQUALS("SubjectStatements element count", 0, assertion.getSubjectStatements().size());
60         TSM_ASSERT_EQUALS("AttributeStatements element count", 0, assertion.getAttributeStatements().size());
61         TSM_ASSERT_EQUALS("AuthenticationStatements element count", 0, assertion.getAuthenticationStatements().size());
62         TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 0, assertion.getAuthorizationDecisionStatements().size());
63     }
64
65     void testSingleElementOptionalAttributesUnmarshall() {
66         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
67         Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());
68
69         assertEquals("Issuer attribute", expectedIssuer, assertion.getIssuer());
70         TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), assertion.getIssueInstant()->getEpoch());
71         assertEquals("ID attribute", expectedID, assertion.getAssertionID());
72         TSM_ASSERT_EQUALS("Issuer expectedMinorVersion", expectedMinorVersion, assertion.getMinorVersion().second);
73
74         TSM_ASSERT("Conditions element", assertion.getConditions()==nullptr);
75         TSM_ASSERT("Advice element", assertion.getAdvice()==nullptr);
76
77         TSM_ASSERT_EQUALS("Statement element count", 0, assertion.getStatements().size());
78         TSM_ASSERT_EQUALS("SubjectStatements element count", 0, assertion.getSubjectStatements().size());
79         TSM_ASSERT_EQUALS("AttributeStatements element count", 0, assertion.getAttributeStatements().size());
80         TSM_ASSERT_EQUALS("AuthenticationStatements element count", 0, assertion.getAuthenticationStatements().size());
81         TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 0, assertion.getAuthorizationDecisionStatements().size());
82     }
83
84     void testChildElementsUnmarshall() {
85         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
86         Assertion& assertion = dynamic_cast<Assertion&>(*xo.get());
87
88         TSM_ASSERT("Issuer attribute", assertion.getIssuer()==nullptr);
89         TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), assertion.getIssueInstant()->getEpoch());
90         assertEquals("ID attribute", expectedID, assertion.getAssertionID());
91
92         TSM_ASSERT("Conditions element null", assertion.getConditions()!=nullptr);
93         TSM_ASSERT("Advice element null", assertion.getAdvice()!=nullptr);
94
95         TSM_ASSERT_EQUALS("AuthenticationStatements element count", 2, assertion.getAuthenticationStatements().size());
96         TSM_ASSERT_EQUALS("AttributeStatements element count", 3, assertion.getAttributeStatements().size());
97         TSM_ASSERT_EQUALS("AuthorizationDecisionStatements element count", 3, assertion.getAuthorizationDecisionStatements().size());
98     }
99
100     void testSingleElementMarshall() {
101         Assertion* assertion=AssertionBuilder::buildAssertion();
102         assertion->setAssertionID(expectedID);
103         assertion->setIssueInstant(expectedIssueInstant);
104         assertEquals(expectedDOM, assertion);
105     }
106
107     void testSingleElementOptionalAttributesMarshall() {
108         Assertion* assertion=AssertionBuilder::buildAssertion();
109         assertion->setIssueInstant(expectedIssueInstant);
110         assertion->setAssertionID(expectedID);
111         assertion->setIssuer(expectedIssuer);
112         assertEquals(expectedOptionalAttributesDOM, assertion);
113     }
114
115     void testChildElementsMarshall() {
116         Assertion* assertion=AssertionBuilder::buildAssertion();
117         assertion->setIssueInstant(expectedIssueInstant);
118         assertion->setAssertionID(expectedID);
119         assertion->setConditions(ConditionsBuilder::buildConditions());
120         assertion->setAdvice(AdviceBuilder::buildAdvice());
121         assertion->getAuthenticationStatements().push_back(
122             AuthenticationStatementBuilder::buildAuthenticationStatement()
123             );
124         assertion->getAuthorizationDecisionStatements().push_back(
125             AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()
126             );
127         assertion->getAttributeStatements().push_back(
128             AttributeStatementBuilder::buildAttributeStatement()
129             );
130         assertion->getAuthenticationStatements().push_back(
131             AuthenticationStatementBuilder::buildAuthenticationStatement()
132             );
133         assertion->getAuthorizationDecisionStatements().push_back(
134             AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()
135             );
136         assertion->getAttributeStatements().push_back(
137             AttributeStatementBuilder::buildAttributeStatement()
138             );
139         assertion->getAuthorizationDecisionStatements().push_back(
140             AuthorizationDecisionStatementBuilder::buildAuthorizationDecisionStatement()
141             );
142         assertion->getAttributeStatements().push_back(
143             AttributeStatementBuilder::buildAttributeStatement()
144             );
145         assertEquals(expectedChildElementsDOM, assertion);
146     }
147
148 };