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 Evidence20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
27 singleElementFile = data_path + "saml2/core/impl/Evidence.xml";
28 childElementsFile = data_path + "saml2/core/impl/EvidenceChildElements.xml";
29 SAMLObjectBaseTestCase::setUp();
33 SAMLObjectBaseTestCase::tearDown();
36 void testSingleElementUnmarshall() {
37 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
38 Evidence* evidence = dynamic_cast<Evidence*>(xo.get());
39 TS_ASSERT(evidence!=NULL);
41 TSM_ASSERT_EQUALS("# of AssertionIDRef child elements", 0, evidence->getAssertionIDRefs().size());
42 TSM_ASSERT_EQUALS("# of AssertionURIRef child elements", 0, evidence->getAssertionURIRefs().size());
43 TSM_ASSERT_EQUALS("# of Assertion child elements", 0, evidence->getAssertions().size());
44 TSM_ASSERT_EQUALS("# of EncryptedAssertion child elements", 0, evidence->getEncryptedAssertions().size());
47 void testChildElementsUnmarshall() {
48 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
49 Evidence* evidence= dynamic_cast<Evidence*>(xo.get());
50 TS_ASSERT(evidence!=NULL);
52 TSM_ASSERT_EQUALS("# of AssertionIDRef child elements", 3, evidence->getAssertionIDRefs().size());
53 TSM_ASSERT_EQUALS("# of AssertionURIRef child elements", 2, evidence->getAssertionURIRefs().size());
54 TSM_ASSERT_EQUALS("# of Assertion child elements", 2, evidence->getAssertions().size());
55 TSM_ASSERT_EQUALS("# of EncryptedAssertion child elements", 1, evidence->getEncryptedAssertions().size());
58 void testSingleElementMarshall() {
59 Evidence* evidence=EvidenceBuilder::buildEvidence();
60 assertEquals(expectedDOM, evidence);
63 void testChildElementsMarshall() {
64 Evidence* evidence=EvidenceBuilder::buildEvidence();
66 Assertion* assertion1 = AssertionBuilder::buildAssertion();
67 assertion1->setID(XMLString::transcode("abc123"));
68 assertion1->setIssueInstant(new DateTime(XMLString::transcode("2006-07-21T22:27:19Z")));
70 Assertion* assertion2 = AssertionBuilder::buildAssertion();
71 assertion2->setID(XMLString::transcode("def456"));
72 assertion2->setIssueInstant(new DateTime(XMLString::transcode("2006-07-21T22:27:19Z")));
74 evidence->getAssertionIDRefs().push_back(AssertionIDRefBuilder::buildAssertionIDRef());
75 evidence->getAssertionIDRefs().push_back(AssertionIDRefBuilder::buildAssertionIDRef());
76 evidence->getAssertionURIRefs().push_back(AssertionURIRefBuilder::buildAssertionURIRef());
77 evidence->getAssertionIDRefs().push_back(AssertionIDRefBuilder::buildAssertionIDRef());
78 evidence->getAssertionURIRefs().push_back(AssertionURIRefBuilder::buildAssertionURIRef());
79 evidence->getAssertions().push_back(assertion1);
80 evidence->getEncryptedAssertions().push_back(EncryptedAssertionBuilder::buildEncryptedAssertion());
81 evidence->getAssertions().push_back(assertion2);
82 assertEquals(expectedChildElementsDOM, evidence);