2 * Copyright 2001-2006 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 #include "internal.h"
\r
18 #include <saml/saml2/core/Assertions.h>
\r
19 #include <saml/util/SAMLConstants.h>
\r
21 using namespace opensaml::saml2;
\r
22 using namespace xmlsignature;
\r
24 //TODO need testing for ElementProxy and wildcard attributes/elements
\r
26 class KeyInfoConfirmationDataType20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
\r
27 DateTime* expectedNotBefore;
\r
28 DateTime* expectedNotOnOrAfter;
\r
29 XMLCh* expectedRecipient;
\r
30 XMLCh* expectedInResponseTo;
\r
31 XMLCh* expectedAddress;
\r
35 expectedNotBefore = new DateTime(XMLString::transcode("1984-08-26T10:01:30.043Z"));
\r
36 expectedNotBefore->parseDateTime();
\r
37 expectedNotOnOrAfter = new DateTime(XMLString::transcode("1984-08-26T10:11:30.043Z"));
\r
38 expectedNotOnOrAfter->parseDateTime();
\r
39 expectedRecipient = (XMLString::transcode("recipient"));
\r
40 expectedInResponseTo = (XMLString::transcode("inresponse"));
\r
41 expectedAddress = (XMLString::transcode("address"));
\r
43 singleElementFile = data_path + "saml2/core/impl/KeyInfoConfirmationDataType.xml";
\r
44 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/KeyInfoConfirmationDataTypeOptionalAttributes.xml";
\r
45 childElementsFile = data_path + "saml2/core/impl/KeyInfoConfirmationDataTypeChildElements.xml";
\r
46 SAMLObjectBaseTestCase::setUp();
\r
50 delete expectedNotBefore;
\r
51 delete expectedNotOnOrAfter;
\r
52 XMLString::release(&expectedRecipient);
\r
53 XMLString::release(&expectedInResponseTo);
\r
54 XMLString::release(&expectedAddress);
\r
55 SAMLObjectBaseTestCase::tearDown();
\r
58 void testSingleElementUnmarshall() {
\r
59 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
\r
60 KeyInfoConfirmationDataType* scd = dynamic_cast<KeyInfoConfirmationDataType*>(xo.get());
\r
61 TS_ASSERT(scd!=NULL);
\r
63 TS_ASSERT(scd->getNotBefore()==NULL);
\r
64 TS_ASSERT(scd->getNotOnOrAfter()==NULL);
\r
65 TS_ASSERT(scd->getRecipient()==NULL);
\r
66 TS_ASSERT(scd->getInResponseTo()==NULL);
\r
67 TS_ASSERT(scd->getAddress()==NULL);
\r
68 TSM_ASSERT_EQUALS("# of KeyInfo child elements", 0, scd->getKeyInfos().size());
\r
71 void testSingleElementOptionalAttributesUnmarshall() {
\r
72 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
\r
73 KeyInfoConfirmationDataType* scd = dynamic_cast<KeyInfoConfirmationDataType*>(xo.get());
\r
74 TS_ASSERT(scd!=NULL);
\r
76 TSM_ASSERT_EQUALS("NotBefore attribute", expectedNotBefore->getEpoch(), scd->getNotBefore()->getEpoch());
\r
77 TSM_ASSERT_EQUALS("NotOnOrAfter attribute", expectedNotOnOrAfter->getEpoch(), scd->getNotOnOrAfter()->getEpoch());
\r
78 assertEquals("Recipient attribute", expectedRecipient, scd->getRecipient());
\r
79 assertEquals("InResponseTo attribute", expectedInResponseTo, scd->getInResponseTo());
\r
80 assertEquals("Address attribute", expectedAddress, scd->getAddress());
\r
81 TSM_ASSERT_EQUALS("# of KeyInfo child elements", 0, scd->getKeyInfos().size());
\r
83 //TODO need to test with some wildcard attributes
\r
86 void testChildElementsUnmarshall() {
\r
87 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
\r
88 KeyInfoConfirmationDataType* scd= dynamic_cast<KeyInfoConfirmationDataType*>(xo.get());
\r
89 TS_ASSERT(scd!=NULL);
\r
91 TS_ASSERT(scd->getNotBefore()==NULL);
\r
92 TS_ASSERT(scd->getNotOnOrAfter()==NULL);
\r
93 TS_ASSERT(scd->getRecipient()==NULL);
\r
94 TS_ASSERT(scd->getInResponseTo()==NULL);
\r
95 TS_ASSERT(scd->getAddress()==NULL);
\r
96 TSM_ASSERT_EQUALS("# of KeyInfo child elements", 1, scd->getKeyInfos().size());
\r
98 //TODO need to test with some wildcard child elements
\r
101 void testSingleElementMarshall() {
\r
102 KeyInfoConfirmationDataType* scd=KeyInfoConfirmationDataTypeBuilder::buildKeyInfoConfirmationDataType();
\r
103 assertEquals(expectedDOM, scd);
\r
106 void testSingleElementOptionalAttributesMarshall() {
\r
107 KeyInfoConfirmationDataType* scd=KeyInfoConfirmationDataTypeBuilder::buildKeyInfoConfirmationDataType();
\r
108 scd->setNotBefore(expectedNotBefore);
\r
109 scd->setNotOnOrAfter(expectedNotOnOrAfter);
\r
110 scd->setRecipient(expectedRecipient);
\r
111 scd->setInResponseTo(expectedInResponseTo);
\r
112 scd->setAddress(expectedAddress);
\r
113 //TODO need to test with some wilcard attributes
\r
114 assertEquals(expectedOptionalAttributesDOM, scd);
\r
117 void testChildElementsMarshall() {
\r
118 KeyInfoConfirmationDataType* scd=KeyInfoConfirmationDataTypeBuilder::buildKeyInfoConfirmationDataType();
\r
119 scd->getKeyInfos().push_back(KeyInfoBuilder::buildKeyInfo());
\r
120 //TODO need to test with some wilcard child elements
\r
121 assertEquals(expectedChildElementsDOM, scd);
\r