Skip to content

Commit

Permalink
add a test for the Account module and fixes the AuthServiceTest
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreybakker committed Jul 10, 2017
1 parent 26528d5 commit e397415
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
5 changes: 5 additions & 0 deletions banq.iml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: com.google.code.gson:gson:2.8.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents.client5:httpclient5:5.0-alpha1" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents.core5:httpcore5:5.0-alpha1" level="project" />
<orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-web:1.5.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter:1.5.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot:1.5.2.RELEASE" level="project" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public void closeAccount(String authToken, String iBAN) throws NotAuthorizedErro
long accountNumber = IBANUtil.getAccountNumber(iBAN);
BankAccount account = repository.findOne((int) accountNumber);

if (account == null) {
throw new InvalidParamValueError("Bank account does not exist");
}

if (!account.getPrimaryHolder().equals(customer)) {
throw new NotAuthorizedError();
}
Expand Down
58 changes: 54 additions & 4 deletions src/test/java/honours/ing/banq/account/BankAccountServiceTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package honours.ing.banq.account;

import honours.ing.banq.InvalidParamValueError;
import honours.ing.banq.account.bean.NewAccountBean;
import honours.ing.banq.auth.AuthService;
import honours.ing.banq.bean.AccountInfo;
import honours.ing.banq.util.IBANUtil;
import honours.ing.banq.util.StringUtil;
import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -39,26 +42,30 @@ public class BankAccountServiceTest {
private String username;
private String password;
private String token;
private String ssn;
private String email;

private Queue<String> accounts;

@Before
public void setUp() throws Exception {
username = StringUtil.generate(10);
password = StringUtil.generate(10);
ssn = StringUtil.generate(10);
email = StringUtil.generate(10);

accounts = new ArrayBlockingQueue<>(10, true);

// First account
NewAccountBean account = service.openAccount(
"University", "of Twente", "UT",
Calendar.getInstance().getTime().toString(), StringUtil.generate(10),
"1996-1-1", ssn,
"Universiteitsstraat 1, Enschede", "06-12345678",
StringUtil.generate(10), username, password);
accounts.add(account.getiBAN());

// Get the auth token
authService.getAuthToken(username, password);
token = authService.getAuthToken(username, password).getAuthToken();

// And a few more
for (int i = 0; i < 4; i++) {
Expand All @@ -80,20 +87,63 @@ public void openAccount() throws Exception {

username = StringUtil.generate(10);
password = StringUtil.generate(10);
ssn = StringUtil.generate(10);
email = StringUtil.generate(10);

NewAccountBean account = service.openAccount(
"University", "of Twente", "UT",
Calendar.getInstance().getTime().toString(), StringUtil.generate(10),
"1996-1-1", StringUtil.generate(10),
"Universiteitsstraat 1, Enschede", "06-12345678",
StringUtil.generate(10), username, password);
email, username, password);
accounts.add(account.getiBAN());

// Get the auth token
token = authService.getAuthToken(username, password).getAuthToken();
}

@Test(expected = InvalidParamValueError.class)
public void openAccountNonUniqueSSN() throws Exception {
service.openAccount(
"University", "of Twente", "UT",
"1996-1-1", ssn,
"Universiteitsstraat 1, Enschede", "06-12345678",
StringUtil.generate(10), StringUtil.generate(10), StringUtil.generate(10));
}

@Test
public void openAccountNonUniqueEmail() throws Exception {
service.openAccount(
"University", "of Twente", "UT",
"1996-1-1", StringUtil.generate(10),
"Universiteitsstraat 1, Enschede", "06-12345678",
email, StringUtil.generate(10), password);
}

@Test
public void openAccountNonUniqueUsername() throws Exception {
service.openAccount(
"University", "of Twente", "UT",
"1996-1-1", StringUtil.generate(10),
"Universiteitsstraat 1, Enschede", "06-12345678",
StringUtil.generate(10), StringUtil.generate(10), StringUtil.generate(10));
}

@Test
public void openAdditionalAccount() throws Exception {
NewAccountBean account = service.openAdditionalAccount(token);
accounts.add(account.getiBAN());
}

@Test
public void closeAccount() throws Exception {
if (!accounts.isEmpty()) {
service.closeAccount(token, accounts.poll());
}
}

@Test(expected = InvalidParamValueError.class)
public void closeNonExistingAccount() throws Exception {
service.closeAccount(token, IBANUtil.generateIBAN(123456789));
}

}
2 changes: 1 addition & 1 deletion src/test/java/honours/ing/banq/auth/AuthServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void setUp() throws Exception {

NewAccountBean account = accountService.openAccount(
"University", "of Twente", "UT",
Calendar.getInstance().getTime().toString(), StringUtil.generate(10),
"1996-1-1", StringUtil.generate(10),
"Universiteitsstraat 1, Enschede", "06-12345678",
StringUtil.generate(10), username, password);

Expand Down

0 comments on commit e397415

Please sign in to comment.