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/Assertions.h>
19 #include <saml/util/SAMLConstants.h>
21 using namespace opensaml::saml2;
23 class Advice20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
25 //TODO test with some non-SAML Other children
29 singleElementFile = data_path + "saml2/core/impl/Advice.xml";
30 childElementsFile = data_path + "saml2/core/impl/AdviceChildElements.xml";
31 SAMLObjectBaseTestCase::setUp();
35 SAMLObjectBaseTestCase::tearDown();
38 void testSingleElementUnmarshall() {
39 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
40 Advice* advice = dynamic_cast<Advice*>(xo.get());
41 TS_ASSERT(advice!=NULL);
43 TSM_ASSERT_EQUALS("# of AssertionIDRef child elements", 0, advice->getAssertionIDRefs().size());
44 TSM_ASSERT_EQUALS("# of AssertionURIRef child elements", 0, advice->getAssertionURIRefs().size());
45 TSM_ASSERT_EQUALS("# of Assertion child elements", 0, advice->getAssertions().size());
46 TSM_ASSERT_EQUALS("# of EncryptedAssertion child elements", 0, advice->getEncryptedAssertions().size());
47 TSM_ASSERT_EQUALS("# of Other child elements", 0, advice->getOthers().size());
50 void testChildElementsUnmarshall() {
51 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
52 Advice* advice= dynamic_cast<Advice*>(xo.get());
53 TS_ASSERT(advice!=NULL);
55 TSM_ASSERT_EQUALS("# of AssertionIDRef child elements", 3, advice->getAssertionIDRefs().size());
56 TSM_ASSERT_EQUALS("# of AssertionURIRef child elements", 2, advice->getAssertionURIRefs().size());
57 TSM_ASSERT_EQUALS("# of Assertion child elements", 2, advice->getAssertions().size());
58 TSM_ASSERT_EQUALS("# of EncryptedAssertion child elements", 1, advice->getEncryptedAssertions().size());
59 TSM_ASSERT_EQUALS("# of Other child elements", 0, advice->getOthers().size());
62 void testSingleElementMarshall() {
63 Advice* advice=AdviceBuilder::buildAdvice();
64 assertEquals(expectedDOM, advice);
67 void testChildElementsMarshall() {
68 Advice* advice=AdviceBuilder::buildAdvice();
70 Assertion* assertion1 = AssertionBuilder::buildAssertion();
71 assertion1->setID(XMLString::transcode("abc123"));
72 assertion1->setIssueInstant(new DateTime(XMLString::transcode("2006-07-21T22:27:19Z")));
74 Assertion* assertion2 = AssertionBuilder::buildAssertion();
75 assertion2->setID(XMLString::transcode("def456"));
76 assertion2->setIssueInstant(new DateTime(XMLString::transcode("2006-07-21T22:27:19Z")));
78 advice->getAssertionIDRefs().push_back(AssertionIDRefBuilder::buildAssertionIDRef());
79 advice->getAssertionIDRefs().push_back(AssertionIDRefBuilder::buildAssertionIDRef());
80 advice->getAssertionURIRefs().push_back(AssertionURIRefBuilder::buildAssertionURIRef());
81 advice->getAssertionIDRefs().push_back(AssertionIDRefBuilder::buildAssertionIDRef());
82 advice->getAssertionURIRefs().push_back(AssertionURIRefBuilder::buildAssertionURIRef());
83 advice->getAssertions().push_back(assertion1);
84 advice->getEncryptedAssertions().push_back(EncryptedAssertionBuilder::buildEncryptedAssertion());
85 advice->getAssertions().push_back(assertion2);
86 assertEquals(expectedChildElementsDOM, advice);