4 nouveaux tests d'intégration pour valider les modules AISSIA : **Nouveaux tests** : - IT_010_SchedulerHyperfocus : Validation détection hyperfocus SchedulerModule - IT_011_NotificationAlert : Test système notifications (3 types alertes) - IT_012_MonitoringActivity : Test classification activité MonitoringModule - IT_013_WebRequest : Test requêtes HTTP via WebModule (GitHub API) **Modifications infrastructure** : - TestRunnerModule.cpp : Fix chemin discovery tests (remove "build/" prefix) - tests/CMakeLists.txt : Ajout des 4 nouveaux tests à la target - tests/integration/README.md : Documentation Phase 4 ajoutée **Total** : 13/13 tests d'intégration compilent et s'exécutent Infrastructure modulaire "Un module = Un test" pleinement fonctionnelle **Note** : Tests IT_010/012/013 nécessitent modules applicatifs chargés (prochaine étape : charger modules en mode test) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
192 lines
6.6 KiB
C++
192 lines
6.6 KiB
C++
#include <shared/testing/ITestModule.h>
|
|
#include <grove/JsonDataNode.h>
|
|
#include <grove/IIO.h>
|
|
#include <spdlog/spdlog.h>
|
|
#include <chrono>
|
|
#include <thread>
|
|
|
|
namespace aissia::testing {
|
|
|
|
/**
|
|
* @brief Test WebModule HTTP request
|
|
*
|
|
* Workflow:
|
|
* 1. Publish web:request to https://api.github.com
|
|
* 2. Wait for web:response (timeout 10s)
|
|
* 3. Validate statusCode == 200
|
|
*/
|
|
class IT_013_WebRequest : public ITestModule {
|
|
public:
|
|
std::string getTestName() const override {
|
|
return "IT_013_WebRequest";
|
|
}
|
|
|
|
std::string getDescription() const override {
|
|
return "Test WebModule HTTP request";
|
|
}
|
|
|
|
void setConfiguration(const grove::IDataNode& config,
|
|
grove::IIO* io,
|
|
grove::ITaskScheduler* scheduler) override {
|
|
m_io = io;
|
|
m_scheduler = scheduler;
|
|
m_timeout = config.getInt("timeoutMs", 10000); // 10s for network
|
|
|
|
// Subscribe to web responses
|
|
grove::SubscriptionConfig subConfig;
|
|
m_io->subscribe("web:response", subConfig);
|
|
|
|
spdlog::info("[{}] Configured with timeout={}ms", getTestName(), m_timeout);
|
|
}
|
|
|
|
void process(const grove::IDataNode& input) override {}
|
|
void shutdown() override {}
|
|
|
|
const grove::IDataNode& getConfiguration() override {
|
|
static grove::JsonDataNode config("config");
|
|
return config;
|
|
}
|
|
|
|
std::unique_ptr<grove::IDataNode> getHealthStatus() override {
|
|
auto status = std::make_unique<grove::JsonDataNode>("health");
|
|
status->setString("status", "healthy");
|
|
return status;
|
|
}
|
|
|
|
std::unique_ptr<grove::IDataNode> getState() override {
|
|
return std::make_unique<grove::JsonDataNode>("state");
|
|
}
|
|
|
|
void setState(const grove::IDataNode& state) override {}
|
|
|
|
std::string getType() const override { return "IT_013_WebRequest"; }
|
|
int getVersion() const override { return 1; }
|
|
bool isIdle() const override { return true; }
|
|
|
|
TestResult execute() override {
|
|
auto start = std::chrono::steady_clock::now();
|
|
TestResult result;
|
|
result.testName = getTestName();
|
|
|
|
try {
|
|
spdlog::info("[{}] Sending GET request to GitHub API...", getTestName());
|
|
|
|
// 1. Send GET request to GitHub API
|
|
auto request = std::make_unique<grove::JsonDataNode>("request");
|
|
request->setString("url", "https://api.github.com");
|
|
request->setString("method", "GET");
|
|
request->setString("requestId", "it013_test");
|
|
|
|
// Add headers
|
|
auto headers = std::make_unique<grove::JsonDataNode>("headers");
|
|
headers->setString("User-Agent", "AISSIA-Integration-Test");
|
|
headers->setString("Accept", "application/json");
|
|
request->setChild("headers", std::move(headers));
|
|
|
|
m_io->publish("web:request", std::move(request));
|
|
|
|
// 2. Wait for response
|
|
auto response = waitForMessage("web:response", m_timeout);
|
|
|
|
if (!response) {
|
|
result.passed = false;
|
|
result.message = "Timeout waiting for web:response";
|
|
return result;
|
|
}
|
|
|
|
// 3. Validate response
|
|
bool success = response->getBool("success", false);
|
|
int statusCode = response->getInt("statusCode", 0);
|
|
std::string body = response->getString("body", "");
|
|
std::string error = response->getString("error", "");
|
|
|
|
if (!success) {
|
|
result.passed = false;
|
|
result.message = "Request failed: " + error;
|
|
result.details["error"] = error;
|
|
result.details["statusCode"] = std::to_string(statusCode);
|
|
return result;
|
|
}
|
|
|
|
if (statusCode != 200) {
|
|
result.passed = false;
|
|
result.message = "Unexpected status code: " + std::to_string(statusCode);
|
|
result.details["statusCode"] = std::to_string(statusCode);
|
|
result.details["body"] = body.substr(0, 200); // First 200 chars
|
|
return result;
|
|
}
|
|
|
|
// Check if body looks like JSON from GitHub API
|
|
bool hasGitHubFields = body.find("current_user_url") != std::string::npos ||
|
|
body.find("gists_url") != std::string::npos;
|
|
|
|
if (!hasGitHubFields) {
|
|
spdlog::warn("[{}] Response doesn't look like GitHub API", getTestName());
|
|
}
|
|
|
|
result.passed = true;
|
|
result.message = "HTTP GET successful: statusCode=200, body=" +
|
|
std::to_string(body.size()) + " bytes";
|
|
result.details["statusCode"] = std::to_string(statusCode);
|
|
result.details["bodySize"] = std::to_string(body.size());
|
|
result.details["hasGitHubFields"] = hasGitHubFields ? "yes" : "no";
|
|
|
|
spdlog::info("[{}] Request successful: {} bytes received",
|
|
getTestName(), body.size());
|
|
|
|
} catch (const std::exception& e) {
|
|
result.passed = false;
|
|
result.message = std::string("Exception: ") + e.what();
|
|
spdlog::error("[{}] {}", getTestName(), result.message);
|
|
}
|
|
|
|
auto end = std::chrono::steady_clock::now();
|
|
result.durationMs = std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
end - start).count();
|
|
|
|
return result;
|
|
}
|
|
|
|
private:
|
|
std::unique_ptr<grove::IDataNode> waitForMessage(
|
|
const std::string& topic, int timeoutMs) {
|
|
|
|
auto start = std::chrono::steady_clock::now();
|
|
|
|
while (true) {
|
|
if (m_io->hasMessages() > 0) {
|
|
auto msg = m_io->pullMessage();
|
|
if (msg.topic == topic && msg.data) {
|
|
return std::move(msg.data);
|
|
}
|
|
}
|
|
|
|
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
std::chrono::steady_clock::now() - start).count();
|
|
|
|
if (elapsed > timeoutMs) {
|
|
return nullptr;
|
|
}
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
}
|
|
}
|
|
|
|
grove::IIO* m_io = nullptr;
|
|
grove::ITaskScheduler* m_scheduler = nullptr;
|
|
int m_timeout = 10000;
|
|
};
|
|
|
|
} // namespace aissia::testing
|
|
|
|
// Factory functions
|
|
extern "C" {
|
|
grove::IModule* createModule() {
|
|
return new aissia::testing::IT_013_WebRequest();
|
|
}
|
|
|
|
void destroyModule(grove::IModule* module) {
|
|
delete module;
|
|
}
|
|
}
|