Change license header, remove stale pkg files.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / SubjectConfirmationData20Test.h
1 /**
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.
6  *
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
10  * License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
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.
19  */
20
21 #include "internal.h"
22 #include <saml/saml2/core/Assertions.h>
23 #include <saml/util/SAMLConstants.h>
24
25 using namespace opensaml::saml2;
26
27 //TODO need testing for ElementProxy and wildcard attributes/elements
28
29 class SubjectConfirmationData20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
30     DateTime* expectedNotBefore;
31     DateTime* expectedNotOnOrAfter;
32     XMLCh* expectedRecipient;
33     XMLCh* expectedInResponseTo;
34     XMLCh* expectedAddress;
35
36 public:
37     void setUp() {
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"));
45
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();
50     }
51     
52     void tearDown() {
53         delete expectedNotBefore;
54         delete expectedNotOnOrAfter;
55         XMLString::release(&expectedRecipient);
56         XMLString::release(&expectedInResponseTo);
57         XMLString::release(&expectedAddress);
58         SAMLObjectBaseTestCase::tearDown();
59     }
60
61     void testSingleElementUnmarshall() {
62         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
63         SubjectConfirmationData* scd = dynamic_cast<SubjectConfirmationData*>(xo.get());
64         TS_ASSERT(scd!=nullptr);
65
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);
71     }
72
73     void testSingleElementOptionalAttributesUnmarshall() {
74         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
75         SubjectConfirmationData* scd = dynamic_cast<SubjectConfirmationData*>(xo.get());
76         TS_ASSERT(scd!=nullptr);
77
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());
83
84         //TODO need to test with some wildcard attributes
85     }
86
87     void testChildElementsUnmarshall() {
88         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
89         SubjectConfirmationData* scd= dynamic_cast<SubjectConfirmationData*>(xo.get());
90         TS_ASSERT(scd!=nullptr);
91
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);
97
98         //TODO need to test with some wildcard child elements
99     }
100
101     void testSingleElementMarshall() {
102         SubjectConfirmationData* scd=SubjectConfirmationDataBuilder::buildSubjectConfirmationData();
103         assertEquals(expectedDOM, scd);
104     }
105
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);
115     }
116
117     void testChildElementsMarshall() {
118         SubjectConfirmationData* scd=SubjectConfirmationDataBuilder::buildSubjectConfirmationData();
119         //TODO need to test with some wilcard child elements
120         assertEquals(expectedChildElementsDOM, scd);
121     }
122
123 };