0e5afe84879693f3224d34f13c893e4069a35f12
[shibboleth/cpp-opensaml.git] / samltest / saml1 / core / impl / AttributeTest.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/saml1/core/Assertions.h>\r
19 \r
20 using namespace opensaml::saml1;\r
21 \r
22 class AttributeTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {\r
23     XMLCh* expectedAttributeName;\r
24     XMLCh* expectedAttributeNamespace;\r
25 \r
26 public:\r
27     void setUp() {\r
28         expectedAttributeName=XMLString::transcode("AttributeName");\r
29         expectedAttributeNamespace=XMLString::transcode("namespace");\r
30         singleElementFile = data_path + "saml1/core/impl/singleAttribute.xml";\r
31         singleElementOptionalAttributesFile = data_path + "saml1/core/impl/singleAttributeAttributes.xml";\r
32         childElementsFile = data_path + "saml1/core/impl/AttributeWithChildren.xml";\r
33         SAMLObjectBaseTestCase::setUp();\r
34     }\r
35     \r
36     void tearDown() {\r
37         XMLString::release(&expectedAttributeName);\r
38         XMLString::release(&expectedAttributeNamespace);\r
39         SAMLObjectBaseTestCase::tearDown();\r
40     }\r
41 \r
42     void testSingleElementUnmarshall() {\r
43         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));\r
44         Attribute& a = dynamic_cast<Attribute&>(*xo.get());\r
45         TSM_ASSERT("AttributeName", a.getAttributeName()==NULL);\r
46         TSM_ASSERT("AttributeNamespace", a.getAttributeNamespace()==NULL);\r
47         TSM_ASSERT_EQUALS("<AttributeValue> subelement found", 0, a.getAttributeValues().size());\r
48     }\r
49 \r
50     void testSingleElementOptionalAttributesUnmarshall() {\r
51         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));\r
52         Attribute& a = dynamic_cast<Attribute&>(*xo.get());\r
53         TSM_ASSERT_SAME_DATA("AttributeName", expectedAttributeName, a.getAttributeName(), XMLString::stringLen(expectedAttributeName));\r
54         TSM_ASSERT_SAME_DATA("AttributeNamespace", expectedAttributeNamespace, a.getAttributeNamespace(), XMLString::stringLen(expectedAttributeNamespace));\r
55     }\r
56 \r
57     void testChildElementsUnmarshall() {\r
58         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));\r
59         Attribute& a = dynamic_cast<Attribute&>(*xo.get());\r
60         TSM_ASSERT_EQUALS("Number of <AttributeValue> subelements", 4, a.getAttributeValues().size());\r
61     }\r
62 \r
63     void testSingleElementMarshall() {\r
64         assertEquals(expectedDOM, AttributeBuilder::buildAttribute());\r
65     }\r
66 \r
67     void testSingleElementOptionalAttributesMarshall() {\r
68         Attribute* a=AttributeBuilder::buildAttribute();\r
69         a->setAttributeName(expectedAttributeName);\r
70         a->setAttributeNamespace(expectedAttributeNamespace);\r
71         assertEquals(expectedOptionalAttributesDOM, a);\r
72     }\r
73 \r
74     void testChildElementsMarshall(){\r
75         Attribute* a=AttributeBuilder::buildAttribute();\r
76         \r
77         const XMLCh xsdstring[] = UNICODE_LITERAL_6(s,t,r,i,n,g);\r
78        \r
79         const XMLObjectBuilder* builder=XMLObjectBuilder::getBuilder(QName(SAMLConstants::SAML1_NS,AttributeValue::LOCAL_NAME));\r
80         TS_ASSERT(builder!=NULL);\r
81         QName xsitype(XMLConstants::XSD_NS,xsdstring,XMLConstants::XSD_PREFIX);\r
82         for (int i=0; i<4; i++)\r
83             a->getAttributeValues().push_back(builder->buildObject(SAMLConstants::SAML1_NS, AttributeValue::LOCAL_NAME, SAMLConstants::SAML1_PREFIX, &xsitype)); \r
84 \r
85         assertEquals(expectedChildElementsDOM, a);\r
86     }\r
87 };\r