Removed unnecessary class from string literals.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / LogoutResponse20Test.h
1 /*
2  *  Copyright 2001-2006 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/Protocols.h>
19 #include <saml/util/SAMLConstants.h>
20
21 using namespace opensaml::saml2p;
22 using namespace opensaml::saml2;
23
24 class LogoutResponse20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
25     XMLCh* expectedID; 
26     XMLCh* expectedInResponseTo; 
27     XMLCh* expectedVersion; 
28     XMLCh* expectedConsent; 
29     XMLCh* expectedDestination; 
30     DateTime* expectedIssueInstant; 
31
32 public:
33     void setUp() {
34         expectedID = XMLString::transcode("def456"); 
35         expectedInResponseTo = XMLString::transcode("abc123"); 
36         expectedVersion = XMLString::transcode("2.0"); 
37         expectedConsent = XMLString::transcode("urn:string:consent"); 
38         expectedDestination = XMLString::transcode("http://sp.example.org/endpoint"); 
39         expectedIssueInstant = new DateTime(XMLString::transcode("2006-02-21T16:40:00.000Z"));
40         expectedIssueInstant->parseDateTime();
41
42         singleElementFile = data_path + "saml2/core/impl/LogoutResponse.xml";
43         singleElementOptionalAttributesFile = data_path + "saml2/core/impl/LogoutResponseOptionalAttributes.xml";
44         childElementsFile  = data_path + "saml2/core/impl/LogoutResponseChildElements.xml";    
45         SAMLObjectBaseTestCase::setUp();
46     }
47     
48     void tearDown() {
49         XMLString::release(&expectedID);
50         XMLString::release(&expectedInResponseTo);
51         XMLString::release(&expectedVersion);
52         XMLString::release(&expectedConsent);
53         XMLString::release(&expectedDestination);
54         delete expectedIssueInstant;
55         SAMLObjectBaseTestCase::tearDown();
56     }
57
58     void testSingleElementUnmarshall() {
59         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
60         LogoutResponse* response = dynamic_cast<LogoutResponse*>(xo.get());
61         TS_ASSERT(response!=NULL);
62
63         assertEquals("ID attribute", expectedID, response->getID());
64         assertEquals("Version attribute", expectedVersion, response->getVersion());
65         TSM_ASSERT_EQUALS("IssueInstant attribute", expectedIssueInstant->getEpoch(), response->getIssueInstant()->getEpoch());
66
67         TS_ASSERT(response->getIssuer()==NULL);
68         TS_ASSERT(response->getSignature()==NULL);
69         TS_ASSERT(response->getExtensions()==NULL);
70         TS_ASSERT(response->getStatus()==NULL);
71     }
72
73     void testSingleElementOptionalAttributesUnmarshall() {
74         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
75         LogoutResponse* response = dynamic_cast<LogoutResponse*>(xo.get());
76         TS_ASSERT(response!=NULL);
77
78         assertEquals("Consent attribute", expectedConsent, response->getConsent());
79         assertEquals("Destination attribute", expectedDestination, response->getDestination());
80         assertEquals("InResponseTo attribute", expectedInResponseTo, response->getInResponseTo());
81
82         TS_ASSERT(response->getIssuer()==NULL);
83         TS_ASSERT(response->getSignature()==NULL);
84         TS_ASSERT(response->getExtensions()==NULL);
85         TS_ASSERT(response->getStatus()==NULL);
86     }
87
88     void testChildElementsUnmarshall() {
89         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
90         LogoutResponse* response= dynamic_cast<LogoutResponse*>(xo.get());
91         TS_ASSERT(response!=NULL);
92
93         TS_ASSERT(response->getIssuer()!=NULL);
94         TS_ASSERT(response->getSignature()==NULL);
95         TS_ASSERT(response->getExtensions()==NULL);
96         TS_ASSERT(response->getStatus()!=NULL);
97     }
98
99     void testSingleElementMarshall() {
100         LogoutResponse* response = LogoutResponseBuilder::buildLogoutResponse();
101         TS_ASSERT(response!=NULL);
102
103         response->setID(expectedID);
104         response->setIssueInstant(expectedIssueInstant);
105         //response->setVersion(expectedVersion);
106         assertEquals(expectedDOM, response);
107     }
108
109     void testSingleElementOptionalAttributesMarshall() {
110         LogoutResponse* response = LogoutResponseBuilder::buildLogoutResponse();
111         TS_ASSERT(response!=NULL);
112
113         response->setID(expectedID);
114         response->setInResponseTo(expectedInResponseTo);
115         response->setIssueInstant(expectedIssueInstant);
116         //response->setVersion(expectedVersion);
117         response->setConsent(expectedConsent);
118         response->setDestination(expectedDestination);
119         response->setInResponseTo(expectedInResponseTo);
120         assertEquals(expectedOptionalAttributesDOM, response);
121     }
122
123     void testChildElementsMarshall() {
124         LogoutResponse* response = LogoutResponseBuilder::buildLogoutResponse();
125         TS_ASSERT(response!=NULL);
126
127         response->setID(expectedID);
128         response->setIssueInstant(expectedIssueInstant);
129         // Do this just so don't have to redeclare the saml namespace prefix on every child element in the control XML file
130         Namespace* ns = new Namespace(samlconstants::SAML20_NS, samlconstants::SAML20_PREFIX);
131         response->addNamespace(*ns);
132         response->setIssuer(IssuerBuilder::buildIssuer());
133         response->setStatus(StatusBuilder::buildStatus());
134
135         assertEquals(expectedChildElementsDOM, response);
136         delete ns;
137     }
138
139 };