JD2022-TU1/main/extern/UbiServices/custom/testsUnit/testParametersInfoHelper.cpp

80 lines
3.7 KiB
C++

////////////////////////////////////////////////////////////////////////////////
// (c) Copyright, Ubisoft Entertainment Inc. || Created by Harbour //
////////////////////////////////////////////////////////////////////////////////
#include "tests/config.h"
#include "tests/fixture/memoryCheckFixture.h"
#include <ubiservices/core/configs/environment.h>
#include "tests/mock/parametersMockHelper.h"
#include <ubiservices/services/parameters/parametersInfo.h>
#include <ubiservices/core/JSON/jsonWriter.h>
#include <ubiservices/core/JSON/json.h>
#include <ubiservices/services/parameters/gatewayResources.h>
#include <ubiservices/services/parameters/parametersInfoHelper.h>
namespace US_NS {;
US_DEFINE_TEST(TestParametersInfoHelper);
#if !defined(US_DLL)
typedef LeakChecker UNIT_CONFIGURATION_HELPER;
namespace TestParametersInfoHelper_BF
{
Vector<String> getExpectedURLs(const ParametersInfo& parametersInfo, bool isPreflight = false)
{
Vector<String> prefixes = TestHelpers_BF::getURLPrefixes(isPreflight);
Vector<String> result;
for (StringKeyMap<UrlInfoResource>::const_iterator gatewayItem = parametersInfo.m_gatewayResources.m_parameters.begin();
gatewayItem != parametersInfo.m_gatewayResources.m_parameters.end(); gatewayItem++)
{
for (Vector<String>::iterator envPrefix = prefixes.begin(); envPrefix != prefixes.end(); envPrefix++)
{
String url = gatewayItem->second.m_url;
uint32 version = gatewayItem->second.m_version;
url = url.replace("{env}",*envPrefix);
url = url.replace("{version}", (StringStream() << "v" << version).getContent());
result.push_back(url);
}
}
return result;
}
}
/// @test Verifies that the resource URLs are properly
/// constructed on all environments with and without preflight
TEST_F(UNIT_CONFIGURATION_HELPER, LOCAL_TestGetResourceUrl)
{
TestParametersInfoHelper parametersHelper;
#if !defined(US_SDK_S2S)
EXPECT_TRUE(parametersHelper.updateGatewayResources(ParametersApplicationMockHelper().createParametersResponseMap()));
#endif
EXPECT_TRUE(parametersHelper.updateGatewayResources(ParametersSpaceMockHelper().createParametersResponseMap()));
Vector<String> expectedUrls = TestParametersInfoHelper_BF::getExpectedURLs(parametersHelper.m_info);
Vector<String> expectedPreflightUrls = TestParametersInfoHelper_BF::getExpectedURLs(parametersHelper.m_info, true);
StringKeyMap<UrlInfoResource> resources = parametersHelper.m_info.m_gatewayResources.m_parameters;
for (StringKeyMap<UrlInfoResource>::const_iterator resItem = resources.begin(); resItem != resources.end(); resItem++)
{
for (int accessCtxt = static_cast<int>(OnlineAccessContext::Standard); accessCtxt < static_cast<int>(OnlineAccessContext::ENUM_COUNT); accessCtxt++)
{
for (int env = static_cast<int>(Environment::Dev); env < static_cast<int>(Environment::ENUM_COUNT); env++)
{
String resultedUrl = ParametersInfoHelper::getResourceUrl(parametersHelper.m_info, resItem->second.m_name,
resItem->second.m_version, static_cast<Environment>(env), static_cast<OnlineAccessContext>(accessCtxt));
TestHelpers_BF::checkValueInExpectedSet(expectedUrls, resultedUrl);
// Preflight
String resultedPreflightUrl = ParametersInfoHelper::getResourceUrl(parametersHelper.m_info, resItem->second.m_name,
resItem->second.m_version, static_cast<Environment>(env), static_cast<OnlineAccessContext>(accessCtxt), true);
TestHelpers_BF::checkValueInExpectedSet(expectedPreflightUrls, resultedPreflightUrl);
}
}
}
}
#endif
};