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