d882ec5fa727a815d5344be71fc86222997b61f5
[shibboleth/cpp-opensaml.git] / samltest / saml1 / core / impl / AdviceTest.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/saml1/core/Assertions.h>
19
20 using namespace opensaml::saml1;
21
22 class AdviceTest : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
23     XMLCh* AssertionID;
24     XMLCh* IssueInstant;
25
26 public:
27     void setUp() {
28         AssertionID=XMLString::transcode("_123456789");
29         IssueInstant=XMLString::transcode("1971-03-19T13:23:00Z");
30         singleElementFile = data_path + "saml1/core/impl/singleAdvice.xml";
31         childElementsFile  = data_path + "saml1/core/impl/AdviceWithChildren.xml";    
32         SAMLObjectBaseTestCase::setUp();
33     }
34     
35     void tearDown() {
36         XMLString::release(&AssertionID);
37         XMLString::release(&IssueInstant);
38         SAMLObjectBaseTestCase::tearDown();
39     }
40
41     void testSingleElementUnmarshall() {
42         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
43         Advice* advice = dynamic_cast<Advice*>(xo.get());
44         TS_ASSERT(advice!=NULL);
45         TSM_ASSERT_EQUALS("Number of child AssertIDReference elements", 0, advice->getAssertionIDReferences().size());
46         TSM_ASSERT_EQUALS("Number of child Assertion elements", 0, advice->getAssertions().size());
47     }
48
49     void testChildElementsUnmarshall() {
50         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
51         Advice* advice = dynamic_cast<Advice*>(xo.get());
52         TSM_ASSERT_EQUALS("Number of child AssertIDReference elements", 2, advice->getAssertionIDReferences().size());
53         TSM_ASSERT_EQUALS("Number of child Assertion elements", 1, advice->getAssertions().size());
54     }
55
56     void testSingleElementMarshall() {
57         assertEquals(expectedDOM, AdviceBuilder::buildAdvice());
58     }
59
60     void testChildElementsMarshall() {
61         Advice* advice=AdviceBuilder::buildAdvice();
62         
63         advice->getAssertionIDReferences().push_back(AssertionIDReferenceBuilder::buildAssertionIDReference());
64         Assertion* assertion=AssertionBuilder::buildAssertion();
65         assertion->setAssertionID(AssertionID);
66         assertion->setIssueInstant(IssueInstant);
67         advice->getAssertions().push_back(assertion);
68         advice->getAssertionIDReferences().push_back(AssertionIDReferenceBuilder::buildAssertionIDReference());
69
70         assertEquals(expectedChildElementsDOM, advice);
71     }
72
73 };