Skip to content

Commit 0c06d1d

Browse files
authored
chore: refactor after upstream changes on postgres tests (#619)
1 parent 506dbdd commit 0c06d1d

File tree

15 files changed

+235
-212
lines changed

15 files changed

+235
-212
lines changed

e2e-tests/admin-api-tests/src/test/java/org/eclipse/edc/identityhub/tests/AttestationApiEndToEndTest.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,17 @@
2626
import org.eclipse.edc.spi.query.Criterion;
2727
import org.eclipse.edc.spi.query.QuerySpec;
2828
import org.eclipse.edc.spi.query.SortOrder;
29+
import org.eclipse.edc.sql.testfixtures.PostgresqlEndToEndExtension;
2930
import org.eclipse.edc.validator.spi.ValidationResult;
3031
import org.eclipse.edc.validator.spi.Violation;
3132
import org.junit.jupiter.api.AfterEach;
3233
import org.junit.jupiter.api.BeforeAll;
3334
import org.junit.jupiter.api.Nested;
35+
import org.junit.jupiter.api.Order;
3436
import org.junit.jupiter.api.Test;
37+
import org.junit.jupiter.api.extension.BeforeAllCallback;
3538
import org.junit.jupiter.api.extension.ExtendWith;
39+
import org.junit.jupiter.api.extension.RegisterExtension;
3640

3741
import java.util.List;
3842
import java.util.Map;
@@ -43,6 +47,7 @@
4347
import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat;
4448
import static org.hamcrest.Matchers.equalTo;
4549

50+
@SuppressWarnings("JUnitMalformedDeclaration")
4651
public class AttestationApiEndToEndTest {
4752
abstract static class Tests {
4853

@@ -176,8 +181,23 @@ class InMemory extends Tests {
176181

177182
@Nested
178183
@PostgresqlIntegrationTest
179-
@ExtendWith(IssuerServiceEndToEndExtension.Postgres.class)
180184
class Postgres extends Tests {
181185

186+
@Order(0)
187+
@RegisterExtension
188+
static final PostgresqlEndToEndExtension POSTGRESQL_EXTENSION = new PostgresqlEndToEndExtension();
189+
190+
private static final String ISSUER = "issuer";
191+
192+
@Order(1)
193+
@RegisterExtension
194+
static final BeforeAllCallback POSTGRES_CONTAINER_STARTER = context -> {
195+
POSTGRESQL_EXTENSION.createDatabase(ISSUER);
196+
};
197+
198+
@Order(2)
199+
@RegisterExtension
200+
static final IssuerServiceEndToEndExtension ISSUER_SERVICE = IssuerServiceEndToEndExtension.Postgres
201+
.withConfig(cfg -> POSTGRESQL_EXTENSION.configFor(ISSUER));
182202
}
183203
}

e2e-tests/admin-api-tests/src/test/java/org/eclipse/edc/identityhub/tests/CredentialApiEndToEndTest.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,17 @@
3636
import org.eclipse.edc.junit.annotations.PostgresqlIntegrationTest;
3737
import org.eclipse.edc.spi.query.QuerySpec;
3838
import org.eclipse.edc.spi.security.Vault;
39+
import org.eclipse.edc.sql.testfixtures.PostgresqlEndToEndExtension;
3940
import org.hamcrest.Matchers;
4041
import org.jetbrains.annotations.NotNull;
4142
import org.junit.jupiter.api.AfterEach;
4243
import org.junit.jupiter.api.BeforeEach;
4344
import org.junit.jupiter.api.Nested;
45+
import org.junit.jupiter.api.Order;
4446
import org.junit.jupiter.api.Test;
47+
import org.junit.jupiter.api.extension.BeforeAllCallback;
4548
import org.junit.jupiter.api.extension.ExtendWith;
49+
import org.junit.jupiter.api.extension.RegisterExtension;
4650

4751
import java.time.Instant;
4852
import java.util.Map;
@@ -55,6 +59,7 @@
5559
import static org.eclipse.edc.identityhub.tests.TestData.EXAMPLE_REVOCATION_CREDENTIAL_JWT_WITH_STATUS_BIT_SET;
5660
import static org.eclipse.edc.identityhub.tests.TestData.EXAMPLE_REVOCATION_CREDENTIAL_WITH_STATUS_BIT_SET;
5761

62+
@SuppressWarnings("JUnitMalformedDeclaration")
5863
public class CredentialApiEndToEndTest {
5964
public static final String SIGNING_KEY_ALIAS = "signing-key";
6065
public static final int STATUS_LIST_INDEX = 94567;
@@ -244,9 +249,24 @@ class InMemory extends Tests {
244249

245250
@Nested
246251
@PostgresqlIntegrationTest
247-
@ExtendWith(IssuerServiceEndToEndExtension.Postgres.class)
248252
class Postgres extends Tests {
249253

254+
@Order(0)
255+
@RegisterExtension
256+
static final PostgresqlEndToEndExtension POSTGRESQL_EXTENSION = new PostgresqlEndToEndExtension();
257+
258+
private static final String ISSUER = "issuer";
259+
260+
@Order(1)
261+
@RegisterExtension
262+
static final BeforeAllCallback POSTGRES_CONTAINER_STARTER = context -> {
263+
POSTGRESQL_EXTENSION.createDatabase(ISSUER);
264+
};
265+
266+
@Order(2)
267+
@RegisterExtension
268+
static final IssuerServiceEndToEndExtension ISSUER_SERVICE = IssuerServiceEndToEndExtension.Postgres
269+
.withConfig(cfg -> POSTGRESQL_EXTENSION.configFor(ISSUER));
250270
}
251271

252272
}

e2e-tests/admin-api-tests/src/test/java/org/eclipse/edc/identityhub/tests/CredentialDefinitionApiEndToEndTest.java

+21-2
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,23 @@
2727
import org.eclipse.edc.junit.annotations.PostgresqlIntegrationTest;
2828
import org.eclipse.edc.spi.query.Criterion;
2929
import org.eclipse.edc.spi.query.QuerySpec;
30+
import org.eclipse.edc.sql.testfixtures.PostgresqlEndToEndExtension;
3031
import org.hamcrest.Matchers;
3132
import org.junit.jupiter.api.AfterEach;
3233
import org.junit.jupiter.api.Nested;
34+
import org.junit.jupiter.api.Order;
3335
import org.junit.jupiter.api.Test;
36+
import org.junit.jupiter.api.extension.BeforeAllCallback;
3437
import org.junit.jupiter.api.extension.ExtendWith;
38+
import org.junit.jupiter.api.extension.RegisterExtension;
3539

3640
import java.util.Map;
3741

3842
import static org.assertj.core.api.Assertions.assertThat;
3943
import static org.eclipse.edc.junit.assertions.AbstractResultAssert.assertThat;
4044
import static org.hamcrest.Matchers.containsString;
4145

42-
46+
@SuppressWarnings("JUnitMalformedDeclaration")
4347
public class CredentialDefinitionApiEndToEndTest {
4448
abstract static class Tests {
4549

@@ -368,8 +372,23 @@ class InMemory extends Tests {
368372

369373
@Nested
370374
@PostgresqlIntegrationTest
371-
@ExtendWith(IssuerServiceEndToEndExtension.Postgres.class)
372375
class Postgres extends Tests {
373376

377+
@Order(0)
378+
@RegisterExtension
379+
static final PostgresqlEndToEndExtension POSTGRESQL_EXTENSION = new PostgresqlEndToEndExtension();
380+
381+
private static final String ISSUER = "issuer";
382+
383+
@Order(1)
384+
@RegisterExtension
385+
static final BeforeAllCallback POSTGRES_CONTAINER_STARTER = context -> {
386+
POSTGRESQL_EXTENSION.createDatabase(ISSUER);
387+
};
388+
389+
@Order(2)
390+
@RegisterExtension
391+
static final IssuerServiceEndToEndExtension ISSUER_SERVICE = IssuerServiceEndToEndExtension.Postgres
392+
.withConfig(cfg -> POSTGRESQL_EXTENSION.configFor(ISSUER));
374393
}
375394
}

e2e-tests/admin-api-tests/src/test/java/org/eclipse/edc/identityhub/tests/ParticipantApiEndToEndTest.java

+21-1
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,23 @@
2525
import org.eclipse.edc.spi.query.Criterion;
2626
import org.eclipse.edc.spi.query.QuerySpec;
2727
import org.eclipse.edc.spi.query.SortOrder;
28+
import org.eclipse.edc.sql.testfixtures.PostgresqlEndToEndExtension;
2829
import org.hamcrest.Matchers;
2930
import org.junit.jupiter.api.AfterEach;
3031
import org.junit.jupiter.api.Nested;
32+
import org.junit.jupiter.api.Order;
3133
import org.junit.jupiter.api.Test;
34+
import org.junit.jupiter.api.extension.BeforeAllCallback;
3235
import org.junit.jupiter.api.extension.ExtendWith;
36+
import org.junit.jupiter.api.extension.RegisterExtension;
3337

3438
import java.util.List;
3539

3640
import static org.assertj.core.api.Assertions.assertThat;
3741
import static org.hamcrest.Matchers.equalTo;
3842
import static org.hamcrest.Matchers.is;
3943

44+
@SuppressWarnings("JUnitMalformedDeclaration")
4045
public class ParticipantApiEndToEndTest {
4146
abstract static class Tests {
4247

@@ -180,8 +185,23 @@ class InMemory extends Tests {
180185

181186
@Nested
182187
@PostgresqlIntegrationTest
183-
@ExtendWith(IssuerServiceEndToEndExtension.Postgres.class)
184188
class Postgres extends Tests {
185189

190+
@Order(0)
191+
@RegisterExtension
192+
static final PostgresqlEndToEndExtension POSTGRESQL_EXTENSION = new PostgresqlEndToEndExtension();
193+
194+
private static final String ISSUER = "issuer";
195+
196+
@Order(1)
197+
@RegisterExtension
198+
static final BeforeAllCallback POSTGRES_CONTAINER_STARTER = context -> {
199+
POSTGRESQL_EXTENSION.createDatabase(ISSUER);
200+
};
201+
202+
@Order(2)
203+
@RegisterExtension
204+
static final IssuerServiceEndToEndExtension ISSUER_SERVICE = IssuerServiceEndToEndExtension.Postgres
205+
.withConfig(cfg -> POSTGRESQL_EXTENSION.configFor(ISSUER));
186206
}
187207
}

e2e-tests/admin-api-tests/src/test/java/org/eclipse/edc/identityhub/tests/dcp/DcpIssuanceApiEndToEndTest.java

+20-4
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,15 @@
4444
import org.eclipse.edc.junit.annotations.PostgresqlIntegrationTest;
4545
import org.eclipse.edc.spi.query.QuerySpec;
4646
import org.eclipse.edc.spi.result.Result;
47+
import org.eclipse.edc.sql.testfixtures.PostgresqlEndToEndExtension;
4748
import org.eclipse.edc.validator.spi.ValidationResult;
4849
import org.jetbrains.annotations.NotNull;
4950
import org.junit.jupiter.api.AfterEach;
5051
import org.junit.jupiter.api.BeforeAll;
5152
import org.junit.jupiter.api.Nested;
5253
import org.junit.jupiter.api.Order;
5354
import org.junit.jupiter.api.Test;
55+
import org.junit.jupiter.api.extension.BeforeAllCallback;
5456
import org.junit.jupiter.api.extension.RegisterExtension;
5557
import org.mockserver.integration.ClientAndServer;
5658

@@ -72,6 +74,7 @@
7274
import static org.mockserver.model.HttpRequest.request;
7375
import static org.mockserver.model.HttpResponse.response;
7476

77+
@SuppressWarnings("JUnitMalformedDeclaration")
7578
public class DcpIssuanceApiEndToEndTest {
7679

7780
protected static final DidPublicKeyResolver DID_PUBLIC_KEY_RESOLVER = mock();
@@ -430,13 +433,26 @@ class InMemory extends Tests {
430433
@PostgresqlIntegrationTest
431434
class Postgres extends Tests {
432435

436+
@Order(0)
433437
@RegisterExtension
434-
static IssuerServiceEndToEndExtension runtime;
438+
static final PostgresqlEndToEndExtension POSTGRESQL_EXTENSION = new PostgresqlEndToEndExtension();
439+
440+
private static final String ISSUER = "issuer";
441+
442+
@Order(1)
443+
@RegisterExtension
444+
static final BeforeAllCallback POSTGRES_CONTAINER_STARTER = context -> {
445+
POSTGRESQL_EXTENSION.createDatabase(ISSUER);
446+
};
447+
448+
@Order(2)
449+
@RegisterExtension
450+
static final IssuerServiceEndToEndExtension ISSUER_SERVICE = IssuerServiceEndToEndExtension.Postgres
451+
.withConfig(cfg -> POSTGRESQL_EXTENSION.configFor(ISSUER));
435452

436453
static {
437-
runtime = new IssuerServiceEndToEndExtension.Postgres();
438-
runtime.registerServiceMock(DidPublicKeyResolver.class, DID_PUBLIC_KEY_RESOLVER);
439-
runtime.registerServiceMock(DidResolverRegistry.class, DID_RESOLVER_REGISTRY);
454+
ISSUER_SERVICE.registerServiceMock(DidPublicKeyResolver.class, DID_PUBLIC_KEY_RESOLVER);
455+
ISSUER_SERVICE.registerServiceMock(DidResolverRegistry.class, DID_RESOLVER_REGISTRY);
440456
}
441457
}
442458
}

e2e-tests/dcp-issuance-tests/src/test/java/org/eclipse/edc/identityhub/tests/dcp/DcpIssuanceFlowEndToEndTest.java

+26-4
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,15 @@
3838
import org.eclipse.edc.junit.annotations.EndToEndTest;
3939
import org.eclipse.edc.junit.annotations.PostgresqlIntegrationTest;
4040
import org.eclipse.edc.spi.result.Result;
41+
import org.eclipse.edc.sql.testfixtures.PostgresqlEndToEndExtension;
4142
import org.eclipse.edc.validator.spi.ValidationResult;
4243
import org.hamcrest.Matchers;
4344
import org.jetbrains.annotations.NotNull;
4445
import org.junit.jupiter.api.BeforeAll;
4546
import org.junit.jupiter.api.Nested;
47+
import org.junit.jupiter.api.Order;
4648
import org.junit.jupiter.api.Test;
49+
import org.junit.jupiter.api.extension.BeforeAllCallback;
4750
import org.junit.jupiter.api.extension.RegisterExtension;
4851

4952
import java.time.Duration;
@@ -52,6 +55,8 @@
5255
import static io.restassured.http.ContentType.JSON;
5356
import static org.assertj.core.api.Assertions.assertThat;
5457
import static org.awaitility.Awaitility.await;
58+
import static org.eclipse.edc.identityhub.tests.dcp.fixtures.IssuanceFlowConfig.identityHubConfig;
59+
import static org.eclipse.edc.identityhub.tests.dcp.fixtures.IssuanceFlowConfig.issuerConfig;
5560
import static org.eclipse.edc.identityhub.tests.fixtures.common.TestFunctions.base64Encode;
5661
import static org.mockito.ArgumentMatchers.any;
5762
import static org.mockito.ArgumentMatchers.eq;
@@ -214,13 +219,30 @@ class InMemory extends Tests {
214219
@PostgresqlIntegrationTest
215220
class Postgres extends Tests {
216221

222+
@Order(0)
217223
@RegisterExtension
218-
static IssuerServiceEndToEndExtension issuerService = IssuerServiceEndToEndExtension.Postgres
219-
.withConfig(IssuanceFlowConfig::issuerConfig);
224+
static final PostgresqlEndToEndExtension POSTGRESQL_EXTENSION = new PostgresqlEndToEndExtension();
225+
private static final String ISSUER = "issuer";
226+
227+
@Order(2)
228+
@RegisterExtension
229+
static final IssuerServiceEndToEndExtension ISSUER_SERVICE = IssuerServiceEndToEndExtension.Postgres
230+
.withConfig(cfg ->
231+
issuerConfig(cfg).merge(POSTGRESQL_EXTENSION.configFor(ISSUER)));
232+
private static final String IDENTITY_HUB = "identityhub";
233+
@Order(1) // must be the first extension to be evaluated since it starts the DB server
234+
@RegisterExtension
235+
static final BeforeAllCallback POSTGRES_CONTAINER_STARTER = context -> {
236+
POSTGRESQL_EXTENSION.createDatabase(ISSUER);
237+
POSTGRESQL_EXTENSION.createDatabase(IDENTITY_HUB);
238+
};
220239

240+
@Order(2)
221241
@RegisterExtension
222-
static IdentityHubEndToEndExtension credentialService = IdentityHubEndToEndExtension.Postgres
223-
.withConfig(IssuanceFlowConfig::identityHubConfig);
242+
static final IdentityHubEndToEndExtension CREDENTIAL_SERVICE = IdentityHubEndToEndExtension.Postgres
243+
.withConfig((cfg) ->
244+
identityHubConfig(cfg).merge(POSTGRESQL_EXTENSION.configFor(IDENTITY_HUB)));
245+
224246

225247
}
226248
}

e2e-tests/fixtures/src/testFixtures/java/org/eclipse/edc/identityhub/tests/fixtures/PostgresSqlService.java

-79
This file was deleted.

0 commit comments

Comments
 (0)