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.
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #include <saml/saml2/core/Assertions.h>
23 #include <saml/util/SAMLConstants.h>
25 using namespace opensaml::saml2;
27 class NameID20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
28 XMLCh* expectedNameQualifier;
29 XMLCh* expectedSPNameQualifier;
30 XMLCh* expectedFormat;
31 XMLCh* expectedSPProvidedID;
32 XMLCh* expectedContent;
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");
42 singleElementFile = data_path + "saml2/core/impl/NameID.xml";
43 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/NameIDOptionalAttributes.xml";
44 SAMLObjectBaseTestCase::setUp();
48 XMLString::release(&expectedNameQualifier);
49 XMLString::release(&expectedSPNameQualifier);
50 XMLString::release(&expectedFormat);
51 XMLString::release(&expectedSPProvidedID);
52 XMLString::release(&expectedContent);
53 SAMLObjectBaseTestCase::tearDown();
56 void testSingleElementUnmarshall() {
57 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
58 NameID* nameid = dynamic_cast<NameID*>(xo.get());
59 TS_ASSERT(nameid!=nullptr);
61 assertEquals("Element content", expectedContent, nameid->getName());
64 void testSingleElementOptionalAttributesUnmarshall() {
65 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
66 NameID* nameid = dynamic_cast<NameID*>(xo.get());
67 TS_ASSERT(nameid!=nullptr);
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());
77 void testSingleElementMarshall() {
78 NameID* nameid = NameIDBuilder::buildNameID();
79 TS_ASSERT(nameid!=nullptr);
81 nameid->setName(expectedContent);
82 assertEquals(expectedDOM, nameid);
85 void testSingleElementOptionalAttributesMarshall() {
86 NameID* nameid = NameIDBuilder::buildNameID();
87 TS_ASSERT(nameid!=nullptr);
89 nameid->setNameQualifier(expectedNameQualifier);
90 nameid->setSPNameQualifier(expectedSPNameQualifier);
91 nameid->setFormat(expectedFormat);
92 nameid->setSPProvidedID(expectedSPProvidedID);
93 nameid->setName(expectedContent);
94 assertEquals(expectedOptionalAttributesDOM, nameid);