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