2 * Copyright 2001-2006 Internet2
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 #include "internal.h"
\r
18 #include <saml/saml2/core/Assertions.h>
\r
19 #include <saml/util/SAMLConstants.h>
\r
21 using namespace opensaml::saml2;
\r
23 class Conditions20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
\r
24 DateTime* expectedNotBefore;
\r
25 DateTime* expectedNotOnOrAfter;
\r
29 expectedNotBefore = new DateTime(XMLString::transcode("1984-08-26T10:01:30.043Z"));
\r
30 expectedNotBefore->parseDateTime();
\r
31 expectedNotOnOrAfter = new DateTime(XMLString::transcode("1984-08-26T10:11:30.043Z"));
\r
32 expectedNotOnOrAfter->parseDateTime();
\r
34 singleElementFile = data_path + "saml2/core/impl/Conditions.xml";
\r
35 singleElementOptionalAttributesFile = data_path + "saml2/core/impl/ConditionsOptionalAttributes.xml";
\r
36 childElementsFile = data_path + "saml2/core/impl/ConditionsChildElements.xml";
\r
37 SAMLObjectBaseTestCase::setUp();
\r
41 delete expectedNotBefore;
\r
42 delete expectedNotOnOrAfter;
\r
43 SAMLObjectBaseTestCase::tearDown();
\r
46 void testSingleElementUnmarshall() {
\r
47 auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
\r
48 Conditions* conditions = dynamic_cast<Conditions*>(xo.get());
\r
49 TS_ASSERT(conditions!=NULL);
\r
52 TS_ASSERT(conditions->getNotBefore()==NULL);
\r
53 TS_ASSERT(conditions->getNotOnOrAfter()==NULL);
\r
55 TSM_ASSERT_EQUALS("# of Condition child elements", 0, conditions->getConditions().size());
\r
56 TSM_ASSERT_EQUALS("# of AudienceRestriction child elements", 0, conditions->getAudienceRestrictions().size());
\r
57 TSM_ASSERT_EQUALS("# of OneTimeUse child elements", 0, conditions->getOneTimeUses().size());
\r
58 TSM_ASSERT_EQUALS("# of ProxyRestriction child elements", 0, conditions->getProxyRestrictions().size());
\r
61 void testSingleElementOptionalAttributesUnmarshall() {
\r
62 auto_ptr<XMLObject> xo(unmarshallElement(singleElementOptionalAttributesFile));
\r
63 Conditions* conditions = dynamic_cast<Conditions*>(xo.get());
\r
64 TS_ASSERT(conditions!=NULL);
\r
66 TSM_ASSERT_EQUALS("NotBefore attribute", expectedNotBefore->getEpoch(), conditions->getNotBefore()->getEpoch());
\r
67 TSM_ASSERT_EQUALS("NotOnOrAfter attribute", expectedNotOnOrAfter->getEpoch(), conditions->getNotOnOrAfter()->getEpoch());
\r
69 TSM_ASSERT_EQUALS("# of Condition child elements", 0, conditions->getConditions().size());
\r
70 TSM_ASSERT_EQUALS("# of AudienceRestriction child elements", 0, conditions->getAudienceRestrictions().size());
\r
71 TSM_ASSERT_EQUALS("# of OneTimeUse child elements", 0, conditions->getOneTimeUses().size());
\r
72 TSM_ASSERT_EQUALS("# of ProxyRestriction child elements", 0, conditions->getProxyRestrictions().size());
\r
75 void testChildElementsUnmarshall() {
\r
76 auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
\r
77 Conditions* conditions= dynamic_cast<Conditions*>(xo.get());
\r
78 TS_ASSERT(conditions!=NULL);
\r
80 TS_ASSERT(conditions->getNotBefore()==NULL);
\r
81 TS_ASSERT(conditions->getNotOnOrAfter()==NULL);
\r
83 TSM_ASSERT_EQUALS("# of Condition child elements", 0, conditions->getConditions().size());
\r
84 TSM_ASSERT_EQUALS("# of AudienceRestriction child elements", 3, conditions->getAudienceRestrictions().size());
\r
85 TSM_ASSERT_EQUALS("# of OneTimeUse child elements", 1, conditions->getOneTimeUses().size());
\r
86 TSM_ASSERT_EQUALS("# of ProxyRestriction child elements", 2, conditions->getProxyRestrictions().size());
\r
89 void testSingleElementMarshall() {
\r
90 Conditions* conditions=ConditionsBuilder::buildConditions();
\r
91 assertEquals(expectedDOM, conditions);
\r
94 void testSingleElementOptionalAttributesMarshall() {
\r
95 Conditions* conditions=ConditionsBuilder::buildConditions();
\r
96 conditions->setNotBefore(expectedNotBefore);
\r
97 conditions->setNotOnOrAfter(expectedNotOnOrAfter);
\r
98 assertEquals(expectedOptionalAttributesDOM, conditions);
\r
101 void testChildElementsMarshall() {
\r
102 Conditions* conditions=ConditionsBuilder::buildConditions();
\r
104 //Test storing children as their direct type
\r
105 conditions->getAudienceRestrictions().push_back(AudienceRestrictionBuilder::buildAudienceRestriction());
\r
106 conditions->getAudienceRestrictions().push_back(AudienceRestrictionBuilder::buildAudienceRestriction());
\r
107 conditions->getProxyRestrictions().push_back(ProxyRestrictionBuilder::buildProxyRestriction());
\r
108 conditions->getAudienceRestrictions().push_back(AudienceRestrictionBuilder::buildAudienceRestriction());
\r
109 conditions->getOneTimeUses().push_back(OneTimeUseBuilder::buildOneTimeUse());
\r
110 conditions->getProxyRestrictions().push_back(ProxyRestrictionBuilder::buildProxyRestriction());
\r
111 assertEquals(expectedChildElementsDOM, conditions);
\r
113 // Note: assertEquals() above has already 'delete'-ed the XMLObject* it was passed
\r
115 conditions=ConditionsBuilder::buildConditions();
\r
117 //Test storing children as a Condition (each is a derived type of ConditionAbstractType)
\r
118 conditions->getConditions().push_back(AudienceRestrictionBuilder::buildAudienceRestriction());
\r
119 conditions->getConditions().push_back(AudienceRestrictionBuilder::buildAudienceRestriction());
\r
120 conditions->getConditions().push_back(ProxyRestrictionBuilder::buildProxyRestriction());
\r
121 conditions->getConditions().push_back(AudienceRestrictionBuilder::buildAudienceRestriction());
\r
122 conditions->getConditions().push_back(OneTimeUseBuilder::buildOneTimeUse());
\r
123 conditions->getConditions().push_back(ProxyRestrictionBuilder::buildProxyRestriction());
\r
124 assertEquals(expectedChildElementsDOM, conditions);
\r