Skip to content

Commit 961609c

Browse files
author
debadutta2015
committed
FINERACT-1474: Remove hard-coded constants from ThitsaWorksCreditBureauTest
1 parent 45eee33 commit 961609c

1 file changed

Lines changed: 34 additions & 29 deletions

File tree

fineract-provider/src/test/java/org/apache/fineract/infrastructure/creditbureau/service/ThitsaWorksCreditBureauIntegrationWritePlatformServiceImplTest.java renamed to fineract-provider/src/test/java/org/apache/fineract/infrastructure/creditbureau/service/ExternalCreditBureauIntegrationWritePlatformServiceImplTest.java

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
import org.springframework.lang.NonNull;
7575

7676
@SuppressFBWarnings(value = "RV_EXCEPTION_NOT_THROWN", justification = "False positive")
77-
public class ThitsaWorksCreditBureauIntegrationWritePlatformServiceImplTest {
77+
public class ExternalCreditBureauIntegrationWritePlatformServiceImplTest {
7878

7979
@Spy
8080
private FromJsonHelper fromJsonHelper = new FromJsonHelper();
@@ -97,24 +97,29 @@ public class ThitsaWorksCreditBureauIntegrationWritePlatformServiceImplTest {
9797
private final ObjectMapper mapper = new ObjectMapper();
9898

9999
@InjectMocks
100-
private ThitsaWorksCreditBureauIntegrationWritePlatformServiceImpl underTest;
100+
private ExternalSourceCreditBureauIntegrationWritePlatformServiceImpl underTest;
101+
private static final long CREDIT_BUREAU_ID = 1L;
102+
private static final String TEST_USERNAME = "testUsername";
103+
private static final String TEST_PASSWORD = "testPassword";
104+
private static final String TEST_URL = "https://nrc.test.url.com";
101105

102106
@BeforeEach
103107
public void setup() {
104108
MockitoAnnotations.openMocks(this);
105-
when(configurationRepositoryWrapper.getCreditBureauConfigData(1, CreditBureauConfigurations.USERNAME.name()))
109+
int cbId = (int) CREDIT_BUREAU_ID;
110+
when(configurationRepositoryWrapper.getCreditBureauConfigData(cbId, CreditBureauConfigurations.USERNAME.name()))
106111
.thenReturn(new CreditBureauConfiguration().setValue("testUsername"));
107-
when(configurationRepositoryWrapper.getCreditBureauConfigData(1, CreditBureauConfigurations.PASSWORD.name()))
112+
when(configurationRepositoryWrapper.getCreditBureauConfigData(cbId, CreditBureauConfigurations.PASSWORD.name()))
108113
.thenReturn(new CreditBureauConfiguration().setValue("testPassword"));
109-
when(configurationRepositoryWrapper.getCreditBureauConfigData(1, CreditBureauConfigurations.CREDITREPORTURL.name()))
114+
when(configurationRepositoryWrapper.getCreditBureauConfigData(cbId, CreditBureauConfigurations.CREDITREPORTURL.name()))
110115
.thenReturn(new CreditBureauConfiguration().setValue("https://credit.report.url/api/"));
111-
when(configurationRepositoryWrapper.getCreditBureauConfigData(1, CreditBureauConfigurations.SEARCHURL.name()))
116+
when(configurationRepositoryWrapper.getCreditBureauConfigData(cbId, CreditBureauConfigurations.SEARCHURL.name()))
112117
.thenReturn(new CreditBureauConfiguration().setValue("https://search.report.url/api/"));
113-
when(configurationRepositoryWrapper.getCreditBureauConfigData(1, CreditBureauConfigurations.TOKENURL.name()))
118+
when(configurationRepositoryWrapper.getCreditBureauConfigData(cbId, CreditBureauConfigurations.TOKENURL.name()))
114119
.thenReturn(new CreditBureauConfiguration().setValue("https://token.url/api/"));
115-
when(configurationRepositoryWrapper.getCreditBureauConfigData(1, CreditBureauConfigurations.SUBSCRIPTIONID.name()))
120+
when(configurationRepositoryWrapper.getCreditBureauConfigData(cbId, CreditBureauConfigurations.SUBSCRIPTIONID.name()))
116121
.thenReturn(new CreditBureauConfiguration().setValue("subscriptionId"));
117-
when(configurationRepositoryWrapper.getCreditBureauConfigData(1, CreditBureauConfigurations.SUBSCRIPTIONKEY.name()))
122+
when(configurationRepositoryWrapper.getCreditBureauConfigData(cbId, CreditBureauConfigurations.SUBSCRIPTIONKEY.name()))
118123
.thenReturn(new CreditBureauConfiguration().setValue("subscriptionKey"));
119124

120125
}
@@ -164,7 +169,7 @@ public void okHttpInternalServerErrorTest() throws IOException {
164169
mockOkHttpCall(request -> createOkhttpResponse(request, 500, "Internal Server Error"));
165170

166171
assertThrows(PlatformDataIntegrityException.class, () -> {
167-
underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId", "https://nrc.test.url.com",
172+
underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId", TEST_URL,
168173
"AccessToken", null, null, 0L, "nrcId", "NRC");
169174

170175
});
@@ -190,7 +195,7 @@ public void okHttpInvalidProcessTestTest() throws IOException {
190195
mockOkHttpCall(request -> createOkhttpResponse(request, 500, "Internal Server Error"));
191196

192197
PlatformDataIntegrityException raisedException = assertThrows(PlatformDataIntegrityException.class, () -> {
193-
underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId", "https://nrc.test.url.com",
198+
underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId", TEST_URL,
194199
"AccessToken", null, null, 0L, "nrcId", "notValidProcess");
195200

196201
});
@@ -204,7 +209,7 @@ public void okHttpIOExceptionTest() throws IOException {
204209
});
205210

206211
assertThrows(PlatformDataIntegrityException.class, () -> {
207-
underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId", "https://nrc.test.url.com",
212+
underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId", TEST_URL,
208213
"AccessToken", null, null, 0L, "nrcId", "NRC");
209214

210215
});
@@ -230,7 +235,7 @@ public void okHttpNrcSuccessTest() throws IOException {
230235
});
231236

