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 //TODO need testing for ElementProxy and wildcard attributes/elements
25 class SubjectConfirmationData20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
26 DateTime* expectedNotBefore;
27 DateTime* expectedNotOnOrAfter;
28 XMLCh* expectedRecipient;
29 XMLCh* expectedInResponseTo;
30 XMLCh* expectedAddress;
34 expectedNotBefore = new DateTime(XMLString::transcode("1984-08-26T10:01:30.043Z"));
35 expectedNotBefore->parseDateTime();
36 expectedNotOnOrAfter = new DateTime(XMLString::transcode("1984-08-26T10:11:30.043Z"));
37 expectedNotOnOrAfter->parseDateTime();
38 expectedRecipient = (XMLString::transcode("recipient"));
39 expectedInResponseTo = (XMLString::transcode("inresponse"));
40 expectedAddress = (XMLString::transcode("address"));
42 singleElementFile = data_path + "saml2/core/impl/SubjectConfirmationData.xml";
43 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/SubjectConfirmationDataOptionalAttributes.xml";
44 childElementsFile = data_path + "saml2/core/impl/SubjectConfirmationDataChildElements.xml";
45 SAMLObjectBaseTestCase::setUp();
49 delete expectedNotBefore;
50 delete expectedNotOnOrAfter;
51 XMLString::release(&expectedRecipient);
52 XMLString::release(&expectedInResponseTo);
53 XMLString::release(&expectedAddress);
54 SAMLObjectBaseTestCase::tearDown();
57 void testSingleElementUnmarshall() {
58 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
59 SubjectConfirmationData* scd = dynamic_cast<SubjectConfirmationData*>(xo.get());
62 TS_ASSERT(scd->getNotBefore()==NULL);
63 TS_ASSERT(scd->getNotOnOrAfter()==NULL);
64 TS_ASSERT(scd->getRecipient()==NULL);
65 TS_ASSERT(scd->getInResponseTo()==NULL);
66 TS_ASSERT(scd->getAddress()==NULL);
69 void testSingleElementOptionalAttributesUnmarshall() {
70 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
71 SubjectConfirmationData* scd = dynamic_cast<SubjectConfirmationData*>(xo.get());
74 TSM_ASSERT_EQUALS("NotBefore attribute", expectedNotBefore->getEpoch(), scd->getNotBefore()->getEpoch());
75 TSM_ASSERT_EQUALS("NotOnOrAfter attribute", expectedNotOnOrAfter->getEpoch(), scd->getNotOnOrAfter()->getEpoch());
76 assertEquals("Recipient attribute", expectedRecipient, scd->getRecipient());
77 assertEquals("InResponseTo attribute", expectedInResponseTo, scd->getInResponseTo());
78 assertEquals("Address attribute", expectedAddress, scd->getAddress());
80 //TODO need to test with some wildcard attributes
83 void testChildElementsUnmarshall() {
84 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
85 SubjectConfirmationData* scd= dynamic_cast<SubjectConfirmationData*>(xo.get());
88 TS_ASSERT(scd->getNotBefore()==NULL);
89 TS_ASSERT(scd->getNotOnOrAfter()==NULL);
90 TS_ASSERT(scd->getRecipient()==NULL);
91 TS_ASSERT(scd->getInResponseTo()==NULL);
92 TS_ASSERT(scd->getAddress()==NULL);
94 //TODO need to test with some wildcard child elements
97 void testSingleElementMarshall() {
98 SubjectConfirmationData* scd=SubjectConfirmationDataBuilder::buildSubjectConfirmationData();
99 assertEquals(expectedDOM, scd);
102 void testSingleElementOptionalAttributesMarshall() {
103 SubjectConfirmationData* scd=SubjectConfirmationDataBuilder::buildSubjectConfirmationData();
104 scd->setNotBefore(expectedNotBefore);
105 scd->setNotOnOrAfter(expectedNotOnOrAfter);
106 scd->setRecipient(expectedRecipient);
107 scd->setInResponseTo(expectedInResponseTo);
108 scd->setAddress(expectedAddress);
109 //TODO need to test with some wilcard attributes
110 assertEquals(expectedOptionalAttributesDOM, scd);
113 void testChildElementsMarshall() {
114 SubjectConfirmationData* scd=SubjectConfirmationDataBuilder::buildSubjectConfirmationData();
115 //TODO need to test with some wilcard child elements
116 assertEquals(expectedChildElementsDOM, scd);