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/saml1/core/Assertions.h>
20 using namespace opensaml::saml1;
22 class AdviceTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
28 AssertionID=XMLString::transcode("_123456789");
29 IssueInstant=XMLString::transcode("1971-03-19T13:23:00Z");
30 singleElementFile = data_path + "saml1/core/impl/singleAdvice.xml";
31 childElementsFile = data_path + "saml1/core/impl/AdviceWithChildren.xml";
32 SAMLObjectBaseTestCase::setUp();
36 XMLString::release(&AssertionID);
37 XMLString::release(&IssueInstant);
38 SAMLObjectBaseTestCase::tearDown();
41 void testSingleElementUnmarshall() {
42 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
43 Advice* advice = dynamic_cast<Advice*>(xo.get());
44 TS_ASSERT(advice!=NULL);
45 TSM_ASSERT_EQUALS("Number of child AssertIDReference elements", 0, advice->getAssertionIDReferences().size());
46 TSM_ASSERT_EQUALS("Number of child Assertion elements", 0, advice->getAssertions().size());
49 void testChildElementsUnmarshall() {
50 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
51 Advice* advice = dynamic_cast<Advice*>(xo.get());
52 TSM_ASSERT_EQUALS("Number of child AssertIDReference elements", 2, advice->getAssertionIDReferences().size());
53 TSM_ASSERT_EQUALS("Number of child Assertion elements", 1, advice->getAssertions().size());
56 void testSingleElementMarshall() {
57 assertEquals(expectedDOM, AdviceBuilder::buildAdvice());
60 void testChildElementsMarshall() {
61 Advice* advice=AdviceBuilder::buildAdvice();
63 advice->getAssertionIDReferences().push_back(AssertionIDReferenceBuilder::buildAssertionIDReference());
64 Assertion* assertion=AssertionBuilder::buildAssertion();
65 assertion->setAssertionID(AssertionID);
66 assertion->setIssueInstant(IssueInstant);
67 advice->getAssertions().push_back(assertion);
68 advice->getAssertionIDReferences().push_back(AssertionIDReferenceBuilder::buildAssertionIDReference());
70 assertEquals(expectedChildElementsDOM, advice);