Commit 1125b5e5 authored by Rostislav Vatolin [SLB]'s avatar Rostislav Vatolin [SLB]
Browse files

Merge branch 'adv-cache-impl' into 'master'

Implement long lived cache

See merge request !73
parents f71e5dab 5f183bd4
Pipeline #42308 passed with stages
in 16 minutes and 34 seconds
......@@ -28,7 +28,7 @@ public class ListGroupOnBehalfOfApi {
private final PartitionHeaderValidationService partitionHeaderValidationService;
@GetMapping("/members/{member_email}/groups")
@PreAuthorize("@authorizationFilter.hasAnyPermission('" + AppProperties.ADMIN + "')")
@PreAuthorize("@authorizationFilter.hasAnyPermission('" + AppProperties.OPS + "', '" + AppProperties.ADMIN + "')")
public ResponseEntity<ListGroupResponseDto> listGroupsOnBehalfOf(@PathVariable("member_email") String memberId,
@RequestParam(name="type", required = false) String type,
@RequestParam(name="appid", required = false) String appId) {
......
......@@ -27,6 +27,7 @@ public class AddMemberService {
private final AppProperties config;
private final JaxRsDpsLog log;
private final PermissionService permissionService;
private final GroupCacheService groupCacheService;
/**
* Add Member only allows to create a member node for a new user (first time add a user to a data partition), but not for a group.
......@@ -63,7 +64,8 @@ public class AddMemberService {
}
AddMemberRepoDto addMemberRepoDto = AddMemberRepoDto.builder().memberNode(memberNode).role(addMemberDto.getRole()).
partitionId(addMemberServiceDto.getPartitionId()).existingParents(allExistingParents).build();
addMemberRepo.addMember(existingGroupEntityNode, addMemberRepoDto);
Set<String> impactedUsers = addMemberRepo.addMember(existingGroupEntityNode, addMemberRepoDto);
groupCacheService.refreshListGroupCache(impactedUsers, addMemberServiceDto.getPartitionId());
}
private EntityNode createNewMemberNode(String memberPrimaryId, String memberDesId, String partitionId) {
......
......@@ -24,13 +24,14 @@ public class CreateGroupService {
private final CreateGroupRepo createGroupRepo;
private final RetrieveGroupRepo retrieveGroupRepo;
private final GroupCacheService groupCacheService;
private final JaxRsDpsLog log;
private final DefaultGroupsService defaultGroupsService;
public EntityNode run(EntityNode groupNode, CreateGroupServiceDto createGroupServiceDto) {
log.info(String.format("requested by %s", createGroupServiceDto.getRequesterId()));
EntityNode requesterNode = EntityNode.createMemberNodeForRequester(createGroupServiceDto.getRequesterId(), createGroupServiceDto.getPartitionId());
Set<ParentReference> allExistingParents = retrieveGroupRepo.loadAllParents(requesterNode).getParentReferences();
Set<ParentReference> allExistingParents = groupCacheService.getFromPartitionCache(requesterNode.getNodeId(), createGroupServiceDto.getPartitionId());
if (allExistingParents.size() >= EntityNode.MAX_PARENTS) {
log.error(String.format("Identity %s already belong to %d groups", createGroupServiceDto.getRequesterId(), allExistingParents.size()));
throw new AppException(HttpStatus.PRECONDITION_FAILED.value(), HttpStatus.PRECONDITION_FAILED.getReasonPhrase(), String.format("%s's group quota hit. Identity can't belong to more than %d groups", createGroupServiceDto.getRequesterId(), EntityNode.MAX_PARENTS));
......@@ -63,6 +64,7 @@ public class CreateGroupService {
}
private void createGroup(EntityNode groupNode, CreateGroupRepoDto createGroupRepoDto) {
createGroupRepo.createGroup(groupNode, createGroupRepoDto);
Set<String> impactedUsers = createGroupRepo.createGroup(groupNode, createGroupRepoDto);
groupCacheService.refreshListGroupCache(impactedUsers, createGroupRepoDto.getPartitionId());
}
}
......@@ -12,6 +12,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import java.util.Optional;
import java.util.Set;
@Service
@RequiredArgsConstructor
......@@ -19,6 +20,7 @@ public class DeleteGroupService {
private final DeleteGroupRepo deleteGroupRepo;
private final RetrieveGroupRepo retrieveGroupRepo;
private final GroupCacheService groupCacheService;
private final JaxRsDpsLog log;
private final DefaultGroupsService defaultGroupsService;
private final RequestInfo requestInfo;
......@@ -39,7 +41,7 @@ public class DeleteGroupService {
if (defaultGroupsService.isDefaultGroupName(groupNode.getName())) {
throw new AppException(HttpStatus.BAD_REQUEST.value(), HttpStatus.BAD_REQUEST.getReasonPhrase(), "Invalid group, bootstrap groups are not allowed to be deleted");
}
deleteGroupRepo.deleteGroup(existingGroupEntityNode.get());
Set<String> impactedUsers = deleteGroupRepo.deleteGroup(existingGroupEntityNode.get());
groupCacheService.refreshListGroupCache(impactedUsers, deleteGroupServiceDto.getPartitionId());
}
}
......@@ -18,12 +18,14 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public class DeleteMemberService {
private final JaxRsDpsLog log;
private final RetrieveGroupRepo retrieveGroup;
private final RetrieveGroupRepo retrieveGroupRepo;
private final GroupCacheService groupCacheService;
private final RemoveMemberService removeMemberService;
public void deleteMember(DeleteMemberDto deleteMemberDto) {
log.info(String.format("Remove member %s from all groups", deleteMemberDto.getMemberEmail()));
createRemoveMemberServiceDtos(deleteMemberDto).forEach(this::removeMemberFromGroup);
groupCacheService.flushListGroupCacheForUser(deleteMemberDto.getMemberEmail(), deleteMemberDto.getPartitionId());
}
private List<RemoveMemberServiceDto> createRemoveMemberServiceDtos(DeleteMemberDto deleteMemberDto) {
......@@ -42,7 +44,7 @@ public class DeleteMemberService {
}
private Set<String> loadDirectParentsEmails(DeleteMemberDto deleteMemberDto) {
List<ParentReference> directParents = retrieveGroup.loadDirectParents(
List<ParentReference> directParents = retrieveGroupRepo.loadDirectParents(
deleteMemberDto.getPartitionId(), deleteMemberDto.getMemberEmail());
return directParents.stream()
.map(ParentReference::getId)
......
......@@ -7,4 +7,8 @@ import java.util.Set;
public interface GroupCacheService {
Set<ParentReference> getFromPartitionCache(String requesterId, String partitionId);
void refreshListGroupCache(final Set<String> userIds, String partitionId);
void flushListGroupCacheForUser(String userId, String partitionId);
}
......@@ -20,6 +20,7 @@ import java.util.Set;
public class RemoveMemberService {
private final RemoveMemberRepo removeMemberRepo;
private final RetrieveGroupRepo retrieveGroupRepo;
private final GroupCacheService groupCacheService;
private final JaxRsDpsLog log;
private final ServiceAccountsConfigurationService serviceAccountsConfigurationService;
private final BootstrapGroupsConfigurationService bootstrapGroupsConfigurationService;
......@@ -62,7 +63,9 @@ public class RemoveMemberService {
memberNode.getName(), existingGroupEntityNode.getName()));
}
return removeMemberRepo.removeMember(existingGroupEntityNode, memberNode, removeMemberServiceDto);
Set<String> impactedUsers = removeMemberRepo.removeMember(existingGroupEntityNode, memberNode, removeMemberServiceDto);
groupCacheService.refreshListGroupCache(impactedUsers, removeMemberServiceDto.getPartitionId());
return impactedUsers;
}
private EntityNode getEntityNode(String id, String partitionId) {
......
package org.opengroup.osdu.entitlements.v2.service;
import lombok.RequiredArgsConstructor;
import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.entitlements.v2.model.EntityNode;
import org.opengroup.osdu.entitlements.v2.model.updategroup.UpdateGroupResponseDto;
......@@ -8,27 +9,24 @@ import org.opengroup.osdu.entitlements.v2.spi.renamegroup.RenameGroupRepo;
import org.opengroup.osdu.entitlements.v2.spi.retrievegroup.RetrieveGroupRepo;
import org.opengroup.osdu.entitlements.v2.spi.updateappids.UpdateAppIdsRepo;
import org.opengroup.osdu.entitlements.v2.util.GroupCreationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@Service
@RequiredArgsConstructor
public class UpdateGroupService {
@Autowired
private RetrieveGroupRepo retrieveGroupRepo;
@Autowired
private RenameGroupRepo renameGroupRepo;
@Autowired
private UpdateAppIdsRepo updateAppIdsRepo;
@Autowired
private DefaultGroupsService defaultGroupsService;
@Autowired
private PermissionService permissionService;
private final RetrieveGroupRepo retrieveGroupRepo;
private final GroupCacheService groupCacheService;
private final RenameGroupRepo renameGroupRepo;
private final UpdateAppIdsRepo updateAppIdsRepo;
private final DefaultGroupsService defaultGroupsService;
private final PermissionService permissionService;
public UpdateGroupResponseDto updateGroup(UpdateGroupServiceDto updateGroupServiceDto) {
String existingGroupEmail = updateGroupServiceDto.getExistingGroupEmail();
......@@ -44,6 +42,7 @@ public class UpdateGroupService {
existingAppIds.addAll(existingGroupEntityNode.getAppIds());
UpdateGroupResponseDto result = new UpdateGroupResponseDto(existingGroupName, existingGroupEmail, existingAppIds);
Set<String> impactedUsers = new HashSet<>();
if (updateGroupServiceDto.getRenameOperation() != null) {
validateIfGroupIsNotDataGroup(existingGroupEmail, existingGroupEntityNode);
String newGroupName = updateGroupServiceDto.getRenameOperation().getValue().get(0).toLowerCase();
......@@ -52,17 +51,17 @@ public class UpdateGroupService {
String newGroupEmail = GroupCreationUtil.createGroupEmail(newGroupName, partitionDomain);
validateIfNewGroupNameDoesNotExist(newGroupName, partitionId, newGroupEmail);
renameGroupRepo.run(existingGroupEntityNode, newGroupName);
impactedUsers.addAll(renameGroupRepo.run(existingGroupEntityNode, newGroupName));
result.setEmail(newGroupEmail);
result.setName(newGroupName);
}
if (updateGroupServiceDto.getAppIdsOperation()!= null) {
if (updateGroupServiceDto.getAppIdsOperation() != null) {
List<String> allowedAppIdsList = updateGroupServiceDto.getAppIdsOperation().getValue();
updateAppIdsRepo.updateAppIds(existingGroupEntityNode, new HashSet<>(allowedAppIdsList));
impactedUsers.addAll(updateAppIdsRepo.updateAppIds(existingGroupEntityNode, new HashSet<>(allowedAppIdsList)));
result.setAppIds(allowedAppIdsList);
}
groupCacheService.refreshListGroupCache(new HashSet<>(impactedUsers), updateGroupServiceDto.getPartitionId());
return result;
}
......
......@@ -5,5 +5,5 @@ import org.opengroup.osdu.entitlements.v2.model.EntityNode;
import java.util.Set;
public interface UpdateAppIdsRepo {
void updateAppIds(EntityNode groupNode, Set<String> allowedAppIds);
Set<String> updateAppIds(EntityNode groupNode, Set<String> allowedAppIds);
}
......@@ -25,9 +25,11 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
......@@ -47,6 +49,8 @@ public class AddMemberServiceTests {
@MockBean
private RetrieveGroupRepo retrieveGroupRepo;
@MockBean
private GroupCacheService groupCacheService;
@MockBean
private AddMemberRepo addMemberRepo;
@MockBean
private JaxRsDpsLog log;
......@@ -87,6 +91,8 @@ public class AddMemberServiceTests {
.requesterId("requesterid")
.partitionId("common")
.build();
Set<String> allImpactUsers = new HashSet<>(Arrays.asList("member@xxx.com"));
when(addMemberRepo.addMember(any(), any())).thenReturn(allImpactUsers);
addMemberService.run(addMemberDto, addMemberServiceDto);
......@@ -94,6 +100,7 @@ public class AddMemberServiceTests {
verify(addMemberRepo).addMember(eq(groupNode), captor.capture());
assertThat(captor.getValue().getRole()).isEqualTo(Role.MEMBER);
assertThat(captor.getValue().getPartitionId()).isEqualTo("common");
verify(groupCacheService).refreshListGroupCache(allImpactUsers, "common");
}
@Test
......@@ -118,6 +125,8 @@ public class AddMemberServiceTests {
.requesterId("datafier@test.com")
.partitionId("common")
.build();
Set<String> allImpactUsers = new HashSet<>(Arrays.asList("member@xxx.com"));
when(addMemberRepo.addMember(any(), any())).thenReturn(allImpactUsers);
addMemberService.run(addMemberDto, addMemberServiceDto);
......@@ -125,6 +134,7 @@ public class AddMemberServiceTests {
verify(addMemberRepo).addMember(eq(groupNode), captor.capture());
assertThat(captor.getValue().getRole()).isEqualTo(Role.MEMBER);
assertThat(captor.getValue().getPartitionId()).isEqualTo("common");
verify(groupCacheService).refreshListGroupCache(allImpactUsers, "common");
}
@Test
......@@ -178,6 +188,8 @@ public class AddMemberServiceTests {
.requesterId("requesterid")
.partitionId("common")
.build();
Set<String> allImpactUsers = new HashSet<>(Arrays.asList("member@xxx.com"));
when(addMemberRepo.addMember(any(), any())).thenReturn(allImpactUsers);
addMemberService.run(addMemberDto, addMemberServiceDto);
......@@ -186,6 +198,7 @@ public class AddMemberServiceTests {
assertThat(captor.getValue().getMemberNode()).isEqualTo(memberNode);
assertThat(captor.getValue().getRole()).isEqualTo(Role.MEMBER);
assertThat(captor.getValue().getPartitionId()).isEqualTo("common");
verify(groupCacheService).refreshListGroupCache(allImpactUsers, "common");
}
@Test
......
......@@ -19,6 +19,7 @@ import org.opengroup.osdu.entitlements.v2.spi.creategroup.CreateGroupRepo;
import org.opengroup.osdu.entitlements.v2.spi.retrievegroup.RetrieveGroupRepo;
import org.powermock.reflect.Whitebox;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
......@@ -26,6 +27,7 @@ import java.util.Set;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
......@@ -40,6 +42,8 @@ public class CreateGroupServiceTests {
@Mock
private RetrieveGroupRepo retrieveGroupRepo;
@Mock
private GroupCacheService groupCacheService;
@Mock
private JaxRsDpsLog logger;
@Mock
private DefaultGroupsService defaultGroupsService;
......@@ -68,8 +72,7 @@ public class CreateGroupServiceTests {
.name("callerdesid")
.dataPartitionId("dp")
.build();
ParentTreeDto parentTreeDto = ParentTreeDto.builder().parentReferences(parents).maxDepth(2).build();
when(retrieveGroupRepo.loadAllParents(requesterNode)).thenReturn(parentTreeDto);
when(groupCacheService.getFromPartitionCache(requesterNode.getNodeId(), "dp")).thenReturn(parents);
try {
CreateGroupServiceDto createGroupServiceDto = CreateGroupServiceDto.builder()
.requesterId("callerdesid")
......@@ -103,9 +106,6 @@ public class CreateGroupServiceTests {
when(retrieveGroupRepo.groupExistenceValidation("users.data.root@dp.domain.com", "dp")).thenReturn(dataRootGroupNode);
when(defaultGroupsService.isNotDefaultGroupName("data.x")).thenReturn(true);
when(retrieveGroupRepo.loadAllParents(dataRootGroupNode)).thenReturn(ParentTreeDto.builder().parentReferences(parents).maxDepth(2).build());
EntityNode requesterNode = EntityNode.createMemberNodeForRequester("callerdesid", "dp");
ParentTreeDto parentTreeDto = ParentTreeDto.builder().parentReferences(Collections.emptySet()).maxDepth(2).build();
when(retrieveGroupRepo.loadAllParents(requesterNode)).thenReturn(parentTreeDto);
try {
CreateGroupServiceDto createGroupServiceDto = CreateGroupServiceDto.builder()
.requesterId("callerdesid")
......@@ -143,14 +143,16 @@ public class CreateGroupServiceTests {
.partitionDomain("dp.domain.com")
.partitionId("dp").build();
EntityNode requesterNode = EntityNode.createMemberNodeForRequester("callerdesid", "dp");
ParentTreeDto parentTreeDto = ParentTreeDto.builder().parentReferences(Collections.emptySet()).maxDepth(2).build();
when(retrieveGroupRepo.loadAllParents(requesterNode)).thenReturn(parentTreeDto);
when(groupCacheService.getFromPartitionCache(requesterNode.getNodeId(), "dp")).thenReturn(Collections.emptySet());
ArgumentCaptor<CreateGroupRepoDto> captor = ArgumentCaptor.forClass(CreateGroupRepoDto.class);
when(defaultGroupsService.isNotDefaultGroupName("data.x")).thenReturn(true);
Set<String> impactedUsers = new HashSet<>(Arrays.asList("callerdesid"));
when(createGroupRepo.createGroup(any(), any())).thenReturn(impactedUsers);
createGroupService.run(groupNode, createGroupServiceDto);
verify(createGroupRepo, times(1)).createGroup(eq(groupNode), captor.capture());
assertThat(captor.getValue().getDataRootGroupNode()).isNotNull();
assertThat(captor.getValue().isAddDataRootGroup()).isTrue();
verify(groupCacheService).refreshListGroupCache(impactedUsers, "dp");
}
@Test
......@@ -166,13 +168,15 @@ public class CreateGroupServiceTests {
.partitionDomain("dp.domain.com")
.partitionId("dp").build();
EntityNode requesterNode = EntityNode.createMemberNodeForRequester("callerdesid", "dp");
ParentTreeDto parentTreeDto = ParentTreeDto.builder().parentReferences(Collections.emptySet()).maxDepth(2).build();
when(retrieveGroupRepo.loadAllParents(requesterNode)).thenReturn(parentTreeDto);
when(groupCacheService.getFromPartitionCache(requesterNode.getNodeId(), "dp")).thenReturn(Collections.emptySet());
ArgumentCaptor<CreateGroupRepoDto> captor = ArgumentCaptor.forClass(CreateGroupRepoDto.class);
Set<String> impactedUsers = new HashSet<>(Arrays.asList("callerdesid"));
when(createGroupRepo.createGroup(any(), any())).thenReturn(impactedUsers);
createGroupService.run(groupNode, createGroupServiceDto);
verify(createGroupRepo, times(1)).createGroup(eq(groupNode), captor.capture());
assertThat(captor.getValue().getDataRootGroupNode()).isNull();
assertThat(captor.getValue().isAddDataRootGroup()).isFalse();
verify(groupCacheService).refreshListGroupCache(impactedUsers, "dp");
}
@Test
......@@ -188,13 +192,15 @@ public class CreateGroupServiceTests {
.partitionDomain("dp.domain.com")
.partitionId("dp").build();
EntityNode requesterNode = EntityNode.createMemberNodeForRequester("callerdesid", "dp");
ParentTreeDto parentTreeDto = ParentTreeDto.builder().parentReferences(Collections.emptySet()).maxDepth(2).build();
when(retrieveGroupRepo.loadAllParents(requesterNode)).thenReturn(parentTreeDto);
when(groupCacheService.getFromPartitionCache(requesterNode.getNodeId(), "dp")).thenReturn(Collections.emptySet());
ArgumentCaptor<CreateGroupRepoDto> captor = ArgumentCaptor.forClass(CreateGroupRepoDto.class);
when(defaultGroupsService.isNotDefaultGroupName("data.x")).thenReturn(false);
Set<String> impactedUsers = new HashSet<>(Arrays.asList("callerdesid"));
when(createGroupRepo.createGroup(any(), any())).thenReturn(impactedUsers);
createGroupService.run(groupNode, createGroupServiceDto);
verify(createGroupRepo, times(1)).createGroup(eq(groupNode), captor.capture());
assertThat(captor.getValue().getDataRootGroupNode()).isNull();
assertThat(captor.getValue().isAddDataRootGroup()).isFalse();
verify(groupCacheService).refreshListGroupCache(impactedUsers, "dp");
}
}
......@@ -22,7 +22,9 @@ import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Collections;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
......@@ -36,10 +38,12 @@ import static org.mockito.Mockito.when;
public class DeleteGroupServiceTests {
@MockBean
private DeleteGroupRepo deleteGroupRepoRedis;
private DeleteGroupRepo deleteGroupRepo;
@MockBean
private RetrieveGroupRepo retrieveGroupRepo;
@MockBean
private GroupCacheService groupCacheService;
@MockBean
private JaxRsDpsLog logger;
@MockBean
private DefaultGroupsService defaultGroupsService;
......@@ -68,10 +72,13 @@ public class DeleteGroupServiceTests {
.requesterId("callerdesid")
.partitionId("common").build();
when(defaultGroupsService.isDefaultGroupName("data.x.viewers")).thenReturn(false);
Set<String> impactedUsers = new HashSet<>(Collections.singletonList("callerdesid"));
when(deleteGroupRepo.deleteGroup(any())).thenReturn(impactedUsers);
this.service.run(groupNode, deleteGroupServiceDto);
verify(deleteGroupRepoRedis).deleteGroup(groupNode);
verify(deleteGroupRepo).deleteGroup(groupNode);
verify(groupCacheService).refreshListGroupCache(impactedUsers, "common");
}
@Test
......@@ -85,7 +92,7 @@ public class DeleteGroupServiceTests {
this.service.run(groupNode, deleteGroupServiceDto);
verify(deleteGroupRepoRedis, never()).deleteGroup(any(EntityNode.class));
verify(deleteGroupRepo, never()).deleteGroup(any(EntityNode.class));
}
@Test
......
......@@ -29,6 +29,8 @@ public class DeleteMemberServiceTest {
private RetrieveGroupRepo retrieveGroupRepo;
@Mock
private RemoveMemberService removeMemberService;
@Mock
private GroupCacheService groupCacheService;
@InjectMocks
private DeleteMemberService deleteMemberService;
......@@ -65,6 +67,7 @@ public class DeleteMemberServiceTest {
verify(retrieveGroupRepo, times(1)).loadDirectParents(DATA_PARTITION_ID, MEMBER_EMAIL);
verify(removeMemberService, times(1)).removeMember(buildRemoveMemberServiceDto(groupEmail1));
verify(removeMemberService, times(1)).removeMember(buildRemoveMemberServiceDto(groupEmail2));
verify(groupCacheService).flushListGroupCacheForUser(MEMBER_EMAIL, DATA_PARTITION_ID);
}
private RemoveMemberServiceDto buildRemoveMemberServiceDto(String groupEmail) {
......
......@@ -25,6 +25,7 @@ import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.Collections;
import java.util.Optional;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -42,6 +43,8 @@ public class RemoveMemberServiceTests {
@MockBean
private RetrieveGroupRepo retrieveGroupRepo;
@MockBean
private GroupCacheService groupCacheService;
@MockBean
private RemoveMemberRepo removeMemberRepo;
@MockBean
private RequestInfo requestInfo;
......@@ -109,10 +112,12 @@ public class RemoveMemberServiceTests {
.requesterId("requesterid")
.partitionId("common")
.build();
when(removeMemberRepo.removeMember(any(), any(), any())).thenReturn(Collections.emptySet());
removeMemberService.removeMember(removeMemberServiceDto);
verify(removeMemberRepo).removeMember(groupNode, memberNode, removeMemberServiceDto);
verify(groupCacheService).refreshListGroupCache(Collections.emptySet(), "common");
}
@Test
......@@ -149,9 +154,11 @@ public class RemoveMemberServiceTests {
.requesterId("datafier@evd-ddl-us-common.iam.gserviceaccount.com")
.partitionId("common")
.build();
when(removeMemberRepo.removeMember(any(), any(), any())).thenReturn(Collections.emptySet());
removeMemberService.removeMember(removeMemberServiceDto);
verify(groupCacheService).refreshListGroupCache(Collections.emptySet(), "common");
verify(removeMemberRepo).removeMember(groupNode, memberNode, removeMemberServiceDto);
}
......
......@@ -20,9 +20,11 @@ import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
@SpringBootTest
@RunWith(SpringRunner.class)
......@@ -42,6 +44,8 @@ public class UpdateGroupServiceTests {
@MockBean
private RetrieveGroupRepo retrieveGroupRepo;
@MockBean
private GroupCacheService groupCacheService;
@MockBean
private RenameGroupRepo renameGroupRepo;
@MockBean
private UpdateAppIdsRepo updateAppIdsRepo;
......@@ -62,12 +66,14 @@ public class UpdateGroupServiceTests {
Mockito.when(retrieveGroupRepo.groupExistenceValidation(TEST_EXISTING_USER_GROUP_EMAIL, TEST_PARTITION)).thenReturn(groupNode);
Mockito.when(permissionService.hasOwnerPermissionOf(Mockito.any(), Mockito.any())).thenReturn(true);
Mockito.when(renameGroupRepo.run(groupNode, newGroupName)).thenReturn(Collections.emptySet());
UpdateGroupResponseDto responseDto = updateGroupService.updateGroup(serviceDto);
Mockito.verify(renameGroupRepo).run(groupNode, newGroupName);
Assert.assertNotNull(responseDto);
Assert.assertEquals("users.test.x@dp.domain", responseDto.getEmail());
Assert.assertEquals("users.test.x", responseDto.getName());
Mockito.verify(groupCacheService).refreshListGroupCache(Collections.emptySet(), "dp");
}
@Test
......@@ -95,7 +101,6 @@ public class UpdateGroupServiceTests {
public void shouldThrow400WhenNewGroupNameIsAlreadyExist() {
String newGroupName = "users.test.x";
String newGroupEmail = "users.test.x@dp.domain";
EntityNode existedNewGroupNode = createGroupNode(newGroupName, newGroupEmail);
EntityNode groupNode = createGroupNode(TEST_EXISTING_USER_GROUP_NAME, TEST_EXISTING_USER_GROUP_EMAIL);
UpdateGroupOperation renameOperation = createUpdateGroupOperation(RENAME_PATH, newGroupName);
......@@ -169,14 +174,18 @@ public class UpdateGroupServiceTests {
Mockito.when(retrieveGroupRepo.groupExistenceValidation(TEST_EXISTING_USER_GROUP_EMAIL, TEST_PARTITION)).thenReturn(groupNode);
Mockito.when(permissionService.hasOwnerPermissionOf(Mockito.any(), Mockito.any())).thenReturn(true);
UpdateGroupResponseDto responseDto = updateGroupService.updateGroup(serviceDto);
List<String> appIds = new ArrayList<>();
appIds.add("app1");
appIds.add("app2");
Mockito.when(updateAppIdsRepo.updateAppIds(groupNode, new HashSet<>(appIds))).thenReturn(Collections.emptySet());