security hardening #12
@@ -27,7 +27,7 @@
|
||||
<url/>
|
||||
</scm>
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<java.version>21</java.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
@@ -80,6 +80,11 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-test</artifactId>
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package de.zendric.app.xpensely_Server;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import de.zendric.app.xpensely_server.model.ExpenseList;
|
||||
import de.zendric.app.xpensely_server.repo.ExpenseListRepository;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
|
||||
import de.zendric.app.xpensely_server.model.ExpenseList;
|
||||
import de.zendric.app.xpensely_server.repo.ExpenseListRepository;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@DataJpaTest
|
||||
class ExpenseListRepositoryTest {
|
||||
@@ -16,11 +17,31 @@ class ExpenseListRepositoryTest {
|
||||
private ExpenseListRepository expenseListRepository;
|
||||
|
||||
@Test
|
||||
void testFindExpenseListById() {
|
||||
// Assuming an ExpenseList with id = 1 exists in your test DB.
|
||||
Optional<ExpenseList> optionalExpenseList = expenseListRepository.findById(1L);
|
||||
void saveAndFindById_returnsExpenseList() {
|
||||
ExpenseList list = new ExpenseList();
|
||||
list.setName("Groceries");
|
||||
ExpenseList saved = expenseListRepository.save(list);
|
||||
|
||||
ExpenseList expenseList = optionalExpenseList.get();
|
||||
System.out.println("ExpenseList name: " + expenseList.getName());
|
||||
Optional<ExpenseList> found = expenseListRepository.findById(saved.getId());
|
||||
|
||||
assertTrue(found.isPresent());
|
||||
assertEquals("Groceries", found.get().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void findById_nonExistentId_returnsEmpty() {
|
||||
Optional<ExpenseList> found = expenseListRepository.findById(999L);
|
||||
assertTrue(found.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void delete_removesFromRepository() {
|
||||
ExpenseList list = new ExpenseList();
|
||||
list.setName("To Delete");
|
||||
ExpenseList saved = expenseListRepository.save(list);
|
||||
|
||||
expenseListRepository.deleteById(saved.getId());
|
||||
|
||||
assertTrue(expenseListRepository.findById(saved.getId()).isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user