Change license header, remove stale pkg files.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / NewEncryptedID20Test.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/Protocols.h>
23 #include <xmltooling/encryption/Encryption.h>
24 #include <xmltooling/util/XMLConstants.h>
25
26 using namespace opensaml;
27 using namespace opensaml::saml2p;
28 using namespace xmlencryption;
29
30 class NewEncryptedID20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {
31
32 public:
33     void setUp() {
34         singleElementFile = data_path + "saml2/core/impl/NewEncryptedID.xml";
35         childElementsFile  = data_path + "saml2/core/impl/NewEncryptedIDChildElements.xml";    
36         SAMLObjectBaseTestCase::setUp();
37     }
38     
39     void tearDown() {
40         SAMLObjectBaseTestCase::tearDown();
41     }
42
43     void testSingleElementUnmarshall() {
44         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));
45         NewEncryptedID* encID = dynamic_cast<NewEncryptedID*>(xo.get());
46         TS_ASSERT(encID!=nullptr);
47         TSM_ASSERT("EncryptedData child element", encID->getEncryptedData()==nullptr);
48         TSM_ASSERT_EQUALS("# of EncryptedKey child elements", 0, encID->getEncryptedKeys().size());
49     }
50
51     void testChildElementsUnmarshall() {
52         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));
53         NewEncryptedID* encID = dynamic_cast<NewEncryptedID*>(xo.get());
54         TS_ASSERT(encID!=nullptr);
55         TSM_ASSERT("EncryptedData child element", encID->getEncryptedData()!=nullptr);
56         TSM_ASSERT_EQUALS("# of EncryptedKey child elements", 2, encID->getEncryptedKeys().size());
57     }
58
59     void testSingleElementMarshall() {
60         NewEncryptedID* encID=NewEncryptedIDBuilder::buildNewEncryptedID();
61         assertEquals(expectedDOM, encID);
62     }
63
64     void testChildElementsMarshall() {
65         NewEncryptedID* encID=NewEncryptedIDBuilder::buildNewEncryptedID();
66         // Do this just so don't have to redeclare the xenc namespace prefix on every child element in the control XML file
67         Namespace* ns = new Namespace(xmlconstants::XMLENC_NS, xmlconstants::XMLENC_PREFIX);
68         encID->addNamespace(*ns);
69         encID->setEncryptedData(EncryptedDataBuilder::buildEncryptedData());
70         encID->getEncryptedKeys().push_back(EncryptedKeyBuilder::buildEncryptedKey());
71         encID->getEncryptedKeys().push_back(EncryptedKeyBuilder::buildEncryptedKey());
72         assertEquals(expectedChildElementsDOM, encID);
73     }
74
75 };