Skip to content

Commit

Permalink
fix!: update account numbers serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
stevecl5 committed Apr 11, 2024
1 parent 8bcc565 commit a9ee598
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class AccountBaseAccessor extends Accessor {

@GatewayAPI
@Getter(AccessLevel.PROTECTED)
private AccountNumberBaseAccessor accountNumbers;
private AccountNumbersBaseAccessor accountNumbers;

@GatewayAPI
@Getter(AccessLevel.PROTECTED)
Expand Down Expand Up @@ -98,7 +98,7 @@ public AccountDetailsBaseAccessor accountDetails() {
* @return
*/
@API(description = "Access account numbers")
public AccountNumberBaseAccessor accountNumbers() {
public AccountNumbersBaseAccessor accountNumbers() {
if (accountNumbers != null) {
return accountNumbers;
}
Expand Down Expand Up @@ -197,7 +197,7 @@ public void setAccountDetails(AccountDetailsBaseAccessor accountDetails) {
*
* @param accountNumbers
*/
public void setAccountNumbers(AccountNumberBaseAccessor accountNumbers) {
public void setAccountNumbers(AccountNumbersBaseAccessor accountNumbers) {
this.accountNumbers = accountNumbers;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
*/
@GatewayClass
@API(description = "Access to user account numbers")
public abstract class AccountNumberBaseAccessor extends Accessor {
public AccountNumberBaseAccessor() {
public abstract class AccountNumbersBaseAccessor extends Accessor {
public AccountNumbersBaseAccessor() {
}

/**
* @param configuration
* @deprecated Use the default constructor, the configuration is set by the accessor construction context code
*/
@Deprecated
public AccountNumberBaseAccessor(AccessorConfiguration configuration) {
public AccountNumbersBaseAccessor(AccessorConfiguration configuration) {
super(configuration);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import com.google.gson.reflect.TypeToken;
import com.mx.path.model.mdx.model.account.Account;
import com.mx.path.model.mdx.model.account.AccountDetails;
import com.mx.path.model.mdx.model.account.AccountNumber;
import com.mx.path.model.mdx.model.account.AccountNumbers;
import com.mx.path.model.mdx.model.account.AccountOwner;
import com.mx.path.model.mdx.model.account.AccountOwnerDetails;
import com.mx.path.model.mdx.model.account.AccountTransactions;
import com.mx.path.model.mdx.model.account.OnDemandAccountNumbers;
import com.mx.path.model.mdx.model.account.OnDemandAccounts;
import com.mx.path.model.mdx.model.account.Overdraft;
import com.mx.path.model.mdx.model.account.StopPayment;
Expand Down Expand Up @@ -48,13 +48,13 @@
import com.mx.path.model.mdx.model.ondemand.MdxOnDemandDeserializer;
import com.mx.path.model.mdx.model.ondemand.MdxOnDemandMdxListSerializer;
import com.mx.path.model.mdx.model.ondemand.MdxOnDemandSerializer;
import com.mx.path.model.mdx.model.ondemand.mixins.AccountNumberXmlMixin;
import com.mx.path.model.mdx.model.ondemand.mixins.AccountNumbersXmlMixin;
import com.mx.path.model.mdx.model.ondemand.mixins.AccountOwnerDetailsXmlMixin;
import com.mx.path.model.mdx.model.ondemand.mixins.AccountOwnerXmlMixin;
import com.mx.path.model.mdx.model.ondemand.mixins.AccountTransactionsMixIn;
import com.mx.path.model.mdx.model.ondemand.mixins.AccountXmlMixin;
import com.mx.path.model.mdx.model.ondemand.mixins.MixinDefinition;
import com.mx.path.model.mdx.model.ondemand.mixins.OnDemandAccountNumbersXmlMixin;
import com.mx.path.model.mdx.model.ondemand.mixins.OnDemandAccountsXmlMixin;
import com.mx.path.model.mdx.model.ondemand.mixins.SessionXmlMixin;
import com.mx.path.model.mdx.model.ondemand.mixins.TransactionMixIn;
Expand Down Expand Up @@ -112,6 +112,7 @@ public static void registerResources(GsonBuilder builder) {
builder.registerTypeAdapter(Account.class, new ModelWrappableSerializer("account"));
builder.registerTypeAdapter(new TypeToken<MdxList<Account>>() {
}.getType(), new ModelWrappableSerializer("accounts"));
builder.registerTypeAdapter(AccountNumbers.class, new ModelWrappableSerializer("account"));
builder.registerTypeAdapter(AccountDetails.class, new ModelWrappableSerializer("account_details"));
builder.registerTypeAdapter(Overdraft.class, new ModelWrappableSerializer("overdraft"));
builder.registerTypeAdapter(StopPayment.class, new ModelWrappableSerializer("stop_payment"));
Expand Down Expand Up @@ -287,16 +288,16 @@ public static void registerOnDemandResources(SimpleModule module) {
new MixinDefinition(TransactionsPage.class, TransactionsPageMixin.class),
new MixinDefinition(Transaction.class, TransactionMixIn.class)));

module.addSerializer(AccountNumbers.class, new MdxOnDemandSerializer<>(
new MixinDefinition(AccountNumbers.class, AccountNumbersXmlMixin.class),
new MixinDefinition(AccountNumber.class, AccountNumberXmlMixin.class)));
module.addSerializer(AccountOwner.class, new MdxOnDemandSerializer<>(
new MixinDefinition(AccountOwner.class, AccountOwnerXmlMixin.class),
new MixinDefinition(AccountOwnerDetails.class, AccountOwnerDetailsXmlMixin.class)));

module.addSerializer(OnDemandAccounts.class, new MdxOnDemandSerializer<>(
new MixinDefinition(OnDemandAccounts.class, OnDemandAccountsXmlMixin.class),
new MixinDefinition(Account.class, AccountXmlMixin.class)));
module.addSerializer(OnDemandAccountNumbers.class, new MdxOnDemandSerializer<>(
new MixinDefinition(OnDemandAccountNumbers.class, OnDemandAccountNumbersXmlMixin.class),
new MixinDefinition(AccountNumbers.class, AccountNumbersXmlMixin.class)));
}

private static void registerProfileModelClasses(GsonBuilder builder) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
import com.mx.path.model.mdx.model.MdxBase;

public final class AccountNumbers extends MdxBase<AccountNumbers> {
private String id;
private AccountNumber accountNumbers;
private String accountNumber;
private String routingNumber;

public String getId() {
return id;
public String getAccountNumber() {
return accountNumber;
}

public void setId(String id) {
this.id = id;
public void setAccountNumber(String accountNumber) {
this.accountNumber = accountNumber;
}

public AccountNumber getAccountNumbers() {
return accountNumbers;
public String getRoutingNumber() {
return routingNumber;
}

public void setAccountNumbers(AccountNumber accountNumbers) {
this.accountNumbers = accountNumbers;
public void setRoutingNumber(String routingNumber) {
this.routingNumber = routingNumber;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.mx.path.model.mdx.model.account;

import com.mx.path.model.mdx.model.MdxBase;

/**
* Wraps account numbers for an account to help with OnDemand serialization.
*/
public final class OnDemandAccountNumbers extends MdxBase<OnDemandAccountNumbers> {
private String id;
private AccountNumbers accountNumbers;

public OnDemandAccountNumbers(AccountNumbers accountNumbers, String id) {
this.id = id;
this.accountNumbers = accountNumbers;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public AccountNumbers getAccountNumbers() {
return accountNumbers;
}

public void setAccountNumbers(AccountNumbers accountNumbers) {
this.accountNumbers = accountNumbers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.mx.path.model.mdx.model.MdxList;

/**
* Represents a list of accounts. Helps for OnDemand serialization
* Wraps a list of accounts to help with OnDemand serialization.
*/
public class OnDemandAccounts extends MdxBase<OnDemandAccounts> {
private MdxList<Account> accounts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonRootName;

@JsonRootName("account")
@JsonRootName("account_numbers")
public interface AccountNumbersXmlMixin {
@JsonIgnore
boolean getWrapped();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonRootName;

@JsonRootName("account_numbers")
public interface AccountNumberXmlMixin {
@JsonRootName("account")
public interface OnDemandAccountNumbersXmlMixin {
@JsonIgnore
boolean getWrapped();
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mx.path.gateway.accessor.AccessorResponse;
import com.mx.path.model.mdx.model.account.AccountNumbers;
import com.mx.path.model.mdx.model.account.OnDemandAccountNumbers;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
Expand All @@ -14,10 +15,11 @@
@RequestMapping(value = "{clientId}")
public class AccountNumbersController extends BaseController {
@RequestMapping(value = "/accounts/{id}/account_numbers", method = RequestMethod.GET, produces = BaseController.MDX_ONDEMAND_MEDIA)
public final ResponseEntity<AccountNumbers> getOnDemandAccountNumbers(@PathVariable("id") String accountId) throws Exception {
public final ResponseEntity<OnDemandAccountNumbers> getOnDemandAccountNumbers(@PathVariable("id") String accountId) throws Exception {
ensureFeature("accounts");
AccessorResponse<AccountNumbers> response = gateway().accounts().accountNumbers().get(accountId);
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
OnDemandAccountNumbers accountNumbers = new OnDemandAccountNumbers(response.getResult(), accountId);
return new ResponseEntity<>(accountNumbers.wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
}

@RequestMapping(value = "/users/{userId}/accounts/{id}/account_number", method = RequestMethod.GET, produces = BaseController.MDX_MEDIA)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.mx.path.core.context.RequestContext
import com.mx.path.gateway.accessor.AccessorResponse
import com.mx.path.gateway.api.Gateway
import com.mx.path.gateway.api.account.AccountGateway
import com.mx.path.gateway.api.account.AccountNumberGateway
import com.mx.path.gateway.api.account.AccountNumbersGateway
import com.mx.path.model.mdx.model.account.AccountNumbers

import spock.lang.Specification
Expand All @@ -17,16 +17,16 @@ class AccountNumbersControllerTest extends Specification {
AccountNumbersController subject
Gateway gateway
AccountGateway accountGateway
AccountNumberGateway accountNumberGateway
AccountNumbersGateway accountNumbersGateway

def setup() {
def clientId = "client-1234"
subject = new AccountNumbersController()

RequestContext.builder().clientId(clientId).build().register()

accountNumberGateway = spy(AccountNumberGateway.builder().clientId(clientId).build())
accountGateway = spy(AccountGateway.builder().clientId(clientId).accountNumbers(accountNumberGateway).build())
accountNumbersGateway = spy(AccountNumbersGateway.builder().clientId(clientId).build())
accountGateway = spy(AccountGateway.builder().clientId(clientId).accountNumbers(accountNumbersGateway).build())
gateway = spy(Gateway.builder().clientId(clientId).accounts(accountGateway).build())
}

Expand All @@ -41,13 +41,14 @@ class AccountNumbersControllerTest extends Specification {
def accountNumbers = new AccountNumbers()

when:
doReturn(new AccessorResponse<AccountNumbers>().withResult(accountNumbers)).when(accountNumberGateway).get("A-123")
doReturn(new AccessorResponse<AccountNumbers>().withResult(accountNumbers)).when(accountNumbersGateway).get("A-123")
def result = subject.getOnDemandAccountNumbers("A-123")

then:
verify(accountGateway).accountNumbers() || true
verify(accountNumberGateway).get("A-123") || true
result.getBody() == accountNumbers
verify(accountNumbersGateway).get("A-123") || true
result.body.accountNumbers == accountNumbers
result.body.id == "A-123"
RequestContext.current().feature == "accounts"
}

Expand All @@ -57,12 +58,12 @@ class AccountNumbersControllerTest extends Specification {
def accountNumbers = new AccountNumbers()

when:
doReturn(new AccessorResponse<AccountNumbers>().withResult(accountNumbers)).when(accountNumberGateway).get("A-123")
doReturn(new AccessorResponse<AccountNumbers>().withResult(accountNumbers)).when(accountNumbersGateway).get("A-123")
def result = subject.getAccountNumbers("A-123")

then:
verify(accountGateway).accountNumbers() || true
verify(accountNumberGateway).get("A-123") || true
result.getBody() == accountNumbers
verify(accountNumbersGateway).get("A-123") || true
result.body == accountNumbers
}
}

0 comments on commit a9ee598

Please sign in to comment.