Multi-line svn commit, see body.
[shibboleth/cpp-opensaml.git] / samltest / saml2 / core / impl / NewEncryptedID20Test.h
1 /*\r
2  *  Copyright 2001-2006 Internet2\r
3  * \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
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\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
15  */\r
16 \r
17 #include "internal.h"\r
18 #include <saml/saml2/core/Protocols.h>\r
19 #include <xmltooling/encryption/Encryption.h>\r
20 #include <xmltooling/util/XMLConstants.h>\r
21 \r
22 using namespace opensaml;\r
23 using namespace opensaml::saml2p;\r
24 using namespace xmlencryption;\r
25 \r
26 class NewEncryptedID20Test : public CxxTest::TestSuite, public SAMLObjectBaseTestCase {\r
27 \r
28 public:\r
29     void setUp() {\r
30         singleElementFile = data_path + "saml2/core/impl/NewEncryptedID.xml";\r
31         childElementsFile  = data_path + "saml2/core/impl/NewEncryptedIDChildElements.xml";    \r
32         SAMLObjectBaseTestCase::setUp();\r
33     }\r
34     \r
35     void tearDown() {\r
36         SAMLObjectBaseTestCase::tearDown();\r
37     }\r
38 \r
39     void testSingleElementUnmarshall() {\r
40         auto_ptr<XMLObject> xo(unmarshallElement(singleElementFile));\r
41         NewEncryptedID* encID = dynamic_cast<NewEncryptedID*>(xo.get());\r
42         TS_ASSERT(encID!=NULL);\r
43         TSM_ASSERT("EncryptedData child element", encID->getEncryptedData()==NULL);\r
44         TSM_ASSERT_EQUALS("# of EncryptedKey child elements", 0, encID->getEncryptedKeys().size());\r
45     }\r
46 \r
47     void testChildElementsUnmarshall() {\r
48         auto_ptr<XMLObject> xo(unmarshallElement(childElementsFile));\r
49         NewEncryptedID* encID = dynamic_cast<NewEncryptedID*>(xo.get());\r
50         TS_ASSERT(encID!=NULL);\r
51         TSM_ASSERT("EncryptedData child element", encID->getEncryptedData()!=NULL);\r
52         TSM_ASSERT_EQUALS("# of EncryptedKey child elements", 2, encID->getEncryptedKeys().size());\r
53     }\r
54 \r
55     void testSingleElementMarshall() {\r
56         NewEncryptedID* encID=NewEncryptedIDBuilder::buildNewEncryptedID();\r
57         assertEquals(expectedDOM, encID);\r
58     }\r
59 \r
60     void testChildElementsMarshall() {\r
61         NewEncryptedID* encID=NewEncryptedIDBuilder::buildNewEncryptedID();\r
62         // Do this just so don't have to redeclare the xenc namespace prefix on every child element in the control XML file\r
63         Namespace* ns = new Namespace(xmltooling::XMLConstants::XMLENC_NS, xmltooling::XMLConstants::XMLENC_PREFIX);\r
64         encID->addNamespace(*ns);\r
65         encID->setEncryptedData(EncryptedDataBuilder::buildEncryptedData());\r
66         encID->getEncryptedKeys().push_back(EncryptedKeyBuilder::buildEncryptedKey());\r
67         encID->getEncryptedKeys().push_back(EncryptedKeyBuilder::buildEncryptedKey());\r
68         assertEquals(expectedChildElementsDOM, encID);\r
69     }\r
70 \r
71 };\r