|
| 1 | +package com.github.binarywang.wxpay.bean.applyment; |
| 2 | + |
| 3 | +import java.util.Arrays; |
| 4 | + |
| 5 | +import org.testng.annotations.Test; |
| 6 | + |
| 7 | +import com.google.gson.Gson; |
| 8 | +import com.google.gson.GsonBuilder; |
| 9 | + |
| 10 | +import static org.testng.Assert.assertEquals; |
| 11 | +import static org.testng.Assert.assertTrue; |
| 12 | + |
| 13 | +public class WxPayApplyment4SubCreateRequestTest { |
| 14 | + |
| 15 | + @Test |
| 16 | + public void testMicroBizInfoSerialization() { |
| 17 | + // 1. Test MicroStoreInfo |
| 18 | + WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo.MicroStoreInfo storeInfo = |
| 19 | + WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo.MicroStoreInfo.builder() |
| 20 | + .microName("门店名称") |
| 21 | + .microAddressCode("440305") |
| 22 | + .microAddress("详细地址") |
| 23 | + .storeEntrancePic("media_id_1") |
| 24 | + .microIndoorCopy("media_id_2") |
| 25 | + .storeLongitude("113.941046") |
| 26 | + .storeLatitude("22.546154") |
| 27 | + .build(); |
| 28 | + |
| 29 | + // 2. Test MicroMobileInfo |
| 30 | + WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo.MicroMobileInfo mobileInfo = |
| 31 | + WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo.MicroMobileInfo.builder() |
| 32 | + .microMobileName("流动经营名称") |
| 33 | + .microMobileCity("440305") |
| 34 | + .microMobileAddress("无") |
| 35 | + .microMobilePics(Arrays.asList("media_id_3", "media_id_4")) |
| 36 | + .build(); |
| 37 | + |
| 38 | + // 3. Test MicroOnlineInfo |
| 39 | + WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo.MicroOnlineInfo onlineInfo = |
| 40 | + WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo.MicroOnlineInfo.builder() |
| 41 | + .microOnlineStore("线上店铺名称") |
| 42 | + .microEcName("电商平台名称") |
| 43 | + .microQrcode("media_id_5") |
| 44 | + .microLink("https://www.example.com") |
| 45 | + .build(); |
| 46 | + |
| 47 | + WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo microBizInfo = |
| 48 | + WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo.builder() |
| 49 | + .microStoreInfo(storeInfo) |
| 50 | + .microMobileInfo(mobileInfo) |
| 51 | + .microOnlineInfo(onlineInfo) |
| 52 | + .build(); |
| 53 | + |
| 54 | + Gson gson = new GsonBuilder().create(); |
| 55 | + String json = gson.toJson(microBizInfo); |
| 56 | + |
| 57 | + // Verify MicroStoreInfo serialization |
| 58 | + assertTrue(json.contains("\"micro_name\":\"门店名称\"")); |
| 59 | + assertTrue(json.contains("\"micro_address_code\":\"440305\"")); |
| 60 | + assertTrue(json.contains("\"micro_address\":\"详细地址\"")); |
| 61 | + assertTrue(json.contains("\"store_entrance_pic\":\"media_id_1\"")); |
| 62 | + assertTrue(json.contains("\"micro_indoor_copy\":\"media_id_2\"")); |
| 63 | + assertTrue(json.contains("\"store_longitude\":\"113.941046\"")); |
| 64 | + assertTrue(json.contains("\"store_latitude\":\"22.546154\"")); |
| 65 | + |
| 66 | + // Verify MicroMobileInfo serialization |
| 67 | + assertTrue(json.contains("\"micro_mobile_name\":\"流动经营名称\"")); |
| 68 | + assertTrue(json.contains("\"micro_mobile_city\":\"440305\"")); |
| 69 | + assertTrue(json.contains("\"micro_mobile_address\":\"无\"")); |
| 70 | + assertTrue(json.contains("\"micro_mobile_pics\":[\"media_id_3\",\"media_id_4\"]")); |
| 71 | + |
| 72 | + // Verify MicroOnlineInfo serialization |
| 73 | + assertTrue(json.contains("\"micro_online_store\":\"线上店铺名称\"")); |
| 74 | + assertTrue(json.contains("\"micro_ec_name\":\"电商平台名称\"")); |
| 75 | + assertTrue(json.contains("\"micro_qrcode\":\"media_id_5\"")); |
| 76 | + assertTrue(json.contains("\"micro_link\":\"https://www.example.com\"")); |
| 77 | + |
| 78 | + // Verify deserialization |
| 79 | + WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo deserialized = |
| 80 | + gson.fromJson(json, WxPayApplyment4SubCreateRequest.SubjectInfo.MicroBizInfo.class); |
| 81 | + |
| 82 | + // Verify MicroStoreInfo deserialization |
| 83 | + assertEquals(deserialized.getMicroStoreInfo().getMicroName(), "门店名称"); |
| 84 | + assertEquals(deserialized.getMicroStoreInfo().getMicroAddressCode(), "440305"); |
| 85 | + assertEquals(deserialized.getMicroStoreInfo().getMicroAddress(), "详细地址"); |
| 86 | + assertEquals(deserialized.getMicroStoreInfo().getStoreEntrancePic(), "media_id_1"); |
| 87 | + assertEquals(deserialized.getMicroStoreInfo().getMicroIndoorCopy(), "media_id_2"); |
| 88 | + assertEquals(deserialized.getMicroStoreInfo().getStoreLongitude(), "113.941046"); |
| 89 | + assertEquals(deserialized.getMicroStoreInfo().getStoreLatitude(), "22.546154"); |
| 90 | + |
| 91 | + // Verify MicroMobileInfo deserialization |
| 92 | + assertEquals(deserialized.getMicroMobileInfo().getMicroMobileName(), "流动经营名称"); |
| 93 | + assertEquals(deserialized.getMicroMobileInfo().getMicroMobileCity(), "440305"); |
| 94 | + assertEquals(deserialized.getMicroMobileInfo().getMicroMobileAddress(), "无"); |
| 95 | + assertEquals(deserialized.getMicroMobileInfo().getMicroMobilePics().size(), 2); |
| 96 | + assertEquals(deserialized.getMicroMobileInfo().getMicroMobilePics(), Arrays.asList("media_id_3", "media_id_4")); |
| 97 | + |
| 98 | + // Verify MicroOnlineInfo deserialization |
| 99 | + assertEquals(deserialized.getMicroOnlineInfo().getMicroOnlineStore(), "线上店铺名称"); |
| 100 | + assertEquals(deserialized.getMicroOnlineInfo().getMicroEcName(), "电商平台名称"); |
| 101 | + assertEquals(deserialized.getMicroOnlineInfo().getMicroQrcode(), "media_id_5"); |
| 102 | + assertEquals(deserialized.getMicroOnlineInfo().getMicroLink(), "https://www.example.com"); |
| 103 | + } |
| 104 | +} |
0 commit comments