--- /dev/null
+/*\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/saml1/core/Assertions.h>\r
+\r
+using namespace opensaml::saml1;\r
+\r
+class AuthenticationStatementTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {\r
+ XMLCh* expectedAuthenticationMethod;\r
+ XMLCh* expectedAuthenticationInstant;\r
+\r
+public:\r
+ void setUp() {\r
+ expectedAuthenticationInstant=XMLString::transcode("1970-01-02T01:01:02.123Z");\r
+ expectedAuthenticationMethod=XMLString::transcode("trustme");\r
+ singleElementFile = data_path + "saml1/core/impl/singleAuthenticationStatement.xml";\r
+ singleElementOptionalAttributesFile = data_path + "saml1/core/impl/singleAuthenticationStatementAttributes.xml";\r
+ childElementsFile = data_path + "saml1/core/impl/AuthenticationStatementWithChildren.xml"; \r
+ SAMLObjectBaseTestCase::setUp();\r
+ }\r
+ \r
+ void tearDown() {\r
+ XMLString::release(&expectedAuthenticationInstant);\r
+ XMLString::release(&expectedAuthenticationMethod);\r
+ SAMLObjectBaseTestCase::tearDown();\r
+ }\r
+\r
+ void testSingleElementUnmarshall() {\r
+ auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));\r
+ AuthenticationStatement& as = dynamic_cast<AuthenticationStatement&>(*xo.get());\r
+ TSM_ASSERT("AuthenticationMethod attribute present", as.getAuthenticationMethod()==NULL);\r
+ TSM_ASSERT("AuthenticationInstant attribute present", as.getAuthenticationInstant()==NULL);\r
+\r
+ TSM_ASSERT("Subject element", as.getSubject()==NULL);\r
+ TSM_ASSERT("SubjectLocality element", as.getSubjectLocality()==NULL);\r
+ TSM_ASSERT_EQUALS("AuthorityBinding element count", 0, as.getAuthorityBindings().size());\r
+ }\r
+\r
+ void testSingleElementOptionalAttributesUnmarshall() {\r
+ auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));\r
+ AuthenticationStatement& as = dynamic_cast<AuthenticationStatement&>(*xo.get());\r
+\r
+ TSM_ASSERT_SAME_DATA("AuthenticationMethod attribute", expectedAuthenticationMethod, as.getAuthenticationMethod(), XMLString::stringLen(expectedAuthenticationMethod));\r
+ TSM_ASSERT_SAME_DATA("AuthenticationInstant attribute", expectedAuthenticationInstant, as.getAuthenticationInstant()->getRawData(), XMLString::stringLen(expectedAuthenticationInstant));\r
+ }\r
+\r
+ void testChildElementsUnmarshall() {\r
+ auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));\r
+ AuthenticationStatement& as = dynamic_cast<AuthenticationStatement&>(*xo.get());\r
+\r
+ TSM_ASSERT("Subject element", as.getSubject()!=NULL);\r
+ TSM_ASSERT("SubjectLocality element", as.getSubjectLocality()!=NULL);\r
+\r
+ TSM_ASSERT_EQUALS("AuthorityBinding element count", 2, as.getAuthorityBindings().size());\r
+ as.getAuthorityBindings().erase(as.getAuthorityBindings().begin());\r
+ TSM_ASSERT_EQUALS("AuthorityBinding element count", 1, as.getAuthorityBindings().size());\r
+ }\r
+\r
+ void testSingleElementMarshall() {\r
+ assertEquals(expectedDOM, AuthenticationStatementBuilder::buildAuthenticationStatement());\r
+ }\r
+\r
+ void testSingleElementOptionalAttributesMarshall() {\r
+ AuthenticationStatement* as=AuthenticationStatementBuilder::buildAuthenticationStatement();\r
+ as->setAuthenticationInstant(expectedAuthenticationInstant);\r
+ as->setAuthenticationMethod(expectedAuthenticationMethod);\r
+ assertEquals(expectedOptionalAttributesDOM, as);\r
+ }\r
+\r
+ void testChildElementsMarshall() {\r
+ AuthenticationStatement* as=AuthenticationStatementBuilder::buildAuthenticationStatement();\r
+ as->setSubject(SubjectBuilder::buildSubject());\r
+ as->setSubjectLocality(SubjectLocalityBuilder::buildSubjectLocality());\r
+ as->getAuthorityBindings().push_back(AuthorityBindingBuilder::buildAuthorityBinding());\r
+ as->getAuthorityBindings().push_back(AuthorityBindingBuilder::buildAuthorityBinding());\r
+ assertEquals(expectedChildElementsDOM, as);\r
+ }\r
+\r
+};\r