-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from ADORSYS-GIS/ManagerAccess#19
feat: updated ManagerAccess and TypeOfManagedAccess models
- Loading branch information
Showing
4 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
...ount-access-repository/src/main/java/de/adorsys/ledgers/baam/db/domain/ManagerAccess.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,26 @@ | ||
package de.adorsys.ledgers.baam.db.domain; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import lombok.AllArgsConstructor; | ||
|
||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
|
||
@Entity | ||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class ManagerAccess extends BankAccountAccess { | ||
|
||
|
||
@ElementCollection | ||
private Set<TypeOfManagedAccess> managedAccessTypes = new HashSet<>(); | ||
|
||
@ElementCollection | ||
private Set<AccessScope> scopeOfAccess = new HashSet<>(); | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...ccess-repository/src/main/java/de/adorsys/ledgers/baam/db/domain/TypeOfManagedAccess.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 de.adorsys.ledgers.baam.db.domain; | ||
|
||
public enum TypeOfManagedAccess { | ||
AGENT_ACCESS, | ||
AUDITOR_ACCESS, | ||
POA_ACCESS; | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
...pository/src/main/java/de/adorsys/ledgers/baam/db/repository/ManagerAccessRepository.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,13 @@ | ||
package de.adorsys.ledgers.baam.db.repository; | ||
|
||
|
||
import de.adorsys.ledgers.baam.db.domain.ManagerAccess; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
|
||
|
||
@Repository | ||
public interface ManagerAccessRepository extends JpaRepository<ManagerAccess, String> { | ||
|
||
} |
102 changes: 102 additions & 0 deletions
102
...sitory/src/test/java/de/adorsys/ledgers/baam/db/repository/ManagerAccessRepositoryIT.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,102 @@ | ||
package de.adorsys.ledgers.baam.db.repository; | ||
|
||
import de.adorsys.ledgers.baam.db.domain.AccessScope; | ||
import de.adorsys.ledgers.baam.db.domain.AccessStatus; | ||
import de.adorsys.ledgers.baam.db.domain.ManagerAccess; | ||
import de.adorsys.ledgers.baam.db.domain.TypeOfManagedAccess; | ||
import de.adorsys.ledgers.baam.db.test.BaamRepositoryApplication; | ||
import jakarta.transaction.Transactional; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.test.annotation.Rollback; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@SpringBootTest(classes = BaamRepositoryApplication.class) | ||
@Transactional // Ensures that each test is executed within a transaction and rolled back afterwards | ||
@Rollback // Reverts the changes made to the database after each test | ||
public class ManagerAccessRepositoryIT { | ||
|
||
|
||
@Autowired | ||
private ManagerAccessRepository managerAccessRepository; | ||
|
||
// Variable to store a ManagerAccess object | ||
private ManagerAccess managerAccess; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
// Initialize a ManagerAccess object for testing | ||
managerAccess = new ManagerAccess(); | ||
managerAccess.setId("1"); | ||
managerAccess.setWeight(0.8); | ||
managerAccess.setStatus(AccessStatus.ACTIVE); | ||
managerAccess.setManagedAccessTypes(new HashSet<>(Set.of(TypeOfManagedAccess.AGENT_ACCESS))); | ||
managerAccess.setScopeOfAccess(new HashSet<>(Set.of(AccessScope.READ))); | ||
} | ||
|
||
@Test | ||
public void testCreateManagerAccess() { | ||
// Save to the database via the injected repository | ||
ManagerAccess savedManager = managerAccessRepository.save(managerAccess); | ||
|
||
// Verify that the object is properly saved and has a generated ID | ||
assertThat(savedManager.getId()).isNotNull(); | ||
} | ||
|
||
@Test | ||
public void testFindManagerAccessById() { | ||
// Save the ManagerAccess entity to the database | ||
managerAccessRepository.save(managerAccess); | ||
String managerId = managerAccess.getId(); | ||
|
||
// Retrieve the ManagerAccess object from the database using the ID | ||
ManagerAccess foundManager = managerAccessRepository.findById(managerId).orElse(null); | ||
|
||
// Verify that the retrieved object matches the one that was saved | ||
assertThat(foundManager).isNotNull(); | ||
assertThat(foundManager.getStatus()).isEqualTo(AccessStatus.ACTIVE); | ||
assertThat(foundManager.getManagedAccessTypes()).contains(TypeOfManagedAccess.AGENT_ACCESS); | ||
assertThat(foundManager.getScopeOfAccess()).contains(AccessScope.READ); | ||
} | ||
|
||
@Test | ||
public void testUpdateManagerAccess() { | ||
// Initially save a ManagerAccess | ||
managerAccessRepository.save(managerAccess); | ||
|
||
// Modify the details of the ManagerAccess | ||
|
||
managerAccess.setStatus(AccessStatus.RESTRICTED); | ||
|
||
Set<AccessScope> newScopes = new HashSet<>(); | ||
newScopes.add(AccessScope.EXECUTE); | ||
managerAccess.setScopeOfAccess(newScopes); | ||
// Update the record | ||
ManagerAccess updatedManager = managerAccessRepository.save(managerAccess); | ||
|
||
// Verify that the information has been updated correctly | ||
|
||
assertThat(updatedManager.getStatus()).isEqualTo(AccessStatus.RESTRICTED); | ||
assertThat(updatedManager.getScopeOfAccess()).contains(AccessScope.EXECUTE); | ||
} | ||
|
||
@Test | ||
public void testDeleteManagerAccess() { | ||
// Save a ManagerAccess to the database | ||
managerAccessRepository.save(managerAccess); | ||
String managerId = managerAccess.getId(); | ||
|
||
// Delete the record | ||
managerAccessRepository.deleteById(managerId); | ||
|
||
// Verify that the entity has been successfully deleted | ||
ManagerAccess deletedManager = managerAccessRepository.findById(managerId).orElse(null); | ||
assertThat(deletedManager).isNull(); | ||
} | ||
} |