-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more backend infrastructure and made small change to maven gith…
…ub workflow configuration (#5) * Added more backend infrastructure and some unit tests * Added remaining Account unit tests * Added temp change to maven yml * Fixed issue with unit test
- Loading branch information
Showing
8 changed files
with
230 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/avengers/example/controller/LoanController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.avengers.example.controller; | ||
|
||
import com.avengers.example.domain.Loan; | ||
import com.avengers.example.service.LoanService; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@AllArgsConstructor | ||
@RestController | ||
public class LoanController | ||
{ | ||
private final LoanService loanService; | ||
|
||
/** | ||
* Creates a new loan object and saves it to the database. | ||
* | ||
* @param loan the loan instance to be added to the database. | ||
* @return The response from the server. | ||
*/ | ||
@PostMapping("/loan") | ||
public ResponseEntity<?> save(@RequestBody Loan loan) | ||
{ | ||
return new ResponseEntity<>(loanService.create(loan), HttpStatus.CREATED); | ||
} | ||
|
||
/** | ||
* @return A response object containing all loans from the database. | ||
*/ | ||
@GetMapping("/loans") | ||
public ResponseEntity<?> findAll() | ||
{ | ||
return new ResponseEntity<>(loanService.findAll(), HttpStatus.OK); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
src/main/java/com/avengers/example/repository/LoanRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.avengers.example.repository; | ||
|
||
import com.avengers.example.domain.Loan; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface LoanRepository extends JpaRepository<Loan, Long> | ||
{ | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/com/avengers/example/service/LoanService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.avengers.example.service; | ||
|
||
import com.avengers.example.domain.Loan; | ||
import com.avengers.example.repository.LoanRepository; | ||
import jakarta.transaction.Transactional; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@AllArgsConstructor | ||
@Service | ||
public class LoanService | ||
{ | ||
private final LoanRepository loanRepository; | ||
|
||
@Transactional | ||
public Loan create(Loan loan) | ||
{ | ||
return loanRepository.save(loan); | ||
} | ||
|
||
public List<Loan> findAll() | ||
{ | ||
return loanRepository.findAll(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,8 @@ | |
@SpringBootTest | ||
class ApplicationTests | ||
{ | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
|
||
@Test | ||
void contextLoads() | ||
{ | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
src/test/java/com/avengers/example/domain/AccountTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package com.avengers.example.domain; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
@SpringBootTest | ||
public class AccountTests | ||
{ | ||
private Account testAccount; | ||
private long acctId = 1L; | ||
private int userType = 1; | ||
private String username = "user"; | ||
private String password = "pass"; | ||
private String email = "[email protected]"; | ||
private String phonenumber = "(111)111-1111"; | ||
|
||
@BeforeEach | ||
public void setup() | ||
{ | ||
testAccount = new Account(userType, username, password, email, phonenumber); | ||
} | ||
|
||
@Test | ||
public void testNoArgumentConstructor() | ||
{ | ||
Account account = new Account(); | ||
assert account != null; | ||
} | ||
|
||
@Test | ||
public void testAllArgumentConstructor() | ||
{ | ||
assert testAccount != null; | ||
} | ||
|
||
@Test | ||
public void testSetUserType() | ||
{ | ||
testAccount.setUserType(2); | ||
assert testAccount.getUserType() == 2; | ||
} | ||
|
||
@Test | ||
public void testSetUserName() | ||
{ | ||
testAccount.setUsername("test"); | ||
assert testAccount.getUsername() == "test"; | ||
} | ||
|
||
@Test | ||
public void testSetUserName_NullUserName() | ||
{ | ||
assertThrows(IllegalArgumentException.class, () -> testAccount.setUsername(null)); | ||
} | ||
|
||
@Test | ||
public void testSetPassword() | ||
{ | ||
testAccount.setPassword("test"); | ||
assert testAccount.getPassword() == "test"; | ||
} | ||
|
||
@Test | ||
public void testSetPassword_NullPassword() | ||
{ | ||
assertThrows(IllegalArgumentException.class, () -> testAccount.setPassword(null)); | ||
} | ||
|
||
@Test | ||
public void testSetPhoneNumber() | ||
{ | ||
testAccount.setPhoneNumber("test"); | ||
assert testAccount.getPhoneNumber() == "test"; | ||
} | ||
|
||
@Test | ||
public void testSetPhoneNumber_NullPhoneNumber() | ||
{ | ||
assertThrows(IllegalArgumentException.class, () -> testAccount.setPhoneNumber(null)); | ||
} | ||
|
||
@Test | ||
public void testSetEmail() | ||
{ | ||
testAccount.setEmail("test"); | ||
assert testAccount.getEmail() == "test"; | ||
} | ||
|
||
@Test | ||
public void testSetEmail_NullEmail() | ||
{ | ||
assertThrows(IllegalArgumentException.class, () -> testAccount.setEmail(null)); | ||
} | ||
} |