2 * Copyright 2001-2010 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include <saml/saml2/core/Assertions.h>
19 #include <saml/util/SAMLConstants.h>
21 using namespace opensaml::saml2;
23 class NameID20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
24 XMLCh* expectedNameQualifier;
25 XMLCh* expectedSPNameQualifier;
26 XMLCh* expectedFormat;
27 XMLCh* expectedSPProvidedID;
28 XMLCh* expectedContent;
32 expectedNameQualifier = XMLString::transcode("nq");
33 expectedSPNameQualifier = XMLString::transcode("spnq");
34 expectedFormat = XMLString::transcode("format");
35 expectedSPProvidedID = XMLString::transcode("spID");
36 expectedContent = XMLString::transcode("someNameID");
38 singleElementFile = data_path + "saml2/core/impl/NameID.xml";
39 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/NameIDOptionalAttributes.xml";
40 SAMLObjectBaseTestCase::setUp();
44 XMLString::release(&expectedNameQualifier);
45 XMLString::release(&expectedSPNameQualifier);
46 XMLString::release(&expectedFormat);
47 XMLString::release(&expectedSPProvidedID);
48 XMLString::release(&expectedContent);
49 SAMLObjectBaseTestCase::tearDown();
52 void testSingleElementUnmarshall() {
53 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
54 NameID* nameid = dynamic_cast<NameID*>(xo.get());
55 TS_ASSERT(nameid!=nullptr);
57 assertEquals("Element content", expectedContent, nameid->getName());
60 void testSingleElementOptionalAttributesUnmarshall() {
61 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
62 NameID* nameid = dynamic_cast<NameID*>(xo.get());
63 TS_ASSERT(nameid!=nullptr);
65 assertEquals("NameQualifier attribute", expectedNameQualifier, nameid->getNameQualifier());
66 assertEquals("SPNameQualifier attribute", expectedSPNameQualifier, nameid->getSPNameQualifier());
67 assertEquals("Format attribute", expectedFormat, nameid->getFormat());
68 assertEquals("SPProvidedID attribute", expectedSPProvidedID, nameid->getSPProvidedID());
69 assertEquals("Element content", expectedContent, nameid->getName());
73 void testSingleElementMarshall() {
74 NameID* nameid = NameIDBuilder::buildNameID();
75 TS_ASSERT(nameid!=nullptr);
77 nameid->setName(expectedContent);
78 assertEquals(expectedDOM, nameid);
81 void testSingleElementOptionalAttributesMarshall() {
82 NameID* nameid = NameIDBuilder::buildNameID();
83 TS_ASSERT(nameid!=nullptr);
85 nameid->setNameQualifier(expectedNameQualifier);
86 nameid->setSPNameQualifier(expectedSPNameQualifier);
87 nameid->setFormat(expectedFormat);
88 nameid->setSPProvidedID(expectedSPProvidedID);
89 nameid->setName(expectedContent);
90 assertEquals(expectedOptionalAttributesDOM, nameid);