Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
import org.springframework.lang.NonNull;

@SuppressFBWarnings(value = "RV_EXCEPTION_NOT_THROWN", justification = "False positive")
public class ThitsaWorksCreditBureauIntegrationWritePlatformServiceImplTest {
public class ExternalCreditBureauIntegrationWritePlatformServiceImplTest {

@Spy
private FromJsonHelper fromJsonHelper = new FromJsonHelper();
Expand All @@ -97,24 +97,29 @@ public class ThitsaWorksCreditBureauIntegrationWritePlatformServiceImplTest {
private final ObjectMapper mapper = new ObjectMapper();

@InjectMocks
private ThitsaWorksCreditBureauIntegrationWritePlatformServiceImpl underTest;
private ExternalSourceCreditBureauIntegrationWritePlatformServiceImpl underTest;
private static final long CREDIT_BUREAU_ID = 1L;
private static final String TEST_USERNAME = "testUsername";
private static final String TEST_PASSWORD = "testPassword";
private static final String TEST_URL = "https://nrc.test.url.com";

@BeforeEach
public void setup() {
MockitoAnnotations.openMocks(this);
when(configurationRepositoryWrapper.getCreditBureauConfigData(1, CreditBureauConfigurations.USERNAME.name()))
int cbId = (int) CREDIT_BUREAU_ID;
when(configurationRepositoryWrapper.getCreditBureauConfigData(cbId, CreditBureauConfigurations.USERNAME.name()))
.thenReturn(new CreditBureauConfiguration().setValue("testUsername"));
when(configurationRepositoryWrapper.getCreditBureauConfigData(1, CreditBureauConfigurations.PASSWORD.name()))
when(configurationRepositoryWrapper.getCreditBureauConfigData(cbId, CreditBureauConfigurations.PASSWORD.name()))
.thenReturn(new CreditBureauConfiguration().setValue("testPassword"));
when(configurationRepositoryWrapper.getCreditBureauConfigData(1, CreditBureauConfigurations.CREDITREPORTURL.name()))
when(configurationRepositoryWrapper.getCreditBureauConfigData(cbId, CreditBureauConfigurations.CREDITREPORTURL.name()))
.thenReturn(new CreditBureauConfiguration().setValue("https://credit.report.url/api/"));
when(configurationRepositoryWrapper.getCreditBureauConfigData(1, CreditBureauConfigurations.SEARCHURL.name()))
when(configurationRepositoryWrapper.getCreditBureauConfigData(cbId, CreditBureauConfigurations.SEARCHURL.name()))
.thenReturn(new CreditBureauConfiguration().setValue("https://search.report.url/api/"));
when(configurationRepositoryWrapper.getCreditBureauConfigData(1, CreditBureauConfigurations.TOKENURL.name()))
when(configurationRepositoryWrapper.getCreditBureauConfigData(cbId, CreditBureauConfigurations.TOKENURL.name()))
.thenReturn(new CreditBureauConfiguration().setValue("https://token.url/api/"));
when(configurationRepositoryWrapper.getCreditBureauConfigData(1, CreditBureauConfigurations.SUBSCRIPTIONID.name()))
when(configurationRepositoryWrapper.getCreditBureauConfigData(cbId, CreditBureauConfigurations.SUBSCRIPTIONID.name()))
.thenReturn(new CreditBureauConfiguration().setValue("subscriptionId"));
when(configurationRepositoryWrapper.getCreditBureauConfigData(1, CreditBureauConfigurations.SUBSCRIPTIONKEY.name()))
when(configurationRepositoryWrapper.getCreditBureauConfigData(cbId, CreditBureauConfigurations.SUBSCRIPTIONKEY.name()))
.thenReturn(new CreditBureauConfiguration().setValue("subscriptionKey"));

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

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

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

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

});
Expand All @@ -204,7 +209,7 @@ public void okHttpIOExceptionTest() throws IOException {
});

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

});
Expand All @@ -230,7 +235,7 @@ public void okHttpNrcSuccessTest() throws IOException {
});

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

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

String result = underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId",
"https://nrc.test.url.com", null, null, null, 0L, "nrcId", "NRC");
TEST_URL, null, null, null, 0L, "nrcId", "NRC");
assertEquals(jsonResponse, result);
}

