# 🧪 Guide de Tests - Kafka + WebSocket UnionFlow ## ✅ Statut Actuel Backend démarré avec succès : - ✅ 5 Producers Kafka connectés - ✅ 5 Consumers Kafka connectés (group: `unionflow-websocket-server`) - ✅ WebSocket endpoint actif sur `/ws/dashboard` - ✅ Aucune erreur `UNKNOWN_TOPIC_OR_PARTITION` --- ## 🧪 Test 1 : Swagger UI ### Action Ouvre ton navigateur : **http://localhost:8085/q/swagger-ui** ### Résultat attendu - Page Swagger UI affichée - Liste de tous les endpoints REST - Section "Schemas" avec les DTOs --- ## 🧪 Test 2 : WebSocket - Test HTML ### Action 1. Ouvre le fichier HTML dans ton navigateur : ``` C:\Users\dadyo\PersonalProjects\lions-workspace\unionflow\scripts\kafka\test-websocket.html ``` 2. Clique sur le bouton **"🔗 Connecter"** ### Résultat attendu ✅ **Status change vers "✅ Connecté"** ✅ **Message dans la console** : "Connexion WebSocket établie avec succès !" ✅ **Dans les logs backend** : Tu devrais voir : ``` INFO WebSocket connection opened from ... ``` ### Test Ping/Pong 1. Clique sur **"📤 Envoyer Ping"** 2. Tu devrais recevoir un **pong** du serveur --- ## 🧪 Test 3 : Publier un Event Kafka → Vérifier Réception WebSocket ### Étape 1 : Ouvrir 3 fenêtres 1. **Fenêtre 1** : Logs backend Quarkus (déjà ouverte) 2. **Fenêtre 2** : Navigateur avec `test-websocket.html` (WebSocket connecté) 3. **Fenêtre 3** : PowerShell pour publier l'event ### Étape 2 : Publier un Event de Test Dans PowerShell (Fenêtre 3) : ```powershell cd C:\Users\dadyo\PersonalProjects\lions-workspace\unionflow\scripts\kafka .\test-event.bat ``` **Ou manuellement** : ```cmd echo {"eventType":"APPROVAL_APPROVED","timestamp":"2026-03-14T19:30:00Z","organizationId":"test-org-123","data":{"id":"test-1","amount":50000}} | docker exec -i kafka /opt/kafka/bin/kafka-console-producer.sh --topic unionflow.finance.approvals --bootstrap-server localhost:9092 ``` ### Résultat attendu #### Dans les logs backend (Fenêtre 1) : ``` INFO [dev.lions.unionflow.server.messaging.KafkaEventConsumer] (smallrye-kafka-consumer-thread-1) Received finance approval event: key=..., value={"eventType":"APPROVAL_APPROVED",...} ``` #### Dans le WebSocket HTML (Fenêtre 2) : ``` [19:30:15] RECEIVED: APPROVAL_APPROVED { "eventType": "APPROVAL_APPROVED", "timestamp": "2026-03-14T19:30:00Z", "organizationId": "test-org-123", "data": { "id": "test-1", "amount": 50000 } } ``` ✅ **Si tu vois l'event dans le WebSocket HTML → SUCCÈS COMPLET !** --- ## 🧪 Test 4 : Vérifier les Topics Kafka ### Lister tous les messages d'un topic ```cmd docker exec kafka /opt/kafka/bin/kafka-console-consumer.sh --topic unionflow.finance.approvals --bootstrap-server localhost:9092 --from-beginning ``` Appuie sur `Ctrl+C` pour arrêter. ### Compter les messages ```cmd docker exec kafka /opt/kafka/bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list localhost:9092 --topic unionflow.finance.approvals ``` --- ## 🧪 Test 5 : Application Mobile Flutter ### Lancer l'app mobile ```bash cd C:\Users\dadyo\PersonalProjects\lions-workspace\unionflow\unionflow-mobile-apps flutter run --dart-define=ENV=dev ``` ### Résultat attendu dans la console mobile ``` I/flutter (12345): ✅ WebSocket connecté I/flutter (12345): DashboardBloc: WebSocket initialisé I/flutter (12345): DashboardBloc: WebSocket connecté - Temps réel actif ``` ### Test complet Mobile + Backend 1. **Mobile** : Ouvre le Dashboard 2. **Backend** : Publie un event via Swagger ou Kafka console 3. **Mobile** : Le dashboard devrait se rafraîchir automatiquement ! --- ## 🧪 Test 6 : End-to-End avec Swagger UI ### Scénario : Approbation Finance 1. **Ouvre Swagger UI** : http://localhost:8085/q/swagger-ui 2. **Trouve l'endpoint** : `POST /api/v1/finance/approvals/{id}/approve` 3. **Exécute la requête** avec un ID de test 4. **Vérifie les logs backend** : ``` INFO KafkaEventProducer: Publishing approval event... INFO KafkaEventConsumer: Received finance approval event... INFO WebSocketBroadcastService: Broadcasting to X clients... ``` 5. **Vérifie le WebSocket HTML** : L'event devrait apparaître ! --- ## 📊 Résumé des Tests | Test | Objectif | Status | |------|----------|--------| | 1. Swagger UI | Accès API REST | ⏳ À tester | | 2. WebSocket HTML | Connexion WebSocket | ⏳ À tester | | 3. Kafka → WebSocket | Flux complet | ⏳ À tester | | 4. Kafka Topics | Vérification messages | ⏳ À tester | | 5. Mobile Flutter | WebSocket mobile | ⏳ À tester | | 6. End-to-End Swagger | Workflow complet | ⏳ À tester | --- ## 🐛 Troubleshooting ### WebSocket ne se connecte pas **Vérifier** : ```cmd netstat -an | findstr 8085 ``` Doit afficher : `0.0.0.0:8085 ... LISTENING` ### Events Kafka non reçus **Vérifier les consumers** : ```cmd docker exec kafka /opt/kafka/bin/kafka-consumer-groups.sh --bootstrap-server localhost:9092 --describe --group unionflow-websocket-server ``` Doit afficher : - LAG = 0 (tous les messages consommés) - 5 topics assignés au group ### Backend logs **Augmenter le niveau de log** dans `application.properties` : ```properties quarkus.log.category."dev.lions.unionflow.server.messaging".level=DEBUG ``` --- ## ✅ Succès Final Quand tous ces tests passent : - ✅ Backend publie events dans Kafka - ✅ Consumers consomment events - ✅ WebSocket broadcast aux clients - ✅ Mobile reçoit events en temps réel - ✅ Dashboard auto-refresh **→ Architecture Event-Driven 100% FONCTIONNELLE ! 🎉** --- **Commence par le Test 2 (WebSocket HTML)** - c'est le plus visuel et le plus rapide pour vérifier que tout fonctionne !