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