SAML 2.0 Core Assertion namespace unit tests.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / AuthnContext20Test.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 AuthnContext20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {\r
24 \r
25 public:\r
26     void setUp() {\r
27         singleElementFile = data_path + "saml2/core/impl/AuthnContext.xml";\r
28         childElementsFile  = data_path + "saml2/core/impl/AuthnContextChildElements.xml";    \r
29         SAMLObjectBaseTestCase::setUp();\r
30     }\r
31     \r
32     void tearDown() {\r
33         SAMLObjectBaseTestCase::tearDown();\r
34     }\r
35 \r
36     void testSingleElementUnmarshall() {\r
37         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));\r
38         AuthnContext* ac = dynamic_cast<AuthnContext*>(xo.get());\r
39         TS_ASSERT(ac!=NULL);\r
40 \r
41         TS_ASSERT(ac->getAuthnContextClassRef()==NULL);\r
42         TS_ASSERT(ac->getAuthnContextDecl()==NULL);\r
43         TS_ASSERT(ac->getAuthnContextDeclRef()==NULL);\r
44         TSM_ASSERT_EQUALS("# of AuthenticatingAuthority child elements", 0, ac->getAuthenticatingAuthoritys().size());\r
45     }\r
46 \r
47     void testChildElementsUnmarshall() {\r
48         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));\r
49         AuthnContext* ac= dynamic_cast<AuthnContext*>(xo.get());\r
50         TS_ASSERT(ac!=NULL);\r
51 \r
52         TS_ASSERT(ac->getAuthnContextClassRef()!=NULL);\r
53         TS_ASSERT(ac->getAuthnContextDecl()==NULL);\r
54         TS_ASSERT(ac->getAuthnContextDeclRef()!=NULL);\r
55         TSM_ASSERT_EQUALS("# of AuthenticatingAuthority child elements", 2, ac->getAuthenticatingAuthoritys().size());\r
56     }\r
57 \r
58     void testSingleElementMarshall() {\r
59         AuthnContext* ac=AuthnContextBuilder::buildAuthnContext();\r
60         assertEquals(expectedDOM, ac);\r
61     }\r
62 \r
63     void testChildElementsMarshall() {\r
64         AuthnContext* ac=AuthnContextBuilder::buildAuthnContext();\r
65         ac->setAuthnContextClassRef(AuthnContextClassRefBuilder::buildAuthnContextClassRef());\r
66         ac->setAuthnContextDeclRef(AuthnContextDeclRefBuilder::buildAuthnContextDeclRef());\r
67         ac->getAuthenticatingAuthoritys().push_back(AuthenticatingAuthorityBuilder::buildAuthenticatingAuthority());\r
68         ac->getAuthenticatingAuthoritys().push_back(AuthenticatingAuthorityBuilder::buildAuthenticatingAuthority());\r
69         assertEquals(expectedChildElementsDOM, ac);\r
70     }\r
71 \r
72 };\r