[framework] TxCore → common-framework (ACM-FW-001)
This commit is contained in:
parent
3491780f0a
commit
bcc27280dc
1 changed files with 75 additions and 0 deletions
|
|
@ -0,0 +1,75 @@
|
||||||
|
package com.klaro.acquirecore.framework;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class TxServiceRegistryTest {
|
||||||
|
|
||||||
|
private TxServiceRegistry registry;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUp() {
|
||||||
|
registry = new TxServiceRegistry();
|
||||||
|
registry.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void registerAndLookupService() {
|
||||||
|
TxService service = (ctx, input) -> "result";
|
||||||
|
registry.registerService("testService", service);
|
||||||
|
assertTrue(registry.isRegistered("testService"));
|
||||||
|
assertEquals(service, registry.lookupService("testService"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void lookupUnregisteredServiceReturnsNull() {
|
||||||
|
assertNull(registry.lookupService("nonExistent"));
|
||||||
|
assertFalse(registry.isRegistered("nonExistent"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void unregisterService() {
|
||||||
|
TxService service = (ctx, input) -> "result";
|
||||||
|
registry.registerService("toRemove", service);
|
||||||
|
registry.unregisterService("toRemove");
|
||||||
|
assertFalse(registry.isRegistered("toRemove"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void dispatchExecutesRegisteredService() {
|
||||||
|
TxService service = (ctx, input) -> "processed: " + input;
|
||||||
|
registry.registerService("echo", service);
|
||||||
|
TxContext ctx = new TxContext("echo");
|
||||||
|
TxResult<String> result = registry.dispatch("echo", ctx, "hello");
|
||||||
|
assertTrue(result.isSuccess());
|
||||||
|
assertEquals("processed: hello", result.getData());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void dispatchFailsForUnregisteredService() {
|
||||||
|
TxContext ctx = new TxContext("unknown");
|
||||||
|
TxResult<?> result = registry.dispatch("unknown", ctx, null);
|
||||||
|
assertFalse(result.isSuccess());
|
||||||
|
assertEquals("SERVICE_NOT_FOUND", result.getErrorCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void dispatchHandlesServiceException() {
|
||||||
|
TxService failingService = (ctx, input) -> { throw new RuntimeException("Service error"); };
|
||||||
|
registry.registerService("failing", failingService);
|
||||||
|
TxContext ctx = new TxContext("failing");
|
||||||
|
TxResult<?> result = registry.dispatch("failing", ctx, null);
|
||||||
|
assertFalse(result.isSuccess());
|
||||||
|
assertEquals("EXECUTION_FAILED", result.getErrorCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void getServiceCount() {
|
||||||
|
assertEquals(0, registry.getServiceCount());
|
||||||
|
registry.registerService("s1", (ctx, input) -> null);
|
||||||
|
registry.registerService("s2", (ctx, input) -> null);
|
||||||
|
assertEquals(2, registry.getServiceCount());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in a new issue