SAML 2.0 Core Assertion namespace unit tests.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / AuthzDecisionStatement20Test.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/saml2/core/Assertions.h>\r
19 #include <saml/util/SAMLConstants.h>\r
20 \r
21 using namespace opensaml::saml2;\r
22 \r
23 class AuthzDecisionStatement20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {\r
24     XMLCh* expectedResource; \r
25     const XMLCh* expectedDecision; \r
26 \r
27 public:\r
28     void setUp() {\r
29         expectedResource = XMLString::transcode("urn:string:resource"); \r
30         expectedDecision = AuthzDecisionStatement::DECISION_PERMIT;\r
31 \r
32         singleElementFile = data_path + "saml2/core/impl/AuthzDecisionStatement.xml";\r
33         childElementsFile  = data_path + "saml2/core/impl/AuthzDecisionStatementChildElements.xml";    \r
34         SAMLObjectBaseTestCase::setUp();\r
35     }\r
36     \r
37     void tearDown() {\r
38         XMLString::release(&expectedResource);\r
39         SAMLObjectBaseTestCase::tearDown();\r
40     }\r
41 \r
42     void testSingleElementUnmarshall() {\r
43         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));\r
44         AuthzDecisionStatement* statement = dynamic_cast<AuthzDecisionStatement*>(xo.get());\r
45         TS_ASSERT(statement!=NULL);\r
46 \r
47         assertEquals("Resource attribute", expectedResource, statement->getResource());\r
48         assertEquals("Decision attribute", expectedDecision, statement->getDecision());\r
49 \r
50         TSM_ASSERT_EQUALS("# of Action child elements", 0, statement->getActions().size());\r
51         TS_ASSERT(statement->getEvidence()==NULL);\r
52     }\r
53 \r
54     void testChildElementsUnmarshall() {\r
55         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));\r
56         AuthzDecisionStatement* statement= dynamic_cast<AuthzDecisionStatement*>(xo.get());\r
57         TS_ASSERT(statement!=NULL);\r
58 \r
59         assertEquals("Resource attribute", NULL, statement->getResource());\r
60         assertEquals("Decision attribute", NULL, statement->getDecision());\r
61 \r
62         TSM_ASSERT_EQUALS("# of Action child elements", 3, statement->getActions().size());\r
63         TS_ASSERT(statement->getEvidence()!=NULL);\r
64     }\r
65 \r
66     void testSingleElementMarshall() {\r
67         AuthzDecisionStatement* statement=AuthzDecisionStatementBuilder::buildAuthzDecisionStatement();\r
68         statement->setResource(expectedResource);\r
69         statement->setDecision(expectedDecision);\r
70         assertEquals(expectedDOM, statement);\r
71     }\r
72 \r
73     void testChildElementsMarshall() {\r
74         AuthzDecisionStatement* statement=AuthzDecisionStatementBuilder::buildAuthzDecisionStatement();\r
75         statement->getActions().push_back(ActionBuilder::buildAction());\r
76         statement->getActions().push_back(ActionBuilder::buildAction());\r
77         statement->getActions().push_back(ActionBuilder::buildAction());\r
78         statement->setEvidence(EvidenceBuilder::buildEvidence());\r
79         assertEquals(expectedChildElementsDOM, statement);\r
80     }\r
81 \r
82 };\r