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/saml1/core/Assertions.h>
24 using namespace opensaml::saml1;
26 class AttributeTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
27 XMLCh* expectedAttributeName;
28 XMLCh* expectedAttributeNamespace;
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();
41 XMLString::release(&expectedAttributeName);
42 XMLString::release(&expectedAttributeNamespace);
43 SAMLObjectBaseTestCase::tearDown();
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());
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());
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());
67 void testSingleElementMarshall() {
68 assertEquals(expectedDOM, AttributeBuilder::buildAttribute());
71 void testSingleElementOptionalAttributesMarshall() {
72 Attribute* a=AttributeBuilder::buildAttribute();
73 a->setAttributeName(expectedAttributeName);
74 a->setAttributeNamespace(expectedAttributeNamespace);
75 assertEquals(expectedOptionalAttributesDOM, a);
78 void testChildElementsMarshall(){
79 Attribute* a=AttributeBuilder::buildAttribute();
81 const XMLCh xsdstring[] = UNICODE_LITERAL_6(s,t,r,i,n,g);
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));
89 assertEquals(expectedChildElementsDOM, a);