232237
String result = underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId",
233-
"https://nrc.test.url.com", "AccessToken", null, null, 0L, "nrcId", "NRC");
238+
TEST_URL, "AccessToken", null, null, 0L, "nrcId", "NRC");
234239
assertEquals(jsonResponse, result);
235240
}
236241

@@ -254,7 +259,7 @@ public void okHttpNrcNoTokenTest() throws IOException {
254259
});
255260

256261
String result = underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId",
257-
"https://nrc.test.url.com", null, null, null, 0L, "nrcId", "NRC");
262+
TEST_URL, null, null, null, 0L, "nrcId", "NRC");
258263
assertEquals(jsonResponse, result);
259264
}
260265

@@ -300,7 +305,7 @@ public void okHttpNoTokenTest() throws IOException {
300305
return createOkhttpResponse(request, 401, "Unauthorized");
301306
});
302307
assertThrows(PlatformDataIntegrityException.class, () -> {
303-
underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId", "https://nrc.test.url.com",
308+
underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId", TEST_URL,
304309
null, null, null, 0L, "nrcId", "token");
305310
});
306311
}
@@ -320,7 +325,7 @@ public void okHttpGetNrcReportSuccessTest() throws IOException {
320325
});
321326

322327
String result = underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId",
323-
"https://nrc.test.url.com", "AccessToken", null, null, 0L, "nrcId", "CreditReport");
328+
TEST_URL, "AccessToken", null, null, 0L, "nrcId", "CreditReport");
324329
assertEquals(jsonResponse, result);
325330
}
326331

@@ -329,7 +334,7 @@ public void okHttpForbiddenTest() throws IOException {
329334
mockOkHttpCall(request -> createOkhttpResponse(request, 403, "Forbidden"));
330335

331336
assertThrows(PlatformDataIntegrityException.class, () -> {
332-
underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId", "https://nrc.test.url.com",
337+
underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId", TEST_URL,
333338
"AccessToken", null, null, 0L, "nrcId", "CreditReport");
334339
});
335340
}
@@ -339,7 +344,7 @@ public void okHttpNoBodyReturned() throws IOException {
339344
mockOkHttpCall(request -> createOkhttpResponse(request, 200, "OK", null));
340345

341346
assertThrows(NullPointerException.class, () -> {
342-
underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId", "https://nrc.test.url.com",
347+
underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId", TEST_URL,
343348
"AccessToken", null, null, 0L, "nrcId", "CreditReport");
344349
});
345350
}
@@ -436,10 +441,10 @@ private void mockTokenGeneration() {
436441
}
437442

