2 * Copyright 2001-2006 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/Protocols.h>
19 #include <saml/util/SAMLConstants.h>
21 using namespace opensaml::saml2p;
22 using namespace opensaml::saml2;
24 class NameIDPolicy20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
25 XMLCh* expectedFormat;
26 XMLCh* expectedSPNameQualifier;
27 bool expectedAllowCreate;
31 expectedFormat = XMLString::transcode("urn:string:format");;
32 expectedSPNameQualifier = XMLString::transcode("urn:string:spname");
33 expectedAllowCreate=true;
35 singleElementFile = data_path + "saml2/core/impl/NameIDPolicy.xml";
36 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/NameIDPolicyOptionalAttributes.xml";
37 SAMLObjectBaseTestCase::setUp();
41 XMLString::release(&expectedFormat);
42 XMLString::release(&expectedSPNameQualifier);
43 SAMLObjectBaseTestCase::tearDown();
46 void testSingleElementUnmarshall() {
47 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
48 NameIDPolicy* policy = dynamic_cast<NameIDPolicy*>(xo.get());
49 TS_ASSERT(policy!=NULL);
50 TSM_ASSERT_EQUALS("AllowCreate attribute presence", XMLConstants::XML_BOOL_NULL, policy->getAllowCreate());
53 void testSingleElementOptionalAttributesUnmarshall() {
54 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
55 NameIDPolicy* policy = dynamic_cast<NameIDPolicy*>(xo.get());
56 TS_ASSERT(policy!=NULL);
57 assertEquals("Format attribute", expectedFormat, policy->getFormat());
58 assertEquals("SPNameQualifier attribute", expectedSPNameQualifier, policy->getSPNameQualifier());
59 TSM_ASSERT_DIFFERS("AllowCreate attribute presence", XMLConstants::XML_BOOL_NULL, policy->getAllowCreate());
60 TSM_ASSERT_EQUALS("AllowCreate attribute value", expectedAllowCreate, policy->AllowCreate());
63 void testSingleElementMarshall() {
64 NameIDPolicy* policy=NameIDPolicyBuilder::buildNameIDPolicy();
65 assertEquals(expectedDOM, policy);
68 void testSingleElementOptionalAttributesMarshall() {
69 NameIDPolicy* policy=NameIDPolicyBuilder::buildNameIDPolicy();
70 policy->setFormat(expectedFormat);
71 policy->setSPNameQualifier(expectedSPNameQualifier);
72 policy->AllowCreate(expectedAllowCreate);
73 assertEquals(expectedOptionalAttributesDOM, policy);