f667818497995da0bbb5cec3628693f695cbcdad
[shibboleth/cpp-opensaml.git] / samltest / saml1 / core / impl / AttributeStatementTest.h
1 /*
2  *  Copyright 2001-2007 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "internal.h"
18 #include <saml/saml1/core/Assertions.h>
19
20 using namespace opensaml::saml1;
21
22 class AttributeStatementTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
23 public:
24     void setUp() {
25         singleElementFile = data_path + "saml1/core/impl/singleAttributeStatement.xml";
26         childElementsFile = data_path + "saml1/core/impl/AttributeStatementWithChildren.xml";
27         SAMLObjectBaseTestCase::setUp();
28     }
29     
30     void tearDown() {
31         SAMLObjectBaseTestCase::tearDown();
32     }
33
34     void testSingleElementUnmarshall() {
35         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
36         AttributeStatement& as = dynamic_cast<AttributeStatement&>(*xo.get());
37         TSM_ASSERT("<Subject> element present", as.getSubject()==NULL);
38         TSM_ASSERT_EQUALS("Non zero count of <Attribute> elements", 0, as.getAttributes().size());
39     }
40
41     void testChildElementsUnmarshall() {
42         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
43         AttributeStatement& as = dynamic_cast<AttributeStatement&>(*xo.get());
44         TSM_ASSERT("<Subject> element not present", as.getSubject()!=NULL);
45         TSM_ASSERT_EQUALS("count of <Attribute> elements", 5, as.getAttributes().size());
46
47         as.getAttributes().erase(as.getAttributes().begin());
48         TSM_ASSERT_EQUALS("count of <Attribute> elements after single remove", 4, as.getAttributes().size());
49
50         as.getAttributes().erase(as.getAttributes().begin());
51         as.getAttributes().erase(as.getAttributes().begin()+1);
52         TSM_ASSERT_EQUALS("count of <Attribute> elements after double remove", 2, as.getAttributes().size());
53     }
54
55     void testSingleElementMarshall() {
56         assertEquals(expectedDOM, AttributeStatementBuilder::buildAttributeStatement());
57     }
58
59     void testChildElementsMarshall() {
60         AttributeStatement* as=AttributeStatementBuilder::buildAttributeStatement();
61         as->setSubject(SubjectBuilder::buildSubject());
62         for (int i = 0; i < 5; i++) {
63             as->getAttributes().push_back(AttributeBuilder::buildAttribute());
64         }
65
66         assertEquals(expectedChildElementsDOM, as);
67     }
68
69 };