1bae5eb2559e3f36a03e14a05763d0f60d5d2609
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / Scoping20Test.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/Protocols.h>
19 #include <saml/util/SAMLConstants.h>
20
21 using namespace opensaml::saml2p;
22 using namespace opensaml::saml2;
23
24 class Scoping20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
25     int expectedProxycount;
26
27 public:
28     void setUp() {
29         expectedProxycount = 5;
30         singleElementFile = data_path + "saml2/core/impl/Scoping.xml";
31         singleElementOptionalAttributesFile = data_path + "saml2/core/impl/ScopingOptionalAttributes.xml";
32         childElementsFile  = data_path + "saml2/core/impl/ScopingChildElements.xml";    
33         SAMLObjectBaseTestCase::setUp();
34     }
35     
36     void tearDown() {
37         SAMLObjectBaseTestCase::tearDown();
38     }
39
40     void testSingleElementUnmarshall() {
41         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
42         Scoping* scoping = dynamic_cast<Scoping*>(xo.get());
43         TS_ASSERT(scoping!=NULL);
44
45         TSM_ASSERT_EQUALS("ProxyCount attribute presence", false, scoping->getProxyCount().first);
46         TS_ASSERT(scoping->getIDPList()==NULL);
47         TSM_ASSERT_EQUALS("# of RequesterID child elements", 0, scoping->getRequesterIDs().size());
48     }
49
50     void testSingleElementOptionalAttributesUnmarshall() {
51         auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
52         Scoping* scoping = dynamic_cast<Scoping*>(xo.get());
53         TS_ASSERT(scoping!=NULL);
54
55         TSM_ASSERT_EQUALS("ProxyCount attribute presence", true, scoping->getProxyCount().first);
56         TSM_ASSERT_EQUALS("ProxyCount attribute value", expectedProxycount, scoping->getProxyCount().second);
57         TS_ASSERT(scoping->getIDPList()==NULL);
58         TSM_ASSERT_EQUALS("# of RequesterID child elements", 0, scoping->getRequesterIDs().size());
59     }
60
61     void testChildElementsUnmarshall() {
62         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
63         Scoping* scoping= dynamic_cast<Scoping*>(xo.get());
64         TS_ASSERT(scoping!=NULL);
65
66         TSM_ASSERT_EQUALS("ProxyCount attribute presence", false, scoping->getProxyCount().first);
67         TS_ASSERT(scoping->getIDPList()!=NULL);
68         TSM_ASSERT_EQUALS("# of RequesterID child elements", 3, scoping->getRequesterIDs().size());
69     }
70
71     void testSingleElementMarshall() {
72         Scoping* scoping=ScopingBuilder::buildScoping();
73         assertEquals(expectedDOM, scoping);
74     }
75
76     void testSingleElementOptionalAttributesMarshall() {
77         Scoping* scoping=ScopingBuilder::buildScoping();
78         scoping->setProxyCount(expectedProxycount);
79         assertEquals(expectedOptionalAttributesDOM, scoping);
80     }
81
82     void testChildElementsMarshall() {
83         Scoping* scoping=ScopingBuilder::buildScoping();
84         scoping->setIDPList(IDPListBuilder::buildIDPList());
85         scoping->getRequesterIDs().push_back(RequesterIDBuilder::buildRequesterID());
86         scoping->getRequesterIDs().push_back(RequesterIDBuilder::buildRequesterID());
87         scoping->getRequesterIDs().push_back(RequesterIDBuilder::buildRequesterID());
88         assertEquals(expectedChildElementsDOM, scoping);
89     }
90
91 };