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