|
14 | 14 |
|
15 | 15 | package org.eclipse.tractusx.edc.boot.runtime;
|
16 | 16 |
|
17 |
| -import static org.junit.jupiter.api.Assertions.*; |
18 |
| - |
19 |
| -import java.util.concurrent.atomic.AtomicInteger; |
20 | 17 | import org.eclipse.dataspaceconnector.spi.EdcException;
|
21 |
| -import org.eclipse.dataspaceconnector.spi.system.ServiceExtensionContext; |
| 18 | +import org.eclipse.dataspaceconnector.spi.monitor.Monitor; |
| 19 | +import org.jetbrains.annotations.NotNull; |
22 | 20 | import org.junit.jupiter.api.Test;
|
| 21 | +import org.mockito.ArgumentMatcher; |
| 22 | + |
| 23 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
| 24 | +import static org.mockito.ArgumentMatchers.argThat; |
| 25 | +import static org.mockito.Mockito.*; |
23 | 26 |
|
24 | 27 | class MultiTenantRuntimeTest {
|
25 | 28 |
|
26 |
| - private final AtomicInteger initializationCount = new AtomicInteger(0); |
| 29 | + private final Monitor monitor = mock(Monitor.class); |
27 | 30 | private final MultiTenantRuntime runtime =
|
28 | 31 | new MultiTenantRuntime() {
|
29 | 32 | @Override
|
30 |
| - protected void initializeContext(ServiceExtensionContext context) { |
31 |
| - initializationCount.addAndGet(1); |
32 |
| - super.initializeContext(context); |
| 33 | + protected @NotNull Monitor createMonitor() { |
| 34 | + return monitor; |
33 | 35 | }
|
34 | 36 | };
|
35 | 37 |
|
36 | 38 | @Test
|
37 | 39 | void throwsExceptionIfNoTenantsPropertyProvided() {
|
38 | 40 | assertThrows(EdcException.class, runtime::boot);
|
39 |
| - assertEquals(0, initializationCount.get()); |
| 41 | + verify(monitor, never()).info(argThat(connectorIsReady())); |
40 | 42 | }
|
41 | 43 |
|
42 | 44 | @Test
|
43 | 45 | void throwsExceptionIfTenantsFileDoesNotExist() {
|
44 | 46 | System.setProperty("edc.tenants.path", "unexistentfile");
|
45 | 47 |
|
46 | 48 | assertThrows(EdcException.class, runtime::boot);
|
47 |
| - assertEquals(0, initializationCount.get()); |
| 49 | + verify(monitor, never()).info(argThat(connectorIsReady())); |
48 | 50 | }
|
49 | 51 |
|
50 | 52 | @Test
|
51 | 53 | void threadForEveryTenant() {
|
52 |
| - int threadsBefore = Thread.activeCount(); |
53 | 54 | System.setProperty("edc.tenants.path", "./src/test/resources/tenants.properties");
|
54 | 55 |
|
55 | 56 | runtime.boot();
|
56 | 57 |
|
57 |
| - assertTrue(Thread.activeCount() > threadsBefore); |
58 |
| - assertEquals(2, initializationCount.get()); |
| 58 | + verify(monitor, times(2)).info(argThat(connectorIsReady())); |
59 | 59 | }
|
| 60 | + |
| 61 | + @NotNull |
| 62 | + private ArgumentMatcher<String> connectorIsReady() { |
| 63 | + return message -> message.endsWith(" ready"); |
| 64 | + } |
60 | 65 | }
|
0 commit comments