2 * Copyright 2001-2010 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/saml2/core/Assertions.h>
19 #include <saml/util/SAMLConstants.h>
21 using namespace opensaml::saml2;
23 class Attribute20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
25 XMLCh* expectedNameFormat;
26 XMLCh* expectedFriendlyName;
30 expectedName = XMLString::transcode("attribName");
31 expectedNameFormat = XMLString::transcode("urn:string:format");
32 expectedFriendlyName = XMLString::transcode("Attribute Name");
34 singleElementFile = data_path + "saml2/core/impl/Attribute.xml";
35 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/AttributeOptionalAttributes.xml";
36 childElementsFile = data_path + "saml2/core/impl/AttributeChildElements.xml";
37 SAMLObjectBaseTestCase::setUp();
41 XMLString::release(&expectedName);
42 XMLString::release(&expectedNameFormat);
43 XMLString::release(&expectedFriendlyName);
44 SAMLObjectBaseTestCase::tearDown();
47 void testSingleElementUnmarshall() {
48 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
49 Attribute* attribute = dynamic_cast<Attribute*>(xo.get());
50 TS_ASSERT(attribute!=nullptr);
52 assertEquals("Name attribute", expectedName, attribute->getName());
53 TS_ASSERT(attribute->getNameFormat()==nullptr);
54 TS_ASSERT(attribute->getFriendlyName()==nullptr);
56 TSM_ASSERT_EQUALS("# of AttributeValue child elements", 0, attribute->getAttributeValues().size());
60 void testSingleElementOptionalAttributesUnmarshall() {
61 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
62 Attribute* attribute = dynamic_cast<Attribute*>(xo.get());
63 TS_ASSERT(attribute!=nullptr);
65 assertEquals("Name attribute", expectedName, attribute->getName());
66 assertEquals("NameFormat attribute", expectedNameFormat, attribute->getNameFormat());
67 assertEquals("FriendlyName attribute", expectedFriendlyName, attribute->getFriendlyName());
69 TSM_ASSERT_EQUALS("# of AttributeValue child elements", 0, attribute->getAttributeValues().size());
72 void testChildElementsUnmarshall() {
73 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
74 Attribute* attribute= dynamic_cast<Attribute*>(xo.get());
75 TS_ASSERT(attribute!=nullptr);
77 TS_ASSERT(attribute->getName()==nullptr);
78 TS_ASSERT(attribute->getNameFormat()==nullptr);
79 TS_ASSERT(attribute->getFriendlyName()==nullptr);
81 TSM_ASSERT_EQUALS("# of AttributeValue child elements", 3, attribute->getAttributeValues().size());
85 void testSingleElementMarshall() {
86 Attribute* attribute=AttributeBuilder::buildAttribute();
87 attribute->setName(expectedName);
88 assertEquals(expectedDOM, attribute);
91 void testSingleElementOptionalAttributesMarshall() {
92 Attribute* attribute=AttributeBuilder::buildAttribute();
93 attribute->setName(expectedName);
94 attribute->setNameFormat(expectedNameFormat);
95 attribute->setFriendlyName(expectedFriendlyName);
96 assertEquals(expectedOptionalAttributesDOM, attribute);
99 void testChildElementsMarshall() {
100 Attribute* attribute=AttributeBuilder::buildAttribute();
101 attribute->getAttributeValues().push_back(AttributeValueBuilder::buildAttributeValue());
102 attribute->getAttributeValues().push_back(AttributeValueBuilder::buildAttributeValue());
103 attribute->getAttributeValues().push_back(AttributeValueBuilder::buildAttributeValue());
104 assertEquals(expectedChildElementsDOM, attribute);