2 * Copyright 2001-2007 Internet2
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <saml/saml1/core/Assertions.h>
20 using namespace opensaml::saml1;
22 class AttributeStatementTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
25 singleElementFile = data_path + "saml1/core/impl/singleAttributeStatement.xml";
26 childElementsFile = data_path + "saml1/core/impl/AttributeStatementWithChildren.xml";
27 SAMLObjectBaseTestCase::setUp();
31 SAMLObjectBaseTestCase::tearDown();
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());
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());
47 as.getAttributes().erase(as.getAttributes().begin());
48 TSM_ASSERT_EQUALS("count of <Attribute> elements after single remove", 4, as.getAttributes().size());
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());
55 void testSingleElementMarshall() {
56 assertEquals(expectedDOM, AttributeStatementBuilder::buildAttributeStatement());
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());
66 assertEquals(expectedChildElementsDOM, as);