Skip to content
This repository was archived by the owner on Jan 20, 2025. It is now read-only.

Commit d8084ee

Browse files
fix: fix integration test
1 parent 5b945fc commit d8084ee

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

src/test/java/org/eclipse/tractusx/managedidentitywallets/service/STSTokenValidationServiceTest.java

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.eclipse.tractusx.managedidentitywallets.utils.TokenValidationUtils;
3838
import org.junit.jupiter.api.AfterEach;
3939
import org.junit.jupiter.api.Assertions;
40+
import org.junit.jupiter.api.BeforeEach;
4041
import org.junit.jupiter.api.Test;
4142
import org.springframework.beans.factory.annotation.Autowired;
4243
import org.springframework.boot.test.context.SpringBootTest;
@@ -96,16 +97,24 @@ class STSTokenValidationServiceTest {
9697
@Autowired
9798
private MIWSettings miwSettings;
9899

100+
private final Wallet wallet1 = buildWallet(BPN_1, DID_BPN_1, DID_JSON_STRING_1);
101+
102+
private final Wallet wallet2 = buildWallet(BPN_2, DID_BPN_2, DID_JSON_STRING_2);
103+
104+
@BeforeEach
105+
public void initWallets() {
106+
walletRepository.save(wallet1);
107+
walletRepository.save(wallet2);
108+
}
109+
99110
@AfterEach
100111
public void cleanWallets() {
101-
walletRepository.deleteAll();
112+
walletRepository.deleteById(wallet1.getId());
113+
walletRepository.deleteById(wallet2.getId());
102114
}
103115

104116
@Test
105117
void validateTokenFailureAccessTokenMissingTest() throws JOSEException {
106-
Wallet wallet = buildWallet(BPN_1, DID_BPN_1, DID_JSON_STRING_1);
107-
walletRepository.save(wallet);
108-
109118
JWTClaimsSet outerSet = buildClaimsSet(DID_BPN_1, DID_BPN_1, DID_BPN_1, "123456", EXP_VALID_DATE, IAT_VALID_DATE);
110119
String siToken = buildJWTToken(JWK_OUTER, outerSet);
111120

@@ -122,12 +131,6 @@ void validateTokenFailureWrongSignatureInnerTokenTest() throws JOSEException {
122131
.keyID("58cb4b32-c2e4-46f0-a3ad-3286e34765ty")
123132
.generate();
124133

125-
Wallet wallet1 = buildWallet(BPN_1, DID_BPN_1, DID_JSON_STRING_1);
126-
walletRepository.save(wallet1);
127-
128-
Wallet wallet2 = buildWallet(BPN_2, DID_BPN_2, DID_JSON_STRING_2);
129-
walletRepository.save(wallet2);
130-
131134
JWTClaimsSet innerSet = buildClaimsSet(DID_BPN_2, DID_BPN_1, DID_BPN_1, "123456", EXP_VALID_DATE, IAT_VALID_DATE);
132135
String accessToken = buildJWTToken(jwkRandom, innerSet);
133136

@@ -143,12 +146,6 @@ void validateTokenFailureWrongSignatureInnerTokenTest() throws JOSEException {
143146

144147
@Test
145148
void validateTokenFailureExpiredTokenIssNotEqualsSubTest() throws JOSEException {
146-
Wallet wallet1 = buildWallet(BPN_1, DID_BPN_1, DID_JSON_STRING_1);
147-
walletRepository.save(wallet1);
148-
149-
Wallet wallet2 = buildWallet(BPN_2, DID_BPN_2, DID_JSON_STRING_2);
150-
walletRepository.save(wallet2);
151-
152149
JWTClaimsSet innerSet = buildClaimsSet(DID_BPN_2, DID_BPN_1, DID_BPN_1, "123456", EXP_VALID_DATE, IAT_VALID_DATE);
153150
String accessToken = buildJWTToken(JWK_INNER, innerSet);
154151

@@ -165,12 +162,6 @@ void validateTokenFailureExpiredTokenIssNotEqualsSubTest() throws JOSEException
165162

166163
@Test
167164
void validateTokenSuccessTest() throws JOSEException {
168-
Wallet wallet1 = buildWallet(BPN_1, DID_BPN_1, DID_JSON_STRING_1);
169-
walletRepository.save(wallet1);
170-
171-
Wallet wallet2 = buildWallet(BPN_2, DID_BPN_2, DID_JSON_STRING_2);
172-
walletRepository.save(wallet2);
173-
174165
JWTClaimsSet innerSet = buildClaimsSet(DID_BPN_2, DID_BPN_1, DID_BPN_1, "123456", EXP_VALID_DATE, IAT_VALID_DATE);
175166
String accessToken = buildJWTToken(JWK_INNER, innerSet);
176167

0 commit comments

Comments
 (0)