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