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 //TODO need testing for ElementProxy and wildcard attributes/elements
29 class SubjectConfirmationData20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
30 DateTime* expectedNotBefore;
31 DateTime* expectedNotOnOrAfter;
32 XMLCh* expectedRecipient;
33 XMLCh* expectedInResponseTo;
34 XMLCh* expectedAddress;
38 expectedNotBefore = new DateTime(XMLString::transcode("1984-08-26T10:01:30.043Z"));
39 expectedNotBefore->parseDateTime();
40 expectedNotOnOrAfter = new DateTime(XMLString::transcode("1984-08-26T10:11:30.043Z"));
41 expectedNotOnOrAfter->parseDateTime();
42 expectedRecipient = (XMLString::transcode("recipient"));
43 expectedInResponseTo = (XMLString::transcode("inresponse"));
44 expectedAddress = (XMLString::transcode("address"));
46 singleElementFile = data_path + "saml2/core/impl/SubjectConfirmationData.xml";
47 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/SubjectConfirmationDataOptionalAttributes.xml";
48 childElementsFile = data_path + "saml2/core/impl/SubjectConfirmationDataChildElements.xml";
49 SAMLObjectBaseTestCase::setUp();
53 delete expectedNotBefore;
54 delete expectedNotOnOrAfter;
55 XMLString::release(&expectedRecipient);
56 XMLString::release(&expectedInResponseTo);
57 XMLString::release(&expectedAddress);
58 SAMLObjectBaseTestCase::tearDown();
61 void testSingleElementUnmarshall() {
62 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
63 SubjectConfirmationData* scd = dynamic_cast<SubjectConfirmationData*>(xo.get());
64 TS_ASSERT(scd!=nullptr);
66 TS_ASSERT(scd->getNotBefore()==nullptr);
67 TS_ASSERT(scd->getNotOnOrAfter()==nullptr);
68 TS_ASSERT(scd->getRecipient()==nullptr);
69 TS_ASSERT(scd->getInResponseTo()==nullptr);
70 TS_ASSERT(scd->getAddress()==nullptr);
73 void testSingleElementOptionalAttributesUnmarshall() {
74 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
75 SubjectConfirmationData* scd = dynamic_cast<SubjectConfirmationData*>(xo.get());
76 TS_ASSERT(scd!=nullptr);
78 TSM_ASSERT_EQUALS("NotBefore attribute", expectedNotBefore->getEpoch(), scd->getNotBefore()->getEpoch());
79 TSM_ASSERT_EQUALS("NotOnOrAfter attribute", expectedNotOnOrAfter->getEpoch(), scd->getNotOnOrAfter()->getEpoch());
80 assertEquals("Recipient attribute", expectedRecipient, scd->getRecipient());
81 assertEquals("InResponseTo attribute", expectedInResponseTo, scd->getInResponseTo());
82 assertEquals("Address attribute", expectedAddress, scd->getAddress());
84 //TODO need to test with some wildcard attributes
87 void testChildElementsUnmarshall() {
88 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
89 SubjectConfirmationData* scd= dynamic_cast<SubjectConfirmationData*>(xo.get());
90 TS_ASSERT(scd!=nullptr);
92 TS_ASSERT(scd->getNotBefore()==nullptr);
93 TS_ASSERT(scd->getNotOnOrAfter()==nullptr);
94 TS_ASSERT(scd->getRecipient()==nullptr);
95 TS_ASSERT(scd->getInResponseTo()==nullptr);
96 TS_ASSERT(scd->getAddress()==nullptr);
98 //TODO need to test with some wildcard child elements
101 void testSingleElementMarshall() {
102 SubjectConfirmationData* scd=SubjectConfirmationDataBuilder::buildSubjectConfirmationData();
103 assertEquals(expectedDOM, scd);
106 void testSingleElementOptionalAttributesMarshall() {
107 SubjectConfirmationData* scd=SubjectConfirmationDataBuilder::buildSubjectConfirmationData();
108 scd->setNotBefore(expectedNotBefore);
109 scd->setNotOnOrAfter(expectedNotOnOrAfter);
110 scd->setRecipient(expectedRecipient);
111 scd->setInResponseTo(expectedInResponseTo);
112 scd->setAddress(expectedAddress);
113 //TODO need to test with some wilcard attributes
114 assertEquals(expectedOptionalAttributesDOM, scd);
117 void testChildElementsMarshall() {
118 SubjectConfirmationData* scd=SubjectConfirmationDataBuilder::buildSubjectConfirmationData();
119 //TODO need to test with some wilcard child elements
120 assertEquals(expectedChildElementsDOM, scd);