Change license header, remove stale pkg files.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / NameID20Test.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 NameID20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
28     XMLCh* expectedNameQualifier; 
29     XMLCh* expectedSPNameQualifier; 
30     XMLCh* expectedFormat; 
31     XMLCh* expectedSPProvidedID; 
32     XMLCh* expectedContent; 
33
34 public:
35     void setUp() {
36         expectedNameQualifier = XMLString::transcode("nq"); 
37         expectedSPNameQualifier = XMLString::transcode("spnq"); 
38         expectedFormat = XMLString::transcode("format"); 
39         expectedSPProvidedID = XMLString::transcode("spID"); 
40         expectedContent = XMLString::transcode("someNameID"); 
41
42         singleElementFile = data_path + "saml2/core/impl/NameID.xml";
43         singleElementOptionalAttributesFile = data_path + "saml2/core/impl/NameIDOptionalAttributes.xml";
44         SAMLObjectBaseTestCase::setUp();
45     }
46     
47     void tearDown() {
48         XMLString::release(&expectedNameQualifier);
49         XMLString::release(&expectedSPNameQualifier);
50         XMLString::release(&expectedFormat);
51         XMLString::release(&expectedSPProvidedID);
52         XMLString::release(&expectedContent);
53         SAMLObjectBaseTestCase::tearDown();
54     }
55
56     void testSingleElementUnmarshall() {
57         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
58         NameID* nameid = dynamic_cast<NameID*>(xo.get());
59         TS_ASSERT(nameid!=nullptr);
60
61         assertEquals("Element content", expectedContent, nameid->getName());
62     }
63
64     void testSingleElementOptionalAttributesUnmarshall() {
65         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
66         NameID* nameid = dynamic_cast<NameID*>(xo.get());
67         TS_ASSERT(nameid!=nullptr);
68
69         assertEquals("NameQualifier attribute", expectedNameQualifier, nameid->getNameQualifier());
70         assertEquals("SPNameQualifier attribute", expectedSPNameQualifier, nameid->getSPNameQualifier());
71         assertEquals("Format attribute", expectedFormat, nameid->getFormat());
72         assertEquals("SPProvidedID attribute", expectedSPProvidedID, nameid->getSPProvidedID());
73         assertEquals("Element content", expectedContent, nameid->getName());
74     }
75
76
77     void testSingleElementMarshall() {
78         NameID* nameid = NameIDBuilder::buildNameID();
79         TS_ASSERT(nameid!=nullptr);
80
81         nameid->setName(expectedContent);
82         assertEquals(expectedDOM, nameid);
83     }
84
85     void testSingleElementOptionalAttributesMarshall() {
86         NameID* nameid = NameIDBuilder::buildNameID();
87         TS_ASSERT(nameid!=nullptr);
88
89         nameid->setNameQualifier(expectedNameQualifier);
90         nameid->setSPNameQualifier(expectedSPNameQualifier);
91         nameid->setFormat(expectedFormat);
92         nameid->setSPProvidedID(expectedSPProvidedID);
93         nameid->setName(expectedContent);
94         assertEquals(expectedOptionalAttributesDOM, nameid);
95     }
96
97 };