1a6823677f5d63ae1be0d07c3d7a7b2073cf9082
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / Attribute20Test.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/saml2/core/Assertions.h>
19 #include <saml/util/SAMLConstants.h>
20
21 using namespace opensaml::saml2;
22
23 class Attribute20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
24     XMLCh* expectedName;
25     XMLCh* expectedNameFormat;
26     XMLCh* expectedFriendlyName;
27
28 public:
29     void setUp() {
30         expectedName = XMLString::transcode("attribName");
31         expectedNameFormat = XMLString::transcode("urn:string:format");
32         expectedFriendlyName = XMLString::transcode("Attribute Name");
33
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();
38     }
39     
40     void tearDown() {
41         XMLString::release(&expectedName);
42         XMLString::release(&expectedNameFormat);
43         XMLString::release(&expectedFriendlyName);
44         SAMLObjectBaseTestCase::tearDown();
45     }
46
47     void testSingleElementUnmarshall() {
48         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
49         Attribute* attribute = dynamic_cast<Attribute*>(xo.get());
50         TS_ASSERT(attribute!=NULL);
51
52         assertEquals("Name attribute", expectedName, attribute->getName());
53         TS_ASSERT(attribute->getNameFormat()==NULL);
54         TS_ASSERT(attribute->getFriendlyName()==NULL);
55
56         TSM_ASSERT_EQUALS("# of AttributeValue child elements", 0, attribute->getAttributeValues().size());
57
58     }
59
60     void testSingleElementOptionalAttributesUnmarshall() {
61         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
62         Attribute* attribute = dynamic_cast<Attribute*>(xo.get());
63         TS_ASSERT(attribute!=NULL);
64
65         assertEquals("Name attribute", expectedName, attribute->getName());
66         assertEquals("NameFormat attribute", expectedNameFormat, attribute->getNameFormat());
67         assertEquals("FriendlyName attribute", expectedFriendlyName, attribute->getFriendlyName());
68
69         TSM_ASSERT_EQUALS("# of AttributeValue child elements", 0, attribute->getAttributeValues().size());
70     }
71
72     void testChildElementsUnmarshall() {
73         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
74         Attribute* attribute= dynamic_cast<Attribute*>(xo.get());
75         TS_ASSERT(attribute!=NULL);
76
77         TS_ASSERT(attribute->getName()==NULL);
78         TS_ASSERT(attribute->getNameFormat()==NULL);
79         TS_ASSERT(attribute->getFriendlyName()==NULL);
80
81         TSM_ASSERT_EQUALS("# of AttributeValue child elements", 3, attribute->getAttributeValues().size());
82
83     }
84
85     void testSingleElementMarshall() {
86         Attribute* attribute=AttributeBuilder::buildAttribute();
87         attribute->setName(expectedName);
88         assertEquals(expectedDOM, attribute);
89     }
90
91     void testSingleElementOptionalAttributesMarshall() {
92         Attribute* attribute=AttributeBuilder::buildAttribute();
93         attribute->setName(expectedName);
94         attribute->setNameFormat(expectedNameFormat);
95         attribute->setFriendlyName(expectedFriendlyName);
96         assertEquals(expectedOptionalAttributesDOM, attribute);
97     }
98
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);
105     }
106
107 };