3 changed files with 130 additions and 99 deletions
-
21app/src/main/java/com/ouxuan/oxface/orderOX/OrderSelectionActivity.java
-
89app/src/test/java/com/ouxuan/oxface/JsonParsingVerification.java
-
113app/src/test/java/com/ouxuan/oxface/OrderVerificationWithoutVCodeTest.java
@ -1,89 +0,0 @@ |
|||||
package com.ouxuan.oxface; |
|
||||
|
|
||||
import com.google.gson.Gson; |
|
||||
import com.google.gson.JsonElement; |
|
||||
import com.google.gson.JsonObject; |
|
||||
import com.ouxuan.oxface.network.api.PadApiService; |
|
||||
|
|
||||
/** |
|
||||
* 验证 JSON 数据解析的简单测试脚本 |
|
||||
*/ |
|
||||
public class JsonParsingVerification { |
|
||||
|
|
||||
public static void main(String[] args) { |
|
||||
Gson gson = new Gson(); |
|
||||
|
|
||||
// 测试次卡核销数据(info 为字符串) |
|
||||
String peopleCardJson = "{\n" + |
|
||||
" \"order_no\": \"RC20250910155115457419\",\n" + |
|
||||
" \"start_time\": \"2025-09-10 15:51:16\",\n" + |
|
||||
" \"end_time\": \"4763-08-07 15:51:16\",\n" + |
|
||||
" \"order_type\": 1,\n" + |
|
||||
" \"project\": \"20230727测试\",\n" + |
|
||||
" \"number\": 1,\n" + |
|
||||
" \"v_code\": [\"250910159819\"],\n" + |
|
||||
" \"info\": \"平时\",\n" + |
|
||||
" \"success\": 0,\n" + |
|
||||
" \"pv_usage_duration\": 1,\n" + |
|
||||
" \"many_enter\": false\n" + |
|
||||
"}"; |
|
||||
|
|
||||
// 测试年月卡核销数据(info 为对象) |
|
||||
String monthlyCardJson = "{\n" + |
|
||||
" \"order_no\": \"MC20250908145253448493\",\n" + |
|
||||
" \"start_time\": \"2025-09-08 14:52:59\",\n" + |
|
||||
" \"end_time\": \"2025-10-08 14:52:59\",\n" + |
|
||||
" \"order_type\": 3,\n" + |
|
||||
" \"project\": \"可多次进出\",\n" + |
|
||||
" \"number\": 7,\n" + |
|
||||
" \"v_code\": [\"2509087910\"],\n" + |
|
||||
" \"info\": {\n" + |
|
||||
" \"card_no\": \"2509085314\",\n" + |
|
||||
" \"rest_number\": 5,\n" + |
|
||||
" \"status\": 1,\n" + |
|
||||
" \"verify_desc\": \"人脸验证\",\n" + |
|
||||
" \"verify_time\": \"2025-09-10 11:26:36\",\n" + |
|
||||
" \"verify_type\": 2\n" + |
|
||||
" },\n" + |
|
||||
" \"success\": 2,\n" + |
|
||||
" \"pv_usage_duration\": 0,\n" + |
|
||||
" \"many_enter\": false\n" + |
|
||||
"}"; |
|
||||
|
|
||||
try {\n" + |
|
||||
" // 测试次卡解析\n" + |
|
||||
" System.out.println(\"=== 测试次卡核销数据解析 ===\");\n" + |
|
||||
" PadApiService.VerifyOrderResult peopleCardResult = gson.fromJson(peopleCardJson, PadApiService.VerifyOrderResult.class);\n" + |
|
||||
" \n" + |
|
||||
" System.out.println(\"订单类型: \" + peopleCardResult.getOrderType());\n" + |
|
||||
" System.out.println(\"订单号: \" + peopleCardResult.getOrderNo());\n" + |
|
||||
" \n" + |
|
||||
" JsonElement peopleInfo = peopleCardResult.getInfo();\n" + |
|
||||
" if (peopleInfo != null && peopleInfo.isJsonPrimitive()) {\n" + |
|
||||
" System.out.println(\"Info(字符串): \" + peopleInfo.getAsString());\n" + |
|
||||
" System.out.println(\"辅助方法 getInfoAsString(): \" + peopleCardResult.getInfoAsString());\n" + |
|
||||
" }\n" + |
|
||||
" \n" + |
|
||||
" // 测试年月卡解析\n" + |
|
||||
" System.out.println(\"\\n=== 测试年月卡核销数据解析 ===\");\n" + |
|
||||
" PadApiService.VerifyOrderResult monthlyCardResult = gson.fromJson(monthlyCardJson, PadApiService.VerifyOrderResult.class);\n" + |
|
||||
" \n" + |
|
||||
" System.out.println(\"订单类型: \" + monthlyCardResult.getOrderType());\n" + |
|
||||
" System.out.println(\"订单号: \" + monthlyCardResult.getOrderNo());\n" + |
|
||||
" \n" + |
|
||||
" JsonElement monthlyInfo = monthlyCardResult.getInfo();\n" + |
|
||||
" if (monthlyInfo != null && monthlyInfo.isJsonObject()) {\n" + |
|
||||
" JsonObject cardInfo = monthlyInfo.getAsJsonObject();\n" + |
|
||||
" System.out.println(\"Info(对象)- 卡号: \" + cardInfo.get(\"card_no\").getAsString());\n" + |
|
||||
" System.out.println(\"Info(对象)- 剩余次数: \" + cardInfo.get(\"rest_number\").getAsInt());\n" + |
|
||||
" System.out.println(\"辅助方法 getCardNoFromInfo(): \" + monthlyCardResult.getCardNoFromInfo());\n" + |
|
||||
" }\n" + |
|
||||
" \n" + |
|
||||
" System.out.println(\"\\n✅ 所有测试通过!JSON 解析修复成功。\");\n" + |
|
||||
" \n" + |
|
||||
" } catch (Exception e) {\n" + |
|
||||
" System.err.println(\"❌ JSON 解析失败: \" + e.getMessage());\n" + |
|
||||
" e.printStackTrace();\n" + |
|
||||
" }\n" + |
|
||||
" }\n" + |
|
||||
"} |
|
@ -0,0 +1,113 @@ |
|||||
|
package com.ouxuan.oxface; |
||||
|
|
||||
|
import com.google.gson.Gson; |
||||
|
import com.ouxuan.oxface.orderOX.model.OrderVerificationData; |
||||
|
|
||||
|
import org.junit.Test; |
||||
|
import org.junit.runner.RunWith; |
||||
|
import org.robolectric.RobolectricTestRunner; |
||||
|
import org.robolectric.annotation.Config; |
||||
|
|
||||
|
import static org.junit.Assert.assertEquals; |
||||
|
import static org.junit.Assert.assertTrue; |
||||
|
|
||||
|
@RunWith(RobolectricTestRunner.class) |
||||
|
@Config(sdk = 28) |
||||
|
public class OrderVerificationWithoutVCodeTest { |
||||
|
|
||||
|
private Gson gson = new Gson(); |
||||
|
|
||||
|
/** |
||||
|
* 测试年月卡订单(order_type=3)不传递v_code的情况 |
||||
|
*/ |
||||
|
@Test |
||||
|
public void testMonthlyCardWithoutVCode() { |
||||
|
// 模拟年月卡订单数据(order_type=3) |
||||
|
String json = "{\n" + |
||||
|
" \"order_no\": \"MC20250910173625971898\",\n" + |
||||
|
" \"start_time\": \"2025-09-10 17:36:30\",\n" + |
||||
|
" \"end_time\": \"2025-09-10 23:59:59\",\n" + |
||||
|
" \"order_type\": 3,\n" + |
||||
|
" \"project\": \"当天有效年月卡\",\n" + |
||||
|
" \"number\": 15,\n" + |
||||
|
" \"v_code\": [\"2509107776\"],\n" + |
||||
|
" \"info\": {\n" + |
||||
|
" \"card_no\": \"2509107498\",\n" + |
||||
|
" \"rest_number\": 15,\n" + |
||||
|
" \"status\": 0,\n" + |
||||
|
" \"user_face_id\": \"\"\n" + |
||||
|
" },\n" + |
||||
|
" \"success\": 0,\n" + |
||||
|
" \"pv_usage_duration\": 0,\n" + |
||||
|
" \"many_enter\": false\n" + |
||||
|
"}"; |
||||
|
|
||||
|
try { |
||||
|
OrderVerificationData.OrderItem orderItem = gson.fromJson(json, OrderVerificationData.OrderItem.class); |
||||
|
|
||||
|
// 验证订单类型 |
||||
|
assertEquals(3, orderItem.getOrder_type()); |
||||
|
|
||||
|
// 验证项目名称 |
||||
|
assertEquals("当天有效年月卡", orderItem.getProject()); |
||||
|
|
||||
|
// 验证info字段 |
||||
|
assertTrue(orderItem.getInfo().isJsonObject()); |
||||
|
assertEquals("2509107498", orderItem.getCardNoFromInfo()); |
||||
|
|
||||
|
// 对于年月卡订单,应该可以不传递v_code进行核销 |
||||
|
// 这里我们验证getVerificationCode方法仍然可以正常工作 |
||||
|
assertEquals("2509107776", orderItem.getVerificationCode()); |
||||
|
|
||||
|
System.out.println("年月卡订单测试通过: " + orderItem.getOrder_no()); |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
System.out.println("年月卡订单测试失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
/** |
||||
|
* 测试非年月卡订单仍需要v_code的情况 |
||||
|
*/ |
||||
|
@Test |
||||
|
public void testNonMonthlyCardWithVCode() { |
||||
|
// 模拟人次票订单数据(order_type=1) |
||||
|
String json = "{\n" + |
||||
|
" \"order_no\": \"RC20250910172452809631\",\n" + |
||||
|
" \"start_time\": \"2025-09-10 17:24:52\",\n" + |
||||
|
" \"end_time\": \"4763-08-07 17:24:52\",\n" + |
||||
|
" \"order_type\": 1,\n" + |
||||
|
" \"project\": \"20230727测试\",\n" + |
||||
|
" \"number\": 5,\n" + |
||||
|
" \"v_code\": [\"250910170565\",\"250910174341\",\"250910177626\"],\n" + |
||||
|
" \"info\": \"平时\",\n" + |
||||
|
" \"success\": 3,\n" + |
||||
|
" \"pv_usage_duration\": 0,\n" + |
||||
|
" \"many_enter\": false\n" + |
||||
|
"}"; |
||||
|
|
||||
|
try { |
||||
|
OrderVerificationData.OrderItem orderItem = gson.fromJson(json, OrderVerificationData.OrderItem.class); |
||||
|
|
||||
|
// 验证订单类型 |
||||
|
assertEquals(1, orderItem.getOrder_type()); |
||||
|
|
||||
|
// 验证项目名称 |
||||
|
assertEquals("20230727测试", orderItem.getProject()); |
||||
|
|
||||
|
// 验证info字段 |
||||
|
assertTrue(orderItem.getInfo().isJsonPrimitive()); |
||||
|
assertEquals("平时", orderItem.getInfoAsString()); |
||||
|
|
||||
|
// 对于非年月卡订单,必须传递v_code进行核销 |
||||
|
assertEquals("250910170565", orderItem.getVerificationCode()); |
||||
|
|
||||
|
System.out.println("非年月卡订单测试通过: " + orderItem.getOrder_no()); |
||||
|
|
||||
|
} catch (Exception e) { |
||||
|
e.printStackTrace(); |
||||
|
System.out.println("非年月卡订单测试失败: " + e.getMessage()); |
||||
|
} |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue