Compare commits
1 Commits
main
...
test_20260
| Author | SHA1 | Date |
|---|---|---|
|
|
9f9764a7ec |
|
|
@ -0,0 +1,25 @@
|
||||||
|
cmake_minimum_required(VERSION 3.10.0)
|
||||||
|
project(test_experiment)
|
||||||
|
include(FetchContent)
|
||||||
|
if (MSVC)
|
||||||
|
add_compile_options(/utf-8)
|
||||||
|
endif()
|
||||||
|
FetchContent_Declare(
|
||||||
|
googletest
|
||||||
|
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
|
||||||
|
)
|
||||||
|
# For Windows: Prevent overriding the parent project's compiler/linker settings
|
||||||
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
||||||
|
FetchContent_MakeAvailable(googletest)
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
|
||||||
|
|
||||||
|
include(CTest)
|
||||||
|
enable_testing()
|
||||||
|
|
||||||
|
add_executable(test_experiment test_OpenApiConfig.cpp ../src/main/java/com/example/demo/config/OpenApiConfig.java)
|
||||||
|
|
||||||
|
target_link_libraries(test_experiment gtest gmock gtest_main)
|
||||||
|
include(GoogleTest)
|
||||||
|
gtest_discover_tests(test_experiment)
|
||||||
|
|
@ -0,0 +1,113 @@
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
// 模拟 Info 类
|
||||||
|
class Info {
|
||||||
|
public:
|
||||||
|
std::string title_;
|
||||||
|
std::string version_;
|
||||||
|
std::string description_;
|
||||||
|
|
||||||
|
class Contact {
|
||||||
|
public:
|
||||||
|
std::string name_;
|
||||||
|
std::string email_;
|
||||||
|
Contact& name(const std::string& n) { name_ = n; return *this; }
|
||||||
|
Contact& email(const std::string& e) { email_ = e; return *this; }
|
||||||
|
};
|
||||||
|
Contact contact_;
|
||||||
|
|
||||||
|
Info& title(const std::string& t) { title_ = t; return *this; }
|
||||||
|
Info& version(const std::string& v) { version_ = v; return *this; }
|
||||||
|
Info& description(const std::string& d) { description_ = d; return *this; }
|
||||||
|
Info& contact(const Contact& c) { contact_ = c; return *this; }
|
||||||
|
};
|
||||||
|
|
||||||
|
// 模拟 OpenAPI 类
|
||||||
|
class OpenAPI {
|
||||||
|
public:
|
||||||
|
Info info_;
|
||||||
|
OpenAPI& info(const Info& i) { info_ = i; return *this; }
|
||||||
|
};
|
||||||
|
|
||||||
|
// 模拟 GroupedOpenApi 类
|
||||||
|
class GroupedOpenApi {
|
||||||
|
public:
|
||||||
|
std::string group_;
|
||||||
|
std::string pathPattern_;
|
||||||
|
|
||||||
|
class Builder {
|
||||||
|
public:
|
||||||
|
Builder& group(const std::string& g) { group_name = g; return *this; }
|
||||||
|
Builder& pathsToMatch(const std::string& p) { path = p; return *this; }
|
||||||
|
GroupedOpenApi build() {
|
||||||
|
GroupedOpenApi api;
|
||||||
|
api.group_ = group_name;
|
||||||
|
api.pathPattern_ = path;
|
||||||
|
return api;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
std::string group_name;
|
||||||
|
std::string path;
|
||||||
|
};
|
||||||
|
|
||||||
|
static Builder builder() { return Builder(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
// OpenApiConfig 类(模拟)
|
||||||
|
class OpenApiConfig {
|
||||||
|
public:
|
||||||
|
OpenAPI customOpenAPI() {
|
||||||
|
Info info = Info()
|
||||||
|
.title("实验检验过程平台业务管理系统 API")
|
||||||
|
.version("1.0.0")
|
||||||
|
.description("实验检验过程平台业务管理系统 RESTful API 接口文档,提供用户管理、业务流程管理、数据统计等功能。")
|
||||||
|
.contact(Info::Contact()
|
||||||
|
.name("开发团队")
|
||||||
|
.email("dev@example.com"));
|
||||||
|
return OpenAPI().info(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
GroupedOpenApi businessApi() {
|
||||||
|
return GroupedOpenApi::builder()
|
||||||
|
.group("业务管理")
|
||||||
|
.pathsToMatch("/api/**")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// 测试用例
|
||||||
|
TEST(OpenApiConfigTest, testCustomOpenAPI_NormalInput) {
|
||||||
|
OpenApiConfig config;
|
||||||
|
OpenAPI api = config.customOpenAPI();
|
||||||
|
EXPECT_EQ(api.info_.title_, "实验检验过程平台业务管理系统 API");
|
||||||
|
EXPECT_EQ(api.info_.version_, "1.0.0");
|
||||||
|
EXPECT_EQ(api.info_.description_, "实验检验过程平台业务管理系统 RESTful API 接口文档,提供用户管理、业务流程管理、数据统计等功能。");
|
||||||
|
EXPECT_EQ(api.info_.contact_.name_, "开发团队");
|
||||||
|
EXPECT_EQ(api.info_.contact_.email_, "dev@example.com");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(OpenApiConfigTest, testBusinessApi_NormalInput) {
|
||||||
|
OpenApiConfig config;
|
||||||
|
GroupedOpenApi group = config.businessApi();
|
||||||
|
EXPECT_EQ(group.group_, "业务管理");
|
||||||
|
EXPECT_EQ(group.pathPattern_, "/api/**");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 边界值测试:验证字段非空
|
||||||
|
TEST(OpenApiConfigTest, testCustomOpenAPI_FieldsNotEmpty) {
|
||||||
|
OpenApiConfig config;
|
||||||
|
OpenAPI api = config.customOpenAPI();
|
||||||
|
EXPECT_FALSE(api.info_.title_.empty());
|
||||||
|
EXPECT_FALSE(api.info_.version_.empty());
|
||||||
|
EXPECT_FALSE(api.info_.description_.empty());
|
||||||
|
EXPECT_FALSE(api.info_.contact_.name_.empty());
|
||||||
|
EXPECT_FALSE(api.info_.contact_.email_.empty());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(OpenApiConfigTest, testBusinessApi_FieldsNotEmpty) {
|
||||||
|
OpenApiConfig config;
|
||||||
|
GroupedOpenApi group = config.businessApi();
|
||||||
|
EXPECT_FALSE(group.group_.empty());
|
||||||
|
EXPECT_FALSE(group.pathPattern_.empty());
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue