Skip to content

Commit

Permalink
Merge pull request #40 from ADORSYS-GIS/ManagerAccess#19
Browse files Browse the repository at this point in the history
feat: updated ManagerAccess and TypeOfManagedAccess models
  • Loading branch information
yvanhenang authored Oct 4, 2024
2 parents 6d08848 + 745ebaf commit 4f4dbd9
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 0 deletions.
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<>();

}
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;

}
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> {

}
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();
}
}

0 comments on commit 4f4dbd9

Please sign in to comment.