puzhibing
2026-02-25 8ad61f4902087c9c7fc95e7ebdf639b5fa70166b
增加测试代码
1个文件已添加
4个文件已修改
188 ■■■■■ 已修改文件
xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/controller/OrderMissionController.java 16 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/util/XPUUtil.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-automatic-pilot-boot/src/test/java/com/xiaopeng/automaticPilot/util/XPUUtilTest.java 155 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-automatic-pilot-boot/src/test/resources/logback-test.xml 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/utils/GDMapGeocodingUtil.java 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/controller/OrderMissionController.java
@@ -19,6 +19,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
@Slf4j
@@ -27,19 +28,18 @@
@Api(tags = "订单任务Api")
public class OrderMissionController {
    private final XPUUtil xpuUtil;
    private final RedisService redisService;
    private final XpVehicleClient xpVehicleClient;
    @Resource
    private XPUUtil xpuUtil;
    @Resource
    private RedisService redisService;
    @Resource
    private XpVehicleClient xpVehicleClient;
    public OrderMissionController(XPUUtil xpuUtil, RedisService redisService, XpVehicleClient xpVehicleClient, Snowflake snowflake) {
        this.xpuUtil = xpuUtil;
        this.redisService = redisService;
        this.xpVehicleClient = xpVehicleClient;
    }
    @PostMapping("/inner/pushOrder")
    public R<Boolean> pushOrder(@RequestBody PushOrderDto dto) {
        RTTask task = new RTTask();
        //TODO 设置目标地点信息
        task.setOrder_id(dto.getOrderId());
        task.setTask_id("MISSION_"+ IdUtil.fastUUID());
        if(dto.getOrderId().contains("XU")){
xp-robotaxi-automatic-pilot-boot/src/main/java/com/xiaopeng/automaticPilot/util/XPUUtil.java
@@ -59,7 +59,7 @@
        header.setTimestamp(System.currentTimeMillis());
        header.setCmd(RTCmdType.CLOUD_CREATE_ORDER);
        header.setSequence(sequence);
        header.setType(MessageType.MESSAGE_TYPE_RESPONSE);
        header.setType(MessageType.MESSAGE_TYPE_REQUEST);
        header.setSource(SourceType.CLOUD);
        msgContent.setHeader(header);
        // 消息内容
xp-robotaxi-automatic-pilot-boot/src/test/java/com/xiaopeng/automaticPilot/util/XPUUtilTest.java
@@ -1,9 +1,19 @@
package com.xiaopeng.automaticPilot.util;
import com.xiaopeng.api.dto.automaticPilot.MqttPublishDto;
import com.xiaopeng.api.feignClient.automaticPilot.VmpOpenServiceClient;
import com.xiaopeng.api.feignClient.automaticPilot.XPUClient;
import com.xiaopeng.api.vo.automaticPilot.MqttPublishVo;
import com.xiaopeng.api.vo.automaticPilot.proto.down.GeoPoint;
import com.xiaopeng.api.vo.automaticPilot.proto.down.ResponseMessage;
import com.xiaopeng.api.vo.automaticPilot.proto.down.StatusCode;
import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudCreateOrder.*;
import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudOrderOperation.*;
import com.xiaopeng.api.vo.automaticPilot.proto.down.cloudPushNavigation.RestoreNavigationData;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import java.lang.reflect.Field;
@@ -15,18 +25,34 @@
public class XPUUtilTest {
    private XPUUtil xpuUtil;
    private XPUClient xpuClient;
    private VmpOpenServiceClient vmpClient;
    @BeforeEach
    public void setUp() throws Exception {
        xpuUtil = new XPUUtil();
        VmpOpenServiceClient vmpClient = Mockito.mock(VmpOpenServiceClient.class);
        // Mock VmpOpenServiceClient
        vmpClient = Mockito.mock(VmpOpenServiceClient.class);
        Map<String, String> mapping = new HashMap<>();
        mapping.put(XPUUtil.XPU_ID_TYPE, "1234567890ABCDEFGHIJKL");
        Mockito.when(vmpClient.getVehicleBindInfoByVin(Mockito.anyString(), Mockito.anyList()))
                .thenReturn(mapping);
        // Mock XPUClient
        xpuClient = Mockito.mock(XPUClient.class);
        Mockito.when(xpuClient.publish(Mockito.any(MqttPublishVo.class)))
                .thenReturn(new MqttPublishDto());
        // Inject mocks
        Field vmpField = XPUUtil.class.getDeclaredField("vmpOpenServiceClient");
        vmpField.setAccessible(true);
        vmpField.set(xpuUtil, vmpClient);
        Field xpuClientField = XPUUtil.class.getDeclaredField("xpuClient");
        xpuClientField.setAccessible(true);
        xpuClientField.set(xpuUtil, xpuClient);
        Field topicField = XPUUtil.class.getDeclaredField("topicPrefix");
        topicField.setAccessible(true);
        topicField.set(xpuUtil, "Robotaxi/Msg/Xpu");
@@ -39,5 +65,130 @@
        String result = (String) buildTopic.invoke(xpuUtil, "VIN123");
        Assertions.assertEquals("Robotaxi/Msg/Xpu/ABCDEFGHIJKL00000000", result);
    }
}
    @Test
    public void testCloudCreateOrder() {
        String orderId = "1881347710714060802";
        RTTask task = new RTTask();
        task.setTask_id("task-123");
        task.setOrder_id(orderId);
        task.setVin("VIN12345678900000");
        task.setTask_type(TaskType.ROBOTAXI);
        task.setStatus(TaskStatus.PENDING);
        NavigationWaypoint point = new NavigationWaypoint();
        point.setType(WaypointType.START_POINT);
        point.setAction(WaypointAction.PICK_UP);
        point.setSequence(1);
        GeoPoint geoPoint = new GeoPoint();
        geoPoint.setLatitude(30.0);
        geoPoint.setLongitude(120.0);
        geoPoint.setPoi_name("Start Point");
        point.setPoint(geoPoint);
        task.setPoints(Collections.singletonList(point));
        String vin = "VIN12345678900000";
        Long sequence = 1L;
        xpuUtil.cloudCreateOrder(task, vin, sequence);
        ArgumentCaptor<MqttPublishVo> captor = ArgumentCaptor.forClass(MqttPublishVo.class);
        Mockito.verify(xpuClient).publish(captor.capture());
        MqttPublishVo capturedVo = captor.getValue();
        Assertions.assertEquals("Robotaxi/Msg/Xpu/ABCDEFGHIJKL00000000", capturedVo.getTopic());
        // Note: Current implementation serializes enum as ordinal. CLOUD_CREATE_ORDER is ordinal 2.
        Assertions.assertTrue(capturedVo.getPayload().contains("\"cmd\":2"), "Payload should contain cmd CLOUD_CREATE_ORDER (ordinal 2), but was: " + capturedVo.getPayload());
    }
    @Test
    public void testCloudOrderOperation() {
        String orderId = "1881347710714060802";
        OrderOperation operation = new OrderOperation();
        operation.setOrder_id(orderId);
        operation.setTask_id("task-123");
        operation.setOperation_type(OrderOperationType.CLOUD_CREATE_ORDER);
        operation.setOrder_type(OrderType.ROBOTAXI);
        Waypoint waypoint = new Waypoint();
        waypoint.setWaypoint_id("wp-1");
        waypoint.setPoint_type(PointType.WAY_POINT);
        waypoint.setAction_type(ActionType.WAIT);
        waypoint.setSequence(2);
        GeoPoint geoPoint = new GeoPoint();
        geoPoint.setLatitude(30.1);
        geoPoint.setLongitude(120.1);
        geoPoint.setPoi_name("Way Point");
        waypoint.setPoint(geoPoint);
        operation.setWaypoints(Collections.singletonList(waypoint));
        TargetPoint targetPoint = new TargetPoint();
        GeoPoint endGeoPoint = new GeoPoint();
        endGeoPoint.setLatitude(30.2);
        endGeoPoint.setLongitude(120.2);
        endGeoPoint.setPoi_name("End Point");
        targetPoint.setPoint(endGeoPoint);
        operation.setTarget_point(targetPoint);
        String vin = "VIN12345678900000";
        Long sequence = 2L;
        xpuUtil.cloudOrderOperation(operation, vin, sequence);
        ArgumentCaptor<MqttPublishVo> captor = ArgumentCaptor.forClass(MqttPublishVo.class);
        Mockito.verify(xpuClient).publish(captor.capture());
        MqttPublishVo capturedVo = captor.getValue();
        Assertions.assertEquals("Robotaxi/Msg/Xpu/ABCDEFGHIJKL00000000", capturedVo.getTopic());
        // Note: CLOUD_ORDER_OPERATION is ordinal 0.
        Assertions.assertTrue(capturedVo.getPayload().contains("\"cmd\":0"), "Payload should contain cmd CLOUD_ORDER_OPERATION (ordinal 0), but was: " + capturedVo.getPayload());
    }
    @Test
    public void testResponseMessage() {
        ResponseMessage responseMessage = new ResponseMessage();
        responseMessage.setRequest_seq(12345L);
        responseMessage.setCode(StatusCode.OK);
        responseMessage.setTimestamp(System.currentTimeMillis());
        String vin = "VIN12345678900000";
        xpuUtil.responseMessage(responseMessage, vin);
        ArgumentCaptor<MqttPublishVo> captor = ArgumentCaptor.forClass(MqttPublishVo.class);
        Mockito.verify(xpuClient).publish(captor.capture());
        MqttPublishVo capturedVo = captor.getValue();
        Assertions.assertEquals("Robotaxi/Msg/Xpu/ABCDEFGHIJKL00000000", capturedVo.getTopic());
        // Note: CLOUD_TASK_CONTROL is ordinal 1.
        Assertions.assertTrue(capturedVo.getPayload().contains("\"cmd\":1"), "Payload should contain cmd CLOUD_TASK_CONTROL (ordinal 1), but was: " + capturedVo.getPayload());
    }
    @Test
    public void testCloudPushNavigation() {
        RestoreNavigationData navigationData = new RestoreNavigationData();
        navigationData.setRequest_id("req-123");
        navigationData.setRoute_id("5939fa259ad6479cbdf8871ceed96b72");
        String content = "{\"startPoint\":{\"location\":\"116.481028,39.989643\"},\"endPoint\":{\"location\":\"116.465302,40.004717\"},\"routeID\":\"xxxxxxxxxxxxx\",\"strategy\":17,\"type\":1,\"ferry\":0,\"disableEndDispatch\":1,\"viaInfo\":[{},{}],\"routeUserType\":2,\"bizScene\":2,\"plate\":\"京A12345\",\"vehicleType\":1}";
        navigationData.setContent(content);
        navigationData.setTimestamp(System.currentTimeMillis());
        String xpuId = "1234567890ABCDEFGHIJKL";
        Long sequence = 3L;
        xpuUtil.cloudPushNavigation(navigationData, xpuId, sequence);
        ArgumentCaptor<MqttPublishVo> captor = ArgumentCaptor.forClass(MqttPublishVo.class);
        Mockito.verify(xpuClient).publish(captor.capture());
        MqttPublishVo capturedVo = captor.getValue();
        Assertions.assertEquals("Robotaxi/Msg/Xpu/ABCDEFGHIJKL00000000", capturedVo.getTopic());
        // Note: CLOUD_NAVIGATION_RESPONSE is ordinal 5.
        Assertions.assertTrue(capturedVo.getPayload().contains("\"cmd\":5"), "Payload should contain cmd CLOUD_NAVIGATION_RESPONSE (ordinal 5), but was: " + capturedVo.getPayload());
    }
}
xp-robotaxi-automatic-pilot-boot/src/test/resources/logback-test.xml
New file
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>
    <root level="INFO">
        <appender-ref ref="STDOUT" />
    </root>
</configuration>
xp-robotaxi-map-boot/src/main/java/com/xiaopeng/map/utils/GDMapGeocodingUtil.java
@@ -63,11 +63,10 @@
        String data = jsonObject.getString("data");
        JSONObject jsonObject1 = JSON.parseObject(data);
        String routeID = jsonObject1.getString("routeID");
        JSONArray path = jsonObject1.getJSONArray("paths");
        for (Object o : path) {
            JSONObject jsonObject2 = (JSONObject) o;
            String routeID = jsonObject2.getString("routeID");
            String points = jsonObject2.getString("points");
            String[] split = points.split(";");
            int temp=0;