Update copyright.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / KeyInfoConfirmationDataType20Test.h
1 /*
2  *  Copyright 2001-2007 Internet2
3  * 
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 #include "internal.h"
18 #include <saml/saml2/core/Assertions.h>
19 #include <saml/util/SAMLConstants.h>
20
21 using namespace opensaml::saml2;
22 using namespace xmlsignature;
23
24 //TODO need testing for ElementProxy and wildcard attributes/elements
25
26 class KeyInfoConfirmationDataType20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
27     DateTime* expectedNotBefore;
28     DateTime* expectedNotOnOrAfter;
29     XMLCh* expectedRecipient;
30     XMLCh* expectedInResponseTo;
31     XMLCh* expectedAddress;
32
33 public:
34     void setUp() {
35         expectedNotBefore = new DateTime(XMLString::transcode("1984-08-26T10:01:30.043Z"));
36         expectedNotBefore->parseDateTime();
37         expectedNotOnOrAfter = new DateTime(XMLString::transcode("1984-08-26T10:11:30.043Z"));
38         expectedNotOnOrAfter->parseDateTime();
39         expectedRecipient = (XMLString::transcode("recipient"));
40         expectedInResponseTo = (XMLString::transcode("inresponse"));
41         expectedAddress = (XMLString::transcode("address"));
42
43         singleElementFile = data_path + "saml2/core/impl/KeyInfoConfirmationDataType.xml";
44         singleElementOptionalAttributesFile = data_path + "saml2/core/impl/KeyInfoConfirmationDataTypeOptionalAttributes.xml";
45         childElementsFile  = data_path + "saml2/core/impl/KeyInfoConfirmationDataTypeChildElements.xml";    
46         SAMLObjectBaseTestCase::setUp();
47     }
48     
49     void tearDown() {
50         delete expectedNotBefore;
51         delete expectedNotOnOrAfter;
52         XMLString::release(&expectedRecipient);
53         XMLString::release(&expectedInResponseTo);
54         XMLString::release(&expectedAddress);
55         SAMLObjectBaseTestCase::tearDown();
56     }
57
58     void testSingleElementUnmarshall() {
59         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
60         KeyInfoConfirmationDataType* scd = dynamic_cast<KeyInfoConfirmationDataType*>(xo.get());
61         TS_ASSERT(scd!=NULL);
62
63         TS_ASSERT(scd->getNotBefore()==NULL);
64         TS_ASSERT(scd->getNotOnOrAfter()==NULL);
65         TS_ASSERT(scd->getRecipient()==NULL);
66         TS_ASSERT(scd->getInResponseTo()==NULL);
67         TS_ASSERT(scd->getAddress()==NULL);
68         TSM_ASSERT_EQUALS("# of KeyInfo child elements", 0, scd->getKeyInfos().size());
69     }
70
71     void testSingleElementOptionalAttributesUnmarshall() {
72         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
73         KeyInfoConfirmationDataType* scd = dynamic_cast<KeyInfoConfirmationDataType*>(xo.get());
74         TS_ASSERT(scd!=NULL);
75
76         TSM_ASSERT_EQUALS("NotBefore attribute", expectedNotBefore->getEpoch(), scd->getNotBefore()->getEpoch());
77         TSM_ASSERT_EQUALS("NotOnOrAfter attribute", expectedNotOnOrAfter->getEpoch(), scd->getNotOnOrAfter()->getEpoch());
78         assertEquals("Recipient attribute", expectedRecipient, scd->getRecipient());
79         assertEquals("InResponseTo attribute", expectedInResponseTo, scd->getInResponseTo());
80         assertEquals("Address attribute", expectedAddress, scd->getAddress());
81         TSM_ASSERT_EQUALS("# of KeyInfo child elements", 0, scd->getKeyInfos().size());
82
83         //TODO need to test with some wildcard attributes
84     }
85
86     void testChildElementsUnmarshall() {
87         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
88         KeyInfoConfirmationDataType* scd= dynamic_cast<KeyInfoConfirmationDataType*>(xo.get());
89         TS_ASSERT(scd!=NULL);
90
91         TS_ASSERT(scd->getNotBefore()==NULL);
92         TS_ASSERT(scd->getNotOnOrAfter()==NULL);
93         TS_ASSERT(scd->getRecipient()==NULL);
94         TS_ASSERT(scd->getInResponseTo()==NULL);
95         TS_ASSERT(scd->getAddress()==NULL);
96         TSM_ASSERT_EQUALS("# of KeyInfo child elements", 1, scd->getKeyInfos().size());
97
98         //TODO need to test with some wildcard child elements
99     }
100
101     void testSingleElementMarshall() {
102         KeyInfoConfirmationDataType* scd=KeyInfoConfirmationDataTypeBuilder::buildKeyInfoConfirmationDataType();
103         assertEquals(expectedDOM, scd);
104     }
105
106     void testSingleElementOptionalAttributesMarshall() {
107         KeyInfoConfirmationDataType* scd=KeyInfoConfirmationDataTypeBuilder::buildKeyInfoConfirmationDataType();
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);
115     }
116
117     void testChildElementsMarshall() {
118         KeyInfoConfirmationDataType* scd=KeyInfoConfirmationDataTypeBuilder::buildKeyInfoConfirmationDataType();
119         scd->getKeyInfos().push_back(KeyInfoBuilder::buildKeyInfo());
120         //TODO need to test with some wilcard child elements
121         assertEquals(expectedChildElementsDOM, scd);
122     }
123
124 };