09416a4debeb50ec1fcb7c9a78b60fdc053d1b2d
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / ProxyRestriction20Test.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 ProxyRestriction20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {\r
24     int expectedCount;\r
25 \r
26 public:\r
27     void setUp() {\r
28         expectedCount = 5;\r
29         singleElementFile = data_path + "saml2/core/impl/ProxyRestriction.xml";\r
30         singleElementOptionalAttributesFile = data_path + "saml2/core/impl/ProxyRestrictionOptionalAttributes.xml";\r
31         childElementsFile  = data_path + "saml2/core/impl/ProxyRestrictionChildElements.xml";    \r
32         SAMLObjectBaseTestCase::setUp();\r
33     }\r
34     \r
35     void tearDown() {\r
36         SAMLObjectBaseTestCase::tearDown();\r
37     }\r
38 \r
39     void testSingleElementUnmarshall() {\r
40         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));\r
41         ProxyRestriction* pr = dynamic_cast<ProxyRestriction*>(xo.get());\r
42         TS_ASSERT(pr!=NULL);\r
43 \r
44         TSM_ASSERT_EQUALS("Count attribute presence", false, pr->getCount().first);\r
45         TSM_ASSERT_EQUALS("# of Audience child elements", 0, pr->getAudiences().size());\r
46     }\r
47 \r
48     void testSingleElementOptionalAttributesUnmarshall() {\r
49         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));\r
50         ProxyRestriction* pr = dynamic_cast<ProxyRestriction*>(xo.get());\r
51         TS_ASSERT(pr!=NULL);\r
52 \r
53         TSM_ASSERT_EQUALS("Count attribute presence", true, pr->getCount().first);\r
54         TSM_ASSERT_EQUALS("Count attribute value", expectedCount, pr->getCount().second);\r
55         TSM_ASSERT_EQUALS("# of Audience child elements", 0, pr->getAudiences().size());\r
56     }\r
57 \r
58     void testChildElementsUnmarshall() {\r
59         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));\r
60         ProxyRestriction* pr= dynamic_cast<ProxyRestriction*>(xo.get());\r
61         TS_ASSERT(pr!=NULL);\r
62 \r
63         TSM_ASSERT_EQUALS("Count attribute presence", false, pr->getCount().first);\r
64         TSM_ASSERT_EQUALS("# of Audience child elements", 2, pr->getAudiences().size());\r
65     }\r
66 \r
67     void testSingleElementMarshall() {\r
68         ProxyRestriction* pr=ProxyRestrictionBuilder::buildProxyRestriction();\r
69         assertEquals(expectedDOM, pr);\r
70     }\r
71 \r
72     void testSingleElementOptionalAttributesMarshall() {\r
73         ProxyRestriction* pr=ProxyRestrictionBuilder::buildProxyRestriction();\r
74         pr->setCount(expectedCount);\r
75         assertEquals(expectedOptionalAttributesDOM, pr);\r
76     }\r
77 \r
78     void testChildElementsMarshall() {\r
79         ProxyRestriction* pr=ProxyRestrictionBuilder::buildProxyRestriction();\r
80         pr->getAudiences().push_back(AudienceBuilder::buildAudience());\r
81         pr->getAudiences().push_back(AudienceBuilder::buildAudience());\r
82         assertEquals(expectedChildElementsDOM, pr);\r
83     }\r
84 \r
85 };\r