SAML 2.0 Core Assertion namespace unit tests.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / AuthzDecisionStatement20Test.h
diff --git a/samltest/saml2/core/impl/AuthzDecisionStatement20Test.h b/samltest/saml2/core/impl/AuthzDecisionStatement20Test.h
new file mode 100644 (file)
index 0000000..fb0d5fd
--- /dev/null
@@ -0,0 +1,82 @@
+/*\r
+ *  Copyright 2001-2006 Internet2\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+\r
+#include "internal.h"\r
+#include <saml/saml2/core/Assertions.h>\r
+#include <saml/util/SAMLConstants.h>\r
+\r
+using namespace opensaml::saml2;\r
+\r
+class AuthzDecisionStatement20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {\r
+    XMLCh* expectedResource; \r
+    const XMLCh* expectedDecision; \r
+\r
+public:\r
+    void setUp() {\r
+        expectedResource = XMLString::transcode("urn:string:resource"); \r
+        expectedDecision = AuthzDecisionStatement::DECISION_PERMIT;\r
+\r
+        singleElementFile = data_path + "saml2/core/impl/AuthzDecisionStatement.xml";\r
+        childElementsFile  = data_path + "saml2/core/impl/AuthzDecisionStatementChildElements.xml";    \r
+        SAMLObjectBaseTestCase::setUp();\r
+    }\r
+    \r
+    void tearDown() {\r
+        XMLString::release(&expectedResource);\r
+        SAMLObjectBaseTestCase::tearDown();\r
+    }\r
+\r
+    void testSingleElementUnmarshall() {\r
+        auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));\r
+        AuthzDecisionStatement* statement = dynamic_cast<AuthzDecisionStatement*>(xo.get());\r
+        TS_ASSERT(statement!=NULL);\r
+\r
+        assertEquals("Resource attribute", expectedResource, statement->getResource());\r
+        assertEquals("Decision attribute", expectedDecision, statement->getDecision());\r
+\r
+        TSM_ASSERT_EQUALS("# of Action child elements", 0, statement->getActions().size());\r
+        TS_ASSERT(statement->getEvidence()==NULL);\r
+    }\r
+\r
+    void testChildElementsUnmarshall() {\r
+        auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));\r
+        AuthzDecisionStatement* statement= dynamic_cast<AuthzDecisionStatement*>(xo.get());\r
+        TS_ASSERT(statement!=NULL);\r
+\r
+        assertEquals("Resource attribute", NULL, statement->getResource());\r
+        assertEquals("Decision attribute", NULL, statement->getDecision());\r
+\r
+        TSM_ASSERT_EQUALS("# of Action child elements", 3, statement->getActions().size());\r
+        TS_ASSERT(statement->getEvidence()!=NULL);\r
+    }\r
+\r
+    void testSingleElementMarshall() {\r
+        AuthzDecisionStatement* statement=AuthzDecisionStatementBuilder::buildAuthzDecisionStatement();\r
+        statement->setResource(expectedResource);\r
+        statement->setDecision(expectedDecision);\r
+        assertEquals(expectedDOM, statement);\r
+    }\r
+\r
+    void testChildElementsMarshall() {\r
+        AuthzDecisionStatement* statement=AuthzDecisionStatementBuilder::buildAuthzDecisionStatement();\r
+        statement->getActions().push_back(ActionBuilder::buildAction());\r
+        statement->getActions().push_back(ActionBuilder::buildAction());\r
+        statement->getActions().push_back(ActionBuilder::buildAction());\r
+        statement->setEvidence(EvidenceBuilder::buildEvidence());\r
+        assertEquals(expectedChildElementsDOM, statement);\r
+    }\r
+\r
+};\r