Commit 1b22c01c authored by Artem Dobrynin (EPAM)'s avatar Artem Dobrynin (EPAM) Committed by Rustam Lotsmanenko (EPAM)
Browse files

Fix Entitlements v2 JDBC unit tests (GONRG-2849)

parent ea1666ba
This diff is collapsed.
......@@ -14,6 +14,8 @@ spec:
metadata:
labels:
app: "{{ .Values.conf.app_name }}"
annotations:
rollme: {{ randAlphaNum 5 | quote }}
spec:
containers:
- image: "{{ .Values.data.image }}"
......
......@@ -221,18 +221,6 @@
<artifactId>java-jwt</artifactId>
<version>3.10.3</version>
</dependency>
<dependency>
<groupId>io.zonky.test</groupId>
<artifactId>embedded-database-spring-test</artifactId>
<version>2.0.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.zonky.test</groupId>
<artifactId>embedded-postgres</artifactId>
<version>1.2.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
......@@ -370,7 +358,6 @@
<include>**/*Test.java</include>
<include>**/*Tests.java</include>
</includes>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
......
package org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.addmember;
import static io.zonky.test.db.AutoConfigureEmbeddedDatabase.DatabaseProvider.ZONKY;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.DATA_PARTITION_ID;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.getMemberNode;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.getDataViewersGroupNode;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import io.zonky.test.db.AutoConfigureEmbeddedDatabase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
......@@ -20,6 +8,7 @@ import org.opengroup.osdu.core.common.model.http.RequestInfo;
import org.opengroup.osdu.entitlements.v2.jdbc.model.GroupInfoEntity;
import org.opengroup.osdu.entitlements.v2.jdbc.model.MemberInfoEntity;
import org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.repository.GroupRepository;
import org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.repository.JdbcTemplateRunner;
import org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.repository.MemberRepository;
import org.opengroup.osdu.entitlements.v2.logging.AuditLogger;
import org.opengroup.osdu.entitlements.v2.model.EntityNode;
......@@ -29,14 +18,19 @@ import org.opengroup.osdu.entitlements.v2.model.addmember.AddMemberRepoDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
import org.springframework.test.context.junit4.SpringRunner;
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:db/create-db-script.sql")
@Sql(executionPhase = ExecutionPhase.AFTER_TEST_METHOD, scripts = "classpath:db/drop-db-script.sql")
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.verify;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.*;
import static org.powermock.api.mockito.PowerMockito.when;
@SpringBootTest
@AutoConfigureEmbeddedDatabase(provider = ZONKY)
@RunWith(SpringRunner.class)
public class AddMemberJdbcTest{
......@@ -49,10 +43,12 @@ public class AddMemberJdbcTest{
@Autowired
private AddMemberRepoJdbc sut;
@Autowired
@MockBean
private MemberRepository memberRepository;
@Autowired
@MockBean
private GroupRepository groupRepository;
@MockBean
private JdbcTemplateRunner jdbcTemplateRunner;
@Test
public void should_createAndSetMemberReference_whenInsertAUser_andAddedMemberNodeDoesNotExist() {
......@@ -65,13 +61,17 @@ public class AddMemberJdbcTest{
.partitionId(DATA_PARTITION_ID)
.build();
GroupInfoEntity group = groupRepository.save(GroupInfoEntity.fromEntityNode(groupNode));
List<MemberInfoEntity> expected = Collections.singletonList(MemberInfoEntity.fromEntityNode(memberNode, addMemberRepoDto.getRole()));
GroupInfoEntity group = GroupInfoEntity.fromEntityNode(groupNode);
when(memberRepository.findMemberByEmailInGroup(any(), any())).thenReturn(expected);
when(groupRepository.findByEmail(any())).thenReturn(Collections.singletonList(GroupInfoEntity.fromEntityNode(groupNode)));
//when
sut.addMember(groupNode, addMemberRepoDto);
//then
List<MemberInfoEntity> expected = Collections.singletonList(MemberInfoEntity.fromEntityNode(memberNode, addMemberRepoDto.getRole()));
List<MemberInfoEntity> actual = memberRepository.findMemberByEmailInGroup(group.getId(), addMemberRepoDto.getMemberNode().getNodeId());
assertEquals(1, actual.size());
......@@ -111,17 +111,18 @@ public class AddMemberJdbcTest{
.partitionId(DATA_PARTITION_ID)
.build();
GroupInfoEntity firstGroup = groupRepository.save(GroupInfoEntity.fromEntityNode(firstGroupNode));
GroupInfoEntity secondGroup = groupRepository.save(GroupInfoEntity.fromEntityNode(secondGroupNode));
List<MemberInfoEntity> expected = Collections.singletonList(MemberInfoEntity.fromEntityNode(memberNode, addMemberRepoDto
.getRole()));
sut.addMember(firstGroupNode, addMemberRepoDto);
GroupInfoEntity secondGroup = GroupInfoEntity.fromEntityNode(secondGroupNode);
when(memberRepository.findMemberByEmailInGroup(any(), any())).thenReturn(expected);
when(groupRepository.findByEmail(any())).thenReturn(Collections.singletonList(secondGroup));
//when
sut.addMember(secondGroupNode, addMemberRepoDto);
//then
List<MemberInfoEntity> expected = Collections.singletonList(MemberInfoEntity.fromEntityNode(memberNode, addMemberRepoDto
.getRole()));
List<MemberInfoEntity> actual = memberRepository.findMemberByEmailInGroup(secondGroup.getId(), addMemberRepoDto
.getMemberNode().getNodeId());
......@@ -157,14 +158,17 @@ public class AddMemberJdbcTest{
.partitionId(DATA_PARTITION_ID)
.build();
GroupInfoEntity firstGroup = groupRepository.save(GroupInfoEntity.fromEntityNode(firstGroupNode));
GroupInfoEntity secondGroup = groupRepository.save(GroupInfoEntity.fromEntityNode(secondGroupNode));
GroupInfoEntity firstGroup = GroupInfoEntity.fromEntityNode(firstGroupNode);
GroupInfoEntity secondGroup = GroupInfoEntity.fromEntityNode(secondGroupNode);
List<GroupInfoEntity> expected = Collections.singletonList(secondGroup);
when(groupRepository.findChildByEmail(any(), any())).thenReturn(expected);
when(groupRepository.findByEmail(any())).thenReturn(Collections.singletonList(firstGroup));
//when
sut.addMember(firstGroupNode, addMemberRepoDto);
//then
List<GroupInfoEntity> expected = Collections.singletonList(GroupInfoEntity.fromEntityNode(secondGroupNode));
List<GroupInfoEntity> actual = groupRepository.findChildByEmail(firstGroup.getId(), addMemberRepoDto.getMemberNode().getNodeId());
assertEquals(expected.size(), actual.size());
......
package org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.creategroup;
import static io.zonky.test.db.AutoConfigureEmbeddedDatabase.DatabaseProvider.ZONKY;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.DATA_PARTITION_ID;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.getDataRootGroupNode;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.getRequesterNode;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.getUsersGroupNode;
import java.util.Collections;
import java.util.List;
import io.zonky.test.db.AutoConfigureEmbeddedDatabase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
......@@ -20,6 +8,7 @@ import org.opengroup.osdu.core.common.model.http.RequestInfo;
import org.opengroup.osdu.entitlements.v2.jdbc.model.GroupInfoEntity;
import org.opengroup.osdu.entitlements.v2.jdbc.model.MemberInfoEntity;
import org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.repository.GroupRepository;
import org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.repository.JdbcTemplateRunner;
import org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.repository.MemberRepository;
import org.opengroup.osdu.entitlements.v2.logging.AuditLogger;
import org.opengroup.osdu.entitlements.v2.model.EntityNode;
......@@ -28,13 +17,18 @@ import org.opengroup.osdu.entitlements.v2.model.creategroup.CreateGroupRepoDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
import org.springframework.test.context.junit4.SpringRunner;
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:db/create-db-script.sql")
@Sql(executionPhase = ExecutionPhase.AFTER_TEST_METHOD, scripts = "classpath:db/drop-db-script.sql")
@AutoConfigureEmbeddedDatabase(provider = ZONKY)
import java.util.Collections;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.*;
@SpringBootTest
@RunWith(SpringRunner.class)
public class CreateGroupJdbcTest {
......@@ -47,10 +41,13 @@ public class CreateGroupJdbcTest {
@Autowired
private CreateGroupRepoJdbc sut;
@Autowired
@MockBean
private MemberRepository memberRepository;
@Autowired
@MockBean
private GroupRepository groupRepository;
@MockBean
private JdbcTemplateRunner jdbcTemplateRunner;
@Test
public void should_updateReference_whenCreateGroup_andNotAddDataRootGroup() {
......@@ -62,6 +59,12 @@ public class CreateGroupJdbcTest {
.addDataRootGroup(false)
.partitionId(DATA_PARTITION_ID).build();
GroupInfoEntity groupEntity = GroupInfoEntity.fromEntityNode(groupNode);
when(groupRepository.save(groupEntity)).thenReturn(groupEntity);
when(groupRepository.findByEmail(any())).thenReturn(Collections.singletonList(groupEntity));
when(memberRepository.findMembersByGroup(any())).thenReturn(Collections.singletonList(MemberInfoEntity.fromEntityNode(requesterNode, Role.OWNER)));
//when
sut.createGroup(groupNode, createGroupRepoDto);
......@@ -94,11 +97,6 @@ public class CreateGroupJdbcTest {
EntityNode requesterNode = getRequesterNode();
EntityNode dataRootGroupNode = getDataRootGroupNode();
CreateGroupRepoDto createRootGroupRepoDto = CreateGroupRepoDto.builder()
.requesterNode(requesterNode)
.dataRootGroupNode(null)
.addDataRootGroup(false)
.partitionId(DATA_PARTITION_ID).build();
CreateGroupRepoDto createChildGroupRepoDto = CreateGroupRepoDto.builder()
.requesterNode(requesterNode)
.dataRootGroupNode(dataRootGroupNode)
......@@ -106,7 +104,11 @@ public class CreateGroupJdbcTest {
.partitionId(DATA_PARTITION_ID).build();
sut.createGroup(dataRootGroupNode, createRootGroupRepoDto);
GroupInfoEntity groupEntity = GroupInfoEntity.fromEntityNode(groupNode);
when(groupRepository.findByEmail(any())).thenReturn(Collections.singletonList(groupEntity));
when(groupRepository.save(groupEntity)).thenReturn(groupEntity);
when(groupRepository.findDirectParents(anyList())).thenReturn(Collections.singletonList(GroupInfoEntity.fromEntityNode(dataRootGroupNode)));
when(memberRepository.findMembersByGroup(any())).thenReturn(Collections.singletonList(MemberInfoEntity.fromEntityNode(requesterNode, Role.OWNER)));
//when
sut.createGroup(groupNode, createChildGroupRepoDto);
......
package org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.deletegroup;
import static io.zonky.test.db.AutoConfigureEmbeddedDatabase.DatabaseProvider.ZONKY;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.verify;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.getCommonGroup;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.getDataGroupNode;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.getUsersGroupNode;
import java.util.Collections;
import io.zonky.test.db.AutoConfigureEmbeddedDatabase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
......@@ -18,19 +8,24 @@ import org.opengroup.osdu.core.common.model.http.AppException;
import org.opengroup.osdu.core.common.model.http.RequestInfo;
import org.opengroup.osdu.entitlements.v2.jdbc.model.GroupInfoEntity;
import org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.repository.GroupRepository;
import org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.repository.MemberRepository;
import org.opengroup.osdu.entitlements.v2.logging.AuditLogger;
import org.opengroup.osdu.entitlements.v2.model.EntityNode;
import org.opengroup.osdu.entitlements.v2.util.RequestInfoUtilService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
import org.springframework.test.context.junit4.SpringRunner;
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:db/create-db-script.sql")
@Sql(executionPhase = ExecutionPhase.AFTER_TEST_METHOD, scripts = "classpath:db/drop-db-script.sql")
@AutoConfigureEmbeddedDatabase(provider = ZONKY)
import java.util.Collections;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.*;
@SpringBootTest
@RunWith(SpringRunner.class)
public class DeleteGroupRepoJdbcTest {
......@@ -44,9 +39,11 @@ public class DeleteGroupRepoJdbcTest {
@MockBean
private RequestInfoUtilService requestInfoUtilService;
@Autowired
private DeleteGroupRepoJdbc deleteGroupRepoJdbc;
@Autowired
private DeleteGroupRepoJdbc sut;
@MockBean
private GroupRepository groupRepository;
@MockBean
private MemberRepository memberRepository;
@Test
public void shouldDeleteGroupAndPreserveParents() {
......@@ -56,17 +53,21 @@ public class DeleteGroupRepoJdbcTest {
EntityNode childGroup2 = getDataGroupNode("y");
EntityNode childGroup3 = getDataGroupNode("z");
GroupInfoEntity savedChild1 = groupRepository.save(GroupInfoEntity.fromEntityNode(childGroup1));
GroupInfoEntity savedChild2 = groupRepository.save(GroupInfoEntity.fromEntityNode(childGroup2));
GroupInfoEntity savedChild3 = groupRepository.save(GroupInfoEntity.fromEntityNode(childGroup3));
GroupInfoEntity savedGroupToDelete = groupRepository.save(GroupInfoEntity.fromEntityNode(groupToDelete));
GroupInfoEntity savedChild1 = GroupInfoEntity.fromEntityNode(childGroup1);
GroupInfoEntity savedChild2 = GroupInfoEntity.fromEntityNode(childGroup2);
GroupInfoEntity savedChild3 = GroupInfoEntity.fromEntityNode(childGroup3);
GroupInfoEntity savedGroupToDelete = GroupInfoEntity.fromEntityNode(groupToDelete);
groupRepository.addChildGroupById(savedGroupToDelete.getId(), savedChild1.getId());
groupRepository.addChildGroupById(savedGroupToDelete.getId(), savedChild2.getId());
groupRepository.addChildGroupById(savedGroupToDelete.getId(), savedChild3.getId());
when(groupRepository.findDirectParents(anyList())).thenReturn(Collections.emptyList());
when(groupRepository.findByEmail(any())).thenReturn(Collections.singletonList(savedGroupToDelete));
//when
deleteGroupRepoJdbc.deleteGroup(groupToDelete);
sut.deleteGroup(groupToDelete);
when(groupRepository.findByEmail(any())).thenReturn(Collections.emptyList());
//then
assertTrue(groupRepository.findByEmail(groupToDelete.getNodeId()).isEmpty());
......@@ -86,17 +87,17 @@ public class DeleteGroupRepoJdbcTest {
EntityNode parentGroup2 = getDataGroupNode("y");
EntityNode parentGroup3 = getDataGroupNode("z");
GroupInfoEntity savedParent1 = groupRepository.save(GroupInfoEntity.fromEntityNode(parentGroup1));
GroupInfoEntity savedParent2 = groupRepository.save(GroupInfoEntity.fromEntityNode(parentGroup2));
GroupInfoEntity savedParent3 = groupRepository.save(GroupInfoEntity.fromEntityNode(parentGroup3));
GroupInfoEntity savedGroupToDelete = groupRepository.save(GroupInfoEntity.fromEntityNode(groupToDelete));
GroupInfoEntity savedParent1 = GroupInfoEntity.fromEntityNode(parentGroup1);
GroupInfoEntity savedParent2 = GroupInfoEntity.fromEntityNode(parentGroup2);
GroupInfoEntity savedParent3 = GroupInfoEntity.fromEntityNode(parentGroup3);
GroupInfoEntity savedGroupToDelete = GroupInfoEntity.fromEntityNode(groupToDelete);
groupRepository.addChildGroupById(savedParent1.getId(), savedGroupToDelete.getId());
groupRepository.addChildGroupById(savedParent2.getId(), savedGroupToDelete.getId());
groupRepository.addChildGroupById(savedParent3.getId(), savedGroupToDelete.getId());
when(groupRepository.findDirectParents(anyList())).thenReturn(Collections.emptyList());
when(groupRepository.findByEmail(any())).thenReturn(Collections.singletonList(savedGroupToDelete));
//when
deleteGroupRepoJdbc.deleteGroup(groupToDelete);
sut.deleteGroup(groupToDelete);
when(groupRepository.findByEmail(any())).thenReturn(Collections.emptyList());
//then
assertTrue(groupRepository.findByEmail(groupToDelete.getNodeId()).isEmpty());
......@@ -112,7 +113,7 @@ public class DeleteGroupRepoJdbcTest {
public void shouldReturnIfTheGivenGroupIsNotFoundWhenDeleteGroup() throws Exception{
EntityNode groupNode = getCommonGroup("newgroup");
deleteGroupRepoJdbc.deleteGroup(groupNode);
sut.deleteGroup(groupNode);
verify(auditLogger).deleteGroup(AuditStatus.SUCCESS, groupNode.getNodeId());
verify(auditLogger).deleteGroup(AuditStatus.SUCCESS, groupNode.getNodeId());
......
package org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.listmember;
import static io.zonky.test.db.AutoConfigureEmbeddedDatabase.DatabaseProvider.ZONKY;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.verify;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.DATA_PARTITION_ID;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.getCommonGroup;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.getDataViewersGroupNode;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.getMemberNode;
import java.util.List;
import java.util.stream.Collectors;
import io.zonky.test.db.AutoConfigureEmbeddedDatabase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
......@@ -23,6 +9,7 @@ import org.opengroup.osdu.entitlements.v2.jdbc.model.GroupInfoEntity;
import org.opengroup.osdu.entitlements.v2.jdbc.model.MemberInfoEntity;
import org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.repository.GroupRepository;
import org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.repository.JdbcTemplateRunner;
import org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.repository.MemberRepository;
import org.opengroup.osdu.entitlements.v2.logging.AuditLogger;
import org.opengroup.osdu.entitlements.v2.model.ChildrenReference;
import org.opengroup.osdu.entitlements.v2.model.EntityNode;
......@@ -31,13 +18,20 @@ import org.opengroup.osdu.entitlements.v2.model.listmember.ListMemberServiceDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
import org.springframework.test.context.junit4.SpringRunner;
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:db/create-db-script.sql")
@Sql(executionPhase = ExecutionPhase.AFTER_TEST_METHOD, scripts = "classpath:db/drop-db-script.sql")
@AutoConfigureEmbeddedDatabase(provider = ZONKY)
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyList;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.*;
@SpringBootTest
@RunWith(SpringRunner.class)
public class ListMemberRepoJdbcTest {
......@@ -50,9 +44,12 @@ public class ListMemberRepoJdbcTest {
@Autowired
private ListMemberRepoJdbc sut;
@Autowired
@MockBean
private GroupRepository groupRepository;
@Autowired
@MockBean
private MemberRepository memberRepository;
@MockBean
private JdbcTemplateRunner jdbcTemplateRunner;
@Test
......@@ -64,26 +61,19 @@ public class ListMemberRepoJdbcTest {
EntityNode childGroup2 = getCommonGroup("g2");
EntityNode childGroup3 = getCommonGroup("g3");
GroupInfoEntity savedGroupToAccess = groupRepository.save(GroupInfoEntity.fromEntityNode(groupToAccess));
GroupInfoEntity savedChild1 = groupRepository.save(GroupInfoEntity.fromEntityNode(childGroup1));
GroupInfoEntity savedChild2 = groupRepository.save(GroupInfoEntity.fromEntityNode(childGroup2));
GroupInfoEntity savedChild3 = groupRepository.save(GroupInfoEntity.fromEntityNode(childGroup3));
Long savedMemberId = jdbcTemplateRunner.saveMemberInfoEntity(
MemberInfoEntity.fromEntityNode(member, Role.OWNER)
);
groupRepository.addMemberById(savedGroupToAccess.getId(), savedMemberId, Role.OWNER.getValue());
groupRepository.addChildGroupById(savedGroupToAccess.getId(), savedChild1.getId());
groupRepository.addChildGroupById(savedGroupToAccess.getId(), savedChild3.getId());
groupRepository.addChildGroupById(savedChild1.getId(), savedChild2.getId());
GroupInfoEntity savedGroupToAccess = GroupInfoEntity.fromEntityNode(groupToAccess);
GroupInfoEntity savedChild1 = GroupInfoEntity.fromEntityNode(childGroup1);
GroupInfoEntity savedChild2 = GroupInfoEntity.fromEntityNode(childGroup2);
GroupInfoEntity savedChild3 = GroupInfoEntity.fromEntityNode(childGroup3);
ListMemberServiceDto listMemberServiceDto = ListMemberServiceDto.builder()
.groupId(groupToAccess.getNodeId())
.partitionId(DATA_PARTITION_ID).build();
when(groupRepository.findDirectChildren(anyList())).thenReturn(Arrays.asList(savedChild1, savedChild3));
when(groupRepository.findByEmail(any())).thenReturn(Collections.singletonList(savedGroupToAccess));
when(memberRepository.findMembersByGroup(any())).thenReturn(Collections.singletonList(MemberInfoEntity.fromEntityNode(member, Role.OWNER)));
//when
List<ChildrenReference> members = sut.run(listMemberServiceDto);
......
package org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.removemember;
import static io.zonky.test.db.AutoConfigureEmbeddedDatabase.DatabaseProvider.ZONKY;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.verify;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.DATA_PARTITION_ID;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.getCommonGroup;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.getDataViewersGroupNode;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.getMemberNode;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.getRequesterNode;
import static org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.util.JdbcTestDataProvider.getUsersGroupNode;
import java.util.Collections;
import java.util.List;
import io.zonky.test.db.AutoConfigureEmbeddedDatabase;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
......@@ -23,6 +9,7 @@ import org.opengroup.osdu.entitlements.v2.jdbc.model.GroupInfoEntity;
import org.opengroup.osdu.entitlements.v2.jdbc.model.MemberInfoEntity;
import org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.addmember.AddMemberRepoJdbc;
import org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.repository.GroupRepository;
import org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.repository.JdbcTemplateRunner;
import org.opengroup.osdu.entitlements.v2.jdbc.spi.jdbc.repository.MemberRepository;
import org.opengroup.osdu.entitlements.v2.logging.AuditLogger;
import org.opengroup.osdu.entitlements.v2.model.ChildrenReference;
......@@ -33,13 +20,16 @@ import org.opengroup.osdu.entitlements.v2.model.removemember.RemoveMemberService
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.jdbc.Sql.ExecutionPhase;
import org.springframework.test.context.junit4.SpringRunner;
@Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD, scripts = "classpath:db/create-db-script.sql")
@Sql(executionPhase = ExecutionPhase.AFTER_TEST_METHOD, scripts = "classpath:db/drop-db-script.sql")
@AutoConfigureEmbeddedDatabase(provider = ZONKY)
import java.util.Collections;