[ Server ] [ Server ] - 新增ServerInfo的测试内容
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
package io.wdd.server.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.wdd.common.response.R;
|
||||
import io.wdd.common.utils.FakeDataUtils;
|
||||
import io.wdd.server.beans.po.ServerInfoPO;
|
||||
import io.wdd.server.beans.request.ServerQueryEntity;
|
||||
import io.wdd.server.beans.vo.ServerInfoVO;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.http.HttpStatus;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@SpringBootTest
|
||||
public class ServerInfoTest {
|
||||
|
||||
@Resource
|
||||
ServerController serverController;
|
||||
|
||||
// Test serverGetAllByPage returns expected result
|
||||
@Test
|
||||
public void test_serverGetAllByPage_returns_expected_result() {
|
||||
// Arrange
|
||||
ServerQueryEntity serverQueryEntity = new ServerQueryEntity();
|
||||
|
||||
// Act
|
||||
R<Page<ServerInfoVO>> result = serverController.serverGetAllByPage(serverQueryEntity);
|
||||
|
||||
// Assert
|
||||
assertNotNull(result);
|
||||
assertEquals(
|
||||
HttpStatus.OK,
|
||||
result.getCode()
|
||||
);
|
||||
assertNotNull(result.getData());
|
||||
}
|
||||
|
||||
// Test serverCreate creates a new server successfully
|
||||
@Test
|
||||
public void test_serverCreate_creates_new_server_successfully() {
|
||||
|
||||
ServerInfoVO serverInfoVO = FakeDataUtils.FakeServerInfo();
|
||||
|
||||
// Act
|
||||
R result = serverController.serverCreate(serverInfoVO);
|
||||
|
||||
// Assert
|
||||
assertNotNull(result);
|
||||
assertEquals(
|
||||
"Create Server Success !",
|
||||
result.getData()
|
||||
);
|
||||
}
|
||||
|
||||
// Test serverGetAllByPage with invalid input returns error
|
||||
@Test
|
||||
public void test_serverGetAllByPage_with_invalid_input_returns_error() {
|
||||
// Arrange
|
||||
ServerQueryEntity serverQueryEntity = null;
|
||||
|
||||
// Act
|
||||
R<Page<ServerInfoVO>> result = serverController.serverGetAllByPage(serverQueryEntity);
|
||||
|
||||
// Assert
|
||||
assertNotNull(result);
|
||||
assertEquals(
|
||||
HttpStatus.BAD_REQUEST,
|
||||
result.getCode()
|
||||
);
|
||||
assertNull(result.getData());
|
||||
}
|
||||
|
||||
// Test serverCreate with invalid input returns error
|
||||
@Test
|
||||
public void test_serverCreate_with_invalid_input_returns_error() {
|
||||
// Arrange
|
||||
ServerInfoVO serverInfoVO = null;
|
||||
|
||||
// Act
|
||||
R result = serverController.serverCreate(serverInfoVO);
|
||||
|
||||
// Assert
|
||||
assertNotNull(result);
|
||||
assertEquals(
|
||||
HttpStatus.BAD_REQUEST,
|
||||
result.getCode()
|
||||
);
|
||||
assertEquals(
|
||||
"Create Server Failed !",
|
||||
result.getData()
|
||||
);
|
||||
}
|
||||
|
||||
// Test serverUpdate with invalid input returns error
|
||||
@Test
|
||||
public void test_serverUpdate_with_invalid_input_returns_error() {
|
||||
// Arrange
|
||||
ServerInfoPO serverInfoPO = null;
|
||||
|
||||
// Act
|
||||
R result = serverController.serverUpdate(serverInfoPO);
|
||||
|
||||
// Assert
|
||||
assertNotNull(result);
|
||||
assertEquals(
|
||||
HttpStatus.BAD_REQUEST,
|
||||
result.getCode()
|
||||
);
|
||||
assertEquals(
|
||||
"Server info update failed !",
|
||||
result.getData()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user