2 * Licensed to the University Corporation for Advanced Internet
3 * Development, Inc. (UCAID) under one or more contributor license
4 * agreements. See the NOTICE file distributed with this work for
5 * additional information regarding copyright ownership.
7 * UCAID licenses this file to you under the Apache License,
8 * Version 2.0 (the "License"); you may not use this file except
9 * in compliance with the License. You may obtain a copy of the
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
17 * either express or implied. See the License for the specific
18 * language governing permissions and limitations under the License.
22 #include <saml/saml2/core/Assertions.h>
23 #include <saml/util/SAMLConstants.h>
25 using namespace opensaml::saml2;
27 class Attribute20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
29 XMLCh* expectedNameFormat;
30 XMLCh* expectedFriendlyName;
34 expectedName = XMLString::transcode("attribName");
35 expectedNameFormat = XMLString::transcode("urn:string:format");
36 expectedFriendlyName = XMLString::transcode("Attribute Name");
38 singleElementFile = data_path + "saml2/core/impl/Attribute.xml";
39 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/AttributeOptionalAttributes.xml";
40 childElementsFile = data_path + "saml2/core/impl/AttributeChildElements.xml";
41 SAMLObjectBaseTestCase::setUp();
45 XMLString::release(&expectedName);
46 XMLString::release(&expectedNameFormat);
47 XMLString::release(&expectedFriendlyName);
48 SAMLObjectBaseTestCase::tearDown();
51 void testSingleElementUnmarshall() {
52 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
53 Attribute* attribute = dynamic_cast<Attribute*>(xo.get());
54 TS_ASSERT(attribute!=nullptr);
56 assertEquals("Name attribute", expectedName, attribute->getName());
57 TS_ASSERT(attribute->getNameFormat()==nullptr);
58 TS_ASSERT(attribute->getFriendlyName()==nullptr);
60 TSM_ASSERT_EQUALS("# of AttributeValue child elements", 0, attribute->getAttributeValues().size());
64 void testSingleElementOptionalAttributesUnmarshall() {
65 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
66 Attribute* attribute = dynamic_cast<Attribute*>(xo.get());
67 TS_ASSERT(attribute!=nullptr);
69 assertEquals("Name attribute", expectedName, attribute->getName());
70 assertEquals("NameFormat attribute", expectedNameFormat, attribute->getNameFormat());
71 assertEquals("FriendlyName attribute", expectedFriendlyName, attribute->getFriendlyName());
73 TSM_ASSERT_EQUALS("# of AttributeValue child elements", 0, attribute->getAttributeValues().size());
76 void testChildElementsUnmarshall() {
77 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
78 Attribute* attribute= dynamic_cast<Attribute*>(xo.get());
79 TS_ASSERT(attribute!=nullptr);
81 TS_ASSERT(attribute->getName()==nullptr);
82 TS_ASSERT(attribute->getNameFormat()==nullptr);
83 TS_ASSERT(attribute->getFriendlyName()==nullptr);
85 TSM_ASSERT_EQUALS("# of AttributeValue child elements", 3, attribute->getAttributeValues().size());
89 void testSingleElementMarshall() {
90 Attribute* attribute=AttributeBuilder::buildAttribute();
91 attribute->setName(expectedName);
92 assertEquals(expectedDOM, attribute);
95 void testSingleElementOptionalAttributesMarshall() {
96 Attribute* attribute=AttributeBuilder::buildAttribute();
97 attribute->setName(expectedName);
98 attribute->setNameFormat(expectedNameFormat);
99 attribute->setFriendlyName(expectedFriendlyName);
100 assertEquals(expectedOptionalAttributesDOM, attribute);
103 void testChildElementsMarshall() {
104 Attribute* attribute=AttributeBuilder::buildAttribute();
105 attribute->getAttributeValues().push_back(AttributeValueBuilder::buildAttributeValue());
106 attribute->getAttributeValues().push_back(AttributeValueBuilder::buildAttributeValue());
107 attribute->getAttributeValues().push_back(AttributeValueBuilder::buildAttributeValue());
108 assertEquals(expectedChildElementsDOM, attribute);