Expand Down Expand Up @@ -300,7 +305,7 @@ public void okHttpNoTokenTest() throws IOException {
return createOkhttpResponse(request, 401, "Unauthorized");
});
assertThrows(PlatformDataIntegrityException.class, () -> {
underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId", "https://nrc.test.url.com",
underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId", TEST_URL,
null, null, null, 0L, "nrcId", "token");
});
}
Expand All @@ -320,7 +325,7 @@ public void okHttpGetNrcReportSuccessTest() throws IOException {
});

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

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

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

assertThrows(NullPointerException.class, () -> {
underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId", "https://nrc.test.url.com",
underTest.okHttpConnectionMethod("testUser", "testPassword", "subscriptionKey", "subscriptionId", TEST_URL,
"AccessToken", null, null, 0L, "nrcId", "CreditReport");
});
}
Expand Down Expand Up @@ -436,10 +441,10 @@ private void mockTokenGeneration() {
}

@Test
public void getCreditReportFromThitsaWorksSuccessTest() throws IOException {
public void getCreditReportFromExternalSourceSuccessTest() throws IOException {
mockTokenGeneration();
mockOkHttpCall(request -> {
// NRC Call
// External API Call
if (request.url().host().equals("search.report.url")) {
return createOkhttpResponse(request, createResponseObjectArrayData(() -> "Success",
data -> data.add(mapper.createObjectNode().put("UniqueID", "123456"))));
Expand All @@ -464,7 +469,7 @@ public void getCreditReportFromThitsaWorksSuccessTest() throws IOException {
return createOkhttpResponse(request, 404, "Not Found");
});

CreditBureauReportData result = underTest.getCreditReportFromThitsaWorks(initialJsonCommand());
CreditBureauReportData result = underTest.getCreditReportFromExternalSource(initialJsonCommand());
assertNotNull(result);
}

Expand Down Expand Up @@ -497,10 +502,10 @@ public void addCreditReportTest() throws IOException {
}

@Test
public void getCreditReportFromThitsaWorksEmptyBorrowerTest() throws IOException {
public void getCreditReportFromExternalSourceEmptyBorrowerTest() throws IOException {
mockTokenGeneration();
mockOkHttpCall(request -> {
// NRC Call
// External API Call
if (request.url().host().equals("search.report.url")) {
return createOkhttpResponse(request, createResponseObjectArrayData(() -> "Success",
data -> data.add(mapper.createObjectNode().put("UniqueID", "123456"))));
Expand All @@ -520,14 +525,14 @@ public void getCreditReportFromThitsaWorksEmptyBorrowerTest() throws IOException
return createOkhttpResponse(request, 404, "Not Found");
});

CreditBureauReportData result = underTest.getCreditReportFromThitsaWorks(initialJsonCommand());
CreditBureauReportData result = underTest.getCreditReportFromExternalSource(initialJsonCommand());
assertNotNull(result);
assertNull(result.getGender());
assertNotNull(result.getCreditScore());
}

@Test
public void getCreditReportFromThitsaWorksNoGenderTest() throws IOException {
public void getCreditReportFromExternalSourceNoGenderTest() throws IOException {
mockTokenGeneration();
mockOkHttpCall(request -> {
// NRC Call
Expand All @@ -554,17 +559,17 @@ public void getCreditReportFromThitsaWorksNoGenderTest() throws IOException {
return createOkhttpResponse(request, 404, "Not Found");
});

CreditBureauReportData result = underTest.getCreditReportFromThitsaWorks(initialJsonCommand());
CreditBureauReportData result = underTest.getCreditReportFromExternalSource(initialJsonCommand());
assertNotNull(result);
assertNull(result.getGender());
assertNotNull(result.getCreditScore());
}

@Test
public void getCreditReportFromThitsaWorksNoLoansTest() throws IOException {
public void getCreditReportFromExternalSourceNoLoansTest() throws IOException {
mockTokenGeneration();
mockOkHttpCall(request -> {
// NRC Call
// External API Call
if (request.url().host().equals("search.report.url")) {
return createOkhttpResponse(request, createResponseObjectArrayData(() -> "Success",
data -> data.add(mapper.createObjectNode().put("UniqueID", "123456"))));
Expand All @@ -586,7 +591,7 @@ public void getCreditReportFromThitsaWorksNoLoansTest() throws IOException {
return createOkhttpResponse(request, 404, "Not Found");
});

CreditBureauReportData result = underTest.getCreditReportFromThitsaWorks(initialJsonCommand());
CreditBureauReportData result = underTest.getCreditReportFromExternalSource(initialJsonCommand());
assertNotNull(result);
assertNotNull(result.getGender());
assertNull(result.getCreditScore());
Expand Down
Loading