Skip to content
Merged
Show file tree
Hide file tree
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
@@ -0,0 +1,31 @@
package com.mx.path.model.mdx.accessor.p2p_transfer;

import com.mx.path.core.common.accessor.API;
import com.mx.path.core.common.accessor.AccessorMethodNotImplementedException;
import com.mx.path.core.common.gateway.GatewayAPI;
import com.mx.path.core.common.gateway.GatewayClass;
import com.mx.path.gateway.accessor.Accessor;
import com.mx.path.gateway.accessor.AccessorResponse;
import com.mx.path.model.mdx.model.MdxList;
import com.mx.path.model.mdx.model.account.Account;

/**
* Accessor base for P2P transfer account operations
*/
@GatewayClass
@API(specificationUrl = "https://developer.mx.com/drafts/mdx/p2p_transfer/index.html#p2p-transfer-accounts")
public class AccountBaseAccessor extends Accessor {
public AccountBaseAccessor() {
}

/**
* Lists all p2p transfer accounts
*
* @return MdxList<Account>
*/
@GatewayAPI
@API(description = "Lists all accounts for P2P transfers")
public AccessorResponse<MdxList<Account>> list() {
throw new AccessorMethodNotImplementedException();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,32 @@
@GatewayClass
@API(specificationUrl = "https://developer.mx.com/drafts/mdx/p2p_transfer/index.html#p2p-transfers")
public class P2PTransferBaseAccessor extends Accessor {
@GatewayAPI
@Getter(AccessLevel.PROTECTED)
private AccountBaseAccessor accounts;

@GatewayAPI
@Getter(AccessLevel.PROTECTED)
private DurationBaseAccessor durations;

/**
* Accessor for account operations
*
* @return accessor
*/
@API
public AccountBaseAccessor accounts() {
return accounts;
}

/**
* Sets account accessor
* @param accounts
*/
public void setAccounts(AccountBaseAccessor accounts) {
this.accounts = accounts;
}

/**
* Accessor for duration operations
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.mx.path.model.mdx.web.controller;

import com.mx.path.gateway.accessor.AccessorResponse;
import com.mx.path.model.mdx.model.MdxList;
import com.mx.path.model.mdx.model.account.Account;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "{clientId}", produces = BaseController.MDX_MEDIA)
public class P2PTransferAccountsController extends BaseController {
@RequestMapping(value = "/users/{userId}/accounts/p2p_transfer", method = RequestMethod.GET)
public final ResponseEntity<MdxList<Account>> list() {
AccessorResponse<MdxList<Account>> response = gateway().p2pTransfers().accounts().list();
return new ResponseEntity<>(response.getResult().wrapped(), createMultiMapForResponse(response.getHeaders()), HttpStatus.OK);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.mx.path.model.mdx.web.controller

import static org.mockito.Mockito.doReturn
import static org.mockito.Mockito.mock
import static org.mockito.Mockito.spy
import static org.mockito.Mockito.verify

import com.mx.path.gateway.accessor.AccessorResponse
import com.mx.path.gateway.api.Gateway
import com.mx.path.gateway.api.p2p_transfer.AccountGateway
import com.mx.path.gateway.api.p2p_transfer.P2PTransferGateway
import com.mx.path.model.mdx.model.MdxList
import com.mx.path.model.mdx.model.account.Account

import org.springframework.http.HttpStatus

import spock.lang.Specification

class P2PTransferAccountsControllerTest extends Specification {
P2PTransferAccountsController subject
Gateway gateway
P2PTransferGateway p2pTransferGateway
AccountGateway accountGateway

def setup() {
subject = new P2PTransferAccountsController()
p2pTransferGateway = mock(P2PTransferGateway)
accountGateway = mock(AccountGateway)

doReturn(accountGateway).when(p2pTransferGateway).accounts()
gateway = spy(Gateway.builder().clientId("client-1234").p2pTransfers(p2pTransferGateway).build())
}

def cleanup() {
BaseController.clearGateway()
}

def "list interacts with gateway"() {
given:
BaseController.setGateway(gateway)
def accounts = new MdxList().tap {
add(new Account())
}
doReturn(new AccessorResponse<MdxList<Account>>().withResult(accounts)).when(accountGateway).list()

when:
def result = subject.list()

then:
HttpStatus.OK == result.statusCode
result.body == accounts
verify(accountGateway).list() || true
}
}