2 * Copyright 2001-2007 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/saml1/core/Assertions.h>
20 using namespace opensaml::saml1;
22 class AttributeTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
23 XMLCh* expectedAttributeName;
24 XMLCh* expectedAttributeNamespace;
28 expectedAttributeName=XMLString::transcode("AttributeName");
29 expectedAttributeNamespace=XMLString::transcode("namespace");
30 singleElementFile = data_path + "saml1/core/impl/singleAttribute.xml";
31 singleElementOptionalAttributesFile = data_path + "saml1/core/impl/singleAttributeAttributes.xml";
32 childElementsFile = data_path + "saml1/core/impl/AttributeWithChildren.xml";
33 SAMLObjectBaseTestCase::setUp();
37 XMLString::release(&expectedAttributeName);
38 XMLString::release(&expectedAttributeNamespace);
39 SAMLObjectBaseTestCase::tearDown();
42 void testSingleElementUnmarshall() {
43 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
44 Attribute& a = dynamic_cast<Attribute&>(*xo.get());
45 TSM_ASSERT("AttributeName", a.getAttributeName()==NULL);
46 TSM_ASSERT("AttributeNamespace", a.getAttributeNamespace()==NULL);
47 TSM_ASSERT_EQUALS("<AttributeValue> subelement found", 0, a.getAttributeValues().size());
50 void testSingleElementOptionalAttributesUnmarshall() {
51 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
52 Attribute& a = dynamic_cast<Attribute&>(*xo.get());
53 assertEquals("AttributeName", expectedAttributeName, a.getAttributeName());
54 assertEquals("AttributeNamespace", expectedAttributeNamespace, a.getAttributeNamespace());
57 void testChildElementsUnmarshall() {
58 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
59 Attribute& a = dynamic_cast<Attribute&>(*xo.get());
60 TSM_ASSERT_EQUALS("Number of <AttributeValue> subelements", 4, a.getAttributeValues().size());
63 void testSingleElementMarshall() {
64 assertEquals(expectedDOM, AttributeBuilder::buildAttribute());
67 void testSingleElementOptionalAttributesMarshall() {
68 Attribute* a=AttributeBuilder::buildAttribute();
69 a->setAttributeName(expectedAttributeName);
70 a->setAttributeNamespace(expectedAttributeNamespace);
71 assertEquals(expectedOptionalAttributesDOM, a);
74 void testChildElementsMarshall(){
75 Attribute* a=AttributeBuilder::buildAttribute();
77 const XMLCh xsdstring[] = UNICODE_LITERAL_6(s,t,r,i,n,g);
79 const XMLObjectBuilder* builder=XMLObjectBuilder::getBuilder(QName(samlconstants::SAML1_NS,AttributeValue::LOCAL_NAME));
80 TS_ASSERT(builder!=NULL);
81 QName xsitype(xmlconstants::XSD_NS,xsdstring,xmlconstants::XSD_PREFIX);
82 for (int i=0; i<4; i++)
83 a->getAttributeValues().push_back(builder->buildObject(samlconstants::SAML1_NS, AttributeValue::LOCAL_NAME, samlconstants::SAML1_PREFIX, &xsitype));
85 assertEquals(expectedChildElementsDOM, a);