|
@@ -1,6 +1,5 @@
|
|
package cn.iselab.mooctest.site.service.impl;
|
|
package cn.iselab.mooctest.site.service.impl;
|
|
|
|
|
|
-import cn.iselab.mooctest.site.Application;
|
|
|
|
import cn.iselab.mooctest.site.dao.Exam2GroupDao;
|
|
import cn.iselab.mooctest.site.dao.Exam2GroupDao;
|
|
import cn.iselab.mooctest.site.dao.Group2WorkerDao;
|
|
import cn.iselab.mooctest.site.dao.Group2WorkerDao;
|
|
import cn.iselab.mooctest.site.dao.GroupDao;
|
|
import cn.iselab.mooctest.site.dao.GroupDao;
|
|
@@ -8,11 +7,12 @@ import cn.iselab.mooctest.site.dao.ManagerPropertyDao;
|
|
import cn.iselab.mooctest.site.data.UserDTOForMT;
|
|
import cn.iselab.mooctest.site.data.UserDTOForMT;
|
|
import cn.iselab.mooctest.site.models.*;
|
|
import cn.iselab.mooctest.site.models.*;
|
|
import cn.iselab.mooctest.site.models.instancePermission.GroupPermission;
|
|
import cn.iselab.mooctest.site.models.instancePermission.GroupPermission;
|
|
|
|
+import cn.iselab.mooctest.site.service.GroupService;
|
|
import cn.iselab.mooctest.site.service.SubmitRecordService;
|
|
import cn.iselab.mooctest.site.service.SubmitRecordService;
|
|
import cn.iselab.mooctest.site.service.UserService;
|
|
import cn.iselab.mooctest.site.service.UserService;
|
|
import cn.iselab.mooctest.site.service.instancePermission.GroupPermissionService;
|
|
import cn.iselab.mooctest.site.service.instancePermission.GroupPermissionService;
|
|
import cn.iselab.mooctest.site.web.exception.IllegalOperationException;
|
|
import cn.iselab.mooctest.site.web.exception.IllegalOperationException;
|
|
-import org.junit.Assert;
|
|
|
|
|
|
+import com.google.common.collect.Lists;
|
|
import org.junit.Before;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.junit.runner.RunWith;
|
|
@@ -20,13 +20,14 @@ import org.mockito.InjectMocks;
|
|
import org.mockito.Mock;
|
|
import org.mockito.Mock;
|
|
import org.mockito.MockitoAnnotations;
|
|
import org.mockito.MockitoAnnotations;
|
|
import org.mockito.runners.MockitoJUnitRunner;
|
|
import org.mockito.runners.MockitoJUnitRunner;
|
|
-import org.springframework.boot.test.SpringApplicationConfiguration;
|
|
|
|
import org.springframework.data.domain.*;
|
|
import org.springframework.data.domain.*;
|
|
-import org.springframework.test.context.web.WebAppConfiguration;
|
|
|
|
|
|
|
|
|
|
+import java.math.BigInteger;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
+import static org.junit.Assert.assertEquals;
|
|
import static org.mockito.Matchers.anyLong;
|
|
import static org.mockito.Matchers.anyLong;
|
|
import static org.mockito.Mockito.*;
|
|
import static org.mockito.Mockito.*;
|
|
|
|
|
|
@@ -34,12 +35,13 @@ import static org.mockito.Mockito.*;
|
|
* Created by major on 2017/6/19.
|
|
* Created by major on 2017/6/19.
|
|
*/
|
|
*/
|
|
|
|
|
|
-@RunWith(MockitoJUnitRunner.class)
|
|
|
|
-@WebAppConfiguration
|
|
|
|
-@SpringApplicationConfiguration(classes = Application.class)
|
|
|
|
|
|
+//@RunWith(MockitoJUnitRunner.class)
|
|
|
|
+//@WebAppConfiguration
|
|
|
|
+//@SpringApplicationConfiguration(classes = Application.class)
|
|
public class GroupServiceTest {
|
|
public class GroupServiceTest {
|
|
|
|
+
|
|
@InjectMocks
|
|
@InjectMocks
|
|
- private GroupServiceImpl groupService = new GroupServiceImpl();
|
|
|
|
|
|
+ private GroupService groupService = new GroupServiceImpl();
|
|
|
|
|
|
@Mock
|
|
@Mock
|
|
private GroupDao groupDao;
|
|
private GroupDao groupDao;
|
|
@@ -96,7 +98,7 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
List<Group> result = groupService.getGroupsByParticipantId(123L);
|
|
List<Group> result = groupService.getGroupsByParticipantId(123L);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(result.get(0).getId(), groupList.get(0).getId());
|
|
|
|
|
|
+ assertEquals(result.get(0).getId(), groupList.get(0).getId());
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -106,7 +108,7 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
Group result = groupService.getGroup(123L);
|
|
Group result = groupService.getGroup(123L);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(group.getId(), result.getId());
|
|
|
|
|
|
+ assertEquals(group.getId(), result.getId());
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -116,7 +118,7 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
List<Group> result = groupService.getGroupsByOwnerId(123L);
|
|
List<Group> result = groupService.getGroupsByOwnerId(123L);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(groupList.get(0).getId(), result.get(0).getId());
|
|
|
|
|
|
+ assertEquals(groupList.get(0).getId(), result.get(0).getId());
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -126,7 +128,7 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
Page<Group> result = groupService.getPageableGroupsByOwnerId(123L, pageable);
|
|
Page<Group> result = groupService.getPageableGroupsByOwnerId(123L, pageable);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(groupList.get(0).getId(), result.getContent().get(0).getId());
|
|
|
|
|
|
+ assertEquals(groupList.get(0).getId(), result.getContent().get(0).getId());
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -136,7 +138,7 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
List<Group> result = groupService.getGroupsByExamIdAndParticipantId(1L, 7L);
|
|
List<Group> result = groupService.getGroupsByExamIdAndParticipantId(1L, 7L);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(groupList.get(0).getId(), result.get(0).getId());
|
|
|
|
|
|
+ assertEquals(groupList.get(0).getId(), result.get(0).getId());
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -146,7 +148,7 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
List<User> result = groupService.getUserByGroupId(123L);
|
|
List<User> result = groupService.getUserByGroupId(123L);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(userList.get(0).getId(), result.get(0).getId());
|
|
|
|
|
|
+ assertEquals(userList.get(0).getId(), result.get(0).getId());
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -158,11 +160,11 @@ public class GroupServiceTest {
|
|
try {
|
|
try {
|
|
groupService.joinGroup(7L, group);
|
|
groupService.joinGroup(7L, group);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
- Assert.assertEquals(IllegalOperationException.class, e.getClass());
|
|
|
|
|
|
+ assertEquals(IllegalOperationException.class, e.getClass());
|
|
}
|
|
}
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(group.getId(), result1.getId());
|
|
|
|
- Assert.assertEquals(group.getId(), result2.getId());
|
|
|
|
|
|
+ assertEquals(group.getId(), result1.getId());
|
|
|
|
+ assertEquals(group.getId(), result2.getId());
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -172,7 +174,7 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
int result = groupService.getWorkerCount(123L);
|
|
int result = groupService.getWorkerCount(123L);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(12, result);
|
|
|
|
|
|
+ assertEquals(12, result);
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -184,7 +186,7 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
List<Integer> result = groupService.getWorkerCounts(groupIds);
|
|
List<Integer> result = groupService.getWorkerCounts(groupIds);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(12, result.get(0), 0);
|
|
|
|
|
|
+ assertEquals(12, result.get(0), 0);
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -196,7 +198,7 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
User result = groupService.addUserIntoGroup(3333L, 1L);
|
|
User result = groupService.addUserIntoGroup(3333L, 1L);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(123L, result.getId(), 0);
|
|
|
|
|
|
+ assertEquals(123L, result.getId(), 0);
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -205,7 +207,7 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
Boolean result = groupService.checkUserExist(1796L, 1L);
|
|
Boolean result = groupService.checkUserExist(1796L, 1L);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(true, result);
|
|
|
|
|
|
+ assertEquals(true, result);
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -221,7 +223,7 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
User result = groupService.deleteUserFromGroup(1796L, 1L);
|
|
User result = groupService.deleteUserFromGroup(1796L, 1L);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(123L, result.getId(), 0);
|
|
|
|
|
|
+ assertEquals(123L, result.getId(), 0);
|
|
verify(group2WorkerDao).delete(group2Worker);
|
|
verify(group2WorkerDao).delete(group2Worker);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -232,7 +234,7 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
Group result = groupService.save(group);
|
|
Group result = groupService.save(group);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(group.getId(), result.getId());
|
|
|
|
|
|
+ assertEquals(group.getId(), result.getId());
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -246,7 +248,7 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
List<Long> result = groupService.getGroupIdsByTaskId(111L);
|
|
List<Long> result = groupService.getGroupIdsByTaskId(111L);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(exam2Group.getGroupId(), result.get(0), 0.0);
|
|
|
|
|
|
+ assertEquals(exam2Group.getGroupId(), result.get(0), 0.0);
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -255,7 +257,7 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
Group result = groupService.joinGroupForRegister(3333L, group);
|
|
Group result = groupService.joinGroupForRegister(3333L, group);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(group.getId(), result.getId());
|
|
|
|
|
|
+ assertEquals(group.getId(), result.getId());
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -265,7 +267,7 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
List<Group> result = groupService.getByExamId(111L);
|
|
List<Group> result = groupService.getByExamId(111L);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(groupList.get(0).getId(), result.get(0).getId());
|
|
|
|
|
|
+ assertEquals(groupList.get(0).getId(), result.get(0).getId());
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -277,7 +279,7 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
User result = groupService.addUserIntoGroupForOauth2(3333L, 1L);
|
|
User result = groupService.addUserIntoGroupForOauth2(3333L, 1L);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(userDTOForMT.getId(), result.getId());
|
|
|
|
|
|
+ assertEquals(userDTOForMT.getId(), result.getId());
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -291,7 +293,7 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
Boolean result = groupService.checkManagerGroupSize(7L);
|
|
Boolean result = groupService.checkManagerGroupSize(7L);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(true, result);
|
|
|
|
|
|
+ assertEquals(true, result);
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -305,7 +307,7 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
Boolean result = groupService.checkManagerGroupSize(7L);
|
|
Boolean result = groupService.checkManagerGroupSize(7L);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(false, result);
|
|
|
|
|
|
+ assertEquals(false, result);
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -314,7 +316,7 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
Boolean result = groupService.isUserInGroup(3333L, 1L);
|
|
Boolean result = groupService.isUserInGroup(3333L, 1L);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(false, result);
|
|
|
|
|
|
+ assertEquals(false, result);
|
|
}
|
|
}
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -323,6 +325,53 @@ public class GroupServiceTest {
|
|
//action
|
|
//action
|
|
Boolean result = groupService.isUserInGroup(1796L, 1L);
|
|
Boolean result = groupService.isUserInGroup(1796L, 1L);
|
|
//assert
|
|
//assert
|
|
- Assert.assertEquals(true, result);
|
|
|
|
|
|
+ assertEquals(true, result);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Test
|
|
|
|
+ public void test_getOwnerAndWorkersCountDTO() {
|
|
|
|
+ List<Long> ownerIds = Lists.newArrayList(7L,8L);
|
|
|
|
+ List<Group> groups = Lists.newArrayList();
|
|
|
|
+ Group group = new Group();
|
|
|
|
+ group.setId(1L);
|
|
|
|
+ group.setOwnerId(7L);
|
|
|
|
+ groups.add(group);
|
|
|
|
+ Group group2 = new Group();
|
|
|
|
+ group2.setId(2L);
|
|
|
|
+ group2.setOwnerId(8L);
|
|
|
|
+ groups.add(group2);
|
|
|
|
+ Group group3 = new Group();
|
|
|
|
+ group3.setId(3L);
|
|
|
|
+ group3.setOwnerId(8L);
|
|
|
|
+ groups.add(group3);
|
|
|
|
+
|
|
|
|
+ List<Object[]> data = Lists.newArrayList();
|
|
|
|
+ data.add(
|
|
|
|
+ new Object[]{
|
|
|
|
+ new BigInteger("1"),
|
|
|
|
+ new BigInteger("100")
|
|
|
|
+ });
|
|
|
|
+ data.add(
|
|
|
|
+ new Object[]{
|
|
|
|
+ new BigInteger("2"),
|
|
|
|
+ new BigInteger("10")
|
|
|
|
+ });
|
|
|
|
+ data.add(
|
|
|
|
+ new Object[]{
|
|
|
|
+ new BigInteger("3"),
|
|
|
|
+ new BigInteger("1000")
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ when(groupDao.findByOwnerIdInAndIsActiveAndIsDeleted(ownerIds,true,false))
|
|
|
|
+ .thenReturn(groups);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ when(group2WorkerDao.getGroupWorkerCount())
|
|
|
|
+ .thenReturn(data);
|
|
|
|
+
|
|
|
|
+ Map<Long, Long> result = groupService.getOwnerAndWorkersCountDTO(ownerIds);
|
|
|
|
+
|
|
|
|
+ assertEquals(1010L, result.get(8L).longValue());
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|