438443
@Test
439-
public void getCreditReportFromThitsaWorksSuccessTest() throws IOException {
444+
public void getCreditReportFromExternalSourceSuccessTest() throws IOException {
440445
mockTokenGeneration();
441446
mockOkHttpCall(request -> {
442-
// NRC Call
447+
// External API Call
443448
if (request.url().host().equals("search.report.url")) {
444449
return createOkhttpResponse(request, createResponseObjectArrayData(() -> "Success",
445450
data -> data.add(mapper.createObjectNode().put("UniqueID", "123456"))));
@@ -464,7 +469,7 @@ public void getCreditReportFromThitsaWorksSuccessTest() throws IOException {
464469
return createOkhttpResponse(request, 404, "Not Found");
465470
});
466471

467-
CreditBureauReportData result = underTest.getCreditReportFromThitsaWorks(initialJsonCommand());
472+
CreditBureauReportData result = underTest.getCreditReportFromExternalSource(initialJsonCommand());
468473
assertNotNull(result);
469474
}
470475

@@ -497,10 +502,10 @@ public void addCreditReportTest() throws IOException {
497502
}
498503

499504
@Test
500-
public void getCreditReportFromThitsaWorksEmptyBorrowerTest() throws IOException {
505+
public void getCreditReportFromExternalSourceEmptyBorrowerTest() throws IOException {
501506
mockTokenGeneration();
502507
mockOkHttpCall(request -> {
503-
// NRC Call
508+
// External API Call
504509
if (request.url().host().equals("search.report.url")) {
505510
return createOkhttpResponse(request, createResponseObjectArrayData(() -> "Success",
506511
data -> data.add(mapper.createObjectNode().put("UniqueID", "123456"))));
@@ -520,14 +525,14 @@ public void getCreditReportFromThitsaWorksEmptyBorrowerTest() throws IOException
520525
return createOkhttpResponse(request, 404, "Not Found");
521526
});
522527

523-
CreditBureauReportData result = underTest.getCreditReportFromThitsaWorks(initialJsonCommand());
528+
CreditBureauReportData result = underTest.getCreditReportFromExternalSource(initialJsonCommand());
524529
assertNotNull(result);
525530
assertNull(result.getGender());
526531
assertNotNull(result.getCreditScore());
527532
}
528533

529534
@Test
530-
public void getCreditReportFromThitsaWorksNoGenderTest() throws IOException {
535+
public void getCreditReportFromExternalSourceNoGenderTest() throws IOException {
531536
mockTokenGeneration();
532537
mockOkHttpCall(request -> {
533538
// NRC Call
@@ -554,17 +559,17 @@ public void getCreditReportFromThitsaWorksNoGenderTest() throws IOException {
554559
return createOkhttpResponse(request, 404, "Not Found");
555560
});
556561

557-
CreditBureauReportData result = underTest.getCreditReportFromThitsaWorks(initialJsonCommand());
562+
CreditBureauReportData result = underTest.getCreditReportFromExternalSource(initialJsonCommand());
558563
assertNotNull(result);
559564
assertNull(result.getGender());
560565
assertNotNull(result.getCreditScore());
561566
}
562567

563568
@Test
564-
public void getCreditReportFromThitsaWorksNoLoansTest() throws IOException {
569+
public void getCreditReportFromExternalSourceNoLoansTest() throws IOException {
565570
mockTokenGeneration();
566571
mockOkHttpCall(request -> {
567-
// NRC Call
572+
// External API Call
568573
if (request.url().host().equals("search.report.url")) {
569574
return createOkhttpResponse(request, createResponseObjectArrayData(() -> "Success",
570575
data -> data.add(mapper.createObjectNode().put("UniqueID", "123456"))));
@@ -586,7 +591,7 @@ public void getCreditReportFromThitsaWorksNoLoansTest() throws IOException {
586591
return createOkhttpResponse(request, 404, "Not Found");
587592
});
588593

589-
CreditBureauReportData result = underTest.getCreditReportFromThitsaWorks(initialJsonCommand());
594+
CreditBureauReportData result = underTest.getCreditReportFromExternalSource(initialJsonCommand());
590595
assertNotNull(result);
591596
assertNotNull(result.getGender());
592597
assertNull(result.getCreditScore());

0 commit comments

Comments
 (0)