[ Server ] [ Project ] - 完成ProjectInfo部分的代码
This commit is contained in:
@@ -0,0 +1,105 @@
|
||||
package io.wdd.server.controller;
|
||||
|
||||
import io.wdd.common.response.R;
|
||||
import io.wdd.server.beans.po.ProjectInfoPO;
|
||||
import io.wdd.server.beans.vo.ProjectInfoVO;
|
||||
import net.datafaker.Faker;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
@SpringBootTest
|
||||
public class ProjectInfoTest {
|
||||
|
||||
@Resource
|
||||
ProjectController projectController;
|
||||
|
||||
@Resource
|
||||
Faker fakeInstance;
|
||||
|
||||
@Test
|
||||
public void test_projectGetAll_returnsNonNullObject() {
|
||||
R<List<ProjectInfoPO>> result = projectController.projectGetAll();
|
||||
assertNotNull(result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_projectCreate_returnsNonNullObjectWithExpectedMessage() {
|
||||
ProjectInfoVO projectInfoVO = new ProjectInfoVO();
|
||||
// Set projectInfoVO properties
|
||||
R<String> result = projectController.projectCreate(projectInfoVO);
|
||||
assertNotNull(result);
|
||||
assertEquals(
|
||||
"创建项目失败!",
|
||||
result.getData()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_projectCreate_createWithFakeData() {
|
||||
ProjectInfoVO projectInfoVO = new ProjectInfoVO();
|
||||
|
||||
projectInfoVO.setProjectName(fakeInstance
|
||||
.funnyName()
|
||||
.name());
|
||||
projectInfoVO.setProjectNamespace(fakeInstance.examplify("dasdd"));
|
||||
projectInfoVO.setDeployNetEnv(fakeInstance
|
||||
.random()
|
||||
.nextInt(3));
|
||||
projectInfoVO.setDeployHardwareEnv(fakeInstance
|
||||
.animal()
|
||||
.name());
|
||||
// Set projectInfoVO properties
|
||||
R<String> result = projectController.projectCreate(projectInfoVO);
|
||||
assertNotNull(result);
|
||||
assertEquals(
|
||||
"创建项目成功!",
|
||||
result.getData()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_projectUpdate_returnsNonNullObjectWithExpectedMessage() {
|
||||
ProjectInfoPO projectInfoPO = new ProjectInfoPO();
|
||||
// Set projectInfoPO properties
|
||||
R<String> result = projectController.projectUpdate(projectInfoPO);
|
||||
assertNotNull(result);
|
||||
assertEquals(
|
||||
"更新项目失败!",
|
||||
result.getData()
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test_projectDelete_returnsNonNullObjectWithExpectedMessage() {
|
||||
|
||||
List<ProjectInfoPO> infoPOList = projectController
|
||||
.projectGetAll()
|
||||
.getData();
|
||||
|
||||
int size = infoPOList.size();
|
||||
ProjectInfoPO infoPO = infoPOList
|
||||
.stream()
|
||||
.skip(fakeInstance
|
||||
.random()
|
||||
.nextInt(size))
|
||||
.findFirst()
|
||||
.get();
|
||||
|
||||
System.out.println("infoPO to delete is = " + infoPO);
|
||||
|
||||
R<String> result = projectController.projectDelete(infoPO.getProjectId());
|
||||
assertNotNull(result);
|
||||
assertEquals(
|
||||
"删除项目成功!",
|
||||
result.getData()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user