1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| @MockBean private RoutingHealthRepository rhRepo; @Test public void HealthTunnelDuringLockTime() { String outChannel = "UBOT"; String reqTime = "2023-11-24T16:30:48.183"; String lastTimeWasLock = "2023-11-24T16:25:48.183"; String healthFlag = "Y"; MockDBObject(outChannel,lastTimeWasLock,healthFlag); boolean isPass = routingHealthService.getRoutingHealthByOutChannel(outChannel,reqTime); Assert.assertFalse(isPass); System.out.println("鎖定狀態下,健康度分流已開啟,交易時間30分鐘內 block success!"); } @Test public void HealthTunnelOverLockTime() { String outChannel = "UBOT"; String reqTime = "2023-11-24T16:56:48.183"; String lastTimeWasLock = "2023-11-24T16:25:48.183"; String healthFlag = "Y"; MockDBObject(outChannel,lastTimeWasLock,healthFlag); boolean isPass = routingHealthService.getRoutingHealthByOutChannel(outChannel,reqTime); Assert.assertTrue(isPass); System.out.println("鎖定狀態下,健康度分流已開啟,交易時間超過30分鐘 pass success!"); } @Test public void HealthTunnelClosed() { String outChannel = "UBOT"; String reqTime = "2023-11-24T16:30:48.183"; String lastTimeWasLock = "2023-11-24T16:25:48.183"; String healthFlag = "N"; MockDBObject(outChannel,lastTimeWasLock,healthFlag); boolean isPass = routingHealthService.getRoutingHealthByOutChannel(outChannel,reqTime); Assert.assertTrue(isPass); System.out.println("鎖定狀態下,健康度分流已關閉,交易時間30分鐘內 pass success!"); }
@Test public void HealthTunnelUBTestBefore() { String outChannel = "UBOT"; String reqTime = "2024-03-15T14:00:48.183"; String lastTimeWasLock = "2024-03-18T16:00:48.183"; String healthFlag = "Y"; MockDBObjectUBTest(outChannel,lastTimeWasLock,healthFlag); boolean isPass = routingHealthService.getRoutingHealthByOutChannel(outChannel,reqTime); Assert.assertTrue(isPass); System.out.println("鎖定狀態下,健康度分流已啟用,交易時間早於鎖定時間 pass success!"); }
@Test public void HealthTunnelUBTestAfter() { String outChannel = "UBOT"; String reqTime = "2024-03-18T17:00:48.183"; String lastTimeWasLock = "2024-03-18T16:00:48.183"; String healthFlag = "Y"; MockDBObjectUBTest(outChannel,lastTimeWasLock,healthFlag); boolean isPass = routingHealthService.getRoutingHealthByOutChannel(outChannel,reqTime); Assert.assertTrue(isPass); System.out.println("鎖定狀態下,健康度分流已啟用,交易時間晚於鎖定時間30分鐘後 pass success!"); }
@Test public void HealthTunnelUBTestDuring() { String outChannel = "UBOT"; String reqTime = "2024-03-18T16:00:49.183"; String lastTimeWasLock = "2024-03-18T16:00:48.183"; String healthFlag = "Y"; MockDBObjectUBTest(outChannel,lastTimeWasLock,healthFlag); boolean isPass = routingHealthService.getRoutingHealthByOutChannel(outChannel,reqTime); Assert.assertFalse(isPass); System.out.println("鎖定狀態下,健康度分流已啟用,交易時間於鎖定時間30分鐘內 ban success!"); }
public void MockDBObjectUBTest(String outChannel,String lastTimeWasLock,String healthFlag) { RoutingHealth rh = new RoutingHealth(); rh.setRhType(outChannel); rh.setRhIsActive("N"); rh.setRhLockTime(LocalDateTime.parse(lastTimeWasLock)); Mockito.when(coreFacade.getSystemSetting(SSCode.LOCK_MINUTES)).thenReturn("30"); Mockito.when(coreFacade.getSystemSetting(SSCode.ROUTING_HEALTH_FLAG)).thenReturn(healthFlag); Mockito.when(rhRepo.getRoutingHealthByRhTypeAndRhLockTimeBetween(outChannel)).thenReturn(rh); }
public void MockDBObject(String outChannel,String lastTimeWasLock,String healthFlag) { RoutingHealth rh = new RoutingHealth(); rh.setRhType(outChannel); rh.setRhIsActive("N"); rh.setRhLockTime(LocalDateTime.parse(lastTimeWasLock)); Mockito.when(coreFacade.getSystemSetting(SSCode.LOCK_MINUTES)).thenReturn("30"); Mockito.when(coreFacade.getSystemSetting(SSCode.ROUTING_HEALTH_FLAG)).thenReturn(healthFlag); Mockito.when(rhRepo.getRoutingHealthByRhTypeAndRhLockTimeBetween(outChannel)).thenReturn(rh); } @Test public void testRefundPoint() throws Exception { MainService mainService = MockConfig();
HashMap reqJson = new HashMap(); reqJson.put("pmMemberNo","GID76683851296887"); reqJson.put("pmPointAmt","50000"); reqJson.put("pointId","ResIsFatF2-4"); reqJson.put("pmSellerName","testMerchantLaLaLa"); reqJson.put("allowInsufficient","Y"); reqJson.put("merchantNo","0904000001"); reqJson.put("refundId","ResIsChubby01"); reqJson.put("mchId","ACpay");
Fundmentals fundmentals = Fundmentals.builder() .tradeType(TradeType.CANCEL) .apiKey("xyz123") .accessUrl("https://icash-apim.icashsys.com.tw/Point-UAT/v1/RefundPoint").build(); String respJSON = mainService.mainprocedure(reqJson,fundmentals); HashMap<String,String> result = objectMapper.readValue(respJSON, HashMap.class); Assert.assertEquals("3003",result.get("resultCode")); }
public MainService MockConfig() throws Exception { MainService mainService = new MainService(); MainService mainService_mock = Mockito.spy(mainService); Mockito.doReturn(null).when(mainService_mock).SendRequest(Mockito.anyObject(),Mockito.anyString()); Mockito.doNothing().when(mainService_mock).validate(Mockito.anyObject()); ReflectionTestUtils.setField(mainService_mock, "queryDomain", "https://icash-apim.icashsys.com.tw/Point-UAT/v1/QueryPoint"); ReflectionTestUtils.setField(mainService_mock, "apiKey", "xyz123"); return mainService_mock; }
|