Skip to content

Commit c4355df

Browse files
committed
chore: improve tests, add more sample documentation
1 parent d398b5b commit c4355df

File tree

3 files changed

+55
-14
lines changed

3 files changed

+55
-14
lines changed

edc-extensions/multi-tenancy/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Multitenancy
1+
# Multi Tenancy
22

33
This extension provide support for a multi-tenant EDC.
44

edc-extensions/multi-tenancy/src/test/java/org/eclipse/tractusx/edc/boot/runtime/MultiTenantRuntimeTest.java

+18-13
Original file line numberDiff line numberDiff line change
@@ -14,47 +14,52 @@
1414

1515
package org.eclipse.tractusx.edc.boot.runtime;
1616

17-
import static org.junit.jupiter.api.Assertions.*;
18-
19-
import java.util.concurrent.atomic.AtomicInteger;
2017
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;
2220
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.*;
2326

2427
class MultiTenantRuntimeTest {
2528

26-
private final AtomicInteger initializationCount = new AtomicInteger(0);
29+
private final Monitor monitor = mock(Monitor.class);
2730
private final MultiTenantRuntime runtime =
2831
new MultiTenantRuntime() {
2932
@Override
30-
protected void initializeContext(ServiceExtensionContext context) {
31-
initializationCount.addAndGet(1);
32-
super.initializeContext(context);
33+
protected @NotNull Monitor createMonitor() {
34+
return monitor;
3335
}
3436
};
3537

3638
@Test
3739
void throwsExceptionIfNoTenantsPropertyProvided() {
3840
assertThrows(EdcException.class, runtime::boot);
39-
assertEquals(0, initializationCount.get());
41+
verify(monitor, never()).info(argThat(connectorIsReady()));
4042
}
4143

4244
@Test
4345
void throwsExceptionIfTenantsFileDoesNotExist() {
4446
System.setProperty("edc.tenants.path", "unexistentfile");
4547

4648
assertThrows(EdcException.class, runtime::boot);
47-
assertEquals(0, initializationCount.get());
49+
verify(monitor, never()).info(argThat(connectorIsReady()));
4850
}
4951

5052
@Test
5153
void threadForEveryTenant() {
52-
int threadsBefore = Thread.activeCount();
5354
System.setProperty("edc.tenants.path", "./src/test/resources/tenants.properties");
5455

5556
runtime.boot();
5657

57-
assertTrue(Thread.activeCount() > threadsBefore);
58-
assertEquals(2, initializationCount.get());
58+
verify(monitor, times(2)).info(argThat(connectorIsReady()));
5959
}
60+
61+
@NotNull
62+
private ArgumentMatcher<String> connectorIsReady() {
63+
return message -> message.endsWith(" ready");
64+
}
6065
}

samples/sample-multi-tenancy/README.md

+36
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,39 @@ Run:
99
```shell
1010
java -jar -Dedc.tenants.path=samples/sample-multi-tenancy/tenants.properties samples/sample-multi-tenancy/target/sample-multi-tenancy.jar
1111
```
12+
13+
Create an asset on `first` tenant:
14+
```shell
15+
curl -X POST http://localhost:18181/api/assets \
16+
--header 'X-Api-Key: password' \
17+
--header 'Content-Type: application/json' \
18+
--data '{
19+
"asset": {
20+
"properties": {
21+
"asset:prop:id": "1",
22+
"asset:prop:description": "Product EDC Demo Asset"
23+
}
24+
},
25+
"dataAddress": {
26+
"properties": {
27+
"type": "HttpData",
28+
"baseUrl": "https://jsonplaceholder.typicode.com/todos/1"
29+
}
30+
}
31+
}'
32+
```
33+
34+
Get `first` tenant assets:
35+
```
36+
curl -X GET http://localhost:18181/api/assets
37+
[{"createdAt":1666075635217,"properties":{"asset:prop:description":"Product EDC Demo Asset","asset:prop:id":"1"},"id":"1"}]
38+
```
39+
40+
`second` and `third` tenants will have no assets:
41+
```shell
42+
curl -X GET http://localhost:28181/api/assets
43+
[]
44+
45+
curl -X GET http://localhost:38181/api/assets
46+
[]
47+
```

0 commit comments

Comments
 (0)