6 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/src/test/java/com/tesobe/obp/AbstractTestSupport.java:
--------------------------------------------------------------------------------
1 | package com.tesobe.obp;
2 |
3 | import com.tesobe.obp.clientapi.DirectAuthenticationClient;
4 | import com.tesobe.obp.clientapi.ObpApiClient;
5 | import com.tesobe.obp.clientapi.ObpBankMetaApiClient;
6 | import com.tesobe.obp.domain.Account;
7 | import com.tesobe.obp.domain.AccountRouting;
8 | import com.tesobe.obp.domain.Branch;
9 | import com.tesobe.obp.domain.User;
10 | import org.joda.money.CurrencyUnit;
11 | import org.joda.money.Money;
12 | import org.junit.Assert;
13 | import org.junit.Before;
14 | import org.junit.runner.RunWith;
15 | import org.springframework.beans.factory.annotation.Autowired;
16 | import org.springframework.beans.factory.annotation.Value;
17 | import org.springframework.boot.test.context.SpringBootTest;
18 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
19 | import org.springframework.security.core.context.SecurityContextHolder;
20 | import org.springframework.security.core.context.SecurityContextImpl;
21 | import org.springframework.test.context.TestPropertySource;
22 | import org.springframework.test.context.junit4.SpringRunner;
23 |
24 | import java.util.Collections;
25 | import java.util.List;
26 | import java.util.UUID;
27 |
28 | @RunWith(SpringRunner.class)
29 | @TestPropertySource(locations = {"classpath:auth.properties"})
30 | @SpringBootTest
31 | public abstract class AbstractTestSupport {
32 | @Value("${obp.username}")
33 | private String username;
34 |
35 | @Value("${obp.password}")
36 | private String password;
37 |
38 | @Value("${obp.consumerKey}")
39 | private String consumerKey;
40 |
41 | @Autowired private DirectAuthenticationClient authClient;
42 | @Autowired private ObpApiClient obpApiClient;
43 | @Autowired private ObpBankMetaApiClient obpBankMetaApiClient;
44 |
45 | @Before
46 | public void init() {
47 | String token = authClient.login(username, password, consumerKey);
48 | SecurityContextHolder.setContext(new SecurityContextImpl(
49 | new UsernamePasswordAuthenticationToken(username, token)));
50 | //a pre-requisite for tests is for the user to have an account
51 | createAccountIfNoneExists();
52 | }
53 |
54 | private void createAccountIfNoneExists() {
55 | User currentUser = obpApiClient.getCurrentUser();
56 |
57 | if(obpApiClient.getPrivateAccountsNoDetails().size() == 0) {
58 | //find a bank with at least a branch
59 | List
bankBranchPair = obpBankMetaApiClient.getBanks().getBanks()
60 | .stream().map(bank -> {
61 | {
62 | try {
63 | List branches = obpBankMetaApiClient.getBranches(bank.getId()).getBranches();
64 | return List.of(bank.getId(), branches.get(0).getId());
65 | } catch (Exception e) {
66 | //TODO: fix API not to return 400 if no branches are found for a bank
67 | return Collections.emptyList();
68 | }
69 | }
70 | })
71 | .filter(v -> !v.isEmpty())
72 | .findFirst().get();
73 |
74 | String accountId = UUID.randomUUID().toString();
75 | Account accountRequest = new Account();
76 | accountRequest.setUserId(currentUser.getUserId());
77 | accountRequest.setBranchId(bankBranchPair.get(1));
78 | accountRequest.setAccountRouting(new AccountRouting("OBP", "UK123456"));
79 | accountRequest.setBalance(Money.zero(CurrencyUnit.EUR));
80 | accountRequest.setType("CURRENT");
81 | accountRequest.setLabel("Label1");
82 | Account account = obpApiClient.createAccount(bankBranchPair.get(0), accountId, accountRequest);
83 | Assert.assertNotNull(account);
84 | }
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/test/java/com/tesobe/obp/auth/DirectAuthenticationServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.tesobe.obp.auth;
2 |
3 | import com.tesobe.obp.clientapi.DirectAuthenticationClient;
4 | import feign.FeignException;
5 | import org.junit.Assert;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.beans.factory.annotation.Value;
10 | import org.springframework.boot.test.context.SpringBootTest;
11 | import org.springframework.http.HttpStatus;
12 | import org.springframework.test.context.TestPropertySource;
13 | import org.springframework.test.context.junit4.SpringRunner;
14 |
15 | @RunWith(SpringRunner.class)
16 | @SpringBootTest
17 | @TestPropertySource(locations = {"classpath:auth.properties"})
18 | public class DirectAuthenticationServiceTest {
19 |
20 | @Value("${obp.username}")
21 | private String username;
22 |
23 | @Value("${obp.password}")
24 | private String password;
25 |
26 | @Value("${obp.consumerKey}")
27 | private String consumerKey;
28 |
29 | @Autowired private DirectAuthenticationClient directAuthenticationClient;
30 |
31 | @Test
32 | public void loginOk() throws Exception {
33 | String token = directAuthenticationClient.login(username, password, consumerKey);
34 | Assert.assertNotNull(token);
35 | }
36 |
37 | @Test
38 | public void badCredentials() throws Exception {
39 | String username = "wrong";
40 | String password = "garble";
41 | try {
42 | directAuthenticationClient.login(username, password, "garble");
43 | } catch (Exception ex) {
44 | Assert.assertEquals(HttpStatus.UNAUTHORIZED.value(), ((FeignException)ex).status());
45 | return;
46 | }
47 | Assert.assertFalse("Should have gotten 401 exception", true);
48 | }
49 |
50 | }
--------------------------------------------------------------------------------
/src/test/java/com/tesobe/obp/bankmeta/BankMetadataTest.java:
--------------------------------------------------------------------------------
1 | package com.tesobe.obp.bankmeta;
2 |
3 | import com.tesobe.obp.AbstractTestSupport;
4 | import com.tesobe.obp.clientapi.ObpBankMetaApiClient;
5 | import com.tesobe.obp.domain.Bank;
6 | import com.tesobe.obp.domain.Branch;
7 | import org.junit.Assert;
8 | import org.junit.Test;
9 | import org.springframework.beans.factory.annotation.Autowired;
10 |
11 | import java.util.Collection;
12 | import java.util.List;
13 | import java.util.Map;
14 | import java.util.Objects;
15 | import java.util.stream.Collectors;
16 |
17 | public class BankMetadataTest extends AbstractTestSupport {
18 |
19 | @Autowired private ObpBankMetaApiClient obpBankMetaApiClient;
20 |
21 | @Test
22 | public void allBanksOk() {
23 | List allBanks = obpBankMetaApiClient.getBanks().getBanks();
24 | Assert.assertTrue(allBanks.size() > 0);
25 | }
26 |
27 | @Test
28 | public void allBranchesOk() {
29 | List allBanks = obpBankMetaApiClient.getBanks().getBanks();
30 | Map> banksWithBranches = allBanks.stream().map(bank -> {
31 | List branches = obpBankMetaApiClient.getBranches(bank.getId()).getBranches();
32 | if(branches.size() == 0) return null;
33 | bank.setBranches(branches);
34 | return bank;
35 | })
36 | .filter(Objects::nonNull) //exclude banks with no branches
37 | .collect(Collectors.toMap(b -> b, Bank::getBranches));
38 |
39 | Assert.assertTrue(banksWithBranches.keySet().stream().map(Bank::getBranches).mapToLong(Collection::size).sum() > 0);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/test/java/com/tesobe/obp/domain/AccountServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.tesobe.obp.domain;
2 |
3 | import com.tesobe.obp.AbstractTestSupport;
4 | import com.tesobe.obp.clientapi.ObpApiClient;
5 | import org.junit.Assert;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 | import org.springframework.beans.factory.annotation.Autowired;
9 | import org.springframework.boot.test.context.SpringBootTest;
10 | import org.springframework.test.context.junit4.SpringRunner;
11 |
12 | import java.util.List;
13 |
14 | import static org.junit.Assert.assertNotNull;
15 | import static org.junit.Assert.assertTrue;
16 |
17 | @RunWith(SpringRunner.class)
18 | @SpringBootTest
19 | public class AccountServiceTest extends AbstractTestSupport {
20 |
21 | @Autowired private ObpApiClient obpApiClient;
22 |
23 | @Test
24 | public void fetchPrivateAccountsNoDetailsOk() {
25 | //fetch private accounts
26 | List privateAccounts = obpApiClient.getPrivateAccountsNoDetails();
27 | assertTrue(privateAccounts.size() > 0);
28 | }
29 |
30 | @Test
31 | public void fetchPrivateAccountsWithDetailsOk() {
32 | //fetch private accounts
33 | List privateAccounts = obpApiClient.getPrivateAccountsWithDetails();
34 | assertTrue(privateAccounts.size() > 0);
35 | privateAccounts.forEach(privateAccount -> assertNotNull(privateAccount.getBalance()));
36 | }
37 |
38 | @Test
39 | public void accountViewsOk() throws Exception {
40 | List privateAccounts = obpApiClient.getPrivateAccountsNoDetails();
41 | Account firstAccount = privateAccounts.get(0);
42 | ObpApiClient.AccountViews views = obpApiClient.getViewsForAccount(firstAccount.getBankId(), firstAccount.getId());
43 | Assert.assertNotNull(views);
44 | }
45 | }
--------------------------------------------------------------------------------
/src/test/java/com/tesobe/obp/transaction/MonetaryTransactionsServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.tesobe.obp.transaction;
2 |
3 | import com.tesobe.obp.AbstractTestSupport;
4 | import com.tesobe.obp.clientapi.ObpApiClient;
5 | import com.tesobe.obp.domain.Account;
6 | import com.tesobe.obp.domain.TransactionRequest;
7 | import com.tesobe.obp.domain.Transaction;
8 | import org.joda.money.CurrencyUnit;
9 | import org.joda.money.Money;
10 | import org.junit.Assert;
11 | import org.junit.Test;
12 | import org.junit.runner.RunWith;
13 | import org.springframework.beans.factory.annotation.Autowired;
14 | import org.springframework.boot.test.context.SpringBootTest;
15 | import org.springframework.test.context.junit4.SpringRunner;
16 |
17 | import java.math.BigDecimal;
18 | import java.util.List;
19 |
20 | @RunWith(SpringRunner.class)
21 | @SpringBootTest
22 | public class MonetaryTransactionsServiceTest extends AbstractTestSupport {
23 |
24 | @Autowired private ObpApiClient obpApiClient;
25 |
26 | @Test
27 | public void fetchTransactionListOk() throws Exception {
28 | List accounts = obpApiClient.getPrivateAccountsNoDetails();
29 | Assert.assertTrue(accounts.size() > 0);
30 |
31 | String bankId = accounts.get(0).getBankId();
32 | String accountIdOne = accounts.get(0).getId();
33 | ObpApiClient.TransactionRequestTypes txTypes = obpApiClient.getTransactionTypes(bankId, accountIdOne);
34 |
35 | TransactionRequest transactionRequest = new TransactionRequest(
36 | new TransactionRequest.DestAccount(bankId, accountIdOne), Money.of(CurrencyUnit.EUR, 5), "some description");
37 |
38 | String result = obpApiClient.initiateTransaction(bankId, accounts.get(1).getId(), "SANDBOX_TAN", transactionRequest);
39 |
40 | List transactions = obpApiClient.getTransactionsForAccount(bankId, accountIdOne).getTransactions();
41 | Assert.assertTrue(transactions.size() > 0);
42 | }
43 |
44 | }
--------------------------------------------------------------------------------
/src/test/java/com/tesobe/obp/transaction/TransactionAnnotationServiceTest.java:
--------------------------------------------------------------------------------
1 | package com.tesobe.obp.transaction;
2 |
3 | import com.tesobe.obp.AbstractTestSupport;
4 | import com.tesobe.obp.clientapi.ObpApiClient;
5 | import com.tesobe.obp.domain.Account;
6 | import com.tesobe.obp.domain.Location;
7 | import com.tesobe.obp.domain.Transaction;
8 | import org.junit.Assert;
9 | import org.junit.Test;
10 | import org.springframework.beans.factory.annotation.Autowired;
11 |
12 | import java.util.List;
13 |
14 | import static com.tesobe.obp.domain.Transaction.Tag;
15 |
16 | public class TransactionAnnotationServiceTest extends AbstractTestSupport {
17 | @Autowired private ObpApiClient obpApiClient;
18 |
19 | @Test
20 | public void addTagOk() {
21 | List accounts = obpApiClient.getPrivateAccountsWithDetails();
22 | Account ownAccount = accounts.get(0);
23 | List transactions = obpApiClient.getTransactionsForAccount(ownAccount.getBankId(), ownAccount.getId()).getTransactions();
24 |
25 | Transaction tx = transactions.get(0);
26 |
27 | String tagValue = "food";
28 | Tag tag = obpApiClient.tagTransaction(ownAccount.getBankId(), ownAccount.getId(), tx.getId(), new Tag(tagValue));
29 | Assert.assertNotNull(tag.getId());
30 | Assert.assertEquals(tagValue, tag.getValue());
31 | List newTags = obpApiClient.getTransactionById(ownAccount.getBankId(), ownAccount.getId(), tx.getId()).getMetadata().getTags();
32 | Assert.assertTrue(newTags.contains(tag));
33 | }
34 |
35 | @Test
36 | public void deleteTagOk() {
37 | List accounts = obpApiClient.getPrivateAccountsWithDetails();
38 | Account ownAccount = accounts.get(0);
39 | List transactions = obpApiClient.getTransactionsForAccount(ownAccount.getBankId(), ownAccount.getId()).getTransactions();
40 |
41 | Transaction tx = transactions.get(0);
42 | //tx.getMetadata().getTags().forEach(tag -> transactionAnnotationService.deleteTransactionTag(authToken, tx, tag));
43 | Tag tag = obpApiClient.tagTransaction(ownAccount.getBankId(), ownAccount.getId(), tx.getId(), new Tag("food"));
44 | List txTags = obpApiClient.getTransactionById(ownAccount.getBankId(), ownAccount.getId(), tx.getId()).getMetadata().getTags();
45 | Assert.assertTrue(txTags.contains(tag));
46 |
47 | obpApiClient.deleteTransactionTag(ownAccount.getBankId(), ownAccount.getId(), tx.getId(), tag.getId());
48 | txTags = obpApiClient.getTransactionById(ownAccount.getBankId(), ownAccount.getId(), tx.getId()).getMetadata().getTags();
49 | Assert.assertTrue(!txTags.contains(tag));
50 | }
51 |
52 | @Test
53 | public void addLocationOk() {
54 | List accounts = obpApiClient.getPrivateAccountsWithDetails();
55 | Account ownAccount = accounts.get(0);
56 | List transactions = obpApiClient.getTransactionsForAccount(ownAccount.getBankId(), ownAccount.getId()).getTransactions();
57 |
58 | Transaction tx = transactions.get(0);
59 |
60 | Location geoLocation = new Location(12.566331, 55.675313);
61 | obpApiClient.addLocation(ownAccount.getBankId(), ownAccount.getId(), tx.getId(), new ObpApiClient.Where(geoLocation));
62 | Location txLocation = obpApiClient.getTransactionById(ownAccount.getBankId(), ownAccount.getId(), tx.getId()).getMetadata().getLocation();
63 | Assert.assertEquals(geoLocation, txLocation);
64 | }
65 |
66 | @Test
67 | public void deleteLocationOk() {
68 | List accounts = obpApiClient.getPrivateAccountsWithDetails();
69 | Account ownAccount = accounts.get(0);
70 | List transactions = obpApiClient.getTransactionsForAccount(ownAccount.getBankId(), ownAccount.getId()).getTransactions();
71 | Transaction tx = transactions.get(0);
72 |
73 | //add location to transaction
74 | Location geoLocation = new Location(12.566331, 55.675313);
75 | obpApiClient.addLocation(ownAccount.getBankId(), ownAccount.getId(), tx.getId(), new ObpApiClient.Where(geoLocation));
76 | Location txLocation = obpApiClient.getTransactionById(ownAccount.getBankId(), ownAccount.getId(), tx.getId()).getMetadata().getLocation();
77 | Assert.assertEquals(geoLocation, txLocation);
78 |
79 | //delete location
80 | obpApiClient.deleteLocation(ownAccount.getBankId(), ownAccount.getId(), tx.getId());
81 | //check null location
82 | txLocation = obpApiClient.getTransactionById(ownAccount.getBankId(), ownAccount.getId(), tx.getId()).getMetadata().getLocation();
83 | Assert.assertNull(txLocation);
84 | }
85 |
86 | }
--------------------------------------------------------------------------------
/src/test/java/com/tesobe/obp/user/EntitlementsTest.java:
--------------------------------------------------------------------------------
1 | package com.tesobe.obp.user;
2 |
3 | import com.tesobe.obp.AbstractTestSupport;
4 | import com.tesobe.obp.clientapi.EntitlementsApiClient;
5 | import org.junit.Assert;
6 | import org.junit.Test;
7 | import org.springframework.beans.factory.annotation.Autowired;
8 | import org.springframework.beans.factory.annotation.Value;
9 |
10 | public class EntitlementsTest extends AbstractTestSupport {
11 |
12 | @Value("${obp.username}")
13 | private String user;
14 | @Autowired private EntitlementsApiClient entitlementsApiClient;
15 |
16 | @Test
17 | public void entitlementsUser() throws Exception {
18 | String entz = entitlementsApiClient.getEntitlements(user);
19 | Assert.assertNotNull(entz);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/test/resources/auth.properties:
--------------------------------------------------------------------------------
1 | obp.username=emmaf
2 | obp.password=xF6ZhTo5$E^S
3 |
--------------------------------------------------------------------------------