SAML 2.0 Core Assertion namespace unit tests.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / Attribute20Test.h
1 /*\r
2  *  Copyright 2001-2006 Internet2\r
3  * \r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 #include "internal.h"\r
18 #include <saml/saml2/core/Assertions.h>\r
19 #include <saml/util/SAMLConstants.h>\r
20 \r
21 using namespace opensaml::saml2;\r
22 \r
23 class Attribute20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {\r
24     XMLCh* expectedName;\r
25     XMLCh* expectedNameFormat;\r
26     XMLCh* expectedFriendlyName;\r
27 \r
28 public:\r
29     void setUp() {\r
30         expectedName = XMLString::transcode("attribName");\r
31         expectedNameFormat = XMLString::transcode("urn:string:format");\r
32         expectedFriendlyName = XMLString::transcode("Attribute Name");\r
33 \r
34         singleElementFile = data_path + "saml2/core/impl/Attribute.xml";\r
35         singleElementOptionalAttributesFile = data_path + "saml2/core/impl/AttributeOptionalAttributes.xml";\r
36         childElementsFile  = data_path + "saml2/core/impl/AttributeChildElements.xml";    \r
37         SAMLObjectBaseTestCase::setUp();\r
38     }\r
39     \r
40     void tearDown() {\r
41         XMLString::release(&expectedName);\r
42         XMLString::release(&expectedNameFormat);\r
43         XMLString::release(&expectedFriendlyName);\r
44         SAMLObjectBaseTestCase::tearDown();\r
45     }\r
46 \r
47     void testSingleElementUnmarshall() {\r
48         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));\r
49         Attribute* attribute = dynamic_cast<Attribute*>(xo.get());\r
50         TS_ASSERT(attribute!=NULL);\r
51 \r
52         assertEquals("Name attribute", expectedName, attribute->getName());\r
53         TS_ASSERT(attribute->getNameFormat()==NULL);\r
54         TS_ASSERT(attribute->getFriendlyName()==NULL);\r
55 \r
56         TSM_ASSERT_EQUALS("# of AttributeValue child elements", 0, attribute->getAttributeValues().size());\r
57 \r
58     }\r
59 \r
60     void testSingleElementOptionalAttributesUnmarshall() {\r
61         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));\r
62         Attribute* attribute = dynamic_cast<Attribute*>(xo.get());\r
63         TS_ASSERT(attribute!=NULL);\r
64 \r
65         assertEquals("Name attribute", expectedName, attribute->getName());\r
66         assertEquals("NameFormat attribute", expectedNameFormat, attribute->getNameFormat());\r
67         assertEquals("FriendlyName attribute", expectedFriendlyName, attribute->getFriendlyName());\r
68 \r
69         TSM_ASSERT_EQUALS("# of AttributeValue child elements", 0, attribute->getAttributeValues().size());\r
70     }\r
71 \r
72     void testChildElementsUnmarshall() {\r
73         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));\r
74         Attribute* attribute= dynamic_cast<Attribute*>(xo.get());\r
75         TS_ASSERT(attribute!=NULL);\r
76 \r
77         TS_ASSERT(attribute->getName()==NULL);\r
78         TS_ASSERT(attribute->getNameFormat()==NULL);\r
79         TS_ASSERT(attribute->getFriendlyName()==NULL);\r
80 \r
81         TSM_ASSERT_EQUALS("# of AttributeValue child elements", 3, attribute->getAttributeValues().size());\r
82 \r
83     }\r
84 \r
85     void testSingleElementMarshall() {\r
86         Attribute* attribute=AttributeBuilder::buildAttribute();\r
87         attribute->setName(expectedName);\r
88         assertEquals(expectedDOM, attribute);\r
89     }\r
90 \r
91     void testSingleElementOptionalAttributesMarshall() {\r
92         Attribute* attribute=AttributeBuilder::buildAttribute();\r
93         attribute->setName(expectedName);\r
94         attribute->setNameFormat(expectedNameFormat);\r
95         attribute->setFriendlyName(expectedFriendlyName);\r
96         assertEquals(expectedOptionalAttributesDOM, attribute);\r
97     }\r
98 \r
99     void testChildElementsMarshall() {\r
100         Attribute* attribute=AttributeBuilder::buildAttribute();\r
101         attribute->getAttributeValues().push_back(AttributeValueBuilder::buildAttributeValue());\r
102         attribute->getAttributeValues().push_back(AttributeValueBuilder::buildAttributeValue());\r
103         attribute->getAttributeValues().push_back(AttributeValueBuilder::buildAttributeValue());\r
104         assertEquals(expectedChildElementsDOM, attribute);\r
105     }\r
106 \r
107 };\r