2 * Copyright 2001-2007 Internet2
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <saml/saml2/core/Assertions.h>
19 #include <saml/util/SAMLConstants.h>
21 using namespace opensaml::saml2;
23 class AuthzDecisionStatement20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
24 XMLCh* expectedResource;
25 const XMLCh* expectedDecision;
29 expectedResource = XMLString::transcode("urn:string:resource");
30 expectedDecision = AuthzDecisionStatement::DECISION_PERMIT;
32 singleElementFile = data_path + "saml2/core/impl/AuthzDecisionStatement.xml";
33 childElementsFile = data_path + "saml2/core/impl/AuthzDecisionStatementChildElements.xml";
34 SAMLObjectBaseTestCase::setUp();
38 XMLString::release(&expectedResource);
39 SAMLObjectBaseTestCase::tearDown();
42 void testSingleElementUnmarshall() {
43 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
44 AuthzDecisionStatement* statement = dynamic_cast<AuthzDecisionStatement*>(xo.get());
45 TS_ASSERT(statement!=NULL);
47 assertEquals("Resource attribute", expectedResource, statement->getResource());
48 assertEquals("Decision attribute", expectedDecision, statement->getDecision());
50 TSM_ASSERT_EQUALS("# of Action child elements", 0, statement->getActions().size());
51 TS_ASSERT(statement->getEvidence()==NULL);
54 void testChildElementsUnmarshall() {
55 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
56 AuthzDecisionStatement* statement= dynamic_cast<AuthzDecisionStatement*>(xo.get());
57 TS_ASSERT(statement!=NULL);
59 assertEquals("Resource attribute", NULL, statement->getResource());
60 assertEquals("Decision attribute", NULL, statement->getDecision());
62 TSM_ASSERT_EQUALS("# of Action child elements", 3, statement->getActions().size());
63 TS_ASSERT(statement->getEvidence()!=NULL);
66 void testSingleElementMarshall() {
67 AuthzDecisionStatement* statement=AuthzDecisionStatementBuilder::buildAuthzDecisionStatement();
68 statement->setResource(expectedResource);
69 statement->setDecision(expectedDecision);
70 assertEquals(expectedDOM, statement);
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);