Skip to content

Commit

Permalink
work on #44
Browse files Browse the repository at this point in the history
  • Loading branch information
OlliL committed Mar 4, 2023
1 parent 48e7486 commit efda7b7
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@
import org.springframework.test.context.jdbc.Sql;

public class ShowMonthlySettlementCreateTest extends AbstractControllerTest {
private String userName;
private String userPassword;
@Inject
private ICapitalsourceService capitalsourceService;
@Inject
private CapitalsourceTransportMapper capitalsourceTransportMapper;

private String userName;
private String userPassword;

@BeforeEach
public void setUp() {
this.userName = UserTransportBuilder.USER1_NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
import org.springframework.test.context.jdbc.Sql;

public class ShowMonthlySettlementCreateYearMonthTest extends AbstractControllerTest {
private String userName;
private String userPassword;
@Inject
private ICapitalsourceService capitalsourceService;
@Inject
private CapitalsourceTransportMapper capitalsourceTransportMapper;

private String userName;
private String userPassword;

@BeforeEach
public void setUp() {
this.userName = UserTransportBuilder.USER1_NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@
import org.springframework.test.context.jdbc.Sql;

public class ShowMonthlySettlementCreateYearTest extends AbstractControllerTest {
private String userName;
private String userPassword;
@Inject
private ICapitalsourceService capitalsourceService;
@Inject
private CapitalsourceTransportMapper capitalsourceTransportMapper;

private String userName;
private String userPassword;

@BeforeEach
public void setUp() {
this.userName = UserTransportBuilder.USER1_NAME;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package org.laladev.moneyjinn.server.controller.postingaccount;

import jakarta.inject.Inject;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Assertions;
Expand All @@ -13,19 +14,19 @@
import org.laladev.moneyjinn.server.builder.UserTransportBuilder;
import org.laladev.moneyjinn.server.builder.ValidationItemTransportBuilder;
import org.laladev.moneyjinn.server.controller.AbstractControllerTest;
import org.laladev.moneyjinn.server.controller.api.PostingAccountControllerApi;
import org.laladev.moneyjinn.server.model.CreatePostingAccountRequest;
import org.laladev.moneyjinn.server.model.CreatePostingAccountResponse;
import org.laladev.moneyjinn.server.model.PostingAccountTransport;
import org.laladev.moneyjinn.server.model.ValidationItemTransport;
import org.laladev.moneyjinn.server.model.ValidationResponse;
import org.laladev.moneyjinn.service.api.IPostingAccountService;
import org.springframework.http.HttpMethod;
import org.springframework.test.context.jdbc.Sql;

public class CreatePostingAccountTest extends AbstractControllerTest {
@Inject
private IPostingAccountService postingAccountService;
private final HttpMethod method = HttpMethod.POST;

private String userName;
private String userPassword;

Expand All @@ -46,8 +47,8 @@ protected String getPassword() {
}

@Override
protected String getUsecase() {
return super.getUsecaseFromTestClassName(this.getClass());
protected Method getMethod() {
return super.getMethodFromTestClassName(PostingAccountControllerApi.class, this.getClass());
}

private void testError(final PostingAccountTransport transport, final ErrorCode errorCode)
Expand All @@ -61,8 +62,7 @@ private void testError(final PostingAccountTransport transport, final ErrorCode
expected.setValidationItemTransports(validationItems);
expected.setResult(Boolean.FALSE);

final ValidationResponse actual = super.callUsecaseExpect422(this.method, request,
ValidationResponse.class);
final ValidationResponse actual = super.callUsecaseExpect422(request, ValidationResponse.class);

Assertions.assertEquals(expected, actual);
}
Expand Down Expand Up @@ -100,9 +100,11 @@ public void test_standardRequest_SuccessfullNoContent() throws Exception {
final CreatePostingAccountResponse expected = new CreatePostingAccountResponse();
expected.setPostingAccountId(PostingAccountTransportBuilder.NEXT_ID);

final CreatePostingAccountResponse actual = super.callUsecaseExpect200(this.method, request,
final CreatePostingAccountResponse actual = super.callUsecaseExpect200(request,
CreatePostingAccountResponse.class);

Assertions.assertEquals(expected, actual);

final PostingAccount postingAccount = this.postingAccountService
.getPostingAccountByName(PostingAccountTransportBuilder.NEWPOSTING_ACCOUNT_NAME);
Assertions.assertEquals(PostingAccountTransportBuilder.NEXT_ID, postingAccount.getId().getId());
Expand All @@ -116,15 +118,15 @@ public void test_OnlyAdminAllowed_ErrorResponse() throws Exception {
this.userName = UserTransportBuilder.USER1_NAME;
this.userPassword = UserTransportBuilder.USER1_PASSWORD;

super.callUsecaseExpect403(this.method, new CreatePostingAccountRequest());
super.callUsecaseExpect403(new CreatePostingAccountRequest());
}

@Test
public void test_AuthorizationRequired_Error() throws Exception {
this.userName = null;
this.userPassword = null;

super.callUsecaseExpect403(this.method, new CreatePostingAccountRequest());
super.callUsecaseExpect403(new CreatePostingAccountRequest());
}

@Test
Expand All @@ -139,7 +141,7 @@ public void test_emptyDatabase_noException() throws Exception {
final CreatePostingAccountResponse expected = new CreatePostingAccountResponse();
expected.setPostingAccountId(1L);

final CreatePostingAccountResponse actual = super.callUsecaseExpect200(this.method, request,
final CreatePostingAccountResponse actual = super.callUsecaseExpect200(request,
CreatePostingAccountResponse.class);

Assertions.assertEquals(expected, actual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package org.laladev.moneyjinn.server.controller.postingaccount;

import jakarta.inject.Inject;
import java.lang.reflect.Method;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand All @@ -11,15 +12,15 @@
import org.laladev.moneyjinn.server.builder.PostingAccountTransportBuilder;
import org.laladev.moneyjinn.server.builder.UserTransportBuilder;
import org.laladev.moneyjinn.server.controller.AbstractControllerTest;
import org.laladev.moneyjinn.server.controller.api.PostingAccountControllerApi;
import org.laladev.moneyjinn.server.model.ErrorResponse;
import org.laladev.moneyjinn.service.api.IPostingAccountService;
import org.springframework.http.HttpMethod;
import org.springframework.test.context.jdbc.Sql;

public class DeletePostingAccountByIdTest extends AbstractControllerTest {
@Inject
private IPostingAccountService postingAccountService;
private final HttpMethod method = HttpMethod.DELETE;

private String userName;
private String userPassword;

Expand All @@ -40,17 +41,18 @@ protected String getPassword() {
}

@Override
protected String getUsecase() {
return super.getUsecaseFromTestClassName(this.getClass());
protected Method getMethod() {
return super.getMethodFromTestClassName(PostingAccountControllerApi.class, this.getClass());
}

@Test
public void test_regularPostingAccountNoData_SuccessfullNoContent() throws Exception {
PostingAccount postingAccount = this.postingAccountService.getPostingAccountById(
new PostingAccountID(PostingAccountTransportBuilder.POSTING_ACCOUNT3_ID));
Assertions.assertNotNull(postingAccount);
super.callUsecaseExpect204("/" + PostingAccountTransportBuilder.POSTING_ACCOUNT3_ID,
this.method);

super.callUsecaseExpect204WithUriVariables(PostingAccountTransportBuilder.POSTING_ACCOUNT3_ID);

postingAccount = this.postingAccountService.getPostingAccountById(
new PostingAccountID(PostingAccountTransportBuilder.POSTING_ACCOUNT3_ID));
Assertions.assertNull(postingAccount);
Expand All @@ -61,7 +63,9 @@ public void test_nonExistingPostingAccount_SuccessfullNoContent() throws Excepti
PostingAccount postingAccount = this.postingAccountService.getPostingAccountById(
new PostingAccountID(PostingAccountTransportBuilder.NON_EXISTING_ID));
Assertions.assertNull(postingAccount);
super.callUsecaseExpect204("/" + PostingAccountTransportBuilder.NON_EXISTING_ID, this.method);

super.callUsecaseExpect204WithUriVariables(PostingAccountTransportBuilder.NON_EXISTING_ID);

postingAccount = this.postingAccountService.getPostingAccountById(
new PostingAccountID(PostingAccountTransportBuilder.NON_EXISTING_ID));
Assertions.assertNull(postingAccount);
Expand All @@ -77,8 +81,8 @@ public void test_regularPostingAccountWithData_SuccessfullNoContent() throws Exc
new PostingAccountID(PostingAccountTransportBuilder.POSTING_ACCOUNT1_ID));
Assertions.assertNotNull(postingAccount);

final ErrorResponse actual = super.callUsecaseExpect400(
"/" + PostingAccountTransportBuilder.POSTING_ACCOUNT1_ID, this.method, ErrorResponse.class);
final ErrorResponse actual = super.callUsecaseExpect400(ErrorResponse.class,
PostingAccountTransportBuilder.POSTING_ACCOUNT1_ID);

postingAccount = this.postingAccountService.getPostingAccountById(
new PostingAccountID(PostingAccountTransportBuilder.POSTING_ACCOUNT1_ID));
Expand All @@ -90,17 +94,16 @@ public void test_regularPostingAccountWithData_SuccessfullNoContent() throws Exc
public void test_OnlyAdminAllowed_ErrorResponse() throws Exception {
this.userName = UserTransportBuilder.USER1_NAME;
this.userPassword = UserTransportBuilder.USER1_PASSWORD;
super.callUsecaseExpect403("/" + PostingAccountTransportBuilder.POSTING_ACCOUNT1_ID,
this.method);

super.callUsecaseExpect403WithUriVariables(PostingAccountTransportBuilder.POSTING_ACCOUNT1_ID);
}

@Test
public void test_AuthorizationRequired_Error() throws Exception {
this.userName = null;
this.userPassword = null;

super.callUsecaseExpect403("/" + PostingAccountTransportBuilder.POSTING_ACCOUNT1_ID,
this.method);
super.callUsecaseExpect403WithUriVariables(PostingAccountTransportBuilder.POSTING_ACCOUNT1_ID);
}

@Test
Expand All @@ -109,7 +112,6 @@ public void test_emptyDatabase_noException() throws Exception {
this.userName = UserTransportBuilder.ADMIN_NAME;
this.userPassword = UserTransportBuilder.ADMIN_PASSWORD;

super.callUsecaseExpect204("/" + PostingAccountTransportBuilder.POSTING_ACCOUNT1_ID,
this.method);
super.callUsecaseExpect204WithUriVariables(PostingAccountTransportBuilder.POSTING_ACCOUNT1_ID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package org.laladev.moneyjinn.server.controller.postingaccount;

import jakarta.inject.Inject;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Assertions;
Expand All @@ -10,16 +11,16 @@
import org.laladev.moneyjinn.server.builder.PostingAccountTransportBuilder;
import org.laladev.moneyjinn.server.builder.UserTransportBuilder;
import org.laladev.moneyjinn.server.controller.AbstractControllerTest;
import org.laladev.moneyjinn.server.controller.api.PostingAccountControllerApi;
import org.laladev.moneyjinn.server.model.PostingAccountTransport;
import org.laladev.moneyjinn.server.model.ShowPostingAccountListResponse;
import org.laladev.moneyjinn.service.api.IPostingAccountService;
import org.springframework.http.HttpMethod;
import org.springframework.test.context.jdbc.Sql;

public class ShowPostingAccountListTest extends AbstractControllerTest {
@Inject
private IPostingAccountService postingAccountService;
private final HttpMethod method = HttpMethod.GET;

private String userName;
private String userPassword;

Expand All @@ -40,8 +41,8 @@ protected String getPassword() {
}

@Override
protected String getUsecase() {
return super.getUsecaseFromTestClassName(this.getClass());
protected Method getMethod() {
return super.getMethodFromTestClassName(PostingAccountControllerApi.class, this.getClass());
}

private ShowPostingAccountListResponse getCompleteResponse() {
Expand All @@ -58,7 +59,7 @@ private ShowPostingAccountListResponse getCompleteResponse() {
public void test_default_FullResponseObject() throws Exception {
final ShowPostingAccountListResponse expected = this.getCompleteResponse();

final ShowPostingAccountListResponse actual = super.callUsecaseExpect200(this.method,
final ShowPostingAccountListResponse actual = super.callUsecaseExpect200(
ShowPostingAccountListResponse.class);

Assertions.assertEquals(expected, actual);
Expand All @@ -69,7 +70,7 @@ public void test_AuthorizationRequired1_Error() throws Exception {
this.userName = null;
this.userPassword = null;

super.callUsecaseExpect403(this.method);
super.callUsecaseExpect403();
}

@Test
Expand All @@ -79,7 +80,7 @@ public void test_emptyDatabase_noException() throws Exception {
this.userPassword = UserTransportBuilder.ADMIN_PASSWORD;
final ShowPostingAccountListResponse expected = new ShowPostingAccountListResponse();

final ShowPostingAccountListResponse actual = super.callUsecaseExpect200(this.method,
final ShowPostingAccountListResponse actual = super.callUsecaseExpect200(
ShowPostingAccountListResponse.class);

Assertions.assertEquals(expected, actual);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package org.laladev.moneyjinn.server.controller.postingaccount;

import jakarta.inject.Inject;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.Assertions;
Expand All @@ -14,18 +15,18 @@
import org.laladev.moneyjinn.server.builder.UserTransportBuilder;
import org.laladev.moneyjinn.server.builder.ValidationItemTransportBuilder;
import org.laladev.moneyjinn.server.controller.AbstractControllerTest;
import org.laladev.moneyjinn.server.controller.api.PostingAccountControllerApi;
import org.laladev.moneyjinn.server.model.PostingAccountTransport;
import org.laladev.moneyjinn.server.model.UpdatePostingAccountRequest;
import org.laladev.moneyjinn.server.model.ValidationItemTransport;
import org.laladev.moneyjinn.server.model.ValidationResponse;
import org.laladev.moneyjinn.service.api.IPostingAccountService;
import org.springframework.http.HttpMethod;
import org.springframework.test.context.jdbc.Sql;

public class UpdatePostingAccountTest extends AbstractControllerTest {
@Inject
private IPostingAccountService postingAccountService;
private final HttpMethod method = HttpMethod.PUT;

private String userName;
private String userPassword;

Expand All @@ -46,8 +47,8 @@ protected String getPassword() {
}

@Override
protected String getUsecase() {
return super.getUsecaseFromTestClassName(this.getClass());
protected Method getMethod() {
return super.getMethodFromTestClassName(PostingAccountControllerApi.class, this.getClass());
}

private void testError(final PostingAccountTransport transport, final ErrorCode errorCode)
Expand All @@ -61,8 +62,7 @@ private void testError(final PostingAccountTransport transport, final ErrorCode
expected.setValidationItemTransports(validationItems);
expected.setResult(Boolean.FALSE);

final ValidationResponse actual = super.callUsecaseExpect422(this.method, request,
ValidationResponse.class);
final ValidationResponse actual = super.callUsecaseExpect422(request, ValidationResponse.class);

Assertions.assertEquals(expected, actual);
}
Expand Down Expand Up @@ -91,7 +91,7 @@ public void test_standardRequest_Successfull() throws Exception {
transport.setName("hugo");
request.setPostingAccountTransport(transport);

super.callUsecaseExpect204(this.method, request);
super.callUsecaseExpect204(request);

final PostingAccount postingAccount = this.postingAccountService.getPostingAccountById(
new PostingAccountID(PostingAccountTransportBuilder.POSTING_ACCOUNT1_ID));
Expand All @@ -105,15 +105,15 @@ public void test_OnlyAdminAllowed_ErrorResponse() throws Exception {
this.userName = UserTransportBuilder.USER1_NAME;
this.userPassword = UserTransportBuilder.USER1_PASSWORD;

super.callUsecaseExpect403(this.method, new UpdatePostingAccountRequest());
super.callUsecaseExpect403(new UpdatePostingAccountRequest());
}

@Test
public void test_AuthorizationRequired_Error() throws Exception {
this.userName = null;
this.userPassword = null;

super.callUsecaseExpect403(this.method, new UpdatePostingAccountRequest());
super.callUsecaseExpect403(new UpdatePostingAccountRequest());
}

@Test
Expand All @@ -126,6 +126,6 @@ public void test_emptyDatabase_noException() throws Exception {
.forPostingAccount1().build();
request.setPostingAccountTransport(transport);

super.callUsecaseExpect204(this.method, request);
super.callUsecaseExpect204(request);
}
}
Loading

0 comments on commit efda7b7

Please sign in to comment.