ConfigMgrUnitTests.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2018 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. /*
  14. * Config Manager 2.0 Unit tests
  15. *
  16. */
  17. #ifdef _USE_CPPUNIT
  18. #include <cppunit/TestFixture.h>
  19. #include "unittests.hpp"
  20. // Config manager includes
  21. #include "SchemaItem.hpp"
  22. #include "InsertableItem.hpp"
  23. #include "jexcept.hpp"
  24. #include "Exceptions.hpp"
  25. #include "EnvironmentMgr.hpp"
  26. #include <iterator>
  27. #include <algorithm>
  28. //
  29. // This class validates that the system XSDs are wellformed and parse with no errors
  30. class ConfigMgr2ValidateXSDs : public CppUnit::TestFixture
  31. {
  32. public:
  33. CPPUNIT_TEST_SUITE(ConfigMgr2ValidateXSDs);
  34. CPPUNIT_TEST(LoadAndParse);
  35. CPPUNIT_TEST_SUITE_END();
  36. protected:
  37. void LoadAndParse()
  38. {
  39. printf("\nConfigMgr 2.0 - Load and Parse - Verifying configuration XSDs are compliant...");
  40. //
  41. // Standard configuration for HPCC
  42. std::string CFG2_MASTER_CONFIG_FILE = "environment.xsd";
  43. std::string CFG2_CONFIG_DIR = std::string(hpccBuildInfo.componentDir) + PATHSEPSTR + "configschema" + PATHSEPSTR + "xsd" + PATHSEPSTR;
  44. std::string CFG2_SOURCE_DIR = hpccBuildInfo.configSourceDir;
  45. //
  46. // Create the environment
  47. printf("\n Creating XML environment manager instance");
  48. bool rc = true;
  49. m_pEnvMgr = getEnvironmentMgrInstance(EnvironmentType::XML);
  50. CPPUNIT_ASSERT_MESSAGE("Unable to allocate an environment manager", m_pEnvMgr != nullptr);
  51. //
  52. // Load all the XSDs to ensure they parse correctly
  53. printf("\n Loading XSDs");
  54. std::map<std::string, std::string> cfgParms;
  55. rc = m_pEnvMgr->loadSchema(CFG2_CONFIG_DIR, CFG2_MASTER_CONFIG_FILE, cfgParms);
  56. CPPUNIT_ASSERT_MESSAGE("Unable to load configuration schema, error = " + m_pEnvMgr->getLastSchemaMessage(), rc);
  57. //
  58. // Test complete
  59. printf("\n Test complete");
  60. }
  61. private:
  62. EnvironmentMgr *m_pEnvMgr;
  63. };
  64. CPPUNIT_TEST_SUITE_REGISTRATION( ConfigMgr2ValidateXSDs );
  65. CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ConfigMgr2ValidateXSDs, "ConfigMgr2ValidateXSDs" );
  66. #endif