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.
17 #include <cxxtest/TestSuite.h>
20 #include <saml/exceptions.h>
21 #include <saml/SAMLConfig.h>
22 #include <saml/util/SAMLConstants.h>
23 #include <xmltooling/XMLObject.h>
24 #include <xmltooling/XMLObjectBuilder.h>
26 using namespace opensaml;
27 using namespace xmltooling;
30 extern string data_path;
32 class SAMLObjectBaseTestCase
35 /** Location of file containing a single element with NO optional attributes */
36 string singleElementFile;
38 /** Location of file containing a single element with all optional attributes */
39 string singleElementOptionalAttributesFile;
41 /** Location of file containing a single element with child elements */
42 string childElementsFile;
44 /** The expected result of a marshalled single element with no optional attributes */
45 DOMDocument* expectedDOM;
47 /** The expected result of a marshalled single element with all optional attributes */
48 DOMDocument* expectedOptionalAttributesDOM;
50 /** The expected result of a marshalled single element with child elements */
51 DOMDocument* expectedChildElementsDOM;
54 * Unmarshalls an element file into its SAML XMLObject.
56 * @return the SAML XMLObject from the file
58 XMLObject* unmarshallElement(string elementFile) {
60 ParserPool& p=XMLToolingConfig::getConfig().getParser();
61 ifstream fs(elementFile.c_str());
62 DOMDocument* doc = p.parse(fs);
63 const XMLObjectBuilder* b = XMLObjectBuilder::getBuilder(doc->getDocumentElement());
64 return b->buildFromDocument(doc);
66 catch (XMLToolingException& e) {
67 TS_TRACE(typeid(e).name());
73 void assertEquals(const char* failMessage, DOMDocument* expectedDOM, XMLObject* xmlObject) {
74 DOMElement* generatedDOM = xmlObject->marshall();
75 TSM_ASSERT(failMessage,generatedDOM->isEqualNode(expectedDOM->getDocumentElement()));
78 void assertEquals(DOMDocument* expectedDOM, XMLObject* xmlObject) {
79 assertEquals("Marshalled DOM was not the same as the expected DOM", expectedDOM, xmlObject);
85 ParserPool& p=XMLToolingConfig::getConfig().getParser();
86 if (!singleElementFile.empty()) {
87 ifstream fs(singleElementFile.c_str());
88 expectedDOM = p.parse(fs);
91 if (!singleElementOptionalAttributesFile.empty()) {
92 ifstream fs(singleElementOptionalAttributesFile.c_str());
93 expectedOptionalAttributesDOM = p.parse(fs);
96 if (!childElementsFile.empty()) {
97 ifstream fs(childElementsFile.c_str());
98 expectedChildElementsDOM = p.parse(fs);
103 if (expectedDOM) expectedDOM->release();
104 if (expectedOptionalAttributesDOM) expectedOptionalAttributesDOM->release();
105 if (expectedChildElementsDOM) expectedChildElementsDOM->release();