3b6c054c44822f63ba7bf3382c9a9e2e73819e9f
[shibboleth/cpp-opensaml.git] / samltest / saml1 / core / impl / AttributeStatementTest.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/saml1/core/Assertions.h>\r
19 \r
20 using namespace opensaml::saml1;\r
21 \r
22 class AttributeStatementTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {\r
23 public:\r
24     void setUp() {\r
25         singleElementFile = data_path + "saml1/core/impl/singleAttributeStatement.xml";\r
26         childElementsFile = data_path + "saml1/core/impl/AttributeStatementWithChildren.xml";\r
27         SAMLObjectBaseTestCase::setUp();\r
28     }\r
29     \r
30     void tearDown() {\r
31         SAMLObjectBaseTestCase::tearDown();\r
32     }\r
33 \r
34     void testSingleElementUnmarshall() {\r
35         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));\r
36         AttributeStatement& as = dynamic_cast<AttributeStatement&>(*xo.get());\r
37         TSM_ASSERT("<Subject> element present", as.getSubject()==NULL);\r
38         TSM_ASSERT_EQUALS("Non zero count of <Attribute> elements", 0, as.getAttributes().size());\r
39     }\r
40 \r
41     void testChildElementsUnmarshall() {\r
42         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));\r
43         AttributeStatement& as = dynamic_cast<AttributeStatement&>(*xo.get());\r
44         TSM_ASSERT("<Subject> element not present", as.getSubject()!=NULL);\r
45         TSM_ASSERT_EQUALS("count of <Attribute> elements", 5, as.getAttributes().size());\r
46 \r
47         as.getAttributes().erase(as.getAttributes().begin());\r
48         TSM_ASSERT_EQUALS("count of <Attribute> elements after single remove", 4, as.getAttributes().size());\r
49 \r
50         as.getAttributes().erase(as.getAttributes().begin());\r
51         as.getAttributes().erase(as.getAttributes().begin()+1);\r
52         TSM_ASSERT_EQUALS("count of <Attribute> elements after double remove", 2, as.getAttributes().size());\r
53     }\r
54 \r
55     void testSingleElementMarshall() {\r
56         assertEquals(expectedDOM, AttributeStatementBuilder::buildAttributeStatement());\r
57     }\r
58 \r
59     void testChildElementsMarshall() {\r
60         AttributeStatement* as=AttributeStatementBuilder::buildAttributeStatement();\r
61         as->setSubject(SubjectBuilder::buildSubject());\r
62         for (int i = 0; i < 5; i++) {\r
63             as->getAttributes().push_back(AttributeBuilder::buildAttribute());\r
64         }\r
65 \r
66         assertEquals(expectedChildElementsDOM, as);\r
67     }\r
68 \r
69 };\r