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