spring boot :2.2.8.RELEASE
shiro:1.4.1
junit:junit-jupiter-api-5.5.2.jar
在测试类中需要引用 到shiro的登录信息SecurityUtils 不使用mock的情况下
import com.hdlh.network.graph.service.GraphService;
import com.product.hdlh.HdlhApplicationTests;
import org.apache.shiro.SecurityUtils;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.WebApplicationContext;
import java.util.List;
import java.util.Map;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class GraphServiceTest extends XxxxApplicationTests {
@Autowired
private GraphService graphService;
@Autowired
private WebApplicationContext webApplicationContext;
@BeforeAll
void setUp() {
SecurityUtils.setSecurityManager(webApplicationContext.getBean(org.apache.shiro.mgt.SecurityManager.class));
SecurityUtils.getSubject();
}
/**
* 获取拓扑坐标
*/
@Test
public void getCoordXxx(){
String showHost = "1";
String businessSystem = "CompanyNetwork";
String isArtificial = "0";
List<Map<String,Object>> graphDatas = graphService.getCoord(showHost, businessSystem,
Integer.parseInt(isArtificial));
}
}
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
setUp() 方法