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