|
@@ -1,5 +1,6 @@
|
|
|
package cn.iselab.mooctest.site.web.logic.impl;
|
|
|
|
|
|
+import cn.iselab.mooctest.site.AbstractShiroTest;
|
|
|
import cn.iselab.mooctest.site.common.constant.AnswerWayConstants;
|
|
|
import cn.iselab.mooctest.site.common.constant.OwningPartyConstants;
|
|
|
import cn.iselab.mooctest.site.common.constant.TargetTypeConstants;
|
|
@@ -30,6 +31,8 @@ import cn.iselab.mooctest.site.web.logic.Oauth2Logic;
|
|
|
import cn.iselab.mooctest.site.web.logic.drools.CaseExtendsDroolsVarifyLogic;
|
|
|
import cn.iselab.mooctest.site.web.logic.fromDev.UpDownloadLogic;
|
|
|
import com.google.gson.Gson;
|
|
|
+import org.apache.shiro.session.Session;
|
|
|
+import org.apache.shiro.subject.Subject;
|
|
|
import org.junit.Assert;
|
|
|
import org.junit.Before;
|
|
|
import org.junit.Test;
|
|
@@ -54,7 +57,7 @@ import static org.mockito.Mockito.*;
|
|
|
/**
|
|
|
* Created by shanshan on 2017/6/29.
|
|
|
*/
|
|
|
-public class CaseLogicImplTest {
|
|
|
+public class CaseLogicImplTest extends AbstractShiroTest {
|
|
|
|
|
|
@InjectMocks
|
|
|
private CaseLogicImpl caseLogic = new CaseLogicImpl();
|
|
@@ -104,6 +107,8 @@ public class CaseLogicImplTest {
|
|
|
private VisitControlService visitControlService;
|
|
|
@Mock
|
|
|
private CaseExtendsDroolsVarifyLogic caseExtendsDroolsVarifyLogic;
|
|
|
+ @Mock
|
|
|
+ private User2RoleService user2RoleService;
|
|
|
|
|
|
private CaseExtendsVO caseExtendsVO;
|
|
|
private List<CaseExtendsVO> caseExtendsVOList = new ArrayList<>();
|
|
@@ -118,6 +123,8 @@ public class CaseLogicImplTest {
|
|
|
|
|
|
private Exam2Case exam2Case;
|
|
|
private List<Exam2Case> exam2Cases= new ArrayList<>();
|
|
|
+ private Subject subject;
|
|
|
+ private Session session;
|
|
|
|
|
|
@Before
|
|
|
public void setUp() {
|
|
@@ -161,6 +168,12 @@ public class CaseLogicImplTest {
|
|
|
exam2Case.setPaperId(2L);
|
|
|
|
|
|
exam2Cases.add(exam2Case);
|
|
|
+ subject=mock(Subject.class);
|
|
|
+ session=mock(Session.class);
|
|
|
+ when(subject.getSession()).thenReturn(session);
|
|
|
+ when(session.getAttribute("userId")).thenReturn(7L);
|
|
|
+ when(subject.isPermitted(any(CasePermission.class))).thenReturn(true);
|
|
|
+ setSubject(subject);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
@@ -261,9 +274,19 @@ public class CaseLogicImplTest {
|
|
|
@Test
|
|
|
public void should_returnCaseExtendsVO_when_deleteCaseExtends(){
|
|
|
//arrange
|
|
|
+ UserDTOForMT user = new UserDTOForMT();
|
|
|
+ user.setName("TEST");
|
|
|
+ user.setId(7L);
|
|
|
+ List<User2Role> user2Roles = new ArrayList<>();
|
|
|
+ User2Role user2Role = new User2Role();
|
|
|
+ user2Role.setRoleId(1L);
|
|
|
+ user2Roles.add(user2Role);
|
|
|
caseExtends.setVisible(false);
|
|
|
when(caseService.getCaseExtendsById(11L)).thenReturn(caseExtends);
|
|
|
when(caseService.saveOnly(caseExtends)).thenReturn(caseExtends);
|
|
|
+ when(userService.findByUserId(anyLong())).thenReturn(user);
|
|
|
+ when(user2RoleService.getByUserId(anyLong())).thenReturn(user2Roles);
|
|
|
+
|
|
|
//action
|
|
|
CaseExtendsVO result = caseLogic.delete(11L);
|
|
|
//assert
|