d2c22bdd81c272f544ad7ad708fda94975af2747
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / Advice20Test.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/Assertions.h>
19 #include <saml/util/SAMLConstants.h>
20
21 using namespace opensaml::saml2;
22
23 class Advice20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
24
25 //TODO test with some non-SAML Other children
26
27 public:
28     void setUp() {
29         singleElementFile = data_path + "saml2/core/impl/Advice.xml";
30         childElementsFile  = data_path + "saml2/core/impl/AdviceChildElements.xml";    
31         SAMLObjectBaseTestCase::setUp();
32     }
33     
34     void tearDown() {
35         SAMLObjectBaseTestCase::tearDown();
36     }
37
38     void testSingleElementUnmarshall() {
39         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
40         Advice* advice = dynamic_cast<Advice*>(xo.get());
41         TS_ASSERT(advice!=NULL);
42
43         TSM_ASSERT_EQUALS("# of AssertionIDRef child elements", 0, advice->getAssertionIDRefs().size());
44         TSM_ASSERT_EQUALS("# of AssertionURIRef child elements", 0, advice->getAssertionURIRefs().size());
45         TSM_ASSERT_EQUALS("# of Assertion child elements", 0, advice->getAssertions().size());
46         TSM_ASSERT_EQUALS("# of EncryptedAssertion child elements", 0, advice->getEncryptedAssertions().size());
47         TSM_ASSERT_EQUALS("# of Other child elements", 0, advice->getUnknownXMLObjects().size());
48     }
49
50     void testChildElementsUnmarshall() {
51         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
52         Advice* advice= dynamic_cast<Advice*>(xo.get());
53         TS_ASSERT(advice!=NULL);
54
55         TSM_ASSERT_EQUALS("# of AssertionIDRef child elements", 3, advice->getAssertionIDRefs().size());
56         TSM_ASSERT_EQUALS("# of AssertionURIRef child elements", 2, advice->getAssertionURIRefs().size());
57         TSM_ASSERT_EQUALS("# of Assertion child elements", 2, advice->getAssertions().size());
58         TSM_ASSERT_EQUALS("# of EncryptedAssertion child elements", 1, advice->getEncryptedAssertions().size());
59         TSM_ASSERT_EQUALS("# of Other child elements", 0, advice->getUnknownXMLObjects().size());
60     }
61
62     void testSingleElementMarshall() {
63         Advice* advice=AdviceBuilder::buildAdvice();
64         assertEquals(expectedDOM, advice);
65     }
66
67     void testChildElementsMarshall() {
68         Advice* advice=AdviceBuilder::buildAdvice();
69
70         Assertion* assertion1 = AssertionBuilder::buildAssertion();
71         assertion1->setID(XMLString::transcode("abc123"));
72         assertion1->setIssueInstant(new DateTime(XMLString::transcode("2006-07-21T22:27:19Z")));
73
74         Assertion* assertion2 = AssertionBuilder::buildAssertion();
75         assertion2->setID(XMLString::transcode("def456"));
76         assertion2->setIssueInstant(new DateTime(XMLString::transcode("2006-07-21T22:27:19Z")));
77
78         advice->getAssertionIDRefs().push_back(AssertionIDRefBuilder::buildAssertionIDRef());
79         advice->getAssertionIDRefs().push_back(AssertionIDRefBuilder::buildAssertionIDRef());
80         advice->getAssertionURIRefs().push_back(AssertionURIRefBuilder::buildAssertionURIRef());
81         advice->getAssertionIDRefs().push_back(AssertionIDRefBuilder::buildAssertionIDRef());
82         advice->getAssertionURIRefs().push_back(AssertionURIRefBuilder::buildAssertionURIRef());
83         advice->getAssertions().push_back(assertion1);
84         advice->getEncryptedAssertions().push_back(EncryptedAssertionBuilder::buildEncryptedAssertion());
85         advice->getAssertions().push_back(assertion2);
86         assertEquals(expectedChildElementsDOM, advice);
87     }
88
89 };