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