Skip to content

Commit

Permalink
Merge pull request #269 from Backbase/generate-real-rtn-as-bank-code-…
Browse files Browse the repository at this point in the history
…for-contacts

Generate real RTN-s as bank code for contacts
  • Loading branch information
polarfish authored Apr 19, 2023
2 parents 761c29a + 5025fbf commit 684fbbe
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 9 deletions.
10 changes: 8 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<api.target>${project.build.directory}/downloaded-api</api.target>
<openapi-generator-version>5.1.0</openapi-generator-version>
<boat-maven-plugin.version>0.14.3</boat-maven-plugin.version>
<jackson-databind.version>2.12.7.1</jackson-databind.version>
<jackson-bom.version>2.14.2</jackson-bom.version>
<jackson-databind-nullable-version>0.2.1</jackson-databind-nullable-version>
<swagger-annotations-version>1.6.0</swagger-annotations-version>
<jsr305-version>3.0.0</jsr305-version>
Expand Down Expand Up @@ -67,6 +67,13 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson</groupId>
<artifactId>jackson-bom</artifactId>
<version>${jackson-bom.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -209,7 +216,6 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson-databind.version}</version>
</dependency>
<dependency>
<groupId>org.openapitools</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import static com.backbase.ct.bbfuel.data.CommonConstants.PROPERTY_CONTACTS_ACCOUNT_TYPES;
import static com.backbase.ct.bbfuel.data.ProductSummaryDataGenerator.generateRandomIban;
import static java.util.Arrays.*;
import static com.backbase.ct.bbfuel.util.CommonHelpers.createRandomValidRtn;
import static java.util.Arrays.asList;

import com.backbase.ct.bbfuel.util.CommonHelpers;
import com.backbase.ct.bbfuel.util.GlobalProperties;
Expand All @@ -13,7 +14,6 @@
import com.backbase.dbs.productsummary.presentation.rest.spec.v2.contacts.ContactsBulkIngestionPostRequestBody;
import com.github.javafaker.Faker;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.UUID;
Expand Down Expand Up @@ -63,7 +63,7 @@ private static ExternalContact generateContact(int numberOfAccounts) {
.withTown(faker.address().cityName())
.withCountry(faker.address().countryCode())
.withCountrySubDivision(faker.address().state()))
.withBankCode(faker.lorem().characters(10))
.withBankCode(createRandomValidRtn())
.withBankAddress(new Address()
.withAddressLine1(faker.address().streetAddress())
.withAddressLine2(faker.address().secondaryAddress())
Expand Down Expand Up @@ -111,7 +111,8 @@ private static ExternalAccountInformation determineTheUseOfIBANorBBAN(

case BBAN:
int randomBbanAccount = CommonHelpers.generateRandomNumberInRange(100000, 999999999);
returnedExternalAccountInformation = externalAccountInformation.withAccountNumber(String.valueOf(randomBbanAccount));
returnedExternalAccountInformation = externalAccountInformation.withAccountNumber(
String.valueOf(randomBbanAccount));
break;

default:
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/backbase/ct/bbfuel/util/CommonHelpers.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.RandomUtils;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class CommonHelpers {
Expand Down Expand Up @@ -70,4 +71,23 @@ public static String generateRandomCardProvider() {
return CreditCardType.values()[new Faker().random().nextInt(CreditCardType.values().length)]
.name().replace("_", " ");
}

public static String createRandomValidRtn() {
return createValidRtn(RandomUtils.nextInt(1000_0000, 9000_0000));
}

public static String createValidRtn(int baseNumber) {
byte[] rtnBytes = new byte[8];
int[] rtn = new int[8];
for (int i = 7; i >= 0; i--) {
rtnBytes[i] = (byte) (baseNumber % 10 + 48);
rtn[i] = baseNumber % 10;
baseNumber = baseNumber / 10;
}

return new String(rtnBytes) + (Math.abs((3 * (rtn[0] + rtn[3] + rtn[6])
+ 7 * (rtn[1] + rtn[4] + rtn[7])
+ (rtn[2] + rtn[5])) % 10 - 10) % 10);
}

}
8 changes: 5 additions & 3 deletions src/main/java/com/backbase/ct/bbfuel/util/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ParserUtil {

private static final ObjectMapper READ_MAPPER = new ObjectMapper().registerModule(new JavaTimeModule());
private static final ObjectMapper WRITE_MAPPER = new ObjectMapper();

public static <T> T convertJsonToObject(String jsonLocation, Class<T> valueType) throws IOException {
InputStream resourceAsStream = valueType.getClassLoader().getResourceAsStream(jsonLocation);
if (resourceAsStream == null) {
resourceAsStream = new FileInputStream(jsonLocation);
}

return mapper.readValue(resourceAsStream, valueType);
return READ_MAPPER.readValue(resourceAsStream, valueType);
}

public static <T> List<T> convertJsonToList(String jsonLocation, Class<T> valueType) throws IOException {
return asList(convertJsonToObject(jsonLocation, valueType));
}

public static void convertObjectToJson(OutputStream output, Object object) throws IOException {
new ObjectMapper().writeValue(output, object);
WRITE_MAPPER.writeValue(output, object);
}

private static ObjectMapper mapper = new ObjectMapper().registerModule(new JavaTimeModule());
}
23 changes: 23 additions & 0 deletions src/test/java/com/backbase/ct/bbfuel/util/CommonHelpersTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.backbase.ct.bbfuel.util;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class CommonHelpersTest {

@Test
public void testCreateValidRtn() {
assertEquals("000000000", CommonHelpers.createValidRtn(0));
assertEquals("000000990", CommonHelpers.createValidRtn(99));
assertEquals("123456780", CommonHelpers.createValidRtn(12345678));
assertEquals("123123123", CommonHelpers.createValidRtn(12312312));
assertEquals("111111118", CommonHelpers.createValidRtn(11111111));
assertEquals("474836473", CommonHelpers.createValidRtn(Integer.MAX_VALUE));
}

@Test
public void testCreateRandomValidRtn() {
assertEquals(9, CommonHelpers.createRandomValidRtn().length());
}
}

0 comments on commit 684fbbe

Please sign in to